blob: 19ca0b519a1dfd230ee15f61879540bdf5f62ae6 [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;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400548 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400549 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550};
551
552/*
553 * START OF "GENERIC" ENCODE ROUTINES.
554 * These may look a little ugly since they are imported from a "generic"
555 * set of XDR encode/decode routines which are intended to be shared by
556 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
557 *
558 * If the pain of reading these is too great, it should be a straightforward
559 * task to translate them into Linux-specific versions which are more
560 * consistent with the style used in NFSv2/v3...
561 */
562#define WRITE32(n) *p++ = htonl(n)
563#define WRITE64(n) do { \
564 *p++ = htonl((uint32_t)((n) >> 32)); \
565 *p++ = htonl((uint32_t)(n)); \
566} while (0)
567#define WRITEMEM(ptr,nbytes) do { \
568 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
569} while (0)
570
571#define RESERVE_SPACE(nbytes) do { \
572 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 BUG_ON(!p); \
574} while (0)
575
576static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
577{
Al Viro8687b632006-10-19 23:28:48 -0700578 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 p = xdr_reserve_space(xdr, 4 + len);
581 BUG_ON(p == NULL);
582 xdr_encode_opaque(p, str, len);
583}
584
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400585static void encode_compound_hdr(struct xdr_stream *xdr,
586 struct rpc_rqst *req,
587 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
Al Viro8687b632006-10-19 23:28:48 -0700589 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400590 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
591
592 /* initialize running count of expected bytes in reply.
593 * NOTE: the replied tag SHOULD be the same is the one sent,
594 * but this is not required as a MUST for the server to do so. */
595 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
598 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
599 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
600 WRITE32(hdr->taglen);
601 WRITEMEM(hdr->tag, hdr->taglen);
Benny Halevy66cc0422009-04-01 09:22:10 -0400602 WRITE32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500603 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500605}
606
607static void encode_nops(struct compound_hdr *hdr)
608{
609 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610}
611
612static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
613{
Al Viro8687b632006-10-19 23:28:48 -0700614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
617 BUG_ON(p == NULL);
618 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
619}
620
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500621static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
623 char owner_name[IDMAP_NAMESZ];
624 char owner_group[IDMAP_NAMESZ];
625 int owner_namelen = 0;
626 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700627 __be32 *p;
628 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 int len;
630 uint32_t bmval0 = 0;
631 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 /*
634 * We reserve enough space to write the entire attribute buffer at once.
635 * In the worst-case, this would be
636 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
637 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000638 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 */
640 len = 16;
641
642 /* Sigh */
643 if (iap->ia_valid & ATTR_SIZE)
644 len += 8;
645 if (iap->ia_valid & ATTR_MODE)
646 len += 4;
647 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400648 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400650 dprintk("nfs: couldn't resolve uid %d to string\n",
651 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 /* XXX */
653 strcpy(owner_name, "nobody");
654 owner_namelen = sizeof("nobody") - 1;
655 /* goto out; */
656 }
657 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
658 }
659 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400660 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400662 dprintk("nfs: couldn't resolve gid %d to string\n",
663 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 strcpy(owner_group, "nobody");
665 owner_grouplen = sizeof("nobody") - 1;
666 /* goto out; */
667 }
668 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
669 }
670 if (iap->ia_valid & ATTR_ATIME_SET)
671 len += 16;
672 else if (iap->ia_valid & ATTR_ATIME)
673 len += 4;
674 if (iap->ia_valid & ATTR_MTIME_SET)
675 len += 16;
676 else if (iap->ia_valid & ATTR_MTIME)
677 len += 4;
678 RESERVE_SPACE(len);
679
680 /*
681 * We write the bitmap length now, but leave the bitmap and the attribute
682 * buffer length to be backfilled at the end of this routine.
683 */
684 WRITE32(2);
685 q = p;
686 p += 3;
687
688 if (iap->ia_valid & ATTR_SIZE) {
689 bmval0 |= FATTR4_WORD0_SIZE;
690 WRITE64(iap->ia_size);
691 }
692 if (iap->ia_valid & ATTR_MODE) {
693 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100694 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696 if (iap->ia_valid & ATTR_UID) {
697 bmval1 |= FATTR4_WORD1_OWNER;
698 WRITE32(owner_namelen);
699 WRITEMEM(owner_name, owner_namelen);
700 }
701 if (iap->ia_valid & ATTR_GID) {
702 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
703 WRITE32(owner_grouplen);
704 WRITEMEM(owner_group, owner_grouplen);
705 }
706 if (iap->ia_valid & ATTR_ATIME_SET) {
707 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
708 WRITE32(NFS4_SET_TO_CLIENT_TIME);
709 WRITE32(0);
710 WRITE32(iap->ia_mtime.tv_sec);
711 WRITE32(iap->ia_mtime.tv_nsec);
712 }
713 else if (iap->ia_valid & ATTR_ATIME) {
714 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
715 WRITE32(NFS4_SET_TO_SERVER_TIME);
716 }
717 if (iap->ia_valid & ATTR_MTIME_SET) {
718 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
719 WRITE32(NFS4_SET_TO_CLIENT_TIME);
720 WRITE32(0);
721 WRITE32(iap->ia_mtime.tv_sec);
722 WRITE32(iap->ia_mtime.tv_nsec);
723 }
724 else if (iap->ia_valid & ATTR_MTIME) {
725 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
726 WRITE32(NFS4_SET_TO_SERVER_TIME);
727 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 /*
730 * Now we backfill the bitmap and the attribute buffer length.
731 */
732 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400733 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 len, ((char *)p - (char *)q) + 4);
735 BUG();
736 }
737 len = (char *)p - (char *)q - 12;
738 *q++ = htonl(bmval0);
739 *q++ = htonl(bmval1);
740 *q++ = htonl(len);
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743}
744
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500745static void encode_access(struct xdr_stream *xdr, u32 access, 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
749 RESERVE_SPACE(8);
750 WRITE32(OP_ACCESS);
751 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500752 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400753 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500756static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Al Viro8687b632006-10-19 23:28:48 -0700758 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400760 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700762 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400763 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500764 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400765 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500768static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
Al Viro8687b632006-10-19 23:28:48 -0700770 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500771
Andy Adamson05d564f2008-12-23 16:06:15 -0500772 RESERVE_SPACE(16);
773 WRITE32(OP_COMMIT);
774 WRITE64(args->offset);
775 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500776 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400777 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500780static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Al Viro8687b632006-10-19 23:28:48 -0700782 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 RESERVE_SPACE(8);
785 WRITE32(OP_CREATE);
786 WRITE32(create->ftype);
787
788 switch (create->ftype) {
789 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400790 RESERVE_SPACE(4);
791 WRITE32(create->u.symlink.len);
792 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 break;
794
795 case NF4BLK: case NF4CHR:
796 RESERVE_SPACE(8);
797 WRITE32(create->u.device.specdata1);
798 WRITE32(create->u.device.specdata2);
799 break;
800
801 default:
802 break;
803 }
804
805 RESERVE_SPACE(4 + create->name->len);
806 WRITE32(create->name->len);
807 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500808 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400809 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500811 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
813
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500814static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Andy Adamson05d564f2008-12-23 16:06:15 -0500816 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Andy Adamson05d564f2008-12-23 16:06:15 -0500818 RESERVE_SPACE(12);
819 WRITE32(OP_GETATTR);
820 WRITE32(1);
821 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500822 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400823 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500826static 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 -0700827{
Andy Adamson05d564f2008-12-23 16:06:15 -0500828 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Andy Adamson05d564f2008-12-23 16:06:15 -0500830 RESERVE_SPACE(16);
831 WRITE32(OP_GETATTR);
832 WRITE32(2);
833 WRITE32(bm0);
834 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500835 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400836 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837}
838
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500839static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500841 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
842 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500845static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500847 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
848 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500851static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400852{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500853 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
854 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400855}
856
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500857static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Al Viro8687b632006-10-19 23:28:48 -0700859 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 RESERVE_SPACE(4);
862 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500863 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400864 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500867static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Al Viro8687b632006-10-19 23:28:48 -0700869 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 RESERVE_SPACE(8 + name->len);
872 WRITE32(OP_LINK);
873 WRITE32(name->len);
874 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500875 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400876 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877}
878
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100879static inline int nfs4_lock_type(struct file_lock *fl, int block)
880{
881 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
882 return block ? NFS4_READW_LT : NFS4_READ_LT;
883 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
884}
885
886static inline uint64_t nfs4_lock_length(struct file_lock *fl)
887{
888 if (fl->fl_end == OFFSET_MAX)
889 return ~(uint64_t)0;
890 return fl->fl_end - fl->fl_start + 1;
891}
892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893/*
894 * opcode,type,reclaim,offset,length,new_lock_owner = 32
895 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
896 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500897static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
Al Viro8687b632006-10-19 23:28:48 -0700899 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 RESERVE_SPACE(32);
902 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100903 WRITE32(nfs4_lock_type(args->fl, args->block));
904 WRITE32(args->reclaim);
905 WRITE64(args->fl->fl_start);
906 WRITE64(nfs4_lock_length(args->fl));
907 WRITE32(args->new_lock_owner);
908 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400909 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100910 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400911 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100912 WRITE32(args->lock_seqid->sequence->counter);
913 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400914 WRITE32(16);
915 WRITEMEM("lock id:", 8);
916 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400919 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
920 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100921 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
Andy Adamsond0179312008-12-23 16:06:17 -0500923 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400924 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925}
926
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500927static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
Al Viro8687b632006-10-19 23:28:48 -0700929 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400931 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100933 WRITE32(nfs4_lock_type(args->fl, 0));
934 WRITE64(args->fl->fl_start);
935 WRITE64(nfs4_lock_length(args->fl));
936 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400937 WRITE32(16);
938 WRITEMEM("lock id:", 8);
939 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -0500940 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400941 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500944static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945{
Al Viro8687b632006-10-19 23:28:48 -0700946 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400948 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100950 WRITE32(nfs4_lock_type(args->fl, 0));
951 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400952 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100953 WRITE64(args->fl->fl_start);
954 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -0500955 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400956 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957}
958
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500959static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
961 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700962 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 RESERVE_SPACE(8 + len);
965 WRITE32(OP_LOOKUP);
966 WRITE32(len);
967 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -0500968 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400969 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500972static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Al Viro8687b632006-10-19 23:28:48 -0700974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500977 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500978 case FMODE_READ:
979 WRITE32(NFS4_SHARE_ACCESS_READ);
980 break;
981 case FMODE_WRITE:
982 WRITE32(NFS4_SHARE_ACCESS_WRITE);
983 break;
984 case FMODE_READ|FMODE_WRITE:
985 WRITE32(NFS4_SHARE_ACCESS_BOTH);
986 break;
987 default:
988 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
990 WRITE32(0); /* for linux, share_deny = 0 always */
991}
992
993static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
994{
Al Viro8687b632006-10-19 23:28:48 -0700995 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 /*
997 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
998 * owner 4 = 32
999 */
1000 RESERVE_SPACE(8);
1001 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001002 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001003 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001004 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001006 WRITE32(16);
1007 WRITEMEM("open id:", 8);
1008 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009}
1010
1011static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1012{
Al Viro8687b632006-10-19 23:28:48 -07001013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 RESERVE_SPACE(4);
1016 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001017 case 0:
1018 WRITE32(NFS4_CREATE_UNCHECKED);
1019 encode_attrs(xdr, arg->u.attrs, arg->server);
1020 break;
1021 default:
1022 WRITE32(NFS4_CREATE_EXCLUSIVE);
1023 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 }
1025}
1026
1027static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1028{
Al Viro8687b632006-10-19 23:28:48 -07001029 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 RESERVE_SPACE(4);
1032 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001033 case 0:
1034 WRITE32(NFS4_OPEN_NOCREATE);
1035 break;
1036 default:
1037 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1038 WRITE32(NFS4_OPEN_CREATE);
1039 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
1041}
1042
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001043static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
Al Viro8687b632006-10-19 23:28:48 -07001045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 RESERVE_SPACE(4);
1048 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001049 case 0:
1050 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1051 break;
1052 case FMODE_READ:
1053 WRITE32(NFS4_OPEN_DELEGATE_READ);
1054 break;
1055 case FMODE_WRITE|FMODE_READ:
1056 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1057 break;
1058 default:
1059 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061}
1062
1063static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1064{
Al Viro8687b632006-10-19 23:28:48 -07001065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
1067 RESERVE_SPACE(4);
1068 WRITE32(NFS4_OPEN_CLAIM_NULL);
1069 encode_string(xdr, name->len, name->name);
1070}
1071
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001072static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
Al Viro8687b632006-10-19 23:28:48 -07001074 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 RESERVE_SPACE(4);
1077 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1078 encode_delegation_type(xdr, type);
1079}
1080
1081static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1082{
Al Viro8687b632006-10-19 23:28:48 -07001083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001085 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001087 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 encode_string(xdr, name->len, name->name);
1089}
1090
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001091static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
1093 encode_openhdr(xdr, arg);
1094 encode_opentype(xdr, arg);
1095 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001096 case NFS4_OPEN_CLAIM_NULL:
1097 encode_claim_null(xdr, arg->name);
1098 break;
1099 case NFS4_OPEN_CLAIM_PREVIOUS:
1100 encode_claim_previous(xdr, arg->u.delegation_type);
1101 break;
1102 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1103 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1104 break;
1105 default:
1106 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 }
Andy Adamsond0179312008-12-23 16:06:17 -05001108 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001109 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001112static 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 -07001113{
Al Viro8687b632006-10-19 23:28:48 -07001114 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001116 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001118 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001119 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001120 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001121 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001124static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Al Viro8687b632006-10-19 23:28:48 -07001126 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001128 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001130 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001131 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001132 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001133 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001134 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001137static void
Andy Adamsond0179312008-12-23 16:06:17 -05001138encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139{
1140 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001141 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 RESERVE_SPACE(8 + len);
1144 WRITE32(OP_PUTFH);
1145 WRITE32(len);
1146 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001147 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001148 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149}
1150
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001151static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152{
Andy Adamson05d564f2008-12-23 16:06:15 -05001153 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001154
Andy Adamson05d564f2008-12-23 16:06:15 -05001155 RESERVE_SPACE(4);
1156 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001157 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001158 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
1161static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1162{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001164 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001166 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 if (ctx->state != NULL) {
1168 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001169 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001171 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001174static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
Al Viro8687b632006-10-19 23:28:48 -07001176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 RESERVE_SPACE(4);
1179 WRITE32(OP_READ);
1180
1181 encode_stateid(xdr, args->context);
1182
1183 RESERVE_SPACE(12);
1184 WRITE64(args->offset);
1185 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001186 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001187 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static 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 -07001191{
Manoj Naik97d312d2005-06-22 17:16:39 +00001192 uint32_t attrs[2] = {
1193 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1194 FATTR4_WORD1_MOUNTED_ON_FILEID,
1195 };
Al Viro8687b632006-10-19 23:28:48 -07001196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001198 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 WRITE32(OP_READDIR);
1200 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001201 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1203 WRITE32(readdir->count);
1204 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001205 /* Switch to mounted_on_fileid if the server supports it */
1206 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1207 attrs[0] &= ~FATTR4_WORD0_FILEID;
1208 else
1209 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1210 WRITE32(attrs[0] & readdir->bitmask[0]);
1211 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001212 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001213 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001214 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1215 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001216 (unsigned long long)readdir->cookie,
1217 ((u32 *)readdir->verifier.data)[0],
1218 ((u32 *)readdir->verifier.data)[1],
1219 attrs[0] & readdir->bitmask[0],
1220 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001223static 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 -07001224{
Al Viro8687b632006-10-19 23:28:48 -07001225 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
1227 RESERVE_SPACE(4);
1228 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001229 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001230 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001233static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234{
Al Viro8687b632006-10-19 23:28:48 -07001235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 RESERVE_SPACE(8 + name->len);
1238 WRITE32(OP_REMOVE);
1239 WRITE32(name->len);
1240 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001241 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001242 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243}
1244
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001245static 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 -07001246{
Al Viro8687b632006-10-19 23:28:48 -07001247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 RESERVE_SPACE(8 + oldname->len);
1250 WRITE32(OP_RENAME);
1251 WRITE32(oldname->len);
1252 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 RESERVE_SPACE(4 + newname->len);
1255 WRITE32(newname->len);
1256 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001257 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001258 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001261static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Al Viro8687b632006-10-19 23:28:48 -07001263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 RESERVE_SPACE(12);
1266 WRITE32(OP_RENEW);
1267 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001268 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001269 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270}
1271
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001272static void
Andy Adamsond0179312008-12-23 16:06:17 -05001273encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001274{
Al Viro8687b632006-10-19 23:28:48 -07001275 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001276
1277 RESERVE_SPACE(4);
1278 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001279 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001280 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001281}
1282
1283static int
Andy Adamsond0179312008-12-23 16:06:17 -05001284encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001285{
Al Viro8687b632006-10-19 23:28:48 -07001286 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001287
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001288 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001289 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001290 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001291 RESERVE_SPACE(2*4);
1292 WRITE32(1);
1293 WRITE32(FATTR4_WORD0_ACL);
1294 if (arg->acl_len % 4)
1295 return -EINVAL;
1296 RESERVE_SPACE(4);
1297 WRITE32(arg->acl_len);
1298 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001299 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001300 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001301 return 0;
1302}
1303
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001304static void
Andy Adamsond0179312008-12-23 16:06:17 -05001305encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
Al Viro8687b632006-10-19 23:28:48 -07001307 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309 RESERVE_SPACE(4);
1310 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001311 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001312 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313}
1314
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001315static 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 -07001316{
Al Viro8687b632006-10-19 23:28:48 -07001317 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001318
Andy Adamson05d564f2008-12-23 16:06:15 -05001319 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1320 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001321 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001322 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001323 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001327static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001331 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001333 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1336 RESERVE_SPACE(4);
1337 WRITE32(setclientid->sc_prog);
1338 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1339 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1340 RESERVE_SPACE(4);
1341 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001342 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001343 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001346static 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 -07001347{
Andy Adamson05d564f2008-12-23 16:06:15 -05001348 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Andy Adamson05d564f2008-12-23 16:06:15 -05001350 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1351 WRITE32(OP_SETCLIENTID_CONFIRM);
1352 WRITE64(client_state->cl_clientid);
1353 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001354 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001355 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001358static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Al Viro8687b632006-10-19 23:28:48 -07001360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362 RESERVE_SPACE(4);
1363 WRITE32(OP_WRITE);
1364
1365 encode_stateid(xdr, args->context);
1366
1367 RESERVE_SPACE(16);
1368 WRITE64(args->offset);
1369 WRITE32(args->stable);
1370 WRITE32(args->count);
1371
1372 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001373 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001374 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375}
1376
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001377static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Al Viro8687b632006-10-19 23:28:48 -07001379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001381 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001384 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001385 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001386 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388/*
1389 * END OF "GENERIC" ENCODE ROUTINES.
1390 */
1391
Benny Halevy66cc0422009-04-01 09:22:10 -04001392static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1393{
1394#if defined(CONFIG_NFS_V4_1)
1395 if (args->sa_session)
1396 return args->sa_session->clp->cl_minorversion;
1397#endif /* CONFIG_NFS_V4_1 */
1398 return 0;
1399}
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401/*
1402 * Encode an ACCESS request
1403 */
Al Viro8687b632006-10-19 23:28:48 -07001404static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405{
1406 struct xdr_stream xdr;
1407 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001408 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001412 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001413 encode_putfh(&xdr, args->fh, &hdr);
1414 encode_access(&xdr, args->access, &hdr);
1415 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001416 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001417 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418}
1419
1420/*
1421 * Encode LOOKUP request
1422 */
Al Viro8687b632006-10-19 23:28:48 -07001423static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
1425 struct xdr_stream xdr;
1426 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001431 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001432 encode_putfh(&xdr, args->dir_fh, &hdr);
1433 encode_lookup(&xdr, args->name, &hdr);
1434 encode_getfh(&xdr, &hdr);
1435 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001436 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001437 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
1440/*
1441 * Encode LOOKUP_ROOT request
1442 */
Al Viro8687b632006-10-19 23:28:48 -07001443static 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 -07001444{
1445 struct xdr_stream xdr;
1446 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001447 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001451 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001452 encode_putrootfh(&xdr, &hdr);
1453 encode_getfh(&xdr, &hdr);
1454 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001455 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001456 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
1459/*
1460 * Encode REMOVE request
1461 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001462static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
1464 struct xdr_stream xdr;
1465 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001466 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
1469 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001470 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001471 encode_putfh(&xdr, args->fh, &hdr);
1472 encode_remove(&xdr, &args->name, &hdr);
1473 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001474 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001475 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476}
1477
1478/*
1479 * Encode RENAME request
1480 */
Al Viro8687b632006-10-19 23:28:48 -07001481static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
1483 struct xdr_stream xdr;
1484 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001485 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001489 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001490 encode_putfh(&xdr, args->old_dir, &hdr);
1491 encode_savefh(&xdr, &hdr);
1492 encode_putfh(&xdr, args->new_dir, &hdr);
1493 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1494 encode_getfattr(&xdr, args->bitmask, &hdr);
1495 encode_restorefh(&xdr, &hdr);
1496 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001497 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001498 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499}
1500
1501/*
1502 * Encode LINK request
1503 */
Al Viro8687b632006-10-19 23:28:48 -07001504static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
1506 struct xdr_stream xdr;
1507 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001508 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
1511 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001512 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001513 encode_putfh(&xdr, args->fh, &hdr);
1514 encode_savefh(&xdr, &hdr);
1515 encode_putfh(&xdr, args->dir_fh, &hdr);
1516 encode_link(&xdr, args->name, &hdr);
1517 encode_getfattr(&xdr, args->bitmask, &hdr);
1518 encode_restorefh(&xdr, &hdr);
1519 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001520 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522}
1523
1524/*
1525 * Encode CREATE request
1526 */
Al Viro8687b632006-10-19 23:28:48 -07001527static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
1529 struct xdr_stream xdr;
1530 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001531 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
1534 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001535 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536 encode_putfh(&xdr, args->dir_fh, &hdr);
1537 encode_savefh(&xdr, &hdr);
1538 encode_create(&xdr, args, &hdr);
1539 encode_getfh(&xdr, &hdr);
1540 encode_getfattr(&xdr, args->bitmask, &hdr);
1541 encode_restorefh(&xdr, &hdr);
1542 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001543 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001544 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
1547/*
1548 * Encode SYMLINK request
1549 */
Al Viro8687b632006-10-19 23:28:48 -07001550static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
1552 return nfs4_xdr_enc_create(req, p, args);
1553}
1554
1555/*
1556 * Encode GETATTR request
1557 */
Al Viro8687b632006-10-19 23:28:48 -07001558static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
1560 struct xdr_stream xdr;
1561 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001562 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001566 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001567 encode_putfh(&xdr, args->fh, &hdr);
1568 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001569 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001570 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
1573/*
1574 * Encode a CLOSE request
1575 */
Al Viro8687b632006-10-19 23:28:48 -07001576static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577{
Andy Adamson05d564f2008-12-23 16:06:15 -05001578 struct xdr_stream xdr;
1579 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001580 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001581 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Andy Adamson05d564f2008-12-23 16:06:15 -05001583 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001584 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001585 encode_putfh(&xdr, args->fh, &hdr);
1586 encode_close(&xdr, args, &hdr);
1587 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001588 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001589 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
1592/*
1593 * Encode an OPEN request
1594 */
Al Viro8687b632006-10-19 23:28:48 -07001595static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596{
1597 struct xdr_stream xdr;
1598 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001599 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001603 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001604 encode_putfh(&xdr, args->fh, &hdr);
1605 encode_savefh(&xdr, &hdr);
1606 encode_open(&xdr, args, &hdr);
1607 encode_getfh(&xdr, &hdr);
1608 encode_getfattr(&xdr, args->bitmask, &hdr);
1609 encode_restorefh(&xdr, &hdr);
1610 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001611 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001612 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613}
1614
1615/*
1616 * Encode an OPEN_CONFIRM request
1617 */
Al Viro8687b632006-10-19 23:28:48 -07001618static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
1620 struct xdr_stream xdr;
1621 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001622 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001626 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627 encode_putfh(&xdr, args->fh, &hdr);
1628 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001629 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001630 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
1633/*
1634 * Encode an OPEN request with no attributes.
1635 */
Al Viro8687b632006-10-19 23:28:48 -07001636static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
1638 struct xdr_stream xdr;
1639 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001640 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
1643 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001644 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645 encode_putfh(&xdr, args->fh, &hdr);
1646 encode_open(&xdr, args, &hdr);
1647 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001648 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001649 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
1652/*
1653 * Encode an OPEN_DOWNGRADE request
1654 */
Al Viro8687b632006-10-19 23:28:48 -07001655static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
1657 struct xdr_stream xdr;
1658 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001659 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
1662 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001663 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001664 encode_putfh(&xdr, args->fh, &hdr);
1665 encode_open_downgrade(&xdr, args, &hdr);
1666 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001667 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669}
1670
1671/*
1672 * Encode a LOCK request
1673 */
Al Viro8687b632006-10-19 23:28:48 -07001674static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
1676 struct xdr_stream xdr;
1677 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001678 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
1681 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001682 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001683 encode_putfh(&xdr, args->fh, &hdr);
1684 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001685 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001686 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687}
1688
1689/*
1690 * Encode a LOCKT request
1691 */
Al Viro8687b632006-10-19 23:28:48 -07001692static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
1694 struct xdr_stream xdr;
1695 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001696 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
1699 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001700 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701 encode_putfh(&xdr, args->fh, &hdr);
1702 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001703 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001704 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
1707/*
1708 * Encode a LOCKU request
1709 */
Al Viro8687b632006-10-19 23:28:48 -07001710static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711{
1712 struct xdr_stream xdr;
1713 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001714 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
1717 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001718 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001719 encode_putfh(&xdr, args->fh, &hdr);
1720 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001721 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001722 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723}
1724
1725/*
1726 * Encode a READLINK request
1727 */
Al Viro8687b632006-10-19 23:28:48 -07001728static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
1730 struct xdr_stream xdr;
1731 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001732 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001736 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001737 encode_putfh(&xdr, args->fh, &hdr);
1738 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001739
Benny Halevy28f56692009-04-01 09:22:09 -04001740 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001741 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05001742 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001743 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744}
1745
1746/*
1747 * Encode a READDIR request
1748 */
Al Viro8687b632006-10-19 23:28:48 -07001749static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750{
1751 struct xdr_stream xdr;
1752 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001753 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001757 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001758 encode_putfh(&xdr, args->fh, &hdr);
1759 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001760
Benny Halevy28f56692009-04-01 09:22:09 -04001761 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001762 args->pgbase, args->count);
1763 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04001764 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001765 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001766 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001767 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
1770/*
1771 * Encode a READ request
1772 */
Al Viro8687b632006-10-19 23:28:48 -07001773static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 struct xdr_stream xdr;
1776 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001777 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
1780 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001781 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001782 encode_putfh(&xdr, args->fh, &hdr);
1783 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Benny Halevy28f56692009-04-01 09:22:09 -04001785 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001787 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05001788 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001789 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790}
1791
1792/*
1793 * Encode an SETATTR request
1794 */
Al Viro8687b632006-10-19 23:28:48 -07001795static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796{
Andy Adamson05d564f2008-12-23 16:06:15 -05001797 struct xdr_stream xdr;
1798 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001799 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001800 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Andy Adamson05d564f2008-12-23 16:06:15 -05001802 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001803 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001804 encode_putfh(&xdr, args->fh, &hdr);
1805 encode_setattr(&xdr, args, args->server, &hdr);
1806 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001807 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001808 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809}
1810
1811/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001812 * Encode a GETACL request
1813 */
1814static int
Al Viro8687b632006-10-19 23:28:48 -07001815nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001816 struct nfs_getaclargs *args)
1817{
1818 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001819 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001820 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00001821 };
Benny Halevy28f56692009-04-01 09:22:09 -04001822 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001823
1824 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001825 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001826 encode_putfh(&xdr, args->fh, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04001827 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001828 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1829
Benny Halevy28f56692009-04-01 09:22:09 -04001830 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001831 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001832 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001833 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001834}
1835
1836/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 * Encode a WRITE request
1838 */
Al Viro8687b632006-10-19 23:28:48 -07001839static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
1841 struct xdr_stream xdr;
1842 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001843 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001847 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001848 encode_putfh(&xdr, args->fh, &hdr);
1849 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001850 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001851 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001852 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001853 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854}
1855
1856/*
1857 * a COMMIT request
1858 */
Al Viro8687b632006-10-19 23:28:48 -07001859static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860{
1861 struct xdr_stream xdr;
1862 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001863 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
1866 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001867 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001868 encode_putfh(&xdr, args->fh, &hdr);
1869 encode_commit(&xdr, args, &hdr);
1870 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001871 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001872 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873}
1874
1875/*
1876 * FSINFO request
1877 */
Al Viro8687b632006-10-19 23:28:48 -07001878static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879{
1880 struct xdr_stream xdr;
1881 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001882 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001886 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001887 encode_putfh(&xdr, args->fh, &hdr);
1888 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001889 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001890 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891}
1892
1893/*
1894 * a PATHCONF request
1895 */
Al Viro8687b632006-10-19 23:28:48 -07001896static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 struct xdr_stream xdr;
1899 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001900 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
1903 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001904 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001905 encode_putfh(&xdr, args->fh, &hdr);
1906 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1907 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001908 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001909 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910}
1911
1912/*
1913 * a STATFS request
1914 */
Al Viro8687b632006-10-19 23:28:48 -07001915static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 struct xdr_stream xdr;
1918 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001919 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001923 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001924 encode_putfh(&xdr, args->fh, &hdr);
1925 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1926 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001927 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001928 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929}
1930
1931/*
1932 * GETATTR_BITMAP request
1933 */
Benny Halevy43652ad2009-04-01 09:21:54 -04001934static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
1935 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936{
1937 struct xdr_stream xdr;
1938 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001939 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
1942 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001943 encode_compound_hdr(&xdr, req, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04001944 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001945 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1946 FATTR4_WORD0_LINK_SUPPORT|
1947 FATTR4_WORD0_SYMLINK_SUPPORT|
1948 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001949 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001950 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
1953/*
1954 * a RENEW request
1955 */
Al Viro8687b632006-10-19 23:28:48 -07001956static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
1958 struct xdr_stream xdr;
1959 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001960 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 };
1962
1963 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001964 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001965 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001966 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001967 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968}
1969
1970/*
1971 * a SETCLIENTID request
1972 */
Al Viro8687b632006-10-19 23:28:48 -07001973static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974{
1975 struct xdr_stream xdr;
1976 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001977 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 };
1979
1980 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001981 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001982 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001983 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001984 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985}
1986
1987/*
1988 * a SETCLIENTID_CONFIRM request
1989 */
Al Viro8687b632006-10-19 23:28:48 -07001990static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991{
1992 struct xdr_stream xdr;
1993 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001994 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 };
1996 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
1998 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001999 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002000 encode_setclientid_confirm(&xdr, clp, &hdr);
2001 encode_putrootfh(&xdr, &hdr);
2002 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002003 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002004 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005}
2006
2007/*
2008 * DELEGRETURN request
2009 */
Al Viro8687b632006-10-19 23:28:48 -07002010static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011{
2012 struct xdr_stream xdr;
2013 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002014 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002018 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002019 encode_putfh(&xdr, args->fhandle, &hdr);
2020 encode_delegreturn(&xdr, args->stateid, &hdr);
2021 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002022 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002023 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024}
2025
2026/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002027 * Encode FS_LOCATIONS request
2028 */
Al Viro8687b632006-10-19 23:28:48 -07002029static 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 -04002030{
2031 struct xdr_stream xdr;
2032 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002034 };
Benny Halevy28f56692009-04-01 09:22:09 -04002035 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002036
2037 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002038 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002039 encode_putfh(&xdr, args->dir_fh, &hdr);
2040 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002041 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002042 encode_fs_locations(&xdr, args->bitmask, &hdr);
2043
Benny Halevy28f56692009-04-01 09:22:09 -04002044 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002045 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002046 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002047 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002048}
2049
2050/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 * START OF "GENERIC" DECODE ROUTINES.
2052 * These may look a little ugly since they are imported from a "generic"
2053 * set of XDR encode/decode routines which are intended to be shared by
2054 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2055 *
2056 * If the pain of reading these is too great, it should be a straightforward
2057 * task to translate them into Linux-specific versions which are more
2058 * consistent with the style used in NFSv2/v3...
2059 */
2060#define READ32(x) (x) = ntohl(*p++)
2061#define READ64(x) do { \
2062 (x) = (u64)ntohl(*p++) << 32; \
2063 (x) |= ntohl(*p++); \
2064} while (0)
2065#define READTIME(x) do { \
2066 p++; \
2067 (x.tv_sec) = ntohl(*p++); \
2068 (x.tv_nsec) = ntohl(*p++); \
2069} while (0)
2070#define COPYMEM(x,nbytes) do { \
2071 memcpy((x), p, nbytes); \
2072 p += XDR_QUADLEN(nbytes); \
2073} while (0)
2074
2075#define READ_BUF(nbytes) do { \
2076 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002077 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002078 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002079 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002080 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002081 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 return -EIO; \
2083 } \
2084} while (0)
2085
Trond Myklebust683b57b2006-06-09 09:34:22 -04002086static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
Al Viro8687b632006-10-19 23:28:48 -07002088 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
2090 READ_BUF(4);
2091 READ32(*len);
2092 READ_BUF(*len);
2093 *string = (char *)p;
2094 return 0;
2095}
2096
2097static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2098{
Al Viro8687b632006-10-19 23:28:48 -07002099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
2101 READ_BUF(8);
2102 READ32(hdr->status);
2103 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 READ_BUF(hdr->taglen + 4);
2106 hdr->tag = (char *)p;
2107 p += XDR_QUADLEN(hdr->taglen);
2108 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002109 if (unlikely(hdr->nops < 1))
2110 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 return 0;
2112}
2113
2114static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2115{
Al Viro8687b632006-10-19 23:28:48 -07002116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 uint32_t opnum;
2118 int32_t nfserr;
2119
2120 READ_BUF(8);
2121 READ32(opnum);
2122 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002123 dprintk("nfs: Server returned operation"
2124 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 opnum, expected);
2126 return -EIO;
2127 }
2128 READ32(nfserr);
2129 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002130 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 return 0;
2132}
2133
2134/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002135static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Al Viro8687b632006-10-19 23:28:48 -07002137 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002138 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 char *str;
2140
2141 READ_BUF(12);
2142 return decode_opaque_inline(xdr, &strlen, &str);
2143}
2144
2145static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2146{
Al Viro8687b632006-10-19 23:28:48 -07002147 uint32_t bmlen;
2148 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
2150 READ_BUF(4);
2151 READ32(bmlen);
2152
2153 bitmap[0] = bitmap[1] = 0;
2154 READ_BUF((bmlen << 2));
2155 if (bmlen > 0) {
2156 READ32(bitmap[0]);
2157 if (bmlen > 1)
2158 READ32(bitmap[1]);
2159 }
2160 return 0;
2161}
2162
Al Viro8687b632006-10-19 23:28:48 -07002163static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Al Viro8687b632006-10-19 23:28:48 -07002165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 READ_BUF(4);
2168 READ32(*attrlen);
2169 *savep = xdr->p;
2170 return 0;
2171}
2172
2173static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2174{
2175 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2176 decode_attr_bitmap(xdr, bitmask);
2177 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2178 } else
2179 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002180 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 return 0;
2182}
2183
2184static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
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 *type = 0;
2190 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2191 return -EIO;
2192 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2193 READ_BUF(4);
2194 READ32(*type);
2195 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002196 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 return -EIO;
2198 }
2199 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002200 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002202 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002203 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2207{
Al Viro8687b632006-10-19 23:28:48 -07002208 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002209 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
2211 *change = 0;
2212 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2213 return -EIO;
2214 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2215 READ_BUF(8);
2216 READ64(*change);
2217 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002218 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002220 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002222 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223}
2224
2225static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2226{
Al Viro8687b632006-10-19 23:28:48 -07002227 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002228 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
2230 *size = 0;
2231 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2232 return -EIO;
2233 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2234 READ_BUF(8);
2235 READ64(*size);
2236 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002237 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002239 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002240 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241}
2242
2243static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2244{
Al Viro8687b632006-10-19 23:28:48 -07002245 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
2247 *res = 0;
2248 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2249 return -EIO;
2250 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2251 READ_BUF(4);
2252 READ32(*res);
2253 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2254 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002255 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 return 0;
2257}
2258
2259static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2260{
Al Viro8687b632006-10-19 23:28:48 -07002261 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263 *res = 0;
2264 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2265 return -EIO;
2266 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2267 READ_BUF(4);
2268 READ32(*res);
2269 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2270 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002271 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 return 0;
2273}
2274
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002275static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
Al Viro8687b632006-10-19 23:28:48 -07002277 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002278 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
2280 fsid->major = 0;
2281 fsid->minor = 0;
2282 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2283 return -EIO;
2284 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2285 READ_BUF(16);
2286 READ64(fsid->major);
2287 READ64(fsid->minor);
2288 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002289 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002291 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 (unsigned long long)fsid->major,
2293 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002294 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295}
2296
2297static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2298{
Al Viro8687b632006-10-19 23:28:48 -07002299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 *res = 60;
2302 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2303 return -EIO;
2304 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2305 READ_BUF(4);
2306 READ32(*res);
2307 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2308 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002309 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 return 0;
2311}
2312
2313static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2314{
Al Viro8687b632006-10-19 23:28:48 -07002315 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
2317 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2318 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2319 return -EIO;
2320 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2321 READ_BUF(4);
2322 READ32(*res);
2323 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2324 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002325 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 return 0;
2327}
2328
2329static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2330{
Al Viro8687b632006-10-19 23:28:48 -07002331 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002332 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
2334 *fileid = 0;
2335 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2336 return -EIO;
2337 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2338 READ_BUF(8);
2339 READ64(*fileid);
2340 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002341 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002343 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002344 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
Manoj Naik99baf622006-06-09 09:34:24 -04002347static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2348{
Al Viro8687b632006-10-19 23:28:48 -07002349 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002350 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002351
2352 *fileid = 0;
2353 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2354 return -EIO;
2355 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2356 READ_BUF(8);
2357 READ64(*fileid);
2358 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002359 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002360 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002361 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002362 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002363}
2364
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2366{
Al Viro8687b632006-10-19 23:28:48 -07002367 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 int status = 0;
2369
2370 *res = 0;
2371 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2372 return -EIO;
2373 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2374 READ_BUF(8);
2375 READ64(*res);
2376 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2377 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002378 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 return status;
2380}
2381
2382static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2383{
Al Viro8687b632006-10-19 23:28:48 -07002384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 int status = 0;
2386
2387 *res = 0;
2388 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2389 return -EIO;
2390 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2391 READ_BUF(8);
2392 READ64(*res);
2393 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2394 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002395 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 return status;
2397}
2398
2399static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2400{
Al Viro8687b632006-10-19 23:28:48 -07002401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 int status = 0;
2403
2404 *res = 0;
2405 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2406 return -EIO;
2407 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2408 READ_BUF(8);
2409 READ64(*res);
2410 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2411 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002412 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 return status;
2414}
2415
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002416static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2417{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002418 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002419 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002420 int status = 0;
2421
2422 READ_BUF(4);
2423 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002424 if (n == 0)
2425 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002426 dprintk("path ");
2427 path->ncomponents = 0;
2428 while (path->ncomponents < n) {
2429 struct nfs4_string *component = &path->components[path->ncomponents];
2430 status = decode_opaque_inline(xdr, &component->len, &component->data);
2431 if (unlikely(status != 0))
2432 goto out_eio;
2433 if (path->ncomponents != n)
2434 dprintk("/");
2435 dprintk("%s", component->data);
2436 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2437 path->ncomponents++;
2438 else {
2439 dprintk("cannot parse %d components in path\n", n);
2440 goto out_eio;
2441 }
2442 }
2443out:
2444 dprintk("\n");
2445 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002446root_path:
2447/* a root pathname is sent as a zero component4 */
2448 path->ncomponents = 1;
2449 path->components[0].len=0;
2450 path->components[0].data=NULL;
2451 dprintk("path /\n");
2452 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002453out_eio:
2454 dprintk(" status %d", status);
2455 status = -EIO;
2456 goto out;
2457}
2458
2459static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002460{
2461 int n;
Al Viro8687b632006-10-19 23:28:48 -07002462 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002463 int status = -EIO;
2464
2465 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2466 goto out;
2467 status = 0;
2468 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2469 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002470 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002471 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002472 if (unlikely(status != 0))
2473 goto out;
2474 READ_BUF(4);
2475 READ32(n);
2476 if (n <= 0)
2477 goto out_eio;
2478 res->nlocations = 0;
2479 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002480 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002481 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002482
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002483 READ_BUF(4);
2484 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002485
2486 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002487 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002488 while (loc->nservers < m) {
2489 struct nfs4_string *server = &loc->servers[loc->nservers];
2490 status = decode_opaque_inline(xdr, &server->len, &server->data);
2491 if (unlikely(status != 0))
2492 goto out_eio;
2493 dprintk("%s ", server->data);
2494 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2495 loc->nservers++;
2496 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002497 unsigned int i;
2498 dprintk("%s: using first %u of %u servers "
2499 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002500 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002501 NFS4_FS_LOCATION_MAXSERVERS,
2502 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002503 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002504 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002505 char *data;
2506 status = decode_opaque_inline(xdr, &len, &data);
2507 if (unlikely(status != 0))
2508 goto out_eio;
2509 }
2510 }
2511 }
2512 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002513 if (unlikely(status != 0))
2514 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002515 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002516 res->nlocations++;
2517 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002518 if (res->nlocations != 0)
2519 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002520out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002521 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002522 return status;
2523out_eio:
2524 status = -EIO;
2525 goto out;
2526}
2527
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2529{
Al Viro8687b632006-10-19 23:28:48 -07002530 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 int status = 0;
2532
2533 *res = 0;
2534 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2535 return -EIO;
2536 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2537 READ_BUF(8);
2538 READ64(*res);
2539 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2540 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002541 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 return status;
2543}
2544
2545static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2546{
Al Viro8687b632006-10-19 23:28:48 -07002547 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 int status = 0;
2549
2550 *maxlink = 1;
2551 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2552 return -EIO;
2553 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2554 READ_BUF(4);
2555 READ32(*maxlink);
2556 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2557 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002558 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 return status;
2560}
2561
2562static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2563{
Al Viro8687b632006-10-19 23:28:48 -07002564 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 int status = 0;
2566
2567 *maxname = 1024;
2568 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2569 return -EIO;
2570 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2571 READ_BUF(4);
2572 READ32(*maxname);
2573 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2574 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002575 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 return status;
2577}
2578
2579static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2580{
Al Viro8687b632006-10-19 23:28:48 -07002581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 int status = 0;
2583
2584 *res = 1024;
2585 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2586 return -EIO;
2587 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2588 uint64_t maxread;
2589 READ_BUF(8);
2590 READ64(maxread);
2591 if (maxread > 0x7FFFFFFF)
2592 maxread = 0x7FFFFFFF;
2593 *res = (uint32_t)maxread;
2594 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2595 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002596 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 return status;
2598}
2599
2600static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2601{
Al Viro8687b632006-10-19 23:28:48 -07002602 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 int status = 0;
2604
2605 *res = 1024;
2606 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2607 return -EIO;
2608 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2609 uint64_t maxwrite;
2610 READ_BUF(8);
2611 READ64(maxwrite);
2612 if (maxwrite > 0x7FFFFFFF)
2613 maxwrite = 0x7FFFFFFF;
2614 *res = (uint32_t)maxwrite;
2615 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2616 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002617 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 return status;
2619}
2620
Trond Myklebustbca79472009-03-11 14:10:26 -04002621static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622{
Trond Myklebustbca79472009-03-11 14:10:26 -04002623 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07002624 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002625 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
2627 *mode = 0;
2628 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2629 return -EIO;
2630 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2631 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04002632 READ32(tmp);
2633 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002635 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002637 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04002638 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
2640
2641static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2642{
Al Viro8687b632006-10-19 23:28:48 -07002643 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002644 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
2646 *nlink = 1;
2647 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2648 return -EIO;
2649 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2650 READ_BUF(4);
2651 READ32(*nlink);
2652 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04002653 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002655 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04002656 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657}
2658
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002659static 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 -07002660{
Al Viro8687b632006-10-19 23:28:48 -07002661 uint32_t len;
2662 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002663 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
2665 *uid = -2;
2666 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2667 return -EIO;
2668 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2669 READ_BUF(4);
2670 READ32(len);
2671 READ_BUF(len);
2672 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002673 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2674 ret = NFS_ATTR_FATTR_OWNER;
2675 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002677 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002679 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002680 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2682 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002683 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002684 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685}
2686
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002687static 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 -07002688{
Al Viro8687b632006-10-19 23:28:48 -07002689 uint32_t len;
2690 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002691 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 *gid = -2;
2694 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2695 return -EIO;
2696 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2697 READ_BUF(4);
2698 READ32(len);
2699 READ_BUF(len);
2700 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002701 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2702 ret = NFS_ATTR_FATTR_GROUP;
2703 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002705 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002707 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002708 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2710 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002711 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002712 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713}
2714
2715static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2716{
Al Viro8687b632006-10-19 23:28:48 -07002717 uint32_t major = 0, minor = 0;
2718 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002719 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
2721 *rdev = MKDEV(0,0);
2722 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2723 return -EIO;
2724 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2725 dev_t tmp;
2726
2727 READ_BUF(8);
2728 READ32(major);
2729 READ32(minor);
2730 tmp = MKDEV(major, minor);
2731 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2732 *rdev = tmp;
2733 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04002734 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002736 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002737 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738}
2739
2740static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2741{
Al Viro8687b632006-10-19 23:28:48 -07002742 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 int status = 0;
2744
2745 *res = 0;
2746 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2747 return -EIO;
2748 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2749 READ_BUF(8);
2750 READ64(*res);
2751 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2752 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002753 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 return status;
2755}
2756
2757static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2758{
Al Viro8687b632006-10-19 23:28:48 -07002759 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 int status = 0;
2761
2762 *res = 0;
2763 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2764 return -EIO;
2765 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2766 READ_BUF(8);
2767 READ64(*res);
2768 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2769 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002770 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 return status;
2772}
2773
2774static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2775{
Al Viro8687b632006-10-19 23:28:48 -07002776 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 int status = 0;
2778
2779 *res = 0;
2780 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2781 return -EIO;
2782 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2783 READ_BUF(8);
2784 READ64(*res);
2785 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2786 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002787 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 return status;
2789}
2790
2791static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2792{
Al Viro8687b632006-10-19 23:28:48 -07002793 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002794 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
2796 *used = 0;
2797 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2798 return -EIO;
2799 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2800 READ_BUF(8);
2801 READ64(*used);
2802 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04002803 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002805 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04002807 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808}
2809
2810static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2811{
Al Viro8687b632006-10-19 23:28:48 -07002812 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 uint64_t sec;
2814 uint32_t nsec;
2815
2816 READ_BUF(12);
2817 READ64(sec);
2818 READ32(nsec);
2819 time->tv_sec = (time_t)sec;
2820 time->tv_nsec = (long)nsec;
2821 return 0;
2822}
2823
2824static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2825{
2826 int status = 0;
2827
2828 time->tv_sec = 0;
2829 time->tv_nsec = 0;
2830 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2831 return -EIO;
2832 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2833 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002834 if (status == 0)
2835 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2837 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002838 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 return status;
2840}
2841
2842static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2843{
2844 int status = 0;
2845
2846 time->tv_sec = 0;
2847 time->tv_nsec = 0;
2848 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2849 return -EIO;
2850 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2851 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002852 if (status == 0)
2853 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2855 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002856 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 return status;
2858}
2859
2860static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2861{
2862 int status = 0;
2863
2864 time->tv_sec = 0;
2865 time->tv_nsec = 0;
2866 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2867 return -EIO;
2868 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2869 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002870 if (status == 0)
2871 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2873 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002874 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 return status;
2876}
2877
Al Viro8687b632006-10-19 23:28:48 -07002878static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879{
2880 unsigned int attrwords = XDR_QUADLEN(attrlen);
2881 unsigned int nwords = xdr->p - savep;
2882
2883 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002884 dprintk("%s: server returned incorrect attribute length: "
2885 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002886 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 attrwords << 2,
2888 (attrwords < nwords) ? '<' : '>',
2889 nwords << 2);
2890 return -EIO;
2891 }
2892 return 0;
2893}
2894
2895static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2896{
Al Viro8687b632006-10-19 23:28:48 -07002897 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
2899 READ_BUF(20);
2900 READ32(cinfo->atomic);
2901 READ64(cinfo->before);
2902 READ64(cinfo->after);
2903 return 0;
2904}
2905
2906static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2907{
Al Viro8687b632006-10-19 23:28:48 -07002908 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 uint32_t supp, acc;
2910 int status;
2911
2912 status = decode_op_hdr(xdr, OP_ACCESS);
2913 if (status)
2914 return status;
2915 READ_BUF(8);
2916 READ32(supp);
2917 READ32(acc);
2918 access->supported = supp;
2919 access->access = acc;
2920 return 0;
2921}
2922
2923static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2924{
Al Viro8687b632006-10-19 23:28:48 -07002925 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 int status;
2927
2928 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04002929 if (status != -EIO)
2930 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 if (status)
2932 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04002933 READ_BUF(NFS4_STATEID_SIZE);
2934 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 return 0;
2936}
2937
2938static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2939{
Al Viro8687b632006-10-19 23:28:48 -07002940 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 int status;
2942
2943 status = decode_op_hdr(xdr, OP_COMMIT);
2944 if (status)
2945 return status;
2946 READ_BUF(8);
2947 COPYMEM(res->verf->verifier, 8);
2948 return 0;
2949}
2950
2951static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2952{
Al Viro8687b632006-10-19 23:28:48 -07002953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 uint32_t bmlen;
2955 int status;
2956
2957 status = decode_op_hdr(xdr, OP_CREATE);
2958 if (status)
2959 return status;
2960 if ((status = decode_change_info(xdr, cinfo)))
2961 return status;
2962 READ_BUF(4);
2963 READ32(bmlen);
2964 READ_BUF(bmlen << 2);
2965 return 0;
2966}
2967
2968static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2969{
Al Viro8687b632006-10-19 23:28:48 -07002970 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002971 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 int status;
2973
2974 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2975 goto xdr_error;
2976 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2977 goto xdr_error;
2978 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2979 goto xdr_error;
2980 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2981 goto xdr_error;
2982 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2983 goto xdr_error;
2984 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2985 goto xdr_error;
2986 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2987 goto xdr_error;
2988 status = verify_attr_len(xdr, savep, attrlen);
2989xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002990 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 return status;
2992}
Andy Adamson6c0195a2008-12-23 16:06:15 -05002993
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2995{
Al Viro8687b632006-10-19 23:28:48 -07002996 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002997 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002999
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3001 goto xdr_error;
3002 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3003 goto xdr_error;
3004 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3005 goto xdr_error;
3006
3007 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3008 goto xdr_error;
3009 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3010 goto xdr_error;
3011 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3012 goto xdr_error;
3013 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3014 goto xdr_error;
3015 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3016 goto xdr_error;
3017 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3018 goto xdr_error;
3019
3020 status = verify_attr_len(xdr, savep, attrlen);
3021xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003022 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 return status;
3024}
3025
3026static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3027{
Al Viro8687b632006-10-19 23:28:48 -07003028 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003029 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003031
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3033 goto xdr_error;
3034 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3035 goto xdr_error;
3036 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3037 goto xdr_error;
3038
3039 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3040 goto xdr_error;
3041 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3042 goto xdr_error;
3043
3044 status = verify_attr_len(xdr, savep, attrlen);
3045xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003046 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 return status;
3048}
3049
3050static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3051{
Al Viro8687b632006-10-19 23:28:48 -07003052 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 uint32_t attrlen,
3054 bitmap[2] = {0},
3055 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003056 int status;
3057 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003058 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003060 status = decode_op_hdr(xdr, OP_GETATTR);
3061 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 goto xdr_error;
3063
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003064 status = decode_attr_bitmap(xdr, bitmap);
3065 if (status < 0)
3066 goto xdr_error;
3067
3068 status = decode_attr_length(xdr, &attrlen, &savep);
3069 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 goto xdr_error;
3071
3072
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003073 status = decode_attr_type(xdr, bitmap, &type);
3074 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003076 fattr->mode = 0;
3077 if (status != 0) {
3078 fattr->mode |= nfs_type2fmt[type];
3079 fattr->valid |= status;
3080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003082 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3083 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 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_size(xdr, bitmap, &fattr->size);
3088 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003090 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003091
3092 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3093 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003095 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003096
3097 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3098 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003100 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003101
3102 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003103 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003104 fattr));
3105 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003106 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003107 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003108
3109 status = decode_attr_mode(xdr, bitmap, &fmode);
3110 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003112 if (status != 0) {
3113 fattr->mode |= fmode;
3114 fattr->valid |= status;
3115 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003116
3117 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3118 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003120 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003121
3122 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3123 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003125 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003126
3127 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3128 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003130 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003131
3132 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3133 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003135 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003136
3137 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3138 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003140 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003141
3142 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3143 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003145 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003146
3147 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3148 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003150 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003151
3152 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3153 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003155 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003156
3157 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3158 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003159 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003160 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003161 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003162 fattr->valid |= status;
3163 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003164
3165 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003167 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 return status;
3169}
3170
3171
3172static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3173{
Al Viro8687b632006-10-19 23:28:48 -07003174 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 uint32_t attrlen, bitmap[2];
3176 int status;
3177
3178 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3179 goto xdr_error;
3180 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3181 goto xdr_error;
3182 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3183 goto xdr_error;
3184
3185 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3186
3187 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3188 goto xdr_error;
3189 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3190 goto xdr_error;
3191 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3192 goto xdr_error;
3193 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3194 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3195 goto xdr_error;
3196 fsinfo->wtpref = fsinfo->wtmax;
3197
3198 status = verify_attr_len(xdr, savep, attrlen);
3199xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003200 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 return status;
3202}
3203
3204static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3205{
Al Viro8687b632006-10-19 23:28:48 -07003206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 uint32_t len;
3208 int status;
3209
Trond Myklebust99367812007-07-17 21:52:41 -04003210 /* Zero handle first to allow comparisons */
3211 memset(fh, 0, sizeof(*fh));
3212
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 status = decode_op_hdr(xdr, OP_GETFH);
3214 if (status)
3215 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
3217 READ_BUF(4);
3218 READ32(len);
3219 if (len > NFS4_FHSIZE)
3220 return -EIO;
3221 fh->size = len;
3222 READ_BUF(len);
3223 COPYMEM(fh->data, len);
3224 return 0;
3225}
3226
3227static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3228{
3229 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003230
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 status = decode_op_hdr(xdr, OP_LINK);
3232 if (status)
3233 return status;
3234 return decode_change_info(xdr, cinfo);
3235}
3236
3237/*
3238 * We create the owner, so we know a proper owner.id length is 4.
3239 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003240static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003242 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003243 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003244 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
3246 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003247 READ64(offset);
3248 READ64(length);
3249 READ32(type);
3250 if (fl != NULL) {
3251 fl->fl_start = (loff_t)offset;
3252 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3253 if (length == ~(uint64_t)0)
3254 fl->fl_end = OFFSET_MAX;
3255 fl->fl_type = F_WRLCK;
3256 if (type & 1)
3257 fl->fl_type = F_RDLCK;
3258 fl->fl_pid = 0;
3259 }
3260 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 READ32(namelen);
3262 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 return -NFS4ERR_DENIED;
3264}
3265
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003266static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267{
Al Viro8687b632006-10-19 23:28:48 -07003268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 int status;
3270
3271 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003272 if (status == -EIO)
3273 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003275 READ_BUF(NFS4_STATEID_SIZE);
3276 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003278 status = decode_lock_denied(xdr, NULL);
3279 if (res->open_seqid != NULL)
3280 nfs_increment_open_seqid(status, res->open_seqid);
3281 nfs_increment_lock_seqid(status, res->lock_seqid);
3282out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 return status;
3284}
3285
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003286static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287{
3288 int status;
3289 status = decode_op_hdr(xdr, OP_LOCKT);
3290 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003291 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 return status;
3293}
3294
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003295static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296{
Al Viro8687b632006-10-19 23:28:48 -07003297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 int status;
3299
3300 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003301 if (status != -EIO)
3302 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003304 READ_BUF(NFS4_STATEID_SIZE);
3305 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 }
3307 return status;
3308}
3309
3310static int decode_lookup(struct xdr_stream *xdr)
3311{
3312 return decode_op_hdr(xdr, OP_LOOKUP);
3313}
3314
3315/* This is too sick! */
3316static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3317{
Andy Adamson05d564f2008-12-23 16:06:15 -05003318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 uint32_t limit_type, nblocks, blocksize;
3320
3321 READ_BUF(12);
3322 READ32(limit_type);
3323 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003324 case 1:
3325 READ64(*maxsize);
3326 break;
3327 case 2:
3328 READ32(nblocks);
3329 READ32(blocksize);
3330 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 }
3332 return 0;
3333}
3334
3335static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3336{
Andy Adamson05d564f2008-12-23 16:06:15 -05003337 __be32 *p;
3338 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
3340 READ_BUF(4);
3341 READ32(delegation_type);
3342 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3343 res->delegation_type = 0;
3344 return 0;
3345 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003346 READ_BUF(NFS4_STATEID_SIZE+4);
3347 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003349
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003351 case NFS4_OPEN_DELEGATE_READ:
3352 res->delegation_type = FMODE_READ;
3353 break;
3354 case NFS4_OPEN_DELEGATE_WRITE:
3355 res->delegation_type = FMODE_WRITE|FMODE_READ;
3356 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 return -EIO;
3358 }
David Howells7539bba2006-08-22 20:06:09 -04003359 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360}
3361
3362static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3363{
Andy Adamson05d564f2008-12-23 16:06:15 -05003364 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003365 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003366 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367
Andy Adamson05d564f2008-12-23 16:06:15 -05003368 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003369 if (status != -EIO)
3370 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003371 if (status)
3372 return status;
3373 READ_BUF(NFS4_STATEID_SIZE);
3374 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
Andy Adamson05d564f2008-12-23 16:06:15 -05003376 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
Andy Adamson05d564f2008-12-23 16:06:15 -05003378 READ_BUF(8);
3379 READ32(res->rflags);
3380 READ32(bmlen);
3381 if (bmlen > 10)
3382 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
Andy Adamson05d564f2008-12-23 16:06:15 -05003384 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003385 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3386 for (i = 0; i < savewords; ++i)
3387 READ32(res->attrset[i]);
3388 for (; i < NFS4_BITMAP_SIZE; i++)
3389 res->attrset[i] = 0;
3390
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 return decode_delegation(xdr, res);
3392xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003393 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 return -EIO;
3395}
3396
3397static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3398{
Andy Adamson05d564f2008-12-23 16:06:15 -05003399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 int status;
3401
Andy Adamson05d564f2008-12-23 16:06:15 -05003402 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003403 if (status != -EIO)
3404 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003405 if (status)
3406 return status;
3407 READ_BUF(NFS4_STATEID_SIZE);
3408 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3409 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410}
3411
3412static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3413{
Al Viro8687b632006-10-19 23:28:48 -07003414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 int status;
3416
3417 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003418 if (status != -EIO)
3419 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 if (status)
3421 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003422 READ_BUF(NFS4_STATEID_SIZE);
3423 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 return 0;
3425}
3426
3427static int decode_putfh(struct xdr_stream *xdr)
3428{
3429 return decode_op_hdr(xdr, OP_PUTFH);
3430}
3431
3432static int decode_putrootfh(struct xdr_stream *xdr)
3433{
3434 return decode_op_hdr(xdr, OP_PUTROOTFH);
3435}
3436
3437static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3438{
3439 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003440 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 uint32_t count, eof, recvd, hdrlen;
3442 int status;
3443
3444 status = decode_op_hdr(xdr, OP_READ);
3445 if (status)
3446 return status;
3447 READ_BUF(8);
3448 READ32(eof);
3449 READ32(count);
3450 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3451 recvd = req->rq_rcv_buf.len - hdrlen;
3452 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003453 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 "count %u > recvd %u\n", count, recvd);
3455 count = recvd;
3456 eof = 0;
3457 }
3458 xdr_read_pages(xdr, count);
3459 res->eof = eof;
3460 res->count = count;
3461 return 0;
3462}
3463
3464static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3465{
3466 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3467 struct page *page = *rcvbuf->pages;
3468 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003469 size_t hdrlen;
3470 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003471 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003472 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003473 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
3475 status = decode_op_hdr(xdr, OP_READDIR);
3476 if (status)
3477 return status;
3478 READ_BUF(8);
3479 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003480 dprintk("%s: verifier = %08x:%08x\n",
3481 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003482 ((u32 *)readdir->verifier.data)[0],
3483 ((u32 *)readdir->verifier.data)[1]);
3484
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485
3486 hdrlen = (char *) p - (char *) iov->iov_base;
3487 recvd = rcvbuf->len - hdrlen;
3488 if (pglen > recvd)
3489 pglen = recvd;
3490 xdr_read_pages(xdr, pglen);
3491
3492 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003493 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003494 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003496
3497 /* Make sure the packet actually has a value_follows and EOF entry */
3498 if ((entry + 1) > end)
3499 goto short_pkt;
3500
3501 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003502 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003503 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003505 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 p += 2; /* cookie */
3507 len = ntohl(*p++); /* filename length */
3508 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003509 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3510 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 goto err_unmap;
3512 }
David Howellse8896492006-08-24 15:44:19 -04003513 xlen = XDR_QUADLEN(len);
3514 if (end - p < xlen + 1)
3515 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003516 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003517 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003519 if (end - p < len + 1)
3520 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003523 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003525 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 entry = p;
3527 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003528 /*
3529 * Apparently some server sends responses that are a valid size, but
3530 * contain no entries, and have value_follows==0 and EOF==0. For
3531 * those, just set the EOF marker.
3532 */
3533 if (!nr && entry[1] == 0) {
3534 dprintk("NFS: readdir reply truncated!\n");
3535 entry[1] = 1;
3536 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003537out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 kunmap_atomic(kaddr, KM_USER0);
3539 return 0;
3540short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003541 /*
3542 * When we get a short packet there are 2 possibilities. We can
3543 * return an error, or fix up the response to look like a valid
3544 * response and return what we have so far. If there are no
3545 * entries and the packet was short, then return -EIO. If there
3546 * are valid entries in the response, return them and pretend that
3547 * the call was successful, but incomplete. The caller can retry the
3548 * readdir starting at the last cookie.
3549 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003550 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003552 if (nr)
3553 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554err_unmap:
3555 kunmap_atomic(kaddr, KM_USER0);
3556 return -errno_NFSERR_IO;
3557}
3558
3559static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3560{
3561 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3562 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003563 size_t hdrlen;
3564 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003565 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 char *kaddr;
3567 int status;
3568
3569 status = decode_op_hdr(xdr, OP_READLINK);
3570 if (status)
3571 return status;
3572
3573 /* Convert length of symlink */
3574 READ_BUF(4);
3575 READ32(len);
3576 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003577 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 return -ENAMETOOLONG;
3579 }
3580 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3581 recvd = req->rq_rcv_buf.len - hdrlen;
3582 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003583 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 "count %u > recvd %u\n", len, recvd);
3585 return -EIO;
3586 }
3587 xdr_read_pages(xdr, len);
3588 /*
3589 * The XDR encode routine has set things up so that
3590 * the link text will be copied directly into the
3591 * buffer. We just have to do overflow-checking,
3592 * and and null-terminate the text (the VFS expects
3593 * null-termination).
3594 */
3595 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3596 kaddr[len+rcvbuf->page_base] = '\0';
3597 kunmap_atomic(kaddr, KM_USER0);
3598 return 0;
3599}
3600
3601static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3602{
3603 int status;
3604
3605 status = decode_op_hdr(xdr, OP_REMOVE);
3606 if (status)
3607 goto out;
3608 status = decode_change_info(xdr, cinfo);
3609out:
3610 return status;
3611}
3612
3613static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3614 struct nfs4_change_info *new_cinfo)
3615{
3616 int status;
3617
3618 status = decode_op_hdr(xdr, OP_RENAME);
3619 if (status)
3620 goto out;
3621 if ((status = decode_change_info(xdr, old_cinfo)))
3622 goto out;
3623 status = decode_change_info(xdr, new_cinfo);
3624out:
3625 return status;
3626}
3627
3628static int decode_renew(struct xdr_stream *xdr)
3629{
3630 return decode_op_hdr(xdr, OP_RENEW);
3631}
3632
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003633static int
3634decode_restorefh(struct xdr_stream *xdr)
3635{
3636 return decode_op_hdr(xdr, OP_RESTOREFH);
3637}
3638
J. Bruce Fields029d1052005-06-22 17:16:22 +00003639static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3640 size_t *acl_len)
3641{
Al Viro8687b632006-10-19 23:28:48 -07003642 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003643 uint32_t attrlen,
3644 bitmap[2] = {0};
3645 struct kvec *iov = req->rq_rcv_buf.head;
3646 int status;
3647
3648 *acl_len = 0;
3649 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3650 goto out;
3651 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3652 goto out;
3653 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3654 goto out;
3655
3656 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3657 return -EIO;
3658 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003659 size_t hdrlen;
3660 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003661
3662 /* We ignore &savep and don't do consistency checks on
3663 * the attr length. Let userspace figure it out.... */
3664 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3665 recvd = req->rq_rcv_buf.len - hdrlen;
3666 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003667 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00003668 " acl reply: attrlen %u > recvd %u\n",
3669 attrlen, recvd);
3670 return -EINVAL;
3671 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003672 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003673 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003674 } else
3675 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003676
3677out:
3678 return status;
3679}
3680
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681static int
3682decode_savefh(struct xdr_stream *xdr)
3683{
3684 return decode_op_hdr(xdr, OP_SAVEFH);
3685}
3686
Benny Halevy9e9ecc02009-04-01 09:22:00 -04003687static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688{
Al Viro8687b632006-10-19 23:28:48 -07003689 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 uint32_t bmlen;
3691 int status;
3692
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 status = decode_op_hdr(xdr, OP_SETATTR);
3694 if (status)
3695 return status;
3696 READ_BUF(4);
3697 READ32(bmlen);
3698 READ_BUF(bmlen << 2);
3699 return 0;
3700}
3701
David Howellsadfa6f92006-08-22 20:06:08 -04003702static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703{
Al Viro8687b632006-10-19 23:28:48 -07003704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 uint32_t opnum;
3706 int32_t nfserr;
3707
3708 READ_BUF(8);
3709 READ32(opnum);
3710 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003711 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05003712 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 return -EIO;
3714 }
3715 READ32(nfserr);
3716 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003717 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003719 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 } else if (nfserr == NFSERR_CLID_INUSE) {
3721 uint32_t len;
3722
3723 /* skip netid string */
3724 READ_BUF(4);
3725 READ32(len);
3726 READ_BUF(len);
3727
3728 /* skip uaddr string */
3729 READ_BUF(4);
3730 READ32(len);
3731 READ_BUF(len);
3732 return -NFSERR_CLID_INUSE;
3733 } else
Benny Halevy856dff32008-03-31 17:39:06 +03003734 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
3736 return 0;
3737}
3738
3739static int decode_setclientid_confirm(struct xdr_stream *xdr)
3740{
3741 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3742}
3743
3744static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3745{
Al Viro8687b632006-10-19 23:28:48 -07003746 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 int status;
3748
3749 status = decode_op_hdr(xdr, OP_WRITE);
3750 if (status)
3751 return status;
3752
3753 READ_BUF(16);
3754 READ32(res->count);
3755 READ32(res->verf->committed);
3756 COPYMEM(res->verf->verifier, 8);
3757 return 0;
3758}
3759
3760static int decode_delegreturn(struct xdr_stream *xdr)
3761{
3762 return decode_op_hdr(xdr, OP_DELEGRETURN);
3763}
3764
3765/*
Benny Halevy49c25592008-12-23 16:06:16 -05003766 * END OF "GENERIC" DECODE ROUTINES.
3767 */
3768
3769/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 * Decode OPEN_DOWNGRADE response
3771 */
Al Viro8687b632006-10-19 23:28:48 -07003772static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773{
Andy Adamson05d564f2008-12-23 16:06:15 -05003774 struct xdr_stream xdr;
3775 struct compound_hdr hdr;
3776 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777
Andy Adamson05d564f2008-12-23 16:06:15 -05003778 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3779 status = decode_compound_hdr(&xdr, &hdr);
3780 if (status)
3781 goto out;
3782 status = decode_putfh(&xdr);
3783 if (status)
3784 goto out;
3785 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003786 if (status != 0)
3787 goto out;
3788 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789out:
Andy Adamson05d564f2008-12-23 16:06:15 -05003790 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791}
3792
3793/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 * Decode ACCESS response
3795 */
Al Viro8687b632006-10-19 23:28:48 -07003796static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797{
3798 struct xdr_stream xdr;
3799 struct compound_hdr hdr;
3800 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003801
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3803 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3804 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04003805 status = decode_putfh(&xdr);
3806 if (status != 0)
3807 goto out;
3808 status = decode_access(&xdr, res);
3809 if (status != 0)
3810 goto out;
3811 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812out:
3813 return status;
3814}
3815
3816/*
3817 * Decode LOOKUP response
3818 */
Al Viro8687b632006-10-19 23:28:48 -07003819static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820{
3821 struct xdr_stream xdr;
3822 struct compound_hdr hdr;
3823 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003824
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3826 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3827 goto out;
3828 if ((status = decode_putfh(&xdr)) != 0)
3829 goto out;
3830 if ((status = decode_lookup(&xdr)) != 0)
3831 goto out;
3832 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3833 goto out;
3834 status = decode_getfattr(&xdr, res->fattr, res->server);
3835out:
3836 return status;
3837}
3838
3839/*
3840 * Decode LOOKUP_ROOT response
3841 */
Al Viro8687b632006-10-19 23:28:48 -07003842static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843{
3844 struct xdr_stream xdr;
3845 struct compound_hdr hdr;
3846 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003847
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3849 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3850 goto out;
3851 if ((status = decode_putrootfh(&xdr)) != 0)
3852 goto out;
3853 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3854 status = decode_getfattr(&xdr, res->fattr, res->server);
3855out:
3856 return status;
3857}
3858
3859/*
3860 * Decode REMOVE response
3861 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003862static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863{
3864 struct xdr_stream xdr;
3865 struct compound_hdr hdr;
3866 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003867
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3869 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3870 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003871 if ((status = decode_putfh(&xdr)) != 0)
3872 goto out;
3873 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3874 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003875 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876out:
3877 return status;
3878}
3879
3880/*
3881 * Decode RENAME response
3882 */
Al Viro8687b632006-10-19 23:28:48 -07003883static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884{
3885 struct xdr_stream xdr;
3886 struct compound_hdr hdr;
3887 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003888
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3890 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3891 goto out;
3892 if ((status = decode_putfh(&xdr)) != 0)
3893 goto out;
3894 if ((status = decode_savefh(&xdr)) != 0)
3895 goto out;
3896 if ((status = decode_putfh(&xdr)) != 0)
3897 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003898 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3899 goto out;
3900 /* Current FH is target directory */
3901 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3902 goto out;
3903 if ((status = decode_restorefh(&xdr)) != 0)
3904 goto out;
3905 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906out:
3907 return status;
3908}
3909
3910/*
3911 * Decode LINK response
3912 */
Al Viro8687b632006-10-19 23:28:48 -07003913static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914{
3915 struct xdr_stream xdr;
3916 struct compound_hdr hdr;
3917 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003918
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3920 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3921 goto out;
3922 if ((status = decode_putfh(&xdr)) != 0)
3923 goto out;
3924 if ((status = decode_savefh(&xdr)) != 0)
3925 goto out;
3926 if ((status = decode_putfh(&xdr)) != 0)
3927 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003928 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3929 goto out;
3930 /*
3931 * Note order: OP_LINK leaves the directory as the current
3932 * filehandle.
3933 */
3934 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3935 goto out;
3936 if ((status = decode_restorefh(&xdr)) != 0)
3937 goto out;
3938 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939out:
3940 return status;
3941}
3942
3943/*
3944 * Decode CREATE response
3945 */
Al Viro8687b632006-10-19 23:28:48 -07003946static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947{
3948 struct xdr_stream xdr;
3949 struct compound_hdr hdr;
3950 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003951
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3953 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3954 goto out;
3955 if ((status = decode_putfh(&xdr)) != 0)
3956 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003957 if ((status = decode_savefh(&xdr)) != 0)
3958 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3960 goto out;
3961 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3962 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003963 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3964 goto out;
3965 if ((status = decode_restorefh(&xdr)) != 0)
3966 goto out;
3967 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968out:
3969 return status;
3970}
3971
3972/*
3973 * Decode SYMLINK response
3974 */
Al Viro8687b632006-10-19 23:28:48 -07003975static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976{
3977 return nfs4_xdr_dec_create(rqstp, p, res);
3978}
3979
3980/*
3981 * Decode GETATTR response
3982 */
Al Viro8687b632006-10-19 23:28:48 -07003983static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984{
3985 struct xdr_stream xdr;
3986 struct compound_hdr hdr;
3987 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003988
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3990 status = decode_compound_hdr(&xdr, &hdr);
3991 if (status)
3992 goto out;
3993 status = decode_putfh(&xdr);
3994 if (status)
3995 goto out;
3996 status = decode_getfattr(&xdr, res->fattr, res->server);
3997out:
3998 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999}
4000
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004001/*
4002 * Encode an SETACL request
4003 */
4004static int
Al Viro8687b632006-10-19 23:28:48 -07004005nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004006{
Andy Adamson05d564f2008-12-23 16:06:15 -05004007 struct xdr_stream xdr;
4008 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004009 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004010 };
4011 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004012
Andy Adamson05d564f2008-12-23 16:06:15 -05004013 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004014 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004015 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004016 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004017 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004018 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004019}
Andy Adamson05d564f2008-12-23 16:06:15 -05004020
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004021/*
4022 * Decode SETACL response
4023 */
4024static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004025nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4026 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004027{
4028 struct xdr_stream xdr;
4029 struct compound_hdr hdr;
4030 int status;
4031
4032 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4033 status = decode_compound_hdr(&xdr, &hdr);
4034 if (status)
4035 goto out;
4036 status = decode_putfh(&xdr);
4037 if (status)
4038 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004039 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004040out:
4041 return status;
4042}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043
4044/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004045 * Decode GETACL response
4046 */
4047static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004048nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4049 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004050{
4051 struct xdr_stream xdr;
4052 struct compound_hdr hdr;
4053 int status;
4054
4055 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4056 status = decode_compound_hdr(&xdr, &hdr);
4057 if (status)
4058 goto out;
4059 status = decode_putfh(&xdr);
4060 if (status)
4061 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004062 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004063
4064out:
4065 return status;
4066}
4067
4068/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 * Decode CLOSE response
4070 */
Al Viro8687b632006-10-19 23:28:48 -07004071static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072{
Andy Adamson05d564f2008-12-23 16:06:15 -05004073 struct xdr_stream xdr;
4074 struct compound_hdr hdr;
4075 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076
Andy Adamson05d564f2008-12-23 16:06:15 -05004077 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4078 status = decode_compound_hdr(&xdr, &hdr);
4079 if (status)
4080 goto out;
4081 status = decode_putfh(&xdr);
4082 if (status)
4083 goto out;
4084 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004085 if (status != 0)
4086 goto out;
4087 /*
4088 * Note: Server may do delete on close for this file
4089 * in which case the getattr call will fail with
4090 * an ESTALE error. Shouldn't be a problem,
4091 * though, since fattr->valid will remain unset.
4092 */
4093 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004095 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096}
4097
4098/*
4099 * Decode OPEN response
4100 */
Al Viro8687b632006-10-19 23:28:48 -07004101static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102{
Andy Adamson05d564f2008-12-23 16:06:15 -05004103 struct xdr_stream xdr;
4104 struct compound_hdr hdr;
4105 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106
Andy Adamson05d564f2008-12-23 16:06:15 -05004107 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4108 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004109 if (status)
4110 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004111 status = decode_putfh(&xdr);
4112 if (status)
4113 goto out;
4114 status = decode_savefh(&xdr);
4115 if (status)
4116 goto out;
4117 status = decode_open(&xdr, res);
4118 if (status)
4119 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004120 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004122 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4123 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004124 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004125 goto out;
4126 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004128 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129}
4130
4131/*
4132 * Decode OPEN_CONFIRM response
4133 */
Al Viro8687b632006-10-19 23:28:48 -07004134static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135{
Andy Adamson05d564f2008-12-23 16:06:15 -05004136 struct xdr_stream xdr;
4137 struct compound_hdr hdr;
4138 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
Andy Adamson05d564f2008-12-23 16:06:15 -05004140 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4141 status = decode_compound_hdr(&xdr, &hdr);
4142 if (status)
4143 goto out;
4144 status = decode_putfh(&xdr);
4145 if (status)
4146 goto out;
4147 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004149 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150}
4151
4152/*
4153 * Decode OPEN response
4154 */
Al Viro8687b632006-10-19 23:28:48 -07004155static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156{
Andy Adamson05d564f2008-12-23 16:06:15 -05004157 struct xdr_stream xdr;
4158 struct compound_hdr hdr;
4159 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160
Andy Adamson05d564f2008-12-23 16:06:15 -05004161 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4162 status = decode_compound_hdr(&xdr, &hdr);
4163 if (status)
4164 goto out;
4165 status = decode_putfh(&xdr);
4166 if (status)
4167 goto out;
4168 status = decode_open(&xdr, res);
4169 if (status)
4170 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004171 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004173 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174}
4175
4176/*
4177 * Decode SETATTR response
4178 */
Al Viro8687b632006-10-19 23:28:48 -07004179static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180{
Andy Adamson05d564f2008-12-23 16:06:15 -05004181 struct xdr_stream xdr;
4182 struct compound_hdr hdr;
4183 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184
Andy Adamson05d564f2008-12-23 16:06:15 -05004185 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4186 status = decode_compound_hdr(&xdr, &hdr);
4187 if (status)
4188 goto out;
4189 status = decode_putfh(&xdr);
4190 if (status)
4191 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004192 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004193 if (status)
4194 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004195 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004197 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198}
4199
4200/*
4201 * Decode LOCK response
4202 */
Al Viro8687b632006-10-19 23:28:48 -07004203static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204{
4205 struct xdr_stream xdr;
4206 struct compound_hdr hdr;
4207 int status;
4208
4209 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4210 status = decode_compound_hdr(&xdr, &hdr);
4211 if (status)
4212 goto out;
4213 status = decode_putfh(&xdr);
4214 if (status)
4215 goto out;
4216 status = decode_lock(&xdr, res);
4217out:
4218 return status;
4219}
4220
4221/*
4222 * Decode LOCKT response
4223 */
Al Viro8687b632006-10-19 23:28:48 -07004224static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225{
4226 struct xdr_stream xdr;
4227 struct compound_hdr hdr;
4228 int status;
4229
4230 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4231 status = decode_compound_hdr(&xdr, &hdr);
4232 if (status)
4233 goto out;
4234 status = decode_putfh(&xdr);
4235 if (status)
4236 goto out;
4237 status = decode_lockt(&xdr, res);
4238out:
4239 return status;
4240}
4241
4242/*
4243 * Decode LOCKU response
4244 */
Al Viro8687b632006-10-19 23:28:48 -07004245static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_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_locku(&xdr, res);
4259out:
4260 return status;
4261}
4262
4263/*
4264 * Decode READLINK response
4265 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004266static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4267 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268{
4269 struct xdr_stream xdr;
4270 struct compound_hdr hdr;
4271 int status;
4272
4273 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4274 status = decode_compound_hdr(&xdr, &hdr);
4275 if (status)
4276 goto out;
4277 status = decode_putfh(&xdr);
4278 if (status)
4279 goto out;
4280 status = decode_readlink(&xdr, rqstp);
4281out:
4282 return status;
4283}
4284
4285/*
4286 * Decode READDIR response
4287 */
Al Viro8687b632006-10-19 23:28:48 -07004288static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289{
4290 struct xdr_stream xdr;
4291 struct compound_hdr hdr;
4292 int status;
4293
4294 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4295 status = decode_compound_hdr(&xdr, &hdr);
4296 if (status)
4297 goto out;
4298 status = decode_putfh(&xdr);
4299 if (status)
4300 goto out;
4301 status = decode_readdir(&xdr, rqstp, res);
4302out:
4303 return status;
4304}
4305
4306/*
4307 * Decode Read response
4308 */
Al Viro8687b632006-10-19 23:28:48 -07004309static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310{
4311 struct xdr_stream xdr;
4312 struct compound_hdr hdr;
4313 int status;
4314
4315 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4316 status = decode_compound_hdr(&xdr, &hdr);
4317 if (status)
4318 goto out;
4319 status = decode_putfh(&xdr);
4320 if (status)
4321 goto out;
4322 status = decode_read(&xdr, rqstp, res);
4323 if (!status)
4324 status = res->count;
4325out:
4326 return status;
4327}
4328
4329/*
4330 * Decode WRITE response
4331 */
Al Viro8687b632006-10-19 23:28:48 -07004332static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333{
4334 struct xdr_stream xdr;
4335 struct compound_hdr hdr;
4336 int status;
4337
4338 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4339 status = decode_compound_hdr(&xdr, &hdr);
4340 if (status)
4341 goto out;
4342 status = decode_putfh(&xdr);
4343 if (status)
4344 goto out;
4345 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004346 if (status)
4347 goto out;
4348 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 if (!status)
4350 status = res->count;
4351out:
4352 return status;
4353}
4354
4355/*
4356 * Decode COMMIT response
4357 */
Al Viro8687b632006-10-19 23:28:48 -07004358static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359{
4360 struct xdr_stream xdr;
4361 struct compound_hdr hdr;
4362 int status;
4363
4364 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4365 status = decode_compound_hdr(&xdr, &hdr);
4366 if (status)
4367 goto out;
4368 status = decode_putfh(&xdr);
4369 if (status)
4370 goto out;
4371 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004372 if (status)
4373 goto out;
4374 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375out:
4376 return status;
4377}
4378
4379/*
4380 * FSINFO request
4381 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04004382static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4383 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384{
4385 struct xdr_stream xdr;
4386 struct compound_hdr hdr;
4387 int status;
4388
4389 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4390 status = decode_compound_hdr(&xdr, &hdr);
4391 if (!status)
4392 status = decode_putfh(&xdr);
4393 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04004394 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 return status;
4396}
4397
4398/*
4399 * PATHCONF request
4400 */
Benny Halevyd45b2982009-04-01 09:21:58 -04004401static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4402 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403{
4404 struct xdr_stream xdr;
4405 struct compound_hdr hdr;
4406 int status;
4407
4408 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4409 status = decode_compound_hdr(&xdr, &hdr);
4410 if (!status)
4411 status = decode_putfh(&xdr);
4412 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04004413 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 return status;
4415}
4416
4417/*
4418 * STATFS request
4419 */
Benny Halevy24ad1482009-04-01 09:21:56 -04004420static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4421 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422{
4423 struct xdr_stream xdr;
4424 struct compound_hdr hdr;
4425 int status;
4426
4427 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4428 status = decode_compound_hdr(&xdr, &hdr);
4429 if (!status)
4430 status = decode_putfh(&xdr);
4431 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04004432 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433 return status;
4434}
4435
4436/*
4437 * GETATTR_BITMAP request
4438 */
Al Viro8687b632006-10-19 23:28:48 -07004439static 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 -07004440{
4441 struct xdr_stream xdr;
4442 struct compound_hdr hdr;
4443 int status;
4444
4445 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4446 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4447 goto out;
4448 if ((status = decode_putfh(&xdr)) != 0)
4449 goto out;
4450 status = decode_server_caps(&xdr, res);
4451out:
4452 return status;
4453}
4454
4455/*
4456 * Decode RENEW response
4457 */
Al Viro8687b632006-10-19 23:28:48 -07004458static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459{
4460 struct xdr_stream xdr;
4461 struct compound_hdr hdr;
4462 int status;
4463
4464 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4465 status = decode_compound_hdr(&xdr, &hdr);
4466 if (!status)
4467 status = decode_renew(&xdr);
4468 return status;
4469}
4470
4471/*
4472 * a SETCLIENTID request
4473 */
Al Viro8687b632006-10-19 23:28:48 -07004474static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004475 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476{
4477 struct xdr_stream xdr;
4478 struct compound_hdr hdr;
4479 int status;
4480
4481 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4482 status = decode_compound_hdr(&xdr, &hdr);
4483 if (!status)
4484 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 return status;
4486}
4487
4488/*
4489 * a SETCLIENTID_CONFIRM request
4490 */
Al Viro8687b632006-10-19 23:28:48 -07004491static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492{
4493 struct xdr_stream xdr;
4494 struct compound_hdr hdr;
4495 int status;
4496
4497 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4498 status = decode_compound_hdr(&xdr, &hdr);
4499 if (!status)
4500 status = decode_setclientid_confirm(&xdr);
4501 if (!status)
4502 status = decode_putrootfh(&xdr);
4503 if (!status)
4504 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 return status;
4506}
4507
4508/*
4509 * DELEGRETURN request
4510 */
Al Viro8687b632006-10-19 23:28:48 -07004511static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512{
4513 struct xdr_stream xdr;
4514 struct compound_hdr hdr;
4515 int status;
4516
4517 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4518 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004519 if (status != 0)
4520 goto out;
4521 status = decode_putfh(&xdr);
4522 if (status != 0)
4523 goto out;
4524 status = decode_delegreturn(&xdr);
4525 decode_getfattr(&xdr, res->fattr, res->server);
4526out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 return status;
4528}
4529
Trond Myklebust683b57b2006-06-09 09:34:22 -04004530/*
4531 * FS_LOCATIONS request
4532 */
Benny Halevy22958462009-04-01 09:22:02 -04004533static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4534 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004535{
4536 struct xdr_stream xdr;
4537 struct compound_hdr hdr;
4538 int status;
4539
4540 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4541 status = decode_compound_hdr(&xdr, &hdr);
4542 if (status != 0)
4543 goto out;
4544 if ((status = decode_putfh(&xdr)) != 0)
4545 goto out;
4546 if ((status = decode_lookup(&xdr)) != 0)
4547 goto out;
4548 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04004549 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4550 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04004551out:
4552 return status;
4553}
4554
Al Viro0dbb4c62006-10-19 23:28:49 -07004555__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556{
4557 uint32_t bitmap[2] = {0};
4558 uint32_t len;
4559
4560 if (!*p++) {
4561 if (!*p)
4562 return ERR_PTR(-EAGAIN);
4563 entry->eof = 1;
4564 return ERR_PTR(-EBADCOOKIE);
4565 }
4566
4567 entry->prev_cookie = entry->cookie;
4568 p = xdr_decode_hyper(p, &entry->cookie);
4569 entry->len = ntohl(*p++);
4570 entry->name = (const char *) p;
4571 p += XDR_QUADLEN(entry->len);
4572
4573 /*
4574 * In case the server doesn't return an inode number,
4575 * we fake one here. (We don't use inode number 0,
4576 * since glibc seems to choke on it...)
4577 */
4578 entry->ino = 1;
4579
4580 len = ntohl(*p++); /* bitmap length */
4581 if (len-- > 0) {
4582 bitmap[0] = ntohl(*p++);
4583 if (len-- > 0) {
4584 bitmap[1] = ntohl(*p++);
4585 p += len;
4586 }
4587 }
4588 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4589 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004590 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4591 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4592 /* Ignore the return value of rdattr_error for now */
4593 p++;
4594 len--;
4595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4597 xdr_decode_hyper(p, &entry->ino);
4598 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4599 xdr_decode_hyper(p, &entry->ino);
4600 p += len;
4601 }
4602
4603 entry->eof = !p[0] && p[1];
4604 return p;
4605}
4606
4607/*
4608 * We need to translate between nfs status return values and
4609 * the local errno values which may not be the same.
4610 */
4611static struct {
4612 int stat;
4613 int errno;
4614} nfs_errtbl[] = {
4615 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03004616 { NFS4ERR_PERM, -EPERM },
4617 { NFS4ERR_NOENT, -ENOENT },
4618 { NFS4ERR_IO, -errno_NFSERR_IO},
4619 { NFS4ERR_NXIO, -ENXIO },
4620 { NFS4ERR_ACCESS, -EACCES },
4621 { NFS4ERR_EXIST, -EEXIST },
4622 { NFS4ERR_XDEV, -EXDEV },
4623 { NFS4ERR_NOTDIR, -ENOTDIR },
4624 { NFS4ERR_ISDIR, -EISDIR },
4625 { NFS4ERR_INVAL, -EINVAL },
4626 { NFS4ERR_FBIG, -EFBIG },
4627 { NFS4ERR_NOSPC, -ENOSPC },
4628 { NFS4ERR_ROFS, -EROFS },
4629 { NFS4ERR_MLINK, -EMLINK },
4630 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4631 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4632 { NFS4ERR_DQUOT, -EDQUOT },
4633 { NFS4ERR_STALE, -ESTALE },
4634 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4635 { NFS4ERR_BADOWNER, -EINVAL },
4636 { NFS4ERR_BADNAME, -EINVAL },
4637 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4638 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4639 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4640 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4641 { NFS4ERR_BADTYPE, -EBADTYPE },
4642 { NFS4ERR_LOCKED, -EAGAIN },
4643 { NFS4ERR_RESOURCE, -EREMOTEIO },
4644 { NFS4ERR_SYMLINK, -ELOOP },
4645 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4646 { NFS4ERR_DEADLOCK, -EDEADLK },
4647 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 * to be handled by a
4649 * middle-layer.
4650 */
Benny Halevy856dff32008-03-31 17:39:06 +03004651 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652};
4653
4654/*
4655 * Convert an NFS error code to a local one.
4656 * This one is used jointly by NFSv2 and NFSv3.
4657 */
4658static int
David Howells0a8ea432006-08-22 20:06:08 -04004659nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660{
4661 int i;
4662 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4663 if (nfs_errtbl[i].stat == stat)
4664 return nfs_errtbl[i].errno;
4665 }
4666 if (stat <= 10000 || stat > 10100) {
4667 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03004668 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 }
4670 /* If we cannot translate the error, the recovery routines should
4671 * handle it.
4672 * Note: remaining NFSv4 error codes have values > 10000, so should
4673 * not conflict with native Linux error codes.
4674 */
Benny Halevy856dff32008-03-31 17:39:06 +03004675 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676}
4677
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678#define PROC(proc, argtype, restype) \
4679[NFSPROC4_CLNT_##proc] = { \
4680 .p_proc = NFSPROC4_COMPOUND, \
4681 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4682 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004683 .p_arglen = NFS4_##argtype##_sz, \
4684 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004685 .p_statidx = NFSPROC4_CLNT_##proc, \
4686 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05004687}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688
4689struct rpc_procinfo nfs4_procedures[] = {
4690 PROC(READ, enc_read, dec_read),
4691 PROC(WRITE, enc_write, dec_write),
4692 PROC(COMMIT, enc_commit, dec_commit),
4693 PROC(OPEN, enc_open, dec_open),
4694 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4695 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4696 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4697 PROC(CLOSE, enc_close, dec_close),
4698 PROC(SETATTR, enc_setattr, dec_setattr),
4699 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4700 PROC(RENEW, enc_renew, dec_renew),
4701 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4702 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4703 PROC(LOCK, enc_lock, dec_lock),
4704 PROC(LOCKT, enc_lockt, dec_lockt),
4705 PROC(LOCKU, enc_locku, dec_locku),
4706 PROC(ACCESS, enc_access, dec_access),
4707 PROC(GETATTR, enc_getattr, dec_getattr),
4708 PROC(LOOKUP, enc_lookup, dec_lookup),
4709 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4710 PROC(REMOVE, enc_remove, dec_remove),
4711 PROC(RENAME, enc_rename, dec_rename),
4712 PROC(LINK, enc_link, dec_link),
4713 PROC(SYMLINK, enc_symlink, dec_symlink),
4714 PROC(CREATE, enc_create, dec_create),
4715 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4716 PROC(STATFS, enc_statfs, dec_statfs),
4717 PROC(READLINK, enc_readlink, dec_readlink),
4718 PROC(READDIR, enc_readdir, dec_readdir),
4719 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4720 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004721 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004722 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004723 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724};
4725
4726struct rpc_version nfs_version4 = {
4727 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004728 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 .procs = nfs4_procedures
4730};
4731
4732/*
4733 * Local variables:
4734 * c-basic-offset: 8
4735 * End:
4736 */