blob: 5b944cd572183cfd3f0d5ca18ca02d5ba1a7dfdb [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)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400247
248#if defined(CONFIG_NFS_V4_1)
249#define encode_sequence_maxsz 0 /* stub */
250#define decode_sequence_maxsz 0 /* stub */
251#else /* CONFIG_NFS_V4_1 */
252#define encode_sequence_maxsz 0
253#define decode_sequence_maxsz 0
254#endif /* CONFIG_NFS_V4_1 */
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
257#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
258#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400259 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400261 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400263 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400265 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400267 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400269 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400271 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400273 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400275 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400277 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400279 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400281 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400283 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400285 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400286 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400288 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400290 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400291 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400293 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400295 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400296 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400298 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400300 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400301 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400303 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400304 encode_putfh_maxsz + \
305 encode_savefh_maxsz + \
306 encode_open_maxsz + \
307 encode_getfh_maxsz + \
308 encode_getattr_maxsz + \
309 encode_restorefh_maxsz + \
310 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400312 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400313 decode_putfh_maxsz + \
314 decode_savefh_maxsz + \
315 decode_open_maxsz + \
316 decode_getfh_maxsz + \
317 decode_getattr_maxsz + \
318 decode_restorefh_maxsz + \
319 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400320#define NFS4_enc_open_confirm_sz \
321 (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_open_confirm_maxsz)
324#define NFS4_dec_open_confirm_sz \
325 (compound_decode_hdr_maxsz + \
326 decode_putfh_maxsz + \
327 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400329 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400331 encode_open_maxsz + \
332 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400334 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400336 decode_open_maxsz + \
337 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#define NFS4_enc_open_downgrade_sz \
339 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400340 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400341 encode_putfh_maxsz + \
342 encode_open_downgrade_maxsz + \
343 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_dec_open_downgrade_sz \
345 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400346 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400347 decode_putfh_maxsz + \
348 decode_open_downgrade_maxsz + \
349 decode_getattr_maxsz)
350#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400351 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 encode_putfh_maxsz + \
353 encode_close_maxsz + \
354 encode_getattr_maxsz)
355#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400356 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400357 decode_putfh_maxsz + \
358 decode_close_maxsz + \
359 decode_getattr_maxsz)
360#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400361 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400362 encode_putfh_maxsz + \
363 encode_setattr_maxsz + \
364 encode_getattr_maxsz)
365#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400366 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400367 decode_putfh_maxsz + \
368 decode_setattr_maxsz + \
369 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400371 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 encode_putfh_maxsz + \
373 encode_fsinfo_maxsz)
374#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400375 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 decode_putfh_maxsz + \
377 decode_fsinfo_maxsz)
378#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
379 encode_renew_maxsz)
380#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
381 decode_renew_maxsz)
382#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
383 encode_setclientid_maxsz)
384#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
385 decode_setclientid_maxsz)
386#define NFS4_enc_setclientid_confirm_sz \
387 (compound_encode_hdr_maxsz + \
388 encode_setclientid_confirm_maxsz + \
389 encode_putrootfh_maxsz + \
390 encode_fsinfo_maxsz)
391#define NFS4_dec_setclientid_confirm_sz \
392 (compound_decode_hdr_maxsz + \
393 decode_setclientid_confirm_maxsz + \
394 decode_putrootfh_maxsz + \
395 decode_fsinfo_maxsz)
396#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400397 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400399 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400401 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400403 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400405 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400407 encode_lockt_maxsz)
408#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400409 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_putfh_maxsz + \
411 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400415 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400421 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400423 encode_access_maxsz + \
424 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400428 decode_access_maxsz + \
429 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400431 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 encode_putfh_maxsz + \
433 encode_getattr_maxsz)
434#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400435 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 decode_putfh_maxsz + \
437 decode_getattr_maxsz)
438#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400439 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 encode_putfh_maxsz + \
441 encode_lookup_maxsz + \
442 encode_getattr_maxsz + \
443 encode_getfh_maxsz)
444#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400445 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400447 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 decode_getattr_maxsz + \
449 decode_getfh_maxsz)
450#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 encode_putrootfh_maxsz + \
453 encode_getattr_maxsz + \
454 encode_getfh_maxsz)
455#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 decode_putrootfh_maxsz + \
458 decode_getattr_maxsz + \
459 decode_getfh_maxsz)
460#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400463 encode_remove_maxsz + \
464 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400468 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400469 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 encode_putfh_maxsz + \
473 encode_savefh_maxsz + \
474 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400475 encode_rename_maxsz + \
476 encode_getattr_maxsz + \
477 encode_restorefh_maxsz + \
478 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 decode_putfh_maxsz + \
482 decode_savefh_maxsz + \
483 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400484 decode_rename_maxsz + \
485 decode_getattr_maxsz + \
486 decode_restorefh_maxsz + \
487 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
491 encode_savefh_maxsz + \
492 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400493 encode_link_maxsz + \
494 decode_getattr_maxsz + \
495 encode_restorefh_maxsz + \
496 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400498 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_putfh_maxsz + \
500 decode_savefh_maxsz + \
501 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400502 decode_link_maxsz + \
503 decode_getattr_maxsz + \
504 decode_restorefh_maxsz + \
505 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 encode_putfh_maxsz + \
509 encode_symlink_maxsz + \
510 encode_getattr_maxsz + \
511 encode_getfh_maxsz)
512#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 decode_putfh_maxsz + \
515 decode_symlink_maxsz + \
516 decode_getattr_maxsz + \
517 decode_getfh_maxsz)
518#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400521 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400523 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400525 encode_restorefh_maxsz + \
526 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400530 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400532 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400534 decode_restorefh_maxsz + \
535 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400537 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 encode_putfh_maxsz + \
539 encode_getattr_maxsz)
540#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 decode_putfh_maxsz + \
543 decode_getattr_maxsz)
544#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400545 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400547 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400549 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400551 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800554 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 encode_getattr_maxsz)
556#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400557 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800558 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 decode_getattr_maxsz)
560#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100563 encode_delegreturn_maxsz + \
564 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100567 decode_delegreturn_maxsz + \
568 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000569#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000571 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400572 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000573#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000575 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400576 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000577#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000579 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400580 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000581#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000583 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400584 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400585#define NFS4_enc_fs_locations_sz \
586 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400588 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400589 encode_lookup_maxsz + \
590 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400591#define NFS4_dec_fs_locations_sz \
592 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400594 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400595 decode_lookup_maxsz + \
596 decode_fs_locations_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Trond Myklebustbca79472009-03-11 14:10:26 -0400598static const umode_t nfs_type2fmt[] = {
599 [NF4BAD] = 0,
600 [NF4REG] = S_IFREG,
601 [NF4DIR] = S_IFDIR,
602 [NF4BLK] = S_IFBLK,
603 [NF4CHR] = S_IFCHR,
604 [NF4LNK] = S_IFLNK,
605 [NF4SOCK] = S_IFSOCK,
606 [NF4FIFO] = S_IFIFO,
607 [NF4ATTRDIR] = 0,
608 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609};
610
611struct compound_hdr {
612 int32_t status;
613 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500614 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 uint32_t taglen;
616 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400617 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400618 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619};
620
621/*
622 * START OF "GENERIC" ENCODE ROUTINES.
623 * These may look a little ugly since they are imported from a "generic"
624 * set of XDR encode/decode routines which are intended to be shared by
625 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
626 *
627 * If the pain of reading these is too great, it should be a straightforward
628 * task to translate them into Linux-specific versions which are more
629 * consistent with the style used in NFSv2/v3...
630 */
631#define WRITE32(n) *p++ = htonl(n)
632#define WRITE64(n) do { \
633 *p++ = htonl((uint32_t)((n) >> 32)); \
634 *p++ = htonl((uint32_t)(n)); \
635} while (0)
636#define WRITEMEM(ptr,nbytes) do { \
637 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
638} while (0)
639
640#define RESERVE_SPACE(nbytes) do { \
641 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 BUG_ON(!p); \
643} while (0)
644
645static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
646{
Al Viro8687b632006-10-19 23:28:48 -0700647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 p = xdr_reserve_space(xdr, 4 + len);
650 BUG_ON(p == NULL);
651 xdr_encode_opaque(p, str, len);
652}
653
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400654static void encode_compound_hdr(struct xdr_stream *xdr,
655 struct rpc_rqst *req,
656 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
Al Viro8687b632006-10-19 23:28:48 -0700658 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400659 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
660
661 /* initialize running count of expected bytes in reply.
662 * NOTE: the replied tag SHOULD be the same is the one sent,
663 * but this is not required as a MUST for the server to do so. */
664 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
667 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
668 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
669 WRITE32(hdr->taglen);
670 WRITEMEM(hdr->tag, hdr->taglen);
Benny Halevy66cc0422009-04-01 09:22:10 -0400671 WRITE32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500672 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500674}
675
676static void encode_nops(struct compound_hdr *hdr)
677{
678 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
681static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
682{
Al Viro8687b632006-10-19 23:28:48 -0700683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
685 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
686 BUG_ON(p == NULL);
687 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
688}
689
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500690static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
692 char owner_name[IDMAP_NAMESZ];
693 char owner_group[IDMAP_NAMESZ];
694 int owner_namelen = 0;
695 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700696 __be32 *p;
697 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 int len;
699 uint32_t bmval0 = 0;
700 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 /*
703 * We reserve enough space to write the entire attribute buffer at once.
704 * In the worst-case, this would be
705 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
706 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000707 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 */
709 len = 16;
710
711 /* Sigh */
712 if (iap->ia_valid & ATTR_SIZE)
713 len += 8;
714 if (iap->ia_valid & ATTR_MODE)
715 len += 4;
716 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400717 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400719 dprintk("nfs: couldn't resolve uid %d to string\n",
720 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 /* XXX */
722 strcpy(owner_name, "nobody");
723 owner_namelen = sizeof("nobody") - 1;
724 /* goto out; */
725 }
726 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
727 }
728 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400729 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400731 dprintk("nfs: couldn't resolve gid %d to string\n",
732 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 strcpy(owner_group, "nobody");
734 owner_grouplen = sizeof("nobody") - 1;
735 /* goto out; */
736 }
737 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
738 }
739 if (iap->ia_valid & ATTR_ATIME_SET)
740 len += 16;
741 else if (iap->ia_valid & ATTR_ATIME)
742 len += 4;
743 if (iap->ia_valid & ATTR_MTIME_SET)
744 len += 16;
745 else if (iap->ia_valid & ATTR_MTIME)
746 len += 4;
747 RESERVE_SPACE(len);
748
749 /*
750 * We write the bitmap length now, but leave the bitmap and the attribute
751 * buffer length to be backfilled at the end of this routine.
752 */
753 WRITE32(2);
754 q = p;
755 p += 3;
756
757 if (iap->ia_valid & ATTR_SIZE) {
758 bmval0 |= FATTR4_WORD0_SIZE;
759 WRITE64(iap->ia_size);
760 }
761 if (iap->ia_valid & ATTR_MODE) {
762 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100763 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765 if (iap->ia_valid & ATTR_UID) {
766 bmval1 |= FATTR4_WORD1_OWNER;
767 WRITE32(owner_namelen);
768 WRITEMEM(owner_name, owner_namelen);
769 }
770 if (iap->ia_valid & ATTR_GID) {
771 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
772 WRITE32(owner_grouplen);
773 WRITEMEM(owner_group, owner_grouplen);
774 }
775 if (iap->ia_valid & ATTR_ATIME_SET) {
776 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
777 WRITE32(NFS4_SET_TO_CLIENT_TIME);
778 WRITE32(0);
779 WRITE32(iap->ia_mtime.tv_sec);
780 WRITE32(iap->ia_mtime.tv_nsec);
781 }
782 else if (iap->ia_valid & ATTR_ATIME) {
783 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
784 WRITE32(NFS4_SET_TO_SERVER_TIME);
785 }
786 if (iap->ia_valid & ATTR_MTIME_SET) {
787 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
788 WRITE32(NFS4_SET_TO_CLIENT_TIME);
789 WRITE32(0);
790 WRITE32(iap->ia_mtime.tv_sec);
791 WRITE32(iap->ia_mtime.tv_nsec);
792 }
793 else if (iap->ia_valid & ATTR_MTIME) {
794 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
795 WRITE32(NFS4_SET_TO_SERVER_TIME);
796 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /*
799 * Now we backfill the bitmap and the attribute buffer length.
800 */
801 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400802 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 len, ((char *)p - (char *)q) + 4);
804 BUG();
805 }
806 len = (char *)p - (char *)q - 12;
807 *q++ = htonl(bmval0);
808 *q++ = htonl(bmval1);
809 *q++ = htonl(len);
810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
813
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500814static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Al Viro8687b632006-10-19 23:28:48 -0700816 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 RESERVE_SPACE(8);
819 WRITE32(OP_ACCESS);
820 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500821 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400822 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500825static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
Al Viro8687b632006-10-19 23:28:48 -0700827 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400829 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700831 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400832 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500833 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400834 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835}
836
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500837static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
Al Viro8687b632006-10-19 23:28:48 -0700839 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500840
Andy Adamson05d564f2008-12-23 16:06:15 -0500841 RESERVE_SPACE(16);
842 WRITE32(OP_COMMIT);
843 WRITE64(args->offset);
844 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500845 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400846 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500849static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Al Viro8687b632006-10-19 23:28:48 -0700851 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 RESERVE_SPACE(8);
854 WRITE32(OP_CREATE);
855 WRITE32(create->ftype);
856
857 switch (create->ftype) {
858 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400859 RESERVE_SPACE(4);
860 WRITE32(create->u.symlink.len);
861 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
863
864 case NF4BLK: case NF4CHR:
865 RESERVE_SPACE(8);
866 WRITE32(create->u.device.specdata1);
867 WRITE32(create->u.device.specdata2);
868 break;
869
870 default:
871 break;
872 }
873
874 RESERVE_SPACE(4 + create->name->len);
875 WRITE32(create->name->len);
876 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500877 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400878 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500880 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500883static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
Andy Adamson05d564f2008-12-23 16:06:15 -0500885 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Andy Adamson05d564f2008-12-23 16:06:15 -0500887 RESERVE_SPACE(12);
888 WRITE32(OP_GETATTR);
889 WRITE32(1);
890 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500891 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400892 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893}
894
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500895static 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 -0700896{
Andy Adamson05d564f2008-12-23 16:06:15 -0500897 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Andy Adamson05d564f2008-12-23 16:06:15 -0500899 RESERVE_SPACE(16);
900 WRITE32(OP_GETATTR);
901 WRITE32(2);
902 WRITE32(bm0);
903 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500904 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400905 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500908static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500910 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
911 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500914static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500916 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
917 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500920static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400921{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500922 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
923 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400924}
925
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500926static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Al Viro8687b632006-10-19 23:28:48 -0700928 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 RESERVE_SPACE(4);
931 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500932 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400933 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500936static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
Al Viro8687b632006-10-19 23:28:48 -0700938 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 RESERVE_SPACE(8 + name->len);
941 WRITE32(OP_LINK);
942 WRITE32(name->len);
943 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500944 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400945 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946}
947
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100948static inline int nfs4_lock_type(struct file_lock *fl, int block)
949{
950 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
951 return block ? NFS4_READW_LT : NFS4_READ_LT;
952 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
953}
954
955static inline uint64_t nfs4_lock_length(struct file_lock *fl)
956{
957 if (fl->fl_end == OFFSET_MAX)
958 return ~(uint64_t)0;
959 return fl->fl_end - fl->fl_start + 1;
960}
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962/*
963 * opcode,type,reclaim,offset,length,new_lock_owner = 32
964 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
965 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500966static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
Al Viro8687b632006-10-19 23:28:48 -0700968 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 RESERVE_SPACE(32);
971 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100972 WRITE32(nfs4_lock_type(args->fl, args->block));
973 WRITE32(args->reclaim);
974 WRITE64(args->fl->fl_start);
975 WRITE64(nfs4_lock_length(args->fl));
976 WRITE32(args->new_lock_owner);
977 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400978 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100979 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400980 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100981 WRITE32(args->lock_seqid->sequence->counter);
982 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400983 WRITE32(16);
984 WRITEMEM("lock id:", 8);
985 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400988 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
989 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100990 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
Andy Adamsond0179312008-12-23 16:06:17 -0500992 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400993 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500996static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997{
Al Viro8687b632006-10-19 23:28:48 -0700998 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001000 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001002 WRITE32(nfs4_lock_type(args->fl, 0));
1003 WRITE64(args->fl->fl_start);
1004 WRITE64(nfs4_lock_length(args->fl));
1005 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001006 WRITE32(16);
1007 WRITEMEM("lock id:", 8);
1008 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001009 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001010 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001013static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Al Viro8687b632006-10-19 23:28:48 -07001015 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001017 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001019 WRITE32(nfs4_lock_type(args->fl, 0));
1020 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001021 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001022 WRITE64(args->fl->fl_start);
1023 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001024 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001025 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
1027
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001028static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029{
1030 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033 RESERVE_SPACE(8 + len);
1034 WRITE32(OP_LOOKUP);
1035 WRITE32(len);
1036 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001037 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001038 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039}
1040
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001041static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
Al Viro8687b632006-10-19 23:28:48 -07001043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001046 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001047 case FMODE_READ:
1048 WRITE32(NFS4_SHARE_ACCESS_READ);
1049 break;
1050 case FMODE_WRITE:
1051 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1052 break;
1053 case FMODE_READ|FMODE_WRITE:
1054 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1055 break;
1056 default:
1057 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 }
1059 WRITE32(0); /* for linux, share_deny = 0 always */
1060}
1061
1062static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1063{
Al Viro8687b632006-10-19 23:28:48 -07001064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 /*
1066 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1067 * owner 4 = 32
1068 */
1069 RESERVE_SPACE(8);
1070 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001071 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001072 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001073 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001075 WRITE32(16);
1076 WRITEMEM("open id:", 8);
1077 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
1080static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1081{
Al Viro8687b632006-10-19 23:28:48 -07001082 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 RESERVE_SPACE(4);
1085 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001086 case 0:
1087 WRITE32(NFS4_CREATE_UNCHECKED);
1088 encode_attrs(xdr, arg->u.attrs, arg->server);
1089 break;
1090 default:
1091 WRITE32(NFS4_CREATE_EXCLUSIVE);
1092 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 }
1094}
1095
1096static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1097{
Al Viro8687b632006-10-19 23:28:48 -07001098 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 RESERVE_SPACE(4);
1101 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001102 case 0:
1103 WRITE32(NFS4_OPEN_NOCREATE);
1104 break;
1105 default:
1106 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1107 WRITE32(NFS4_OPEN_CREATE);
1108 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 }
1110}
1111
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001112static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
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
1116 RESERVE_SPACE(4);
1117 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001118 case 0:
1119 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1120 break;
1121 case FMODE_READ:
1122 WRITE32(NFS4_OPEN_DELEGATE_READ);
1123 break;
1124 case FMODE_WRITE|FMODE_READ:
1125 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1126 break;
1127 default:
1128 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 }
1130}
1131
1132static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1133{
Al Viro8687b632006-10-19 23:28:48 -07001134 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 RESERVE_SPACE(4);
1137 WRITE32(NFS4_OPEN_CLAIM_NULL);
1138 encode_string(xdr, name->len, name->name);
1139}
1140
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001141static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Al Viro8687b632006-10-19 23:28:48 -07001143 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
1145 RESERVE_SPACE(4);
1146 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1147 encode_delegation_type(xdr, type);
1148}
1149
1150static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1151{
Al Viro8687b632006-10-19 23:28:48 -07001152 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001154 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001156 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 encode_string(xdr, name->len, name->name);
1158}
1159
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001160static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161{
1162 encode_openhdr(xdr, arg);
1163 encode_opentype(xdr, arg);
1164 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001165 case NFS4_OPEN_CLAIM_NULL:
1166 encode_claim_null(xdr, arg->name);
1167 break;
1168 case NFS4_OPEN_CLAIM_PREVIOUS:
1169 encode_claim_previous(xdr, arg->u.delegation_type);
1170 break;
1171 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1172 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1173 break;
1174 default:
1175 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 }
Andy Adamsond0179312008-12-23 16:06:17 -05001177 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001178 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001181static 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 -07001182{
Al Viro8687b632006-10-19 23:28:48 -07001183 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001185 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001187 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001188 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001189 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001190 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
Al Viro8687b632006-10-19 23:28:48 -07001195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001197 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001199 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001200 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001201 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001202 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001203 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204}
1205
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001206static void
Andy Adamsond0179312008-12-23 16:06:17 -05001207encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
1209 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001210 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 RESERVE_SPACE(8 + len);
1213 WRITE32(OP_PUTFH);
1214 WRITE32(len);
1215 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001216 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001217 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218}
1219
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001220static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
Andy Adamson05d564f2008-12-23 16:06:15 -05001222 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001223
Andy Adamson05d564f2008-12-23 16:06:15 -05001224 RESERVE_SPACE(4);
1225 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001226 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001227 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
1230static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001235 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (ctx->state != NULL) {
1237 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001238 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001240 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001243static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244{
Al Viro8687b632006-10-19 23:28:48 -07001245 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 RESERVE_SPACE(4);
1248 WRITE32(OP_READ);
1249
1250 encode_stateid(xdr, args->context);
1251
1252 RESERVE_SPACE(12);
1253 WRITE64(args->offset);
1254 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001255 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001256 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257}
1258
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001259static 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 -07001260{
Manoj Naik97d312d2005-06-22 17:16:39 +00001261 uint32_t attrs[2] = {
1262 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1263 FATTR4_WORD1_MOUNTED_ON_FILEID,
1264 };
Al Viro8687b632006-10-19 23:28:48 -07001265 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001267 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 WRITE32(OP_READDIR);
1269 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001270 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1272 WRITE32(readdir->count);
1273 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001274 /* Switch to mounted_on_fileid if the server supports it */
1275 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1276 attrs[0] &= ~FATTR4_WORD0_FILEID;
1277 else
1278 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1279 WRITE32(attrs[0] & readdir->bitmask[0]);
1280 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001281 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001282 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001283 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1284 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001285 (unsigned long long)readdir->cookie,
1286 ((u32 *)readdir->verifier.data)[0],
1287 ((u32 *)readdir->verifier.data)[1],
1288 attrs[0] & readdir->bitmask[0],
1289 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290}
1291
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001292static 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 -07001293{
Al Viro8687b632006-10-19 23:28:48 -07001294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 RESERVE_SPACE(4);
1297 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001298 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001299 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300}
1301
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001302static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
Al Viro8687b632006-10-19 23:28:48 -07001304 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
1306 RESERVE_SPACE(8 + name->len);
1307 WRITE32(OP_REMOVE);
1308 WRITE32(name->len);
1309 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001310 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001311 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static 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 -07001315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 RESERVE_SPACE(8 + oldname->len);
1319 WRITE32(OP_RENAME);
1320 WRITE32(oldname->len);
1321 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001322
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 RESERVE_SPACE(4 + newname->len);
1324 WRITE32(newname->len);
1325 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001326 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001327 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328}
1329
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001330static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331{
Al Viro8687b632006-10-19 23:28:48 -07001332 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 RESERVE_SPACE(12);
1335 WRITE32(OP_RENEW);
1336 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001337 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001338 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339}
1340
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001341static void
Andy Adamsond0179312008-12-23 16:06:17 -05001342encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001343{
Al Viro8687b632006-10-19 23:28:48 -07001344 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001345
1346 RESERVE_SPACE(4);
1347 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001348 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001349 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001350}
1351
1352static int
Andy Adamsond0179312008-12-23 16:06:17 -05001353encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001354{
Al Viro8687b632006-10-19 23:28:48 -07001355 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001356
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001357 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001358 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001359 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001360 RESERVE_SPACE(2*4);
1361 WRITE32(1);
1362 WRITE32(FATTR4_WORD0_ACL);
1363 if (arg->acl_len % 4)
1364 return -EINVAL;
1365 RESERVE_SPACE(4);
1366 WRITE32(arg->acl_len);
1367 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001368 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001369 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001370 return 0;
1371}
1372
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001373static void
Andy Adamsond0179312008-12-23 16:06:17 -05001374encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
Al Viro8687b632006-10-19 23:28:48 -07001376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 RESERVE_SPACE(4);
1379 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001380 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001381 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001384static 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 -07001385{
Al Viro8687b632006-10-19 23:28:48 -07001386 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001387
Andy Adamson05d564f2008-12-23 16:06:15 -05001388 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1389 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001390 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001391 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001392 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001393 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394}
1395
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001396static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
Al Viro8687b632006-10-19 23:28:48 -07001398 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001400 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001402 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1405 RESERVE_SPACE(4);
1406 WRITE32(setclientid->sc_prog);
1407 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1408 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1409 RESERVE_SPACE(4);
1410 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001411 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001412 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413}
1414
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001415static 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 -07001416{
Andy Adamson05d564f2008-12-23 16:06:15 -05001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Andy Adamson05d564f2008-12-23 16:06:15 -05001419 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1420 WRITE32(OP_SETCLIENTID_CONFIRM);
1421 WRITE64(client_state->cl_clientid);
1422 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001423 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001424 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001427static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Al Viro8687b632006-10-19 23:28:48 -07001429 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431 RESERVE_SPACE(4);
1432 WRITE32(OP_WRITE);
1433
1434 encode_stateid(xdr, args->context);
1435
1436 RESERVE_SPACE(16);
1437 WRITE64(args->offset);
1438 WRITE32(args->stable);
1439 WRITE32(args->count);
1440
1441 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001442 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001443 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001446static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
Al Viro8687b632006-10-19 23:28:48 -07001448 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001450 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
1452 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001453 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001454 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001455 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001457
1458/* NFSv4.1 operations */
1459static void encode_sequence(struct xdr_stream *xdr,
1460 const struct nfs4_sequence_args *args,
1461 struct compound_hdr *hdr)
1462{
1463#if defined(CONFIG_NFS_V4_1)
1464 struct nfs4_session *session = args->sa_session;
1465
1466 if (!session)
1467 return;
1468
1469 /* stub */
1470 hdr->nops++;
1471 hdr->replen += decode_sequence_maxsz;
1472#endif /* CONFIG_NFS_V4_1 */
1473}
1474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475/*
1476 * END OF "GENERIC" ENCODE ROUTINES.
1477 */
1478
Benny Halevy66cc0422009-04-01 09:22:10 -04001479static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1480{
1481#if defined(CONFIG_NFS_V4_1)
1482 if (args->sa_session)
1483 return args->sa_session->clp->cl_minorversion;
1484#endif /* CONFIG_NFS_V4_1 */
1485 return 0;
1486}
1487
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488/*
1489 * Encode an ACCESS request
1490 */
Al Viro8687b632006-10-19 23:28:48 -07001491static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
1493 struct xdr_stream xdr;
1494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001499 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001500 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001501 encode_putfh(&xdr, args->fh, &hdr);
1502 encode_access(&xdr, args->access, &hdr);
1503 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001504 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001505 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506}
1507
1508/*
1509 * Encode LOOKUP request
1510 */
Al Viro8687b632006-10-19 23:28:48 -07001511static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
1513 struct xdr_stream xdr;
1514 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001519 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001520 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521 encode_putfh(&xdr, args->dir_fh, &hdr);
1522 encode_lookup(&xdr, args->name, &hdr);
1523 encode_getfh(&xdr, &hdr);
1524 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001525 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001526 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527}
1528
1529/*
1530 * Encode LOOKUP_ROOT request
1531 */
Al Viro8687b632006-10-19 23:28:48 -07001532static 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 -07001533{
1534 struct xdr_stream xdr;
1535 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001540 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001541 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001542 encode_putrootfh(&xdr, &hdr);
1543 encode_getfh(&xdr, &hdr);
1544 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001545 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001546 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
1549/*
1550 * Encode REMOVE request
1551 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001552static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
1554 struct xdr_stream xdr;
1555 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001556 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001560 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001561 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562 encode_putfh(&xdr, args->fh, &hdr);
1563 encode_remove(&xdr, &args->name, &hdr);
1564 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001565 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001566 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
1569/*
1570 * Encode RENAME request
1571 */
Al Viro8687b632006-10-19 23:28:48 -07001572static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573{
1574 struct xdr_stream xdr;
1575 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001580 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001581 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001582 encode_putfh(&xdr, args->old_dir, &hdr);
1583 encode_savefh(&xdr, &hdr);
1584 encode_putfh(&xdr, args->new_dir, &hdr);
1585 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1586 encode_getfattr(&xdr, args->bitmask, &hdr);
1587 encode_restorefh(&xdr, &hdr);
1588 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001589 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591}
1592
1593/*
1594 * Encode LINK request
1595 */
Al Viro8687b632006-10-19 23:28:48 -07001596static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597{
1598 struct xdr_stream xdr;
1599 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001600 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
1603 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001604 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001605 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001606 encode_putfh(&xdr, args->fh, &hdr);
1607 encode_savefh(&xdr, &hdr);
1608 encode_putfh(&xdr, args->dir_fh, &hdr);
1609 encode_link(&xdr, args->name, &hdr);
1610 encode_getfattr(&xdr, args->bitmask, &hdr);
1611 encode_restorefh(&xdr, &hdr);
1612 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001613 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
1617/*
1618 * Encode CREATE request
1619 */
Al Viro8687b632006-10-19 23:28:48 -07001620static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
1622 struct xdr_stream xdr;
1623 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
1627 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001628 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001629 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001630 encode_putfh(&xdr, args->dir_fh, &hdr);
1631 encode_savefh(&xdr, &hdr);
1632 encode_create(&xdr, args, &hdr);
1633 encode_getfh(&xdr, &hdr);
1634 encode_getfattr(&xdr, args->bitmask, &hdr);
1635 encode_restorefh(&xdr, &hdr);
1636 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001637 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001638 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639}
1640
1641/*
1642 * Encode SYMLINK request
1643 */
Al Viro8687b632006-10-19 23:28:48 -07001644static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
1646 return nfs4_xdr_enc_create(req, p, args);
1647}
1648
1649/*
1650 * Encode GETATTR request
1651 */
Al Viro8687b632006-10-19 23:28:48 -07001652static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
1654 struct xdr_stream xdr;
1655 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001656 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001660 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001661 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001662 encode_putfh(&xdr, args->fh, &hdr);
1663 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001664 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
1668/*
1669 * Encode a CLOSE request
1670 */
Al Viro8687b632006-10-19 23:28:48 -07001671static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
Andy Adamson05d564f2008-12-23 16:06:15 -05001673 struct xdr_stream xdr;
1674 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001675 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001676 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Andy Adamson05d564f2008-12-23 16:06:15 -05001678 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001679 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001680 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001681 encode_putfh(&xdr, args->fh, &hdr);
1682 encode_close(&xdr, args, &hdr);
1683 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001684 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001685 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686}
1687
1688/*
1689 * Encode an OPEN request
1690 */
Al Viro8687b632006-10-19 23:28:48 -07001691static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
1693 struct xdr_stream xdr;
1694 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001695 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001699 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001700 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701 encode_putfh(&xdr, args->fh, &hdr);
1702 encode_savefh(&xdr, &hdr);
1703 encode_open(&xdr, args, &hdr);
1704 encode_getfh(&xdr, &hdr);
1705 encode_getfattr(&xdr, args->bitmask, &hdr);
1706 encode_restorefh(&xdr, &hdr);
1707 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001708 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001709 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
1712/*
1713 * Encode an OPEN_CONFIRM request
1714 */
Al Viro8687b632006-10-19 23:28:48 -07001715static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 struct xdr_stream xdr;
1718 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001719 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001723 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001724 encode_putfh(&xdr, args->fh, &hdr);
1725 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001726 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001727 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
1730/*
1731 * Encode an OPEN request with no attributes.
1732 */
Al Viro8687b632006-10-19 23:28:48 -07001733static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734{
1735 struct xdr_stream xdr;
1736 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001737 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001741 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001742 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001743 encode_putfh(&xdr, args->fh, &hdr);
1744 encode_open(&xdr, args, &hdr);
1745 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001746 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001747 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748}
1749
1750/*
1751 * Encode an OPEN_DOWNGRADE request
1752 */
Al Viro8687b632006-10-19 23:28:48 -07001753static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
1755 struct xdr_stream xdr;
1756 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001757 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
1760 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001761 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001762 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001763 encode_putfh(&xdr, args->fh, &hdr);
1764 encode_open_downgrade(&xdr, args, &hdr);
1765 encode_getfattr(&xdr, args->bitmask, &hdr);
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 LOCK request
1772 */
Al Viro8687b632006-10-19 23:28:48 -07001773static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 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 Adamson9b7b9fc2009-04-01 09:22:11 -04001782 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001783 encode_putfh(&xdr, args->fh, &hdr);
1784 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001785 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001786 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
1789/*
1790 * Encode a LOCKT request
1791 */
Al Viro8687b632006-10-19 23:28:48 -07001792static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
1794 struct xdr_stream xdr;
1795 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001796 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001800 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001801 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001802 encode_putfh(&xdr, args->fh, &hdr);
1803 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001804 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001805 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
1808/*
1809 * Encode a LOCKU request
1810 */
Al Viro8687b632006-10-19 23:28:48 -07001811static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
1813 struct xdr_stream xdr;
1814 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001815 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
1818 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001819 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001820 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001821 encode_putfh(&xdr, args->fh, &hdr);
1822 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001823 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001824 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825}
1826
1827/*
1828 * Encode a READLINK request
1829 */
Al Viro8687b632006-10-19 23:28:48 -07001830static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
1832 struct xdr_stream xdr;
1833 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001834 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
1837 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001838 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001839 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001840 encode_putfh(&xdr, args->fh, &hdr);
1841 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001842
Benny Halevy28f56692009-04-01 09:22:09 -04001843 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001844 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05001845 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001846 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847}
1848
1849/*
1850 * Encode a READDIR request
1851 */
Al Viro8687b632006-10-19 23:28:48 -07001852static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
1854 struct xdr_stream xdr;
1855 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001856 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001860 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001861 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001862 encode_putfh(&xdr, args->fh, &hdr);
1863 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001864
Benny Halevy28f56692009-04-01 09:22:09 -04001865 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001866 args->pgbase, args->count);
1867 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04001868 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001869 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001870 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001871 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872}
1873
1874/*
1875 * Encode a READ request
1876 */
Al Viro8687b632006-10-19 23:28:48 -07001877static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 struct xdr_stream xdr;
1880 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001881 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
1884 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001885 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001886 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001887 encode_putfh(&xdr, args->fh, &hdr);
1888 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Benny Halevy28f56692009-04-01 09:22:09 -04001890 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001892 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05001893 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001894 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
1897/*
1898 * Encode an SETATTR request
1899 */
Al Viro8687b632006-10-19 23:28:48 -07001900static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901{
Andy Adamson05d564f2008-12-23 16:06:15 -05001902 struct xdr_stream xdr;
1903 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001904 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001905 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Andy Adamson05d564f2008-12-23 16:06:15 -05001907 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001908 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001910 encode_putfh(&xdr, args->fh, &hdr);
1911 encode_setattr(&xdr, args, args->server, &hdr);
1912 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001913 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001914 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915}
1916
1917/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001918 * Encode a GETACL request
1919 */
1920static int
Al Viro8687b632006-10-19 23:28:48 -07001921nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001922 struct nfs_getaclargs *args)
1923{
1924 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001925 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001926 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00001927 };
Benny Halevy28f56692009-04-01 09:22:09 -04001928 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001929
1930 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001931 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001932 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001933 encode_putfh(&xdr, args->fh, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04001934 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001935 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1936
Benny Halevy28f56692009-04-01 09:22:09 -04001937 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001938 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001939 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001940 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001941}
1942
1943/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 * Encode a WRITE request
1945 */
Al Viro8687b632006-10-19 23:28:48 -07001946static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001954 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001955 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001956 encode_putfh(&xdr, args->fh, &hdr);
1957 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001958 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001959 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001960 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001961 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962}
1963
1964/*
1965 * a COMMIT request
1966 */
Al Viro8687b632006-10-19 23:28:48 -07001967static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
1969 struct xdr_stream xdr;
1970 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001971 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
1974 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001975 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001976 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001977 encode_putfh(&xdr, args->fh, &hdr);
1978 encode_commit(&xdr, args, &hdr);
1979 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001980 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001981 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982}
1983
1984/*
1985 * FSINFO request
1986 */
Al Viro8687b632006-10-19 23:28:48 -07001987static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988{
1989 struct xdr_stream xdr;
1990 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001995 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001996 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001997 encode_putfh(&xdr, args->fh, &hdr);
1998 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001999 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002000 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
2003/*
2004 * a PATHCONF request
2005 */
Al Viro8687b632006-10-19 23:28:48 -07002006static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 struct xdr_stream xdr;
2009 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
2013 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002014 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002015 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002016 encode_putfh(&xdr, args->fh, &hdr);
2017 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2018 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002019 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002020 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021}
2022
2023/*
2024 * a STATFS request
2025 */
Al Viro8687b632006-10-19 23:28:48 -07002026static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 struct xdr_stream xdr;
2029 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
2033 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002034 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002035 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002036 encode_putfh(&xdr, args->fh, &hdr);
2037 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2038 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002039 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002040 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041}
2042
2043/*
2044 * GETATTR_BITMAP request
2045 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002046static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2047 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048{
2049 struct xdr_stream xdr;
2050 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002051 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002055 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002056 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002057 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002058 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2059 FATTR4_WORD0_LINK_SUPPORT|
2060 FATTR4_WORD0_SYMLINK_SUPPORT|
2061 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002062 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002063 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064}
2065
2066/*
2067 * a RENEW request
2068 */
Al Viro8687b632006-10-19 23:28:48 -07002069static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
2071 struct xdr_stream xdr;
2072 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002073 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 };
2075
2076 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002077 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002078 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002079 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002080 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
2083/*
2084 * a SETCLIENTID request
2085 */
Al Viro8687b632006-10-19 23:28:48 -07002086static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
2088 struct xdr_stream xdr;
2089 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002090 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 };
2092
2093 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002094 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002095 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002096 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002097 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098}
2099
2100/*
2101 * a SETCLIENTID_CONFIRM request
2102 */
Al Viro8687b632006-10-19 23:28:48 -07002103static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
2105 struct xdr_stream xdr;
2106 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002107 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 };
2109 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
2111 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002112 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002113 encode_setclientid_confirm(&xdr, clp, &hdr);
2114 encode_putrootfh(&xdr, &hdr);
2115 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002116 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002117 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118}
2119
2120/*
2121 * DELEGRETURN request
2122 */
Al Viro8687b632006-10-19 23:28:48 -07002123static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 struct xdr_stream xdr;
2126 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002127 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
2130 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002131 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002132 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002133 encode_putfh(&xdr, args->fhandle, &hdr);
2134 encode_delegreturn(&xdr, args->stateid, &hdr);
2135 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002136 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138}
2139
2140/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002141 * Encode FS_LOCATIONS request
2142 */
Al Viro8687b632006-10-19 23:28:48 -07002143static 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 -04002144{
2145 struct xdr_stream xdr;
2146 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002147 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002148 };
Benny Halevy28f56692009-04-01 09:22:09 -04002149 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002150
2151 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002152 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002153 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002154 encode_putfh(&xdr, args->dir_fh, &hdr);
2155 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002156 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002157 encode_fs_locations(&xdr, args->bitmask, &hdr);
2158
Benny Halevy28f56692009-04-01 09:22:09 -04002159 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002160 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002161 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002162 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002163}
2164
2165/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 * START OF "GENERIC" DECODE ROUTINES.
2167 * These may look a little ugly since they are imported from a "generic"
2168 * set of XDR encode/decode routines which are intended to be shared by
2169 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2170 *
2171 * If the pain of reading these is too great, it should be a straightforward
2172 * task to translate them into Linux-specific versions which are more
2173 * consistent with the style used in NFSv2/v3...
2174 */
2175#define READ32(x) (x) = ntohl(*p++)
2176#define READ64(x) do { \
2177 (x) = (u64)ntohl(*p++) << 32; \
2178 (x) |= ntohl(*p++); \
2179} while (0)
2180#define READTIME(x) do { \
2181 p++; \
2182 (x.tv_sec) = ntohl(*p++); \
2183 (x.tv_nsec) = ntohl(*p++); \
2184} while (0)
2185#define COPYMEM(x,nbytes) do { \
2186 memcpy((x), p, nbytes); \
2187 p += XDR_QUADLEN(nbytes); \
2188} while (0)
2189
2190#define READ_BUF(nbytes) do { \
2191 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002192 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002193 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002194 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002195 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002196 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 return -EIO; \
2198 } \
2199} while (0)
2200
Trond Myklebust683b57b2006-06-09 09:34:22 -04002201static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Al Viro8687b632006-10-19 23:28:48 -07002203 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
2205 READ_BUF(4);
2206 READ32(*len);
2207 READ_BUF(*len);
2208 *string = (char *)p;
2209 return 0;
2210}
2211
2212static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2213{
Al Viro8687b632006-10-19 23:28:48 -07002214 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216 READ_BUF(8);
2217 READ32(hdr->status);
2218 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002219
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 READ_BUF(hdr->taglen + 4);
2221 hdr->tag = (char *)p;
2222 p += XDR_QUADLEN(hdr->taglen);
2223 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002224 if (unlikely(hdr->nops < 1))
2225 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 return 0;
2227}
2228
2229static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2230{
Al Viro8687b632006-10-19 23:28:48 -07002231 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 uint32_t opnum;
2233 int32_t nfserr;
2234
2235 READ_BUF(8);
2236 READ32(opnum);
2237 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002238 dprintk("nfs: Server returned operation"
2239 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 opnum, expected);
2241 return -EIO;
2242 }
2243 READ32(nfserr);
2244 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002245 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 return 0;
2247}
2248
2249/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002250static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251{
Al Viro8687b632006-10-19 23:28:48 -07002252 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002253 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 char *str;
2255
2256 READ_BUF(12);
2257 return decode_opaque_inline(xdr, &strlen, &str);
2258}
2259
2260static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2261{
Al Viro8687b632006-10-19 23:28:48 -07002262 uint32_t bmlen;
2263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
2265 READ_BUF(4);
2266 READ32(bmlen);
2267
2268 bitmap[0] = bitmap[1] = 0;
2269 READ_BUF((bmlen << 2));
2270 if (bmlen > 0) {
2271 READ32(bitmap[0]);
2272 if (bmlen > 1)
2273 READ32(bitmap[1]);
2274 }
2275 return 0;
2276}
2277
Al Viro8687b632006-10-19 23:28:48 -07002278static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
Al Viro8687b632006-10-19 23:28:48 -07002280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
2282 READ_BUF(4);
2283 READ32(*attrlen);
2284 *savep = xdr->p;
2285 return 0;
2286}
2287
2288static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2289{
2290 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2291 decode_attr_bitmap(xdr, bitmask);
2292 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2293 } else
2294 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002295 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 return 0;
2297}
2298
2299static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2300{
Al Viro8687b632006-10-19 23:28:48 -07002301 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002302 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
2304 *type = 0;
2305 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2306 return -EIO;
2307 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2308 READ_BUF(4);
2309 READ32(*type);
2310 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002311 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 return -EIO;
2313 }
2314 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002315 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002317 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002318 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319}
2320
2321static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2322{
Al Viro8687b632006-10-19 23:28:48 -07002323 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002324 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 *change = 0;
2327 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2328 return -EIO;
2329 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2330 READ_BUF(8);
2331 READ64(*change);
2332 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002333 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002335 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002337 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338}
2339
2340static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2341{
Al Viro8687b632006-10-19 23:28:48 -07002342 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002343 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
2345 *size = 0;
2346 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2347 return -EIO;
2348 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2349 READ_BUF(8);
2350 READ64(*size);
2351 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002352 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002354 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002355 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
2358static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2359{
Al Viro8687b632006-10-19 23:28:48 -07002360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
2362 *res = 0;
2363 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2364 return -EIO;
2365 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2366 READ_BUF(4);
2367 READ32(*res);
2368 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2369 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002370 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 return 0;
2372}
2373
2374static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2375{
Al Viro8687b632006-10-19 23:28:48 -07002376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
2378 *res = 0;
2379 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2380 return -EIO;
2381 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2382 READ_BUF(4);
2383 READ32(*res);
2384 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2385 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002386 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 return 0;
2388}
2389
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002390static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
Al Viro8687b632006-10-19 23:28:48 -07002392 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002393 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 fsid->major = 0;
2396 fsid->minor = 0;
2397 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2398 return -EIO;
2399 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2400 READ_BUF(16);
2401 READ64(fsid->major);
2402 READ64(fsid->minor);
2403 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002404 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002406 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 (unsigned long long)fsid->major,
2408 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002409 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410}
2411
2412static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2413{
Al Viro8687b632006-10-19 23:28:48 -07002414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
2416 *res = 60;
2417 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2418 return -EIO;
2419 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2420 READ_BUF(4);
2421 READ32(*res);
2422 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2423 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002424 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 return 0;
2426}
2427
2428static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2429{
Al Viro8687b632006-10-19 23:28:48 -07002430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
2432 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2433 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2434 return -EIO;
2435 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2436 READ_BUF(4);
2437 READ32(*res);
2438 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2439 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002440 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 return 0;
2442}
2443
2444static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2445{
Al Viro8687b632006-10-19 23:28:48 -07002446 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002447 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
2449 *fileid = 0;
2450 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2451 return -EIO;
2452 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2453 READ_BUF(8);
2454 READ64(*fileid);
2455 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002456 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002458 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002459 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
Manoj Naik99baf622006-06-09 09:34:24 -04002462static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2463{
Al Viro8687b632006-10-19 23:28:48 -07002464 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002465 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002466
2467 *fileid = 0;
2468 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2469 return -EIO;
2470 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2471 READ_BUF(8);
2472 READ64(*fileid);
2473 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002474 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002475 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002476 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002477 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002478}
2479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2481{
Al Viro8687b632006-10-19 23:28:48 -07002482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 int status = 0;
2484
2485 *res = 0;
2486 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2487 return -EIO;
2488 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2489 READ_BUF(8);
2490 READ64(*res);
2491 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2492 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002493 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 return status;
2495}
2496
2497static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2498{
Al Viro8687b632006-10-19 23:28:48 -07002499 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 int status = 0;
2501
2502 *res = 0;
2503 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2504 return -EIO;
2505 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2506 READ_BUF(8);
2507 READ64(*res);
2508 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2509 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002510 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 return status;
2512}
2513
2514static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2515{
Al Viro8687b632006-10-19 23:28:48 -07002516 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 int status = 0;
2518
2519 *res = 0;
2520 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2521 return -EIO;
2522 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2523 READ_BUF(8);
2524 READ64(*res);
2525 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2526 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002527 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 return status;
2529}
2530
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002531static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2532{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002533 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002534 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002535 int status = 0;
2536
2537 READ_BUF(4);
2538 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002539 if (n == 0)
2540 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002541 dprintk("path ");
2542 path->ncomponents = 0;
2543 while (path->ncomponents < n) {
2544 struct nfs4_string *component = &path->components[path->ncomponents];
2545 status = decode_opaque_inline(xdr, &component->len, &component->data);
2546 if (unlikely(status != 0))
2547 goto out_eio;
2548 if (path->ncomponents != n)
2549 dprintk("/");
2550 dprintk("%s", component->data);
2551 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2552 path->ncomponents++;
2553 else {
2554 dprintk("cannot parse %d components in path\n", n);
2555 goto out_eio;
2556 }
2557 }
2558out:
2559 dprintk("\n");
2560 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002561root_path:
2562/* a root pathname is sent as a zero component4 */
2563 path->ncomponents = 1;
2564 path->components[0].len=0;
2565 path->components[0].data=NULL;
2566 dprintk("path /\n");
2567 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002568out_eio:
2569 dprintk(" status %d", status);
2570 status = -EIO;
2571 goto out;
2572}
2573
2574static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002575{
2576 int n;
Al Viro8687b632006-10-19 23:28:48 -07002577 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002578 int status = -EIO;
2579
2580 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2581 goto out;
2582 status = 0;
2583 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2584 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002585 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002586 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002587 if (unlikely(status != 0))
2588 goto out;
2589 READ_BUF(4);
2590 READ32(n);
2591 if (n <= 0)
2592 goto out_eio;
2593 res->nlocations = 0;
2594 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002595 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002596 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002597
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002598 READ_BUF(4);
2599 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002600
2601 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002602 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002603 while (loc->nservers < m) {
2604 struct nfs4_string *server = &loc->servers[loc->nservers];
2605 status = decode_opaque_inline(xdr, &server->len, &server->data);
2606 if (unlikely(status != 0))
2607 goto out_eio;
2608 dprintk("%s ", server->data);
2609 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2610 loc->nservers++;
2611 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002612 unsigned int i;
2613 dprintk("%s: using first %u of %u servers "
2614 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002615 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002616 NFS4_FS_LOCATION_MAXSERVERS,
2617 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002618 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002619 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002620 char *data;
2621 status = decode_opaque_inline(xdr, &len, &data);
2622 if (unlikely(status != 0))
2623 goto out_eio;
2624 }
2625 }
2626 }
2627 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002628 if (unlikely(status != 0))
2629 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002630 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002631 res->nlocations++;
2632 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002633 if (res->nlocations != 0)
2634 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002635out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002636 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002637 return status;
2638out_eio:
2639 status = -EIO;
2640 goto out;
2641}
2642
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2644{
Al Viro8687b632006-10-19 23:28:48 -07002645 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 int status = 0;
2647
2648 *res = 0;
2649 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2650 return -EIO;
2651 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2652 READ_BUF(8);
2653 READ64(*res);
2654 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2655 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002656 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 return status;
2658}
2659
2660static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2661{
Al Viro8687b632006-10-19 23:28:48 -07002662 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 int status = 0;
2664
2665 *maxlink = 1;
2666 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2667 return -EIO;
2668 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2669 READ_BUF(4);
2670 READ32(*maxlink);
2671 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2672 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002673 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 return status;
2675}
2676
2677static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2678{
Al Viro8687b632006-10-19 23:28:48 -07002679 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 int status = 0;
2681
2682 *maxname = 1024;
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2684 return -EIO;
2685 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2686 READ_BUF(4);
2687 READ32(*maxname);
2688 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002690 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 return status;
2692}
2693
2694static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2695{
Al Viro8687b632006-10-19 23:28:48 -07002696 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 int status = 0;
2698
2699 *res = 1024;
2700 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2701 return -EIO;
2702 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2703 uint64_t maxread;
2704 READ_BUF(8);
2705 READ64(maxread);
2706 if (maxread > 0x7FFFFFFF)
2707 maxread = 0x7FFFFFFF;
2708 *res = (uint32_t)maxread;
2709 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2710 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002711 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 return status;
2713}
2714
2715static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2716{
Al Viro8687b632006-10-19 23:28:48 -07002717 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 int status = 0;
2719
2720 *res = 1024;
2721 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2722 return -EIO;
2723 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2724 uint64_t maxwrite;
2725 READ_BUF(8);
2726 READ64(maxwrite);
2727 if (maxwrite > 0x7FFFFFFF)
2728 maxwrite = 0x7FFFFFFF;
2729 *res = (uint32_t)maxwrite;
2730 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2731 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002732 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 return status;
2734}
2735
Trond Myklebustbca79472009-03-11 14:10:26 -04002736static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737{
Trond Myklebustbca79472009-03-11 14:10:26 -04002738 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07002739 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002740 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
2742 *mode = 0;
2743 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2744 return -EIO;
2745 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2746 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04002747 READ32(tmp);
2748 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002750 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002752 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04002753 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754}
2755
2756static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2757{
Al Viro8687b632006-10-19 23:28:48 -07002758 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002759 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
2761 *nlink = 1;
2762 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2763 return -EIO;
2764 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2765 READ_BUF(4);
2766 READ32(*nlink);
2767 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04002768 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002770 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04002771 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772}
2773
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002774static 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 -07002775{
Al Viro8687b632006-10-19 23:28:48 -07002776 uint32_t len;
2777 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002778 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779
2780 *uid = -2;
2781 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2782 return -EIO;
2783 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2784 READ_BUF(4);
2785 READ32(len);
2786 READ_BUF(len);
2787 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002788 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2789 ret = NFS_ATTR_FATTR_OWNER;
2790 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002792 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002794 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002795 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2797 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002798 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002799 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800}
2801
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002802static 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 -07002803{
Al Viro8687b632006-10-19 23:28:48 -07002804 uint32_t len;
2805 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002806 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 *gid = -2;
2809 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2810 return -EIO;
2811 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2812 READ_BUF(4);
2813 READ32(len);
2814 READ_BUF(len);
2815 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002816 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2817 ret = NFS_ATTR_FATTR_GROUP;
2818 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002820 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002822 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002823 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2825 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002826 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002827 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828}
2829
2830static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2831{
Al Viro8687b632006-10-19 23:28:48 -07002832 uint32_t major = 0, minor = 0;
2833 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002834 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
2836 *rdev = MKDEV(0,0);
2837 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2838 return -EIO;
2839 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2840 dev_t tmp;
2841
2842 READ_BUF(8);
2843 READ32(major);
2844 READ32(minor);
2845 tmp = MKDEV(major, minor);
2846 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2847 *rdev = tmp;
2848 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04002849 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002851 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002852 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853}
2854
2855static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2856{
Al Viro8687b632006-10-19 23:28:48 -07002857 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 int status = 0;
2859
2860 *res = 0;
2861 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2862 return -EIO;
2863 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2864 READ_BUF(8);
2865 READ64(*res);
2866 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2867 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002868 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 return status;
2870}
2871
2872static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2873{
Al Viro8687b632006-10-19 23:28:48 -07002874 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 int status = 0;
2876
2877 *res = 0;
2878 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2879 return -EIO;
2880 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2881 READ_BUF(8);
2882 READ64(*res);
2883 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2884 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002885 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 return status;
2887}
2888
2889static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2890{
Al Viro8687b632006-10-19 23:28:48 -07002891 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 int status = 0;
2893
2894 *res = 0;
2895 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2896 return -EIO;
2897 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2898 READ_BUF(8);
2899 READ64(*res);
2900 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2901 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002902 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 return status;
2904}
2905
2906static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2907{
Al Viro8687b632006-10-19 23:28:48 -07002908 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002909 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
2911 *used = 0;
2912 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2913 return -EIO;
2914 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2915 READ_BUF(8);
2916 READ64(*used);
2917 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04002918 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002920 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04002922 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923}
2924
2925static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2926{
Al Viro8687b632006-10-19 23:28:48 -07002927 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 uint64_t sec;
2929 uint32_t nsec;
2930
2931 READ_BUF(12);
2932 READ64(sec);
2933 READ32(nsec);
2934 time->tv_sec = (time_t)sec;
2935 time->tv_nsec = (long)nsec;
2936 return 0;
2937}
2938
2939static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2940{
2941 int status = 0;
2942
2943 time->tv_sec = 0;
2944 time->tv_nsec = 0;
2945 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2946 return -EIO;
2947 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2948 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002949 if (status == 0)
2950 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2952 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002953 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 return status;
2955}
2956
2957static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2958{
2959 int status = 0;
2960
2961 time->tv_sec = 0;
2962 time->tv_nsec = 0;
2963 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2964 return -EIO;
2965 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2966 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002967 if (status == 0)
2968 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2970 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002971 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 return status;
2973}
2974
2975static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2976{
2977 int status = 0;
2978
2979 time->tv_sec = 0;
2980 time->tv_nsec = 0;
2981 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2982 return -EIO;
2983 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2984 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002985 if (status == 0)
2986 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2988 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002989 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 return status;
2991}
2992
Al Viro8687b632006-10-19 23:28:48 -07002993static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994{
2995 unsigned int attrwords = XDR_QUADLEN(attrlen);
2996 unsigned int nwords = xdr->p - savep;
2997
2998 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002999 dprintk("%s: server returned incorrect attribute length: "
3000 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003001 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 attrwords << 2,
3003 (attrwords < nwords) ? '<' : '>',
3004 nwords << 2);
3005 return -EIO;
3006 }
3007 return 0;
3008}
3009
3010static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3011{
Al Viro8687b632006-10-19 23:28:48 -07003012 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
3014 READ_BUF(20);
3015 READ32(cinfo->atomic);
3016 READ64(cinfo->before);
3017 READ64(cinfo->after);
3018 return 0;
3019}
3020
3021static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3022{
Al Viro8687b632006-10-19 23:28:48 -07003023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 uint32_t supp, acc;
3025 int status;
3026
3027 status = decode_op_hdr(xdr, OP_ACCESS);
3028 if (status)
3029 return status;
3030 READ_BUF(8);
3031 READ32(supp);
3032 READ32(acc);
3033 access->supported = supp;
3034 access->access = acc;
3035 return 0;
3036}
3037
3038static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3039{
Al Viro8687b632006-10-19 23:28:48 -07003040 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 int status;
3042
3043 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003044 if (status != -EIO)
3045 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 if (status)
3047 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003048 READ_BUF(NFS4_STATEID_SIZE);
3049 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 return 0;
3051}
3052
3053static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3054{
Al Viro8687b632006-10-19 23:28:48 -07003055 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 int status;
3057
3058 status = decode_op_hdr(xdr, OP_COMMIT);
3059 if (status)
3060 return status;
3061 READ_BUF(8);
3062 COPYMEM(res->verf->verifier, 8);
3063 return 0;
3064}
3065
3066static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3067{
Al Viro8687b632006-10-19 23:28:48 -07003068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 uint32_t bmlen;
3070 int status;
3071
3072 status = decode_op_hdr(xdr, OP_CREATE);
3073 if (status)
3074 return status;
3075 if ((status = decode_change_info(xdr, cinfo)))
3076 return status;
3077 READ_BUF(4);
3078 READ32(bmlen);
3079 READ_BUF(bmlen << 2);
3080 return 0;
3081}
3082
3083static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3084{
Al Viro8687b632006-10-19 23:28:48 -07003085 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003086 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 int status;
3088
3089 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3090 goto xdr_error;
3091 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3092 goto xdr_error;
3093 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3094 goto xdr_error;
3095 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3096 goto xdr_error;
3097 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3098 goto xdr_error;
3099 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3100 goto xdr_error;
3101 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3102 goto xdr_error;
3103 status = verify_attr_len(xdr, savep, attrlen);
3104xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003105 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 return status;
3107}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003108
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3110{
Al Viro8687b632006-10-19 23:28:48 -07003111 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003112 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003114
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3116 goto xdr_error;
3117 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3118 goto xdr_error;
3119 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3120 goto xdr_error;
3121
3122 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3123 goto xdr_error;
3124 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3125 goto xdr_error;
3126 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3127 goto xdr_error;
3128 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3129 goto xdr_error;
3130 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3131 goto xdr_error;
3132 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3133 goto xdr_error;
3134
3135 status = verify_attr_len(xdr, savep, attrlen);
3136xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003137 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 return status;
3139}
3140
3141static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3142{
Al Viro8687b632006-10-19 23:28:48 -07003143 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003144 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003146
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3148 goto xdr_error;
3149 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3150 goto xdr_error;
3151 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3152 goto xdr_error;
3153
3154 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3155 goto xdr_error;
3156 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3157 goto xdr_error;
3158
3159 status = verify_attr_len(xdr, savep, attrlen);
3160xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003161 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 return status;
3163}
3164
3165static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 uint32_t attrlen,
3169 bitmap[2] = {0},
3170 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003171 int status;
3172 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003173 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003175 status = decode_op_hdr(xdr, OP_GETATTR);
3176 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 goto xdr_error;
3178
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003179 status = decode_attr_bitmap(xdr, bitmap);
3180 if (status < 0)
3181 goto xdr_error;
3182
3183 status = decode_attr_length(xdr, &attrlen, &savep);
3184 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 goto xdr_error;
3186
3187
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003188 status = decode_attr_type(xdr, bitmap, &type);
3189 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003191 fattr->mode = 0;
3192 if (status != 0) {
3193 fattr->mode |= nfs_type2fmt[type];
3194 fattr->valid |= status;
3195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003197 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3198 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003200 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003201
3202 status = decode_attr_size(xdr, bitmap, &fattr->size);
3203 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003205 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003206
3207 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3208 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003210 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003211
3212 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3213 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003215 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003216
3217 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003218 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003219 fattr));
3220 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003221 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003222 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003223
3224 status = decode_attr_mode(xdr, bitmap, &fmode);
3225 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003227 if (status != 0) {
3228 fattr->mode |= fmode;
3229 fattr->valid |= status;
3230 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003231
3232 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3233 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003235 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003236
3237 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3238 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003241
3242 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3243 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003245 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003246
3247 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3248 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003250 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003251
3252 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3253 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003255 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003256
3257 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3258 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003260 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003261
3262 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3263 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003266
3267 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3268 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003271
3272 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3273 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003274 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003275 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003276 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003277 fattr->valid |= status;
3278 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003279
3280 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003282 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 return status;
3284}
3285
3286
3287static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3288{
Al Viro8687b632006-10-19 23:28:48 -07003289 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 uint32_t attrlen, bitmap[2];
3291 int status;
3292
3293 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3294 goto xdr_error;
3295 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3296 goto xdr_error;
3297 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3298 goto xdr_error;
3299
3300 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3301
3302 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3303 goto xdr_error;
3304 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3305 goto xdr_error;
3306 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3307 goto xdr_error;
3308 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3309 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3310 goto xdr_error;
3311 fsinfo->wtpref = fsinfo->wtmax;
3312
3313 status = verify_attr_len(xdr, savep, attrlen);
3314xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003315 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 return status;
3317}
3318
3319static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3320{
Al Viro8687b632006-10-19 23:28:48 -07003321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 uint32_t len;
3323 int status;
3324
Trond Myklebust99367812007-07-17 21:52:41 -04003325 /* Zero handle first to allow comparisons */
3326 memset(fh, 0, sizeof(*fh));
3327
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 status = decode_op_hdr(xdr, OP_GETFH);
3329 if (status)
3330 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
3332 READ_BUF(4);
3333 READ32(len);
3334 if (len > NFS4_FHSIZE)
3335 return -EIO;
3336 fh->size = len;
3337 READ_BUF(len);
3338 COPYMEM(fh->data, len);
3339 return 0;
3340}
3341
3342static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3343{
3344 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003345
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 status = decode_op_hdr(xdr, OP_LINK);
3347 if (status)
3348 return status;
3349 return decode_change_info(xdr, cinfo);
3350}
3351
3352/*
3353 * We create the owner, so we know a proper owner.id length is 4.
3354 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003355static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003357 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003358 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003359 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
3361 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003362 READ64(offset);
3363 READ64(length);
3364 READ32(type);
3365 if (fl != NULL) {
3366 fl->fl_start = (loff_t)offset;
3367 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3368 if (length == ~(uint64_t)0)
3369 fl->fl_end = OFFSET_MAX;
3370 fl->fl_type = F_WRLCK;
3371 if (type & 1)
3372 fl->fl_type = F_RDLCK;
3373 fl->fl_pid = 0;
3374 }
3375 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 READ32(namelen);
3377 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 return -NFS4ERR_DENIED;
3379}
3380
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003381static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382{
Al Viro8687b632006-10-19 23:28:48 -07003383 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 int status;
3385
3386 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003387 if (status == -EIO)
3388 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003390 READ_BUF(NFS4_STATEID_SIZE);
3391 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003393 status = decode_lock_denied(xdr, NULL);
3394 if (res->open_seqid != NULL)
3395 nfs_increment_open_seqid(status, res->open_seqid);
3396 nfs_increment_lock_seqid(status, res->lock_seqid);
3397out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 return status;
3399}
3400
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003401static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402{
3403 int status;
3404 status = decode_op_hdr(xdr, OP_LOCKT);
3405 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003406 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 return status;
3408}
3409
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003410static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411{
Al Viro8687b632006-10-19 23:28:48 -07003412 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 int status;
3414
3415 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003416 if (status != -EIO)
3417 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003419 READ_BUF(NFS4_STATEID_SIZE);
3420 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 }
3422 return status;
3423}
3424
3425static int decode_lookup(struct xdr_stream *xdr)
3426{
3427 return decode_op_hdr(xdr, OP_LOOKUP);
3428}
3429
3430/* This is too sick! */
3431static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3432{
Andy Adamson05d564f2008-12-23 16:06:15 -05003433 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 uint32_t limit_type, nblocks, blocksize;
3435
3436 READ_BUF(12);
3437 READ32(limit_type);
3438 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003439 case 1:
3440 READ64(*maxsize);
3441 break;
3442 case 2:
3443 READ32(nblocks);
3444 READ32(blocksize);
3445 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 }
3447 return 0;
3448}
3449
3450static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3451{
Andy Adamson05d564f2008-12-23 16:06:15 -05003452 __be32 *p;
3453 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454
3455 READ_BUF(4);
3456 READ32(delegation_type);
3457 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3458 res->delegation_type = 0;
3459 return 0;
3460 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003461 READ_BUF(NFS4_STATEID_SIZE+4);
3462 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003464
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003466 case NFS4_OPEN_DELEGATE_READ:
3467 res->delegation_type = FMODE_READ;
3468 break;
3469 case NFS4_OPEN_DELEGATE_WRITE:
3470 res->delegation_type = FMODE_WRITE|FMODE_READ;
3471 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return -EIO;
3473 }
David Howells7539bba2006-08-22 20:06:09 -04003474 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475}
3476
3477static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3478{
Andy Adamson05d564f2008-12-23 16:06:15 -05003479 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003480 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003481 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
Andy Adamson05d564f2008-12-23 16:06:15 -05003483 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003484 if (status != -EIO)
3485 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003486 if (status)
3487 return status;
3488 READ_BUF(NFS4_STATEID_SIZE);
3489 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490
Andy Adamson05d564f2008-12-23 16:06:15 -05003491 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
Andy Adamson05d564f2008-12-23 16:06:15 -05003493 READ_BUF(8);
3494 READ32(res->rflags);
3495 READ32(bmlen);
3496 if (bmlen > 10)
3497 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
Andy Adamson05d564f2008-12-23 16:06:15 -05003499 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003500 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3501 for (i = 0; i < savewords; ++i)
3502 READ32(res->attrset[i]);
3503 for (; i < NFS4_BITMAP_SIZE; i++)
3504 res->attrset[i] = 0;
3505
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 return decode_delegation(xdr, res);
3507xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003508 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 return -EIO;
3510}
3511
3512static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3513{
Andy Adamson05d564f2008-12-23 16:06:15 -05003514 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 int status;
3516
Andy Adamson05d564f2008-12-23 16:06:15 -05003517 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003518 if (status != -EIO)
3519 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003520 if (status)
3521 return status;
3522 READ_BUF(NFS4_STATEID_SIZE);
3523 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3524 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525}
3526
3527static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3528{
Al Viro8687b632006-10-19 23:28:48 -07003529 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 int status;
3531
3532 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003533 if (status != -EIO)
3534 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 if (status)
3536 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003537 READ_BUF(NFS4_STATEID_SIZE);
3538 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 return 0;
3540}
3541
3542static int decode_putfh(struct xdr_stream *xdr)
3543{
3544 return decode_op_hdr(xdr, OP_PUTFH);
3545}
3546
3547static int decode_putrootfh(struct xdr_stream *xdr)
3548{
3549 return decode_op_hdr(xdr, OP_PUTROOTFH);
3550}
3551
3552static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3553{
3554 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003555 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 uint32_t count, eof, recvd, hdrlen;
3557 int status;
3558
3559 status = decode_op_hdr(xdr, OP_READ);
3560 if (status)
3561 return status;
3562 READ_BUF(8);
3563 READ32(eof);
3564 READ32(count);
3565 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3566 recvd = req->rq_rcv_buf.len - hdrlen;
3567 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003568 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 "count %u > recvd %u\n", count, recvd);
3570 count = recvd;
3571 eof = 0;
3572 }
3573 xdr_read_pages(xdr, count);
3574 res->eof = eof;
3575 res->count = count;
3576 return 0;
3577}
3578
3579static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3580{
3581 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3582 struct page *page = *rcvbuf->pages;
3583 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003584 size_t hdrlen;
3585 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003586 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003587 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003588 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
3590 status = decode_op_hdr(xdr, OP_READDIR);
3591 if (status)
3592 return status;
3593 READ_BUF(8);
3594 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003595 dprintk("%s: verifier = %08x:%08x\n",
3596 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003597 ((u32 *)readdir->verifier.data)[0],
3598 ((u32 *)readdir->verifier.data)[1]);
3599
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600
3601 hdrlen = (char *) p - (char *) iov->iov_base;
3602 recvd = rcvbuf->len - hdrlen;
3603 if (pglen > recvd)
3604 pglen = recvd;
3605 xdr_read_pages(xdr, pglen);
3606
3607 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003608 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003609 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003611
3612 /* Make sure the packet actually has a value_follows and EOF entry */
3613 if ((entry + 1) > end)
3614 goto short_pkt;
3615
3616 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003617 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003618 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003620 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 p += 2; /* cookie */
3622 len = ntohl(*p++); /* filename length */
3623 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003624 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3625 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 goto err_unmap;
3627 }
David Howellse8896492006-08-24 15:44:19 -04003628 xlen = XDR_QUADLEN(len);
3629 if (end - p < xlen + 1)
3630 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003631 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003632 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003634 if (end - p < len + 1)
3635 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003638 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003640 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 entry = p;
3642 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003643 /*
3644 * Apparently some server sends responses that are a valid size, but
3645 * contain no entries, and have value_follows==0 and EOF==0. For
3646 * those, just set the EOF marker.
3647 */
3648 if (!nr && entry[1] == 0) {
3649 dprintk("NFS: readdir reply truncated!\n");
3650 entry[1] = 1;
3651 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003652out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 kunmap_atomic(kaddr, KM_USER0);
3654 return 0;
3655short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003656 /*
3657 * When we get a short packet there are 2 possibilities. We can
3658 * return an error, or fix up the response to look like a valid
3659 * response and return what we have so far. If there are no
3660 * entries and the packet was short, then return -EIO. If there
3661 * are valid entries in the response, return them and pretend that
3662 * the call was successful, but incomplete. The caller can retry the
3663 * readdir starting at the last cookie.
3664 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003665 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003667 if (nr)
3668 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669err_unmap:
3670 kunmap_atomic(kaddr, KM_USER0);
3671 return -errno_NFSERR_IO;
3672}
3673
3674static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3675{
3676 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3677 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003678 size_t hdrlen;
3679 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003680 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 char *kaddr;
3682 int status;
3683
3684 status = decode_op_hdr(xdr, OP_READLINK);
3685 if (status)
3686 return status;
3687
3688 /* Convert length of symlink */
3689 READ_BUF(4);
3690 READ32(len);
3691 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003692 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 return -ENAMETOOLONG;
3694 }
3695 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3696 recvd = req->rq_rcv_buf.len - hdrlen;
3697 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003698 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 "count %u > recvd %u\n", len, recvd);
3700 return -EIO;
3701 }
3702 xdr_read_pages(xdr, len);
3703 /*
3704 * The XDR encode routine has set things up so that
3705 * the link text will be copied directly into the
3706 * buffer. We just have to do overflow-checking,
3707 * and and null-terminate the text (the VFS expects
3708 * null-termination).
3709 */
3710 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3711 kaddr[len+rcvbuf->page_base] = '\0';
3712 kunmap_atomic(kaddr, KM_USER0);
3713 return 0;
3714}
3715
3716static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3717{
3718 int status;
3719
3720 status = decode_op_hdr(xdr, OP_REMOVE);
3721 if (status)
3722 goto out;
3723 status = decode_change_info(xdr, cinfo);
3724out:
3725 return status;
3726}
3727
3728static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3729 struct nfs4_change_info *new_cinfo)
3730{
3731 int status;
3732
3733 status = decode_op_hdr(xdr, OP_RENAME);
3734 if (status)
3735 goto out;
3736 if ((status = decode_change_info(xdr, old_cinfo)))
3737 goto out;
3738 status = decode_change_info(xdr, new_cinfo);
3739out:
3740 return status;
3741}
3742
3743static int decode_renew(struct xdr_stream *xdr)
3744{
3745 return decode_op_hdr(xdr, OP_RENEW);
3746}
3747
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003748static int
3749decode_restorefh(struct xdr_stream *xdr)
3750{
3751 return decode_op_hdr(xdr, OP_RESTOREFH);
3752}
3753
J. Bruce Fields029d1052005-06-22 17:16:22 +00003754static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3755 size_t *acl_len)
3756{
Al Viro8687b632006-10-19 23:28:48 -07003757 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003758 uint32_t attrlen,
3759 bitmap[2] = {0};
3760 struct kvec *iov = req->rq_rcv_buf.head;
3761 int status;
3762
3763 *acl_len = 0;
3764 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3765 goto out;
3766 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3767 goto out;
3768 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3769 goto out;
3770
3771 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3772 return -EIO;
3773 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003774 size_t hdrlen;
3775 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003776
3777 /* We ignore &savep and don't do consistency checks on
3778 * the attr length. Let userspace figure it out.... */
3779 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3780 recvd = req->rq_rcv_buf.len - hdrlen;
3781 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003782 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00003783 " acl reply: attrlen %u > recvd %u\n",
3784 attrlen, recvd);
3785 return -EINVAL;
3786 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003787 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003788 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003789 } else
3790 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003791
3792out:
3793 return status;
3794}
3795
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796static int
3797decode_savefh(struct xdr_stream *xdr)
3798{
3799 return decode_op_hdr(xdr, OP_SAVEFH);
3800}
3801
Benny Halevy9e9ecc02009-04-01 09:22:00 -04003802static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803{
Al Viro8687b632006-10-19 23:28:48 -07003804 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 uint32_t bmlen;
3806 int status;
3807
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 status = decode_op_hdr(xdr, OP_SETATTR);
3809 if (status)
3810 return status;
3811 READ_BUF(4);
3812 READ32(bmlen);
3813 READ_BUF(bmlen << 2);
3814 return 0;
3815}
3816
David Howellsadfa6f92006-08-22 20:06:08 -04003817static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818{
Al Viro8687b632006-10-19 23:28:48 -07003819 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 uint32_t opnum;
3821 int32_t nfserr;
3822
3823 READ_BUF(8);
3824 READ32(opnum);
3825 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003826 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05003827 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 return -EIO;
3829 }
3830 READ32(nfserr);
3831 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003832 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003834 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 } else if (nfserr == NFSERR_CLID_INUSE) {
3836 uint32_t len;
3837
3838 /* skip netid string */
3839 READ_BUF(4);
3840 READ32(len);
3841 READ_BUF(len);
3842
3843 /* skip uaddr string */
3844 READ_BUF(4);
3845 READ32(len);
3846 READ_BUF(len);
3847 return -NFSERR_CLID_INUSE;
3848 } else
Benny Halevy856dff32008-03-31 17:39:06 +03003849 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850
3851 return 0;
3852}
3853
3854static int decode_setclientid_confirm(struct xdr_stream *xdr)
3855{
3856 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3857}
3858
3859static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3860{
Al Viro8687b632006-10-19 23:28:48 -07003861 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 int status;
3863
3864 status = decode_op_hdr(xdr, OP_WRITE);
3865 if (status)
3866 return status;
3867
3868 READ_BUF(16);
3869 READ32(res->count);
3870 READ32(res->verf->committed);
3871 COPYMEM(res->verf->verifier, 8);
3872 return 0;
3873}
3874
3875static int decode_delegreturn(struct xdr_stream *xdr)
3876{
3877 return decode_op_hdr(xdr, OP_DELEGRETURN);
3878}
3879
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04003880static int decode_sequence(struct xdr_stream *xdr,
3881 struct nfs4_sequence_res *res,
3882 struct rpc_rqst *rqstp)
3883{
3884#if defined(CONFIG_NFS_V4_1)
3885 if (!res->sr_session)
3886 return 0;
3887
3888 /* stub */
3889#endif /* CONFIG_NFS_V4_1 */
3890
3891 return 0;
3892}
3893
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894/*
Benny Halevy49c25592008-12-23 16:06:16 -05003895 * END OF "GENERIC" DECODE ROUTINES.
3896 */
3897
3898/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 * Decode OPEN_DOWNGRADE response
3900 */
Al Viro8687b632006-10-19 23:28:48 -07003901static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902{
Andy Adamson05d564f2008-12-23 16:06:15 -05003903 struct xdr_stream xdr;
3904 struct compound_hdr hdr;
3905 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906
Andy Adamson05d564f2008-12-23 16:06:15 -05003907 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3908 status = decode_compound_hdr(&xdr, &hdr);
3909 if (status)
3910 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04003911 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3912 if (status)
3913 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05003914 status = decode_putfh(&xdr);
3915 if (status)
3916 goto out;
3917 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003918 if (status != 0)
3919 goto out;
3920 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921out:
Andy Adamson05d564f2008-12-23 16:06:15 -05003922 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923}
3924
3925/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 * Decode ACCESS response
3927 */
Al Viro8687b632006-10-19 23:28:48 -07003928static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929{
3930 struct xdr_stream xdr;
3931 struct compound_hdr hdr;
3932 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003933
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04003935 status = decode_compound_hdr(&xdr, &hdr);
3936 if (status)
3937 goto out;
3938 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3939 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04003941 status = decode_putfh(&xdr);
3942 if (status != 0)
3943 goto out;
3944 status = decode_access(&xdr, res);
3945 if (status != 0)
3946 goto out;
3947 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948out:
3949 return status;
3950}
3951
3952/*
3953 * Decode LOOKUP response
3954 */
Al Viro8687b632006-10-19 23:28:48 -07003955static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956{
3957 struct xdr_stream xdr;
3958 struct compound_hdr hdr;
3959 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003960
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04003962 status = decode_compound_hdr(&xdr, &hdr);
3963 if (status)
3964 goto out;
3965 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3966 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 goto out;
3968 if ((status = decode_putfh(&xdr)) != 0)
3969 goto out;
3970 if ((status = decode_lookup(&xdr)) != 0)
3971 goto out;
3972 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3973 goto out;
3974 status = decode_getfattr(&xdr, res->fattr, res->server);
3975out:
3976 return status;
3977}
3978
3979/*
3980 * Decode LOOKUP_ROOT response
3981 */
Al Viro8687b632006-10-19 23:28:48 -07003982static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983{
3984 struct xdr_stream xdr;
3985 struct compound_hdr hdr;
3986 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003987
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04003989 status = decode_compound_hdr(&xdr, &hdr);
3990 if (status)
3991 goto out;
3992 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3993 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 goto out;
3995 if ((status = decode_putrootfh(&xdr)) != 0)
3996 goto out;
3997 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3998 status = decode_getfattr(&xdr, res->fattr, res->server);
3999out:
4000 return status;
4001}
4002
4003/*
4004 * Decode REMOVE response
4005 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004006static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007{
4008 struct xdr_stream xdr;
4009 struct compound_hdr hdr;
4010 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004011
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004013 status = decode_compound_hdr(&xdr, &hdr);
4014 if (status)
4015 goto out;
4016 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4017 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004019 if ((status = decode_putfh(&xdr)) != 0)
4020 goto out;
4021 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4022 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004023 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024out:
4025 return status;
4026}
4027
4028/*
4029 * Decode RENAME response
4030 */
Al Viro8687b632006-10-19 23:28:48 -07004031static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032{
4033 struct xdr_stream xdr;
4034 struct compound_hdr hdr;
4035 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004036
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004038 status = decode_compound_hdr(&xdr, &hdr);
4039 if (status)
4040 goto out;
4041 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4042 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 goto out;
4044 if ((status = decode_putfh(&xdr)) != 0)
4045 goto out;
4046 if ((status = decode_savefh(&xdr)) != 0)
4047 goto out;
4048 if ((status = decode_putfh(&xdr)) != 0)
4049 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004050 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4051 goto out;
4052 /* Current FH is target directory */
4053 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4054 goto out;
4055 if ((status = decode_restorefh(&xdr)) != 0)
4056 goto out;
4057 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058out:
4059 return status;
4060}
4061
4062/*
4063 * Decode LINK response
4064 */
Al Viro8687b632006-10-19 23:28:48 -07004065static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066{
4067 struct xdr_stream xdr;
4068 struct compound_hdr hdr;
4069 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004070
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004072 status = decode_compound_hdr(&xdr, &hdr);
4073 if (status)
4074 goto out;
4075 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4076 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 goto out;
4078 if ((status = decode_putfh(&xdr)) != 0)
4079 goto out;
4080 if ((status = decode_savefh(&xdr)) != 0)
4081 goto out;
4082 if ((status = decode_putfh(&xdr)) != 0)
4083 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004084 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4085 goto out;
4086 /*
4087 * Note order: OP_LINK leaves the directory as the current
4088 * filehandle.
4089 */
4090 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4091 goto out;
4092 if ((status = decode_restorefh(&xdr)) != 0)
4093 goto out;
4094 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095out:
4096 return status;
4097}
4098
4099/*
4100 * Decode CREATE response
4101 */
Al Viro8687b632006-10-19 23:28:48 -07004102static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103{
4104 struct xdr_stream xdr;
4105 struct compound_hdr hdr;
4106 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004107
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004109 status = decode_compound_hdr(&xdr, &hdr);
4110 if (status)
4111 goto out;
4112 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4113 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 goto out;
4115 if ((status = decode_putfh(&xdr)) != 0)
4116 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004117 if ((status = decode_savefh(&xdr)) != 0)
4118 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4120 goto out;
4121 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4122 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004123 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4124 goto out;
4125 if ((status = decode_restorefh(&xdr)) != 0)
4126 goto out;
4127 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128out:
4129 return status;
4130}
4131
4132/*
4133 * Decode SYMLINK response
4134 */
Al Viro8687b632006-10-19 23:28:48 -07004135static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136{
4137 return nfs4_xdr_dec_create(rqstp, p, res);
4138}
4139
4140/*
4141 * Decode GETATTR response
4142 */
Al Viro8687b632006-10-19 23:28:48 -07004143static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144{
4145 struct xdr_stream xdr;
4146 struct compound_hdr hdr;
4147 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004148
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4150 status = decode_compound_hdr(&xdr, &hdr);
4151 if (status)
4152 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004153 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4154 if (status)
4155 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 status = decode_putfh(&xdr);
4157 if (status)
4158 goto out;
4159 status = decode_getfattr(&xdr, res->fattr, res->server);
4160out:
4161 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162}
4163
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004164/*
4165 * Encode an SETACL request
4166 */
4167static int
Al Viro8687b632006-10-19 23:28:48 -07004168nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004169{
Andy Adamson05d564f2008-12-23 16:06:15 -05004170 struct xdr_stream xdr;
4171 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004173 };
4174 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004175
Andy Adamson05d564f2008-12-23 16:06:15 -05004176 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004177 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004178 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004179 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004180 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004181 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004182 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004183}
Andy Adamson05d564f2008-12-23 16:06:15 -05004184
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004185/*
4186 * Decode SETACL response
4187 */
4188static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004189nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4190 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004191{
4192 struct xdr_stream xdr;
4193 struct compound_hdr hdr;
4194 int status;
4195
4196 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4197 status = decode_compound_hdr(&xdr, &hdr);
4198 if (status)
4199 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004200 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4201 if (status)
4202 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004203 status = decode_putfh(&xdr);
4204 if (status)
4205 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004206 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004207out:
4208 return status;
4209}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210
4211/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004212 * Decode GETACL response
4213 */
4214static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004215nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4216 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004217{
4218 struct xdr_stream xdr;
4219 struct compound_hdr hdr;
4220 int status;
4221
4222 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4223 status = decode_compound_hdr(&xdr, &hdr);
4224 if (status)
4225 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004226 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4227 if (status)
4228 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004229 status = decode_putfh(&xdr);
4230 if (status)
4231 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004232 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004233
4234out:
4235 return status;
4236}
4237
4238/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 * Decode CLOSE response
4240 */
Al Viro8687b632006-10-19 23:28:48 -07004241static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242{
Andy Adamson05d564f2008-12-23 16:06:15 -05004243 struct xdr_stream xdr;
4244 struct compound_hdr hdr;
4245 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246
Andy Adamson05d564f2008-12-23 16:06:15 -05004247 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4248 status = decode_compound_hdr(&xdr, &hdr);
4249 if (status)
4250 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004251 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4252 if (status)
4253 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004254 status = decode_putfh(&xdr);
4255 if (status)
4256 goto out;
4257 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004258 if (status != 0)
4259 goto out;
4260 /*
4261 * Note: Server may do delete on close for this file
4262 * in which case the getattr call will fail with
4263 * an ESTALE error. Shouldn't be a problem,
4264 * though, since fattr->valid will remain unset.
4265 */
4266 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004268 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269}
4270
4271/*
4272 * Decode OPEN response
4273 */
Al Viro8687b632006-10-19 23:28:48 -07004274static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275{
Andy Adamson05d564f2008-12-23 16:06:15 -05004276 struct xdr_stream xdr;
4277 struct compound_hdr hdr;
4278 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279
Andy Adamson05d564f2008-12-23 16:06:15 -05004280 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4281 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004282 if (status)
4283 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004284 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4285 if (status)
4286 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004287 status = decode_putfh(&xdr);
4288 if (status)
4289 goto out;
4290 status = decode_savefh(&xdr);
4291 if (status)
4292 goto out;
4293 status = decode_open(&xdr, res);
4294 if (status)
4295 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004296 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004298 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4299 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004300 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004301 goto out;
4302 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004304 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305}
4306
4307/*
4308 * Decode OPEN_CONFIRM response
4309 */
Al Viro8687b632006-10-19 23:28:48 -07004310static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311{
Andy Adamson05d564f2008-12-23 16:06:15 -05004312 struct xdr_stream xdr;
4313 struct compound_hdr hdr;
4314 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315
Andy Adamson05d564f2008-12-23 16:06:15 -05004316 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4317 status = decode_compound_hdr(&xdr, &hdr);
4318 if (status)
4319 goto out;
4320 status = decode_putfh(&xdr);
4321 if (status)
4322 goto out;
4323 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004325 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326}
4327
4328/*
4329 * Decode OPEN response
4330 */
Al Viro8687b632006-10-19 23:28:48 -07004331static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332{
Andy Adamson05d564f2008-12-23 16:06:15 -05004333 struct xdr_stream xdr;
4334 struct compound_hdr hdr;
4335 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336
Andy Adamson05d564f2008-12-23 16:06:15 -05004337 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4338 status = decode_compound_hdr(&xdr, &hdr);
4339 if (status)
4340 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004341 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4342 if (status)
4343 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004344 status = decode_putfh(&xdr);
4345 if (status)
4346 goto out;
4347 status = decode_open(&xdr, res);
4348 if (status)
4349 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004350 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004352 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353}
4354
4355/*
4356 * Decode SETATTR response
4357 */
Al Viro8687b632006-10-19 23:28:48 -07004358static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359{
Andy Adamson05d564f2008-12-23 16:06:15 -05004360 struct xdr_stream xdr;
4361 struct compound_hdr hdr;
4362 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363
Andy Adamson05d564f2008-12-23 16:06:15 -05004364 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4365 status = decode_compound_hdr(&xdr, &hdr);
4366 if (status)
4367 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004368 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4369 if (status)
4370 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004371 status = decode_putfh(&xdr);
4372 if (status)
4373 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004374 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004375 if (status)
4376 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004377 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004379 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380}
4381
4382/*
4383 * Decode LOCK response
4384 */
Al Viro8687b632006-10-19 23:28:48 -07004385static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386{
4387 struct xdr_stream xdr;
4388 struct compound_hdr hdr;
4389 int status;
4390
4391 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4392 status = decode_compound_hdr(&xdr, &hdr);
4393 if (status)
4394 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004395 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4396 if (status)
4397 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 status = decode_putfh(&xdr);
4399 if (status)
4400 goto out;
4401 status = decode_lock(&xdr, res);
4402out:
4403 return status;
4404}
4405
4406/*
4407 * Decode LOCKT response
4408 */
Al Viro8687b632006-10-19 23:28:48 -07004409static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410{
4411 struct xdr_stream xdr;
4412 struct compound_hdr hdr;
4413 int status;
4414
4415 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4416 status = decode_compound_hdr(&xdr, &hdr);
4417 if (status)
4418 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004419 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4420 if (status)
4421 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 status = decode_putfh(&xdr);
4423 if (status)
4424 goto out;
4425 status = decode_lockt(&xdr, res);
4426out:
4427 return status;
4428}
4429
4430/*
4431 * Decode LOCKU response
4432 */
Al Viro8687b632006-10-19 23:28:48 -07004433static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434{
4435 struct xdr_stream xdr;
4436 struct compound_hdr hdr;
4437 int status;
4438
4439 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4440 status = decode_compound_hdr(&xdr, &hdr);
4441 if (status)
4442 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004443 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4444 if (status)
4445 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 status = decode_putfh(&xdr);
4447 if (status)
4448 goto out;
4449 status = decode_locku(&xdr, res);
4450out:
4451 return status;
4452}
4453
4454/*
4455 * Decode READLINK response
4456 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004457static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4458 struct nfs4_readlink_res *res)
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 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004468 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4469 if (status)
4470 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471 status = decode_putfh(&xdr);
4472 if (status)
4473 goto out;
4474 status = decode_readlink(&xdr, rqstp);
4475out:
4476 return status;
4477}
4478
4479/*
4480 * Decode READDIR response
4481 */
Al Viro8687b632006-10-19 23:28:48 -07004482static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483{
4484 struct xdr_stream xdr;
4485 struct compound_hdr hdr;
4486 int status;
4487
4488 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4489 status = decode_compound_hdr(&xdr, &hdr);
4490 if (status)
4491 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004492 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4493 if (status)
4494 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 status = decode_putfh(&xdr);
4496 if (status)
4497 goto out;
4498 status = decode_readdir(&xdr, rqstp, res);
4499out:
4500 return status;
4501}
4502
4503/*
4504 * Decode Read response
4505 */
Al Viro8687b632006-10-19 23:28:48 -07004506static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507{
4508 struct xdr_stream xdr;
4509 struct compound_hdr hdr;
4510 int status;
4511
4512 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4513 status = decode_compound_hdr(&xdr, &hdr);
4514 if (status)
4515 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004516 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4517 if (status)
4518 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 status = decode_putfh(&xdr);
4520 if (status)
4521 goto out;
4522 status = decode_read(&xdr, rqstp, res);
4523 if (!status)
4524 status = res->count;
4525out:
4526 return status;
4527}
4528
4529/*
4530 * Decode WRITE response
4531 */
Al Viro8687b632006-10-19 23:28:48 -07004532static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533{
4534 struct xdr_stream xdr;
4535 struct compound_hdr hdr;
4536 int status;
4537
4538 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4539 status = decode_compound_hdr(&xdr, &hdr);
4540 if (status)
4541 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004542 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4543 if (status)
4544 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 status = decode_putfh(&xdr);
4546 if (status)
4547 goto out;
4548 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004549 if (status)
4550 goto out;
4551 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 if (!status)
4553 status = res->count;
4554out:
4555 return status;
4556}
4557
4558/*
4559 * Decode COMMIT response
4560 */
Al Viro8687b632006-10-19 23:28:48 -07004561static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562{
4563 struct xdr_stream xdr;
4564 struct compound_hdr hdr;
4565 int status;
4566
4567 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4568 status = decode_compound_hdr(&xdr, &hdr);
4569 if (status)
4570 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004571 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4572 if (status)
4573 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 status = decode_putfh(&xdr);
4575 if (status)
4576 goto out;
4577 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004578 if (status)
4579 goto out;
4580 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581out:
4582 return status;
4583}
4584
4585/*
4586 * FSINFO request
4587 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04004588static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4589 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590{
4591 struct xdr_stream xdr;
4592 struct compound_hdr hdr;
4593 int status;
4594
4595 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4596 status = decode_compound_hdr(&xdr, &hdr);
4597 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004598 status = decode_sequence(&xdr, &res->seq_res, req);
4599 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 status = decode_putfh(&xdr);
4601 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04004602 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 return status;
4604}
4605
4606/*
4607 * PATHCONF request
4608 */
Benny Halevyd45b2982009-04-01 09:21:58 -04004609static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4610 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611{
4612 struct xdr_stream xdr;
4613 struct compound_hdr hdr;
4614 int status;
4615
4616 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4617 status = decode_compound_hdr(&xdr, &hdr);
4618 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004619 status = decode_sequence(&xdr, &res->seq_res, req);
4620 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 status = decode_putfh(&xdr);
4622 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04004623 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 return status;
4625}
4626
4627/*
4628 * STATFS request
4629 */
Benny Halevy24ad1482009-04-01 09:21:56 -04004630static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4631 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632{
4633 struct xdr_stream xdr;
4634 struct compound_hdr hdr;
4635 int status;
4636
4637 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4638 status = decode_compound_hdr(&xdr, &hdr);
4639 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004640 status = decode_sequence(&xdr, &res->seq_res, req);
4641 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 status = decode_putfh(&xdr);
4643 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04004644 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 return status;
4646}
4647
4648/*
4649 * GETATTR_BITMAP request
4650 */
Al Viro8687b632006-10-19 23:28:48 -07004651static 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 -07004652{
4653 struct xdr_stream xdr;
4654 struct compound_hdr hdr;
4655 int status;
4656
4657 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004658 status = decode_compound_hdr(&xdr, &hdr);
4659 if (status)
4660 goto out;
4661 status = decode_sequence(&xdr, &res->seq_res, req);
4662 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 goto out;
4664 if ((status = decode_putfh(&xdr)) != 0)
4665 goto out;
4666 status = decode_server_caps(&xdr, res);
4667out:
4668 return status;
4669}
4670
4671/*
4672 * Decode RENEW response
4673 */
Al Viro8687b632006-10-19 23:28:48 -07004674static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675{
4676 struct xdr_stream xdr;
4677 struct compound_hdr hdr;
4678 int status;
4679
4680 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4681 status = decode_compound_hdr(&xdr, &hdr);
4682 if (!status)
4683 status = decode_renew(&xdr);
4684 return status;
4685}
4686
4687/*
4688 * a SETCLIENTID request
4689 */
Al Viro8687b632006-10-19 23:28:48 -07004690static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004691 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692{
4693 struct xdr_stream xdr;
4694 struct compound_hdr hdr;
4695 int status;
4696
4697 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4698 status = decode_compound_hdr(&xdr, &hdr);
4699 if (!status)
4700 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 return status;
4702}
4703
4704/*
4705 * a SETCLIENTID_CONFIRM request
4706 */
Al Viro8687b632006-10-19 23:28:48 -07004707static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708{
4709 struct xdr_stream xdr;
4710 struct compound_hdr hdr;
4711 int status;
4712
4713 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4714 status = decode_compound_hdr(&xdr, &hdr);
4715 if (!status)
4716 status = decode_setclientid_confirm(&xdr);
4717 if (!status)
4718 status = decode_putrootfh(&xdr);
4719 if (!status)
4720 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 return status;
4722}
4723
4724/*
4725 * DELEGRETURN request
4726 */
Al Viro8687b632006-10-19 23:28:48 -07004727static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728{
4729 struct xdr_stream xdr;
4730 struct compound_hdr hdr;
4731 int status;
4732
4733 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4734 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004735 if (status)
4736 goto out;
4737 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4738 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01004739 goto out;
4740 status = decode_putfh(&xdr);
4741 if (status != 0)
4742 goto out;
4743 status = decode_delegreturn(&xdr);
4744 decode_getfattr(&xdr, res->fattr, res->server);
4745out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 return status;
4747}
4748
Trond Myklebust683b57b2006-06-09 09:34:22 -04004749/*
4750 * FS_LOCATIONS request
4751 */
Benny Halevy22958462009-04-01 09:22:02 -04004752static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4753 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004754{
4755 struct xdr_stream xdr;
4756 struct compound_hdr hdr;
4757 int status;
4758
4759 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4760 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004761 if (status)
4762 goto out;
4763 status = decode_sequence(&xdr, &res->seq_res, req);
4764 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004765 goto out;
4766 if ((status = decode_putfh(&xdr)) != 0)
4767 goto out;
4768 if ((status = decode_lookup(&xdr)) != 0)
4769 goto out;
4770 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04004771 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4772 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04004773out:
4774 return status;
4775}
4776
Al Viro0dbb4c62006-10-19 23:28:49 -07004777__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778{
4779 uint32_t bitmap[2] = {0};
4780 uint32_t len;
4781
4782 if (!*p++) {
4783 if (!*p)
4784 return ERR_PTR(-EAGAIN);
4785 entry->eof = 1;
4786 return ERR_PTR(-EBADCOOKIE);
4787 }
4788
4789 entry->prev_cookie = entry->cookie;
4790 p = xdr_decode_hyper(p, &entry->cookie);
4791 entry->len = ntohl(*p++);
4792 entry->name = (const char *) p;
4793 p += XDR_QUADLEN(entry->len);
4794
4795 /*
4796 * In case the server doesn't return an inode number,
4797 * we fake one here. (We don't use inode number 0,
4798 * since glibc seems to choke on it...)
4799 */
4800 entry->ino = 1;
4801
4802 len = ntohl(*p++); /* bitmap length */
4803 if (len-- > 0) {
4804 bitmap[0] = ntohl(*p++);
4805 if (len-- > 0) {
4806 bitmap[1] = ntohl(*p++);
4807 p += len;
4808 }
4809 }
4810 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4811 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004812 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4813 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4814 /* Ignore the return value of rdattr_error for now */
4815 p++;
4816 len--;
4817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4819 xdr_decode_hyper(p, &entry->ino);
4820 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4821 xdr_decode_hyper(p, &entry->ino);
4822 p += len;
4823 }
4824
4825 entry->eof = !p[0] && p[1];
4826 return p;
4827}
4828
4829/*
4830 * We need to translate between nfs status return values and
4831 * the local errno values which may not be the same.
4832 */
4833static struct {
4834 int stat;
4835 int errno;
4836} nfs_errtbl[] = {
4837 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03004838 { NFS4ERR_PERM, -EPERM },
4839 { NFS4ERR_NOENT, -ENOENT },
4840 { NFS4ERR_IO, -errno_NFSERR_IO},
4841 { NFS4ERR_NXIO, -ENXIO },
4842 { NFS4ERR_ACCESS, -EACCES },
4843 { NFS4ERR_EXIST, -EEXIST },
4844 { NFS4ERR_XDEV, -EXDEV },
4845 { NFS4ERR_NOTDIR, -ENOTDIR },
4846 { NFS4ERR_ISDIR, -EISDIR },
4847 { NFS4ERR_INVAL, -EINVAL },
4848 { NFS4ERR_FBIG, -EFBIG },
4849 { NFS4ERR_NOSPC, -ENOSPC },
4850 { NFS4ERR_ROFS, -EROFS },
4851 { NFS4ERR_MLINK, -EMLINK },
4852 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4853 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4854 { NFS4ERR_DQUOT, -EDQUOT },
4855 { NFS4ERR_STALE, -ESTALE },
4856 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4857 { NFS4ERR_BADOWNER, -EINVAL },
4858 { NFS4ERR_BADNAME, -EINVAL },
4859 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4860 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4861 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4862 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4863 { NFS4ERR_BADTYPE, -EBADTYPE },
4864 { NFS4ERR_LOCKED, -EAGAIN },
4865 { NFS4ERR_RESOURCE, -EREMOTEIO },
4866 { NFS4ERR_SYMLINK, -ELOOP },
4867 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4868 { NFS4ERR_DEADLOCK, -EDEADLK },
4869 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 * to be handled by a
4871 * middle-layer.
4872 */
Benny Halevy856dff32008-03-31 17:39:06 +03004873 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874};
4875
4876/*
4877 * Convert an NFS error code to a local one.
4878 * This one is used jointly by NFSv2 and NFSv3.
4879 */
4880static int
David Howells0a8ea432006-08-22 20:06:08 -04004881nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882{
4883 int i;
4884 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4885 if (nfs_errtbl[i].stat == stat)
4886 return nfs_errtbl[i].errno;
4887 }
4888 if (stat <= 10000 || stat > 10100) {
4889 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03004890 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 }
4892 /* If we cannot translate the error, the recovery routines should
4893 * handle it.
4894 * Note: remaining NFSv4 error codes have values > 10000, so should
4895 * not conflict with native Linux error codes.
4896 */
Benny Halevy856dff32008-03-31 17:39:06 +03004897 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898}
4899
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900#define PROC(proc, argtype, restype) \
4901[NFSPROC4_CLNT_##proc] = { \
4902 .p_proc = NFSPROC4_COMPOUND, \
4903 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4904 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004905 .p_arglen = NFS4_##argtype##_sz, \
4906 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004907 .p_statidx = NFSPROC4_CLNT_##proc, \
4908 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05004909}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910
4911struct rpc_procinfo nfs4_procedures[] = {
4912 PROC(READ, enc_read, dec_read),
4913 PROC(WRITE, enc_write, dec_write),
4914 PROC(COMMIT, enc_commit, dec_commit),
4915 PROC(OPEN, enc_open, dec_open),
4916 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4917 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4918 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4919 PROC(CLOSE, enc_close, dec_close),
4920 PROC(SETATTR, enc_setattr, dec_setattr),
4921 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4922 PROC(RENEW, enc_renew, dec_renew),
4923 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4924 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4925 PROC(LOCK, enc_lock, dec_lock),
4926 PROC(LOCKT, enc_lockt, dec_lockt),
4927 PROC(LOCKU, enc_locku, dec_locku),
4928 PROC(ACCESS, enc_access, dec_access),
4929 PROC(GETATTR, enc_getattr, dec_getattr),
4930 PROC(LOOKUP, enc_lookup, dec_lookup),
4931 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4932 PROC(REMOVE, enc_remove, dec_remove),
4933 PROC(RENAME, enc_rename, dec_rename),
4934 PROC(LINK, enc_link, dec_link),
4935 PROC(SYMLINK, enc_symlink, dec_symlink),
4936 PROC(CREATE, enc_create, dec_create),
4937 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4938 PROC(STATFS, enc_statfs, dec_statfs),
4939 PROC(READLINK, enc_readlink, dec_readlink),
4940 PROC(READDIR, enc_readdir, dec_readdir),
4941 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4942 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004943 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004944 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004945 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946};
4947
4948struct rpc_version nfs_version4 = {
4949 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004950 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 .procs = nfs4_procedures
4952};
4953
4954/*
4955 * Local variables:
4956 * c-basic-offset: 8
4957 * End:
4958 */