Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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> | |
6c0195a4 | 11 | * |
1da177e4 LT |
12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | |
15 | * | |
16 | * 1. Redistributions of source code must retain the above copyright | |
17 | * notice, this list of conditions and the following disclaimer. | |
18 | * 2. Redistributions in binary form must reproduce the above copyright | |
19 | * notice, this list of conditions and the following disclaimer in the | |
20 | * documentation and/or other materials provided with the distribution. | |
21 | * 3. Neither the name of the University nor the names of its | |
22 | * contributors may be used to endorse or promote products derived | |
23 | * from this software without specific prior written permission. | |
24 | * | |
25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
38 | #include <linux/param.h> | |
39 | #include <linux/time.h> | |
40 | #include <linux/mm.h> | |
41 | #include <linux/slab.h> | |
1da177e4 LT |
42 | #include <linux/errno.h> |
43 | #include <linux/string.h> | |
44 | #include <linux/in.h> | |
45 | #include <linux/pagemap.h> | |
46 | #include <linux/proc_fs.h> | |
47 | #include <linux/kdev_t.h> | |
48 | #include <linux/sunrpc/clnt.h> | |
2449ea2e | 49 | #include <linux/sunrpc/msg_prot.h> |
1da177e4 LT |
50 | #include <linux/nfs.h> |
51 | #include <linux/nfs4.h> | |
52 | #include <linux/nfs_fs.h> | |
53 | #include <linux/nfs_idmap.h> | |
4ce79717 | 54 | #include "nfs4_fs.h" |
4882ef72 | 55 | #include "internal.h" |
1da177e4 LT |
56 | |
57 | #define NFSDBG_FACILITY NFSDBG_XDR | |
58 | ||
59 | /* Mapping from NFS error code to "errno" error code. */ | |
60 | #define errno_NFSERR_IO EIO | |
61 | ||
0a8ea437 | 62 | static int nfs4_stat_to_errno(int); |
1da177e4 LT |
63 | |
64 | /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ | |
65 | #ifdef DEBUG | |
66 | #define NFS4_MAXTAGLEN 20 | |
67 | #else | |
68 | #define NFS4_MAXTAGLEN 0 | |
69 | #endif | |
70 | ||
6c0195a4 | 71 | /* lock,open owner id: |
9f958ab8 | 72 | * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) |
1da177e4 | 73 | */ |
9f958ab8 TM |
74 | #define open_owner_id_maxsz (1 + 4) |
75 | #define lock_owner_id_maxsz (1 + 4) | |
9104a55d | 76 | #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
1da177e4 LT |
77 | #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
78 | #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) | |
79 | #define op_encode_hdr_maxsz (1) | |
80 | #define op_decode_hdr_maxsz (2) | |
9104a55d TM |
81 | #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) |
82 | #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) | |
83 | #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) | |
84 | #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) | |
1da177e4 LT |
85 | #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ |
86 | (NFS4_FHSIZE >> 2)) | |
87 | #define decode_putfh_maxsz (op_decode_hdr_maxsz) | |
88 | #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) | |
89 | #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) | |
90 | #define encode_getfh_maxsz (op_encode_hdr_maxsz) | |
91 | #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ | |
92 | ((3+NFS4_FHSIZE) >> 2)) | |
96928206 BF |
93 | #define nfs4_fattr_bitmap_maxsz 3 |
94 | #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) | |
1da177e4 LT |
95 | #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) |
96 | #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) | |
bd625ba8 TM |
97 | #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
98 | #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) | |
96928206 BF |
99 | /* This is based on getfattr, which uses the most attributes: */ |
100 | #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ | |
bd625ba8 | 101 | 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz)) |
96928206 BF |
102 | #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ |
103 | nfs4_fattr_value_maxsz) | |
104 | #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) | |
9104a55d TM |
105 | #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ |
106 | 1 + 2 + 1 + \ | |
107 | nfs4_owner_maxsz + \ | |
108 | nfs4_group_maxsz + \ | |
109 | 4 + 4) | |
1da177e4 LT |
110 | #define encode_savefh_maxsz (op_encode_hdr_maxsz) |
111 | #define decode_savefh_maxsz (op_decode_hdr_maxsz) | |
56ae19f3 TM |
112 | #define encode_restorefh_maxsz (op_encode_hdr_maxsz) |
113 | #define decode_restorefh_maxsz (op_decode_hdr_maxsz) | |
2f42b5d0 | 114 | #define encode_fsinfo_maxsz (encode_getattr_maxsz) |
1da177e4 LT |
115 | #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11) |
116 | #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) | |
117 | #define decode_renew_maxsz (op_decode_hdr_maxsz) | |
118 | #define encode_setclientid_maxsz \ | |
119 | (op_encode_hdr_maxsz + \ | |
cc38bac3 CL |
120 | XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ |
121 | XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ | |
122 | 1 /* sc_prog */ + \ | |
123 | XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ | |
124 | XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ | |
125 | 1) /* sc_cb_ident */ | |
1da177e4 LT |
126 | #define decode_setclientid_maxsz \ |
127 | (op_decode_hdr_maxsz + \ | |
128 | 2 + \ | |
129 | 1024) /* large value for CLID_INUSE */ | |
130 | #define encode_setclientid_confirm_maxsz \ | |
131 | (op_encode_hdr_maxsz + \ | |
132 | 3 + (NFS4_VERIFIER_SIZE >> 2)) | |
133 | #define decode_setclientid_confirm_maxsz \ | |
134 | (op_decode_hdr_maxsz) | |
e6889620 TM |
135 | #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) |
136 | #define decode_lookup_maxsz (op_decode_hdr_maxsz) | |
2cebf828 TM |
137 | #define encode_share_access_maxsz \ |
138 | (2) | |
4882ef72 | 139 | #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) |
2cebf828 TM |
140 | #define encode_opentype_maxsz (1 + encode_createmode_maxsz) |
141 | #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) | |
142 | #define encode_open_maxsz (op_encode_hdr_maxsz + \ | |
143 | 2 + encode_share_access_maxsz + 2 + \ | |
144 | open_owner_id_maxsz + \ | |
145 | encode_opentype_maxsz + \ | |
146 | encode_claim_null_maxsz) | |
147 | #define decode_ace_maxsz (3 + nfs4_owner_maxsz) | |
9104a55d | 148 | #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ |
2cebf828 TM |
149 | decode_ace_maxsz) |
150 | #define decode_change_info_maxsz (5) | |
151 | #define decode_open_maxsz (op_decode_hdr_maxsz + \ | |
9104a55d | 152 | decode_stateid_maxsz + \ |
2cebf828 TM |
153 | decode_change_info_maxsz + 1 + \ |
154 | nfs4_fattr_bitmap_maxsz + \ | |
155 | decode_delegation_maxsz) | |
9104a55d TM |
156 | #define encode_open_confirm_maxsz \ |
157 | (op_encode_hdr_maxsz + \ | |
158 | encode_stateid_maxsz + 1) | |
159 | #define decode_open_confirm_maxsz \ | |
160 | (op_decode_hdr_maxsz + \ | |
161 | decode_stateid_maxsz) | |
162 | #define encode_open_downgrade_maxsz \ | |
163 | (op_encode_hdr_maxsz + \ | |
164 | encode_stateid_maxsz + 1 + \ | |
165 | encode_share_access_maxsz) | |
166 | #define decode_open_downgrade_maxsz \ | |
167 | (op_decode_hdr_maxsz + \ | |
168 | decode_stateid_maxsz) | |
169 | #define encode_close_maxsz (op_encode_hdr_maxsz + \ | |
170 | 1 + encode_stateid_maxsz) | |
171 | #define decode_close_maxsz (op_decode_hdr_maxsz + \ | |
172 | decode_stateid_maxsz) | |
173 | #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ | |
174 | encode_stateid_maxsz + \ | |
175 | encode_attrs_maxsz) | |
176 | #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ | |
177 | nfs4_fattr_bitmap_maxsz) | |
178 | #define encode_read_maxsz (op_encode_hdr_maxsz + \ | |
179 | encode_stateid_maxsz + 3) | |
180 | #define decode_read_maxsz (op_decode_hdr_maxsz + 2) | |
181 | #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ | |
182 | 2 + encode_verifier_maxsz + 5) | |
183 | #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ | |
184 | decode_verifier_maxsz) | |
185 | #define encode_readlink_maxsz (op_encode_hdr_maxsz) | |
186 | #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) | |
187 | #define encode_write_maxsz (op_encode_hdr_maxsz + \ | |
188 | encode_stateid_maxsz + 4) | |
189 | #define decode_write_maxsz (op_decode_hdr_maxsz + \ | |
190 | 2 + decode_verifier_maxsz) | |
191 | #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) | |
192 | #define decode_commit_maxsz (op_decode_hdr_maxsz + \ | |
193 | decode_verifier_maxsz) | |
1da177e4 LT |
194 | #define encode_remove_maxsz (op_encode_hdr_maxsz + \ |
195 | nfs4_name_maxsz) | |
6ce18391 BH |
196 | #define decode_remove_maxsz (op_decode_hdr_maxsz + \ |
197 | decode_change_info_maxsz) | |
1da177e4 LT |
198 | #define encode_rename_maxsz (op_encode_hdr_maxsz + \ |
199 | 2 * nfs4_name_maxsz) | |
6ce18391 BH |
200 | #define decode_rename_maxsz (op_decode_hdr_maxsz + \ |
201 | decode_change_info_maxsz + \ | |
202 | decode_change_info_maxsz) | |
1da177e4 LT |
203 | #define encode_link_maxsz (op_encode_hdr_maxsz + \ |
204 | nfs4_name_maxsz) | |
6ce18391 | 205 | #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) |
9104a55d TM |
206 | #define encode_lock_maxsz (op_encode_hdr_maxsz + \ |
207 | 7 + \ | |
208 | 1 + encode_stateid_maxsz + 8) | |
209 | #define decode_lock_denied_maxsz \ | |
210 | (8 + decode_lockowner_maxsz) | |
211 | #define decode_lock_maxsz (op_decode_hdr_maxsz + \ | |
212 | decode_lock_denied_maxsz) | |
213 | #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12) | |
214 | #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ | |
215 | decode_lock_denied_maxsz) | |
216 | #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ | |
217 | encode_stateid_maxsz + \ | |
218 | 4) | |
219 | #define decode_locku_maxsz (op_decode_hdr_maxsz + \ | |
220 | decode_stateid_maxsz) | |
221 | #define encode_access_maxsz (op_encode_hdr_maxsz + 1) | |
222 | #define decode_access_maxsz (op_decode_hdr_maxsz + 2) | |
1da177e4 LT |
223 | #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ |
224 | 1 + nfs4_name_maxsz + \ | |
94a6d753 | 225 | 1 + \ |
96928206 | 226 | nfs4_fattr_maxsz) |
1da177e4 LT |
227 | #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) |
228 | #define encode_create_maxsz (op_encode_hdr_maxsz + \ | |
9104a55d TM |
229 | 1 + 2 + nfs4_name_maxsz + \ |
230 | encode_attrs_maxsz) | |
2cebf828 TM |
231 | #define decode_create_maxsz (op_decode_hdr_maxsz + \ |
232 | decode_change_info_maxsz + \ | |
233 | nfs4_fattr_bitmap_maxsz) | |
9104a55d TM |
234 | #define encode_statfs_maxsz (encode_getattr_maxsz) |
235 | #define decode_statfs_maxsz (decode_getattr_maxsz) | |
1da177e4 LT |
236 | #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) |
237 | #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) | |
9104a55d TM |
238 | #define encode_getacl_maxsz (encode_getattr_maxsz) |
239 | #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ | |
240 | nfs4_fattr_bitmap_maxsz + 1) | |
241 | #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ | |
242 | encode_stateid_maxsz + 3) | |
243 | #define decode_setacl_maxsz (decode_setattr_maxsz) | |
e6889620 TM |
244 | #define encode_fs_locations_maxsz \ |
245 | (encode_getattr_maxsz) | |
246 | #define decode_fs_locations_maxsz \ | |
247 | (0) | |
9b7b9fcc AA |
248 | |
249 | #if defined(CONFIG_NFS_V4_1) | |
fc931582 AA |
250 | #define NFS4_MAX_MACHINE_NAME_LEN (64) |
251 | ||
99fe60d0 BH |
252 | #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ |
253 | encode_verifier_maxsz + \ | |
254 | 1 /* co_ownerid.len */ + \ | |
255 | XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ | |
256 | 1 /* flags */ + \ | |
257 | 1 /* spa_how */ + \ | |
258 | 0 /* SP4_NONE (for now) */ + \ | |
259 | 1 /* zero implemetation id array */) | |
260 | #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ | |
261 | 2 /* eir_clientid */ + \ | |
262 | 1 /* eir_sequenceid */ + \ | |
263 | 1 /* eir_flags */ + \ | |
264 | 1 /* spr_how */ + \ | |
265 | 0 /* SP4_NONE (for now) */ + \ | |
266 | 2 /* eir_server_owner.so_minor_id */ + \ | |
267 | /* eir_server_owner.so_major_id<> */ \ | |
268 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ | |
269 | /* eir_server_scope<> */ \ | |
270 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ | |
271 | 1 /* eir_server_impl_id array length */ + \ | |
272 | 0 /* ignored eir_server_impl_id contents */) | |
fc931582 AA |
273 | #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) |
274 | #define decode_channel_attrs_maxsz (6 + \ | |
275 | 1 /* ca_rdma_ird.len */ + \ | |
276 | 1 /* ca_rdma_ird */) | |
277 | #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ | |
278 | 2 /* csa_clientid */ + \ | |
279 | 1 /* csa_sequence */ + \ | |
280 | 1 /* csa_flags */ + \ | |
281 | encode_channel_attrs_maxsz + \ | |
282 | encode_channel_attrs_maxsz + \ | |
283 | 1 /* csa_cb_program */ + \ | |
284 | 1 /* csa_sec_parms.len (1) */ + \ | |
285 | 1 /* cb_secflavor (AUTH_SYS) */ + \ | |
286 | 1 /* stamp */ + \ | |
287 | 1 /* machinename.len */ + \ | |
288 | XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ | |
289 | 1 /* uid */ + \ | |
290 | 1 /* gid */ + \ | |
291 | 1 /* gids.len (0) */) | |
292 | #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ | |
293 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ | |
294 | 1 /* csr_sequence */ + \ | |
295 | 1 /* csr_flags */ + \ | |
296 | decode_channel_attrs_maxsz + \ | |
297 | decode_channel_attrs_maxsz) | |
0f3e66c6 AA |
298 | #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) |
299 | #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) | |
fc01cea9 AA |
300 | #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ |
301 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) | |
302 | #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ | |
303 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) | |
9b7b9fcc AA |
304 | #else /* CONFIG_NFS_V4_1 */ |
305 | #define encode_sequence_maxsz 0 | |
306 | #define decode_sequence_maxsz 0 | |
307 | #endif /* CONFIG_NFS_V4_1 */ | |
308 | ||
1da177e4 LT |
309 | #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ |
310 | #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ | |
311 | #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 312 | encode_sequence_maxsz + \ |
1da177e4 | 313 | encode_putfh_maxsz + \ |
9104a55d | 314 | encode_read_maxsz) |
1da177e4 | 315 | #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 316 | decode_sequence_maxsz + \ |
1da177e4 | 317 | decode_putfh_maxsz + \ |
9104a55d | 318 | decode_read_maxsz) |
1da177e4 | 319 | #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 320 | encode_sequence_maxsz + \ |
1da177e4 | 321 | encode_putfh_maxsz + \ |
9104a55d | 322 | encode_readlink_maxsz) |
1da177e4 | 323 | #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 324 | decode_sequence_maxsz + \ |
1da177e4 | 325 | decode_putfh_maxsz + \ |
9104a55d | 326 | decode_readlink_maxsz) |
1da177e4 | 327 | #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 328 | encode_sequence_maxsz + \ |
1da177e4 | 329 | encode_putfh_maxsz + \ |
9104a55d | 330 | encode_readdir_maxsz) |
1da177e4 | 331 | #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 332 | decode_sequence_maxsz + \ |
1da177e4 | 333 | decode_putfh_maxsz + \ |
9104a55d | 334 | decode_readdir_maxsz) |
1da177e4 | 335 | #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 336 | encode_sequence_maxsz + \ |
1da177e4 | 337 | encode_putfh_maxsz + \ |
9104a55d | 338 | encode_write_maxsz + \ |
4f9838c7 | 339 | encode_getattr_maxsz) |
1da177e4 | 340 | #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 341 | decode_sequence_maxsz + \ |
1da177e4 | 342 | decode_putfh_maxsz + \ |
9104a55d | 343 | decode_write_maxsz + \ |
4f9838c7 | 344 | decode_getattr_maxsz) |
1da177e4 | 345 | #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 346 | encode_sequence_maxsz + \ |
1da177e4 | 347 | encode_putfh_maxsz + \ |
9104a55d | 348 | encode_commit_maxsz + \ |
4f9838c7 | 349 | encode_getattr_maxsz) |
1da177e4 | 350 | #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 351 | decode_sequence_maxsz + \ |
1da177e4 | 352 | decode_putfh_maxsz + \ |
9104a55d | 353 | decode_commit_maxsz + \ |
4f9838c7 | 354 | decode_getattr_maxsz) |
1da177e4 | 355 | #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 356 | encode_sequence_maxsz + \ |
2cebf828 TM |
357 | encode_putfh_maxsz + \ |
358 | encode_savefh_maxsz + \ | |
359 | encode_open_maxsz + \ | |
360 | encode_getfh_maxsz + \ | |
361 | encode_getattr_maxsz + \ | |
362 | encode_restorefh_maxsz + \ | |
363 | encode_getattr_maxsz) | |
1da177e4 | 364 | #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 365 | decode_sequence_maxsz + \ |
2cebf828 TM |
366 | decode_putfh_maxsz + \ |
367 | decode_savefh_maxsz + \ | |
368 | decode_open_maxsz + \ | |
369 | decode_getfh_maxsz + \ | |
370 | decode_getattr_maxsz + \ | |
371 | decode_restorefh_maxsz + \ | |
372 | decode_getattr_maxsz) | |
9104a55d TM |
373 | #define NFS4_enc_open_confirm_sz \ |
374 | (compound_encode_hdr_maxsz + \ | |
375 | encode_putfh_maxsz + \ | |
376 | encode_open_confirm_maxsz) | |
377 | #define NFS4_dec_open_confirm_sz \ | |
378 | (compound_decode_hdr_maxsz + \ | |
379 | decode_putfh_maxsz + \ | |
380 | decode_open_confirm_maxsz) | |
1da177e4 | 381 | #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 382 | encode_sequence_maxsz + \ |
1da177e4 | 383 | encode_putfh_maxsz + \ |
2cebf828 TM |
384 | encode_open_maxsz + \ |
385 | encode_getattr_maxsz) | |
1da177e4 | 386 | #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 387 | decode_sequence_maxsz + \ |
1da177e4 | 388 | decode_putfh_maxsz + \ |
2cebf828 TM |
389 | decode_open_maxsz + \ |
390 | decode_getattr_maxsz) | |
1da177e4 LT |
391 | #define NFS4_enc_open_downgrade_sz \ |
392 | (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 393 | encode_sequence_maxsz + \ |
9104a55d TM |
394 | encode_putfh_maxsz + \ |
395 | encode_open_downgrade_maxsz + \ | |
396 | encode_getattr_maxsz) | |
1da177e4 LT |
397 | #define NFS4_dec_open_downgrade_sz \ |
398 | (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 399 | decode_sequence_maxsz + \ |
9104a55d TM |
400 | decode_putfh_maxsz + \ |
401 | decode_open_downgrade_maxsz + \ | |
402 | decode_getattr_maxsz) | |
403 | #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 404 | encode_sequence_maxsz + \ |
9104a55d TM |
405 | encode_putfh_maxsz + \ |
406 | encode_close_maxsz + \ | |
407 | encode_getattr_maxsz) | |
408 | #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 409 | decode_sequence_maxsz + \ |
9104a55d TM |
410 | decode_putfh_maxsz + \ |
411 | decode_close_maxsz + \ | |
412 | decode_getattr_maxsz) | |
413 | #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 414 | encode_sequence_maxsz + \ |
9104a55d TM |
415 | encode_putfh_maxsz + \ |
416 | encode_setattr_maxsz + \ | |
417 | encode_getattr_maxsz) | |
418 | #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 419 | decode_sequence_maxsz + \ |
9104a55d TM |
420 | decode_putfh_maxsz + \ |
421 | decode_setattr_maxsz + \ | |
422 | decode_getattr_maxsz) | |
1da177e4 | 423 | #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 424 | encode_sequence_maxsz + \ |
1da177e4 LT |
425 | encode_putfh_maxsz + \ |
426 | encode_fsinfo_maxsz) | |
427 | #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 428 | decode_sequence_maxsz + \ |
1da177e4 LT |
429 | decode_putfh_maxsz + \ |
430 | decode_fsinfo_maxsz) | |
431 | #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ | |
432 | encode_renew_maxsz) | |
433 | #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ | |
434 | decode_renew_maxsz) | |
435 | #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ | |
436 | encode_setclientid_maxsz) | |
437 | #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ | |
438 | decode_setclientid_maxsz) | |
439 | #define NFS4_enc_setclientid_confirm_sz \ | |
440 | (compound_encode_hdr_maxsz + \ | |
441 | encode_setclientid_confirm_maxsz + \ | |
442 | encode_putrootfh_maxsz + \ | |
443 | encode_fsinfo_maxsz) | |
444 | #define NFS4_dec_setclientid_confirm_sz \ | |
445 | (compound_decode_hdr_maxsz + \ | |
446 | decode_setclientid_confirm_maxsz + \ | |
447 | decode_putrootfh_maxsz + \ | |
448 | decode_fsinfo_maxsz) | |
449 | #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 450 | encode_sequence_maxsz + \ |
1da177e4 | 451 | encode_putfh_maxsz + \ |
9104a55d | 452 | encode_lock_maxsz) |
1da177e4 | 453 | #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 454 | decode_sequence_maxsz + \ |
1da177e4 | 455 | decode_putfh_maxsz + \ |
9104a55d | 456 | decode_lock_maxsz) |
1da177e4 | 457 | #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 458 | encode_sequence_maxsz + \ |
1da177e4 | 459 | encode_putfh_maxsz + \ |
9104a55d TM |
460 | encode_lockt_maxsz) |
461 | #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 462 | decode_sequence_maxsz + \ |
9104a55d TM |
463 | decode_putfh_maxsz + \ |
464 | decode_lockt_maxsz) | |
1da177e4 | 465 | #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 466 | encode_sequence_maxsz + \ |
1da177e4 | 467 | encode_putfh_maxsz + \ |
9104a55d | 468 | encode_locku_maxsz) |
1da177e4 | 469 | #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 470 | decode_sequence_maxsz + \ |
1da177e4 | 471 | decode_putfh_maxsz + \ |
9104a55d | 472 | decode_locku_maxsz) |
1da177e4 | 473 | #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 474 | encode_sequence_maxsz + \ |
1da177e4 | 475 | encode_putfh_maxsz + \ |
76b32999 TM |
476 | encode_access_maxsz + \ |
477 | encode_getattr_maxsz) | |
1da177e4 | 478 | #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 479 | decode_sequence_maxsz + \ |
1da177e4 | 480 | decode_putfh_maxsz + \ |
76b32999 TM |
481 | decode_access_maxsz + \ |
482 | decode_getattr_maxsz) | |
1da177e4 | 483 | #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 484 | encode_sequence_maxsz + \ |
1da177e4 LT |
485 | encode_putfh_maxsz + \ |
486 | encode_getattr_maxsz) | |
487 | #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 488 | decode_sequence_maxsz + \ |
1da177e4 LT |
489 | decode_putfh_maxsz + \ |
490 | decode_getattr_maxsz) | |
491 | #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 492 | encode_sequence_maxsz + \ |
1da177e4 LT |
493 | encode_putfh_maxsz + \ |
494 | encode_lookup_maxsz + \ | |
495 | encode_getattr_maxsz + \ | |
496 | encode_getfh_maxsz) | |
497 | #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 498 | decode_sequence_maxsz + \ |
1da177e4 | 499 | decode_putfh_maxsz + \ |
e6889620 | 500 | decode_lookup_maxsz + \ |
1da177e4 LT |
501 | decode_getattr_maxsz + \ |
502 | decode_getfh_maxsz) | |
503 | #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 504 | encode_sequence_maxsz + \ |
1da177e4 LT |
505 | encode_putrootfh_maxsz + \ |
506 | encode_getattr_maxsz + \ | |
507 | encode_getfh_maxsz) | |
508 | #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 509 | decode_sequence_maxsz + \ |
1da177e4 LT |
510 | decode_putrootfh_maxsz + \ |
511 | decode_getattr_maxsz + \ | |
512 | decode_getfh_maxsz) | |
513 | #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 514 | encode_sequence_maxsz + \ |
1da177e4 | 515 | encode_putfh_maxsz + \ |
16e42959 TM |
516 | encode_remove_maxsz + \ |
517 | encode_getattr_maxsz) | |
1da177e4 | 518 | #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 519 | decode_sequence_maxsz + \ |
1da177e4 | 520 | decode_putfh_maxsz + \ |
6ce18391 | 521 | decode_remove_maxsz + \ |
16e42959 | 522 | decode_getattr_maxsz) |
1da177e4 | 523 | #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 524 | encode_sequence_maxsz + \ |
1da177e4 LT |
525 | encode_putfh_maxsz + \ |
526 | encode_savefh_maxsz + \ | |
527 | encode_putfh_maxsz + \ | |
6caf2c82 TM |
528 | encode_rename_maxsz + \ |
529 | encode_getattr_maxsz + \ | |
530 | encode_restorefh_maxsz + \ | |
531 | encode_getattr_maxsz) | |
1da177e4 | 532 | #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 533 | decode_sequence_maxsz + \ |
1da177e4 LT |
534 | decode_putfh_maxsz + \ |
535 | decode_savefh_maxsz + \ | |
536 | decode_putfh_maxsz + \ | |
6caf2c82 TM |
537 | decode_rename_maxsz + \ |
538 | decode_getattr_maxsz + \ | |
539 | decode_restorefh_maxsz + \ | |
540 | decode_getattr_maxsz) | |
1da177e4 | 541 | #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 542 | encode_sequence_maxsz + \ |
1da177e4 LT |
543 | encode_putfh_maxsz + \ |
544 | encode_savefh_maxsz + \ | |
545 | encode_putfh_maxsz + \ | |
91ba2eee TM |
546 | encode_link_maxsz + \ |
547 | decode_getattr_maxsz + \ | |
548 | encode_restorefh_maxsz + \ | |
549 | decode_getattr_maxsz) | |
1da177e4 | 550 | #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 551 | decode_sequence_maxsz + \ |
1da177e4 LT |
552 | decode_putfh_maxsz + \ |
553 | decode_savefh_maxsz + \ | |
554 | decode_putfh_maxsz + \ | |
91ba2eee TM |
555 | decode_link_maxsz + \ |
556 | decode_getattr_maxsz + \ | |
557 | decode_restorefh_maxsz + \ | |
558 | decode_getattr_maxsz) | |
1da177e4 | 559 | #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 560 | encode_sequence_maxsz + \ |
1da177e4 LT |
561 | encode_putfh_maxsz + \ |
562 | encode_symlink_maxsz + \ | |
563 | encode_getattr_maxsz + \ | |
564 | encode_getfh_maxsz) | |
565 | #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 566 | decode_sequence_maxsz + \ |
1da177e4 LT |
567 | decode_putfh_maxsz + \ |
568 | decode_symlink_maxsz + \ | |
569 | decode_getattr_maxsz + \ | |
570 | decode_getfh_maxsz) | |
571 | #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 572 | encode_sequence_maxsz + \ |
1da177e4 | 573 | encode_putfh_maxsz + \ |
56ae19f3 | 574 | encode_savefh_maxsz + \ |
1da177e4 | 575 | encode_create_maxsz + \ |
56ae19f3 | 576 | encode_getfh_maxsz + \ |
1da177e4 | 577 | encode_getattr_maxsz + \ |
56ae19f3 TM |
578 | encode_restorefh_maxsz + \ |
579 | encode_getattr_maxsz) | |
1da177e4 | 580 | #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 581 | decode_sequence_maxsz + \ |
1da177e4 | 582 | decode_putfh_maxsz + \ |
56ae19f3 | 583 | decode_savefh_maxsz + \ |
1da177e4 | 584 | decode_create_maxsz + \ |
56ae19f3 | 585 | decode_getfh_maxsz + \ |
1da177e4 | 586 | decode_getattr_maxsz + \ |
56ae19f3 TM |
587 | decode_restorefh_maxsz + \ |
588 | decode_getattr_maxsz) | |
1da177e4 | 589 | #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 590 | encode_sequence_maxsz + \ |
1da177e4 LT |
591 | encode_putfh_maxsz + \ |
592 | encode_getattr_maxsz) | |
593 | #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 594 | decode_sequence_maxsz + \ |
1da177e4 LT |
595 | decode_putfh_maxsz + \ |
596 | decode_getattr_maxsz) | |
597 | #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 598 | encode_sequence_maxsz + \ |
1da177e4 | 599 | encode_putfh_maxsz + \ |
9104a55d | 600 | encode_statfs_maxsz) |
1da177e4 | 601 | #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 602 | decode_sequence_maxsz + \ |
1da177e4 | 603 | decode_putfh_maxsz + \ |
9104a55d | 604 | decode_statfs_maxsz) |
1da177e4 | 605 | #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 606 | encode_sequence_maxsz + \ |
ab91f264 | 607 | encode_putfh_maxsz + \ |
1da177e4 LT |
608 | encode_getattr_maxsz) |
609 | #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 610 | decode_sequence_maxsz + \ |
ab91f264 | 611 | decode_putfh_maxsz + \ |
1da177e4 LT |
612 | decode_getattr_maxsz) |
613 | #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 614 | encode_sequence_maxsz + \ |
1da177e4 | 615 | encode_putfh_maxsz + \ |
fa178f29 TM |
616 | encode_delegreturn_maxsz + \ |
617 | encode_getattr_maxsz) | |
1da177e4 | 618 | #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 619 | decode_sequence_maxsz + \ |
fa178f29 TM |
620 | decode_delegreturn_maxsz + \ |
621 | decode_getattr_maxsz) | |
029d105e | 622 | #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 623 | encode_sequence_maxsz + \ |
029d105e | 624 | encode_putfh_maxsz + \ |
9104a55d | 625 | encode_getacl_maxsz) |
029d105e | 626 | #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 627 | decode_sequence_maxsz + \ |
029d105e | 628 | decode_putfh_maxsz + \ |
9104a55d | 629 | decode_getacl_maxsz) |
23ec6965 | 630 | #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ |
9b7b9fcc | 631 | encode_sequence_maxsz + \ |
23ec6965 | 632 | encode_putfh_maxsz + \ |
9104a55d | 633 | encode_setacl_maxsz) |
23ec6965 | 634 | #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ |
9b7b9fcc | 635 | decode_sequence_maxsz + \ |
23ec6965 | 636 | decode_putfh_maxsz + \ |
9104a55d | 637 | decode_setacl_maxsz) |
683b57b4 TM |
638 | #define NFS4_enc_fs_locations_sz \ |
639 | (compound_encode_hdr_maxsz + \ | |
9b7b9fcc | 640 | encode_sequence_maxsz + \ |
683b57b4 | 641 | encode_putfh_maxsz + \ |
e6889620 TM |
642 | encode_lookup_maxsz + \ |
643 | encode_fs_locations_maxsz) | |
683b57b4 TM |
644 | #define NFS4_dec_fs_locations_sz \ |
645 | (compound_decode_hdr_maxsz + \ | |
9b7b9fcc | 646 | decode_sequence_maxsz + \ |
683b57b4 | 647 | decode_putfh_maxsz + \ |
e6889620 TM |
648 | decode_lookup_maxsz + \ |
649 | decode_fs_locations_maxsz) | |
99fe60d0 BH |
650 | #if defined(CONFIG_NFS_V4_1) |
651 | #define NFS4_enc_exchange_id_sz \ | |
652 | (compound_encode_hdr_maxsz + \ | |
653 | encode_exchange_id_maxsz) | |
654 | #define NFS4_dec_exchange_id_sz \ | |
655 | (compound_decode_hdr_maxsz + \ | |
656 | decode_exchange_id_maxsz) | |
fc931582 AA |
657 | #define NFS4_enc_create_session_sz \ |
658 | (compound_encode_hdr_maxsz + \ | |
659 | encode_create_session_maxsz) | |
660 | #define NFS4_dec_create_session_sz \ | |
661 | (compound_decode_hdr_maxsz + \ | |
662 | decode_create_session_maxsz) | |
0f3e66c6 AA |
663 | #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ |
664 | encode_destroy_session_maxsz) | |
665 | #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ | |
666 | decode_destroy_session_maxsz) | |
fc01cea9 AA |
667 | #define NFS4_enc_sequence_sz \ |
668 | (compound_decode_hdr_maxsz + \ | |
669 | encode_sequence_maxsz) | |
670 | #define NFS4_dec_sequence_sz \ | |
671 | (compound_decode_hdr_maxsz + \ | |
672 | decode_sequence_maxsz) | |
2050f0cc AA |
673 | #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ |
674 | encode_sequence_maxsz + \ | |
675 | encode_putrootfh_maxsz + \ | |
676 | encode_fsinfo_maxsz) | |
677 | #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ | |
678 | decode_sequence_maxsz + \ | |
679 | decode_putrootfh_maxsz + \ | |
680 | decode_fsinfo_maxsz) | |
2449ea2e AB |
681 | |
682 | const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + | |
683 | compound_encode_hdr_maxsz + | |
684 | encode_sequence_maxsz + | |
685 | encode_putfh_maxsz + | |
686 | encode_getattr_maxsz) * | |
687 | XDR_UNIT); | |
688 | ||
689 | const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + | |
690 | compound_decode_hdr_maxsz + | |
691 | decode_sequence_maxsz + | |
692 | decode_putfh_maxsz) * | |
693 | XDR_UNIT); | |
99fe60d0 | 694 | #endif /* CONFIG_NFS_V4_1 */ |
1da177e4 | 695 | |
bca79478 TM |
696 | static const umode_t nfs_type2fmt[] = { |
697 | [NF4BAD] = 0, | |
698 | [NF4REG] = S_IFREG, | |
699 | [NF4DIR] = S_IFDIR, | |
700 | [NF4BLK] = S_IFBLK, | |
701 | [NF4CHR] = S_IFCHR, | |
702 | [NF4LNK] = S_IFLNK, | |
703 | [NF4SOCK] = S_IFSOCK, | |
704 | [NF4FIFO] = S_IFIFO, | |
705 | [NF4ATTRDIR] = 0, | |
706 | [NF4NAMEDATTR] = 0, | |
1da177e4 LT |
707 | }; |
708 | ||
709 | struct compound_hdr { | |
710 | int32_t status; | |
711 | uint32_t nops; | |
d017931c | 712 | __be32 * nops_p; |
1da177e4 LT |
713 | uint32_t taglen; |
714 | char * tag; | |
0c4e8c18 | 715 | uint32_t replen; /* expected reply words */ |
66cc0429 | 716 | u32 minorversion; |
1da177e4 LT |
717 | }; |
718 | ||
13c65ce9 BH |
719 | static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) |
720 | { | |
721 | __be32 *p = xdr_reserve_space(xdr, nbytes); | |
722 | BUG_ON(!p); | |
723 | return p; | |
724 | } | |
1da177e4 LT |
725 | |
726 | static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) | |
727 | { | |
8687b63a | 728 | __be32 *p; |
1da177e4 LT |
729 | |
730 | p = xdr_reserve_space(xdr, 4 + len); | |
731 | BUG_ON(p == NULL); | |
732 | xdr_encode_opaque(p, str, len); | |
733 | } | |
734 | ||
0c4e8c18 BH |
735 | static void encode_compound_hdr(struct xdr_stream *xdr, |
736 | struct rpc_rqst *req, | |
737 | struct compound_hdr *hdr) | |
1da177e4 | 738 | { |
8687b63a | 739 | __be32 *p; |
0c4e8c18 BH |
740 | struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth; |
741 | ||
742 | /* initialize running count of expected bytes in reply. | |
743 | * NOTE: the replied tag SHOULD be the same is the one sent, | |
744 | * but this is not required as a MUST for the server to do so. */ | |
745 | hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; | |
1da177e4 LT |
746 | |
747 | dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); | |
748 | BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); | |
811652bd BH |
749 | p = reserve_space(xdr, 4 + hdr->taglen + 8); |
750 | p = xdr_encode_opaque(p, hdr->tag, hdr->taglen); | |
e75bc1c8 | 751 | *p++ = cpu_to_be32(hdr->minorversion); |
d017931c | 752 | hdr->nops_p = p; |
34558513 | 753 | *p = cpu_to_be32(hdr->nops); |
d017931c AA |
754 | } |
755 | ||
756 | static void encode_nops(struct compound_hdr *hdr) | |
757 | { | |
fc931582 | 758 | BUG_ON(hdr->nops > NFS4_MAX_OPS); |
d017931c | 759 | *hdr->nops_p = htonl(hdr->nops); |
1da177e4 LT |
760 | } |
761 | ||
762 | static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) | |
763 | { | |
8687b63a | 764 | __be32 *p; |
1da177e4 LT |
765 | |
766 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); | |
767 | BUG_ON(p == NULL); | |
768 | xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); | |
769 | } | |
770 | ||
cf8cdbe5 | 771 | static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) |
1da177e4 LT |
772 | { |
773 | char owner_name[IDMAP_NAMESZ]; | |
774 | char owner_group[IDMAP_NAMESZ]; | |
775 | int owner_namelen = 0; | |
776 | int owner_grouplen = 0; | |
8687b63a AV |
777 | __be32 *p; |
778 | __be32 *q; | |
1da177e4 LT |
779 | int len; |
780 | uint32_t bmval0 = 0; | |
781 | uint32_t bmval1 = 0; | |
1da177e4 LT |
782 | |
783 | /* | |
784 | * We reserve enough space to write the entire attribute buffer at once. | |
785 | * In the worst-case, this would be | |
786 | * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) | |
787 | * = 36 bytes, plus any contribution from variable-length fields | |
23ec6965 | 788 | * such as owner/group. |
1da177e4 LT |
789 | */ |
790 | len = 16; | |
791 | ||
792 | /* Sigh */ | |
793 | if (iap->ia_valid & ATTR_SIZE) | |
794 | len += 8; | |
795 | if (iap->ia_valid & ATTR_MODE) | |
796 | len += 4; | |
797 | if (iap->ia_valid & ATTR_UID) { | |
7539bbab | 798 | owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name); |
1da177e4 | 799 | if (owner_namelen < 0) { |
fe82a183 CL |
800 | dprintk("nfs: couldn't resolve uid %d to string\n", |
801 | iap->ia_uid); | |
1da177e4 LT |
802 | /* XXX */ |
803 | strcpy(owner_name, "nobody"); | |
804 | owner_namelen = sizeof("nobody") - 1; | |
805 | /* goto out; */ | |
806 | } | |
807 | len += 4 + (XDR_QUADLEN(owner_namelen) << 2); | |
808 | } | |
809 | if (iap->ia_valid & ATTR_GID) { | |
7539bbab | 810 | owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group); |
1da177e4 | 811 | if (owner_grouplen < 0) { |
fe82a183 CL |
812 | dprintk("nfs: couldn't resolve gid %d to string\n", |
813 | iap->ia_gid); | |
1da177e4 LT |
814 | strcpy(owner_group, "nobody"); |
815 | owner_grouplen = sizeof("nobody") - 1; | |
816 | /* goto out; */ | |
817 | } | |
818 | len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); | |
819 | } | |
820 | if (iap->ia_valid & ATTR_ATIME_SET) | |
821 | len += 16; | |
822 | else if (iap->ia_valid & ATTR_ATIME) | |
823 | len += 4; | |
824 | if (iap->ia_valid & ATTR_MTIME_SET) | |
825 | len += 16; | |
826 | else if (iap->ia_valid & ATTR_MTIME) | |
827 | len += 4; | |
13c65ce9 | 828 | p = reserve_space(xdr, len); |
1da177e4 LT |
829 | |
830 | /* | |
831 | * We write the bitmap length now, but leave the bitmap and the attribute | |
832 | * buffer length to be backfilled at the end of this routine. | |
833 | */ | |
e75bc1c8 | 834 | *p++ = cpu_to_be32(2); |
1da177e4 LT |
835 | q = p; |
836 | p += 3; | |
837 | ||
838 | if (iap->ia_valid & ATTR_SIZE) { | |
839 | bmval0 |= FATTR4_WORD0_SIZE; | |
b95be5a9 | 840 | p = xdr_encode_hyper(p, iap->ia_size); |
1da177e4 LT |
841 | } |
842 | if (iap->ia_valid & ATTR_MODE) { | |
843 | bmval1 |= FATTR4_WORD1_MODE; | |
e75bc1c8 | 844 | *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); |
1da177e4 LT |
845 | } |
846 | if (iap->ia_valid & ATTR_UID) { | |
847 | bmval1 |= FATTR4_WORD1_OWNER; | |
811652bd | 848 | p = xdr_encode_opaque(p, owner_name, owner_namelen); |
1da177e4 LT |
849 | } |
850 | if (iap->ia_valid & ATTR_GID) { | |
851 | bmval1 |= FATTR4_WORD1_OWNER_GROUP; | |
811652bd | 852 | p = xdr_encode_opaque(p, owner_group, owner_grouplen); |
1da177e4 LT |
853 | } |
854 | if (iap->ia_valid & ATTR_ATIME_SET) { | |
855 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; | |
e75bc1c8 BH |
856 | *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); |
857 | *p++ = cpu_to_be32(0); | |
858 | *p++ = cpu_to_be32(iap->ia_mtime.tv_sec); | |
859 | *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); | |
1da177e4 LT |
860 | } |
861 | else if (iap->ia_valid & ATTR_ATIME) { | |
862 | bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; | |
e75bc1c8 | 863 | *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); |
1da177e4 LT |
864 | } |
865 | if (iap->ia_valid & ATTR_MTIME_SET) { | |
866 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; | |
e75bc1c8 BH |
867 | *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); |
868 | *p++ = cpu_to_be32(0); | |
869 | *p++ = cpu_to_be32(iap->ia_mtime.tv_sec); | |
870 | *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); | |
1da177e4 LT |
871 | } |
872 | else if (iap->ia_valid & ATTR_MTIME) { | |
873 | bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; | |
e75bc1c8 | 874 | *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); |
1da177e4 | 875 | } |
6c0195a4 | 876 | |
1da177e4 LT |
877 | /* |
878 | * Now we backfill the bitmap and the attribute buffer length. | |
879 | */ | |
880 | if (len != ((char *)p - (char *)q) + 4) { | |
fe82a183 | 881 | printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n", |
1da177e4 LT |
882 | len, ((char *)p - (char *)q) + 4); |
883 | BUG(); | |
884 | } | |
885 | len = (char *)p - (char *)q - 12; | |
886 | *q++ = htonl(bmval0); | |
887 | *q++ = htonl(bmval1); | |
34558513 | 888 | *q = htonl(len); |
1da177e4 | 889 | |
1da177e4 | 890 | /* out: */ |
1da177e4 LT |
891 | } |
892 | ||
cf8cdbe5 | 893 | static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) |
1da177e4 | 894 | { |
8687b63a | 895 | __be32 *p; |
1da177e4 | 896 | |
13c65ce9 | 897 | p = reserve_space(xdr, 8); |
e75bc1c8 | 898 | *p++ = cpu_to_be32(OP_ACCESS); |
34558513 | 899 | *p = cpu_to_be32(access); |
d017931c | 900 | hdr->nops++; |
dadf0c27 | 901 | hdr->replen += decode_access_maxsz; |
1da177e4 LT |
902 | } |
903 | ||
cf8cdbe5 | 904 | static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) |
1da177e4 | 905 | { |
8687b63a | 906 | __be32 *p; |
1da177e4 | 907 | |
13c65ce9 | 908 | p = reserve_space(xdr, 8+NFS4_STATEID_SIZE); |
e75bc1c8 BH |
909 | *p++ = cpu_to_be32(OP_CLOSE); |
910 | *p++ = cpu_to_be32(arg->seqid->sequence->counter); | |
34558513 | 911 | xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); |
d017931c | 912 | hdr->nops++; |
dadf0c27 | 913 | hdr->replen += decode_close_maxsz; |
1da177e4 LT |
914 | } |
915 | ||
cf8cdbe5 | 916 | static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) |
1da177e4 | 917 | { |
8687b63a | 918 | __be32 *p; |
6c0195a4 | 919 | |
13c65ce9 | 920 | p = reserve_space(xdr, 16); |
e75bc1c8 | 921 | *p++ = cpu_to_be32(OP_COMMIT); |
b95be5a9 | 922 | p = xdr_encode_hyper(p, args->offset); |
34558513 | 923 | *p = cpu_to_be32(args->count); |
d017931c | 924 | hdr->nops++; |
dadf0c27 | 925 | hdr->replen += decode_commit_maxsz; |
1da177e4 LT |
926 | } |
927 | ||
cf8cdbe5 | 928 | static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) |
1da177e4 | 929 | { |
8687b63a | 930 | __be32 *p; |
6c0195a4 | 931 | |
13c65ce9 | 932 | p = reserve_space(xdr, 8); |
e75bc1c8 | 933 | *p++ = cpu_to_be32(OP_CREATE); |
34558513 | 934 | *p = cpu_to_be32(create->ftype); |
1da177e4 LT |
935 | |
936 | switch (create->ftype) { | |
937 | case NF4LNK: | |
13c65ce9 | 938 | p = reserve_space(xdr, 4); |
34558513 | 939 | *p = cpu_to_be32(create->u.symlink.len); |
94a6d753 | 940 | xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); |
1da177e4 LT |
941 | break; |
942 | ||
943 | case NF4BLK: case NF4CHR: | |
13c65ce9 | 944 | p = reserve_space(xdr, 8); |
e75bc1c8 | 945 | *p++ = cpu_to_be32(create->u.device.specdata1); |
34558513 | 946 | *p = cpu_to_be32(create->u.device.specdata2); |
1da177e4 LT |
947 | break; |
948 | ||
949 | default: | |
950 | break; | |
951 | } | |
952 | ||
811652bd | 953 | encode_string(xdr, create->name->len, create->name->name); |
d017931c | 954 | hdr->nops++; |
dadf0c27 | 955 | hdr->replen += decode_create_maxsz; |
1da177e4 | 956 | |
cf8cdbe5 | 957 | encode_attrs(xdr, create->attrs, create->server); |
1da177e4 LT |
958 | } |
959 | ||
cf8cdbe5 | 960 | static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) |
1da177e4 | 961 | { |
05d564fe | 962 | __be32 *p; |
1da177e4 | 963 | |
13c65ce9 | 964 | p = reserve_space(xdr, 12); |
e75bc1c8 BH |
965 | *p++ = cpu_to_be32(OP_GETATTR); |
966 | *p++ = cpu_to_be32(1); | |
34558513 | 967 | *p = cpu_to_be32(bitmap); |
d017931c | 968 | hdr->nops++; |
dadf0c27 | 969 | hdr->replen += decode_getattr_maxsz; |
1da177e4 LT |
970 | } |
971 | ||
cf8cdbe5 | 972 | static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) |
1da177e4 | 973 | { |
05d564fe | 974 | __be32 *p; |
1da177e4 | 975 | |
13c65ce9 | 976 | p = reserve_space(xdr, 16); |
e75bc1c8 BH |
977 | *p++ = cpu_to_be32(OP_GETATTR); |
978 | *p++ = cpu_to_be32(2); | |
979 | *p++ = cpu_to_be32(bm0); | |
34558513 | 980 | *p = cpu_to_be32(bm1); |
d017931c | 981 | hdr->nops++; |
dadf0c27 | 982 | hdr->replen += decode_getattr_maxsz; |
1da177e4 LT |
983 | } |
984 | ||
cf8cdbe5 | 985 | static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
1da177e4 | 986 | { |
cf8cdbe5 AA |
987 | encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], |
988 | bitmask[1] & nfs4_fattr_bitmap[1], hdr); | |
1da177e4 LT |
989 | } |
990 | ||
cf8cdbe5 | 991 | static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
1da177e4 | 992 | { |
cf8cdbe5 AA |
993 | encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0], |
994 | bitmask[1] & nfs4_fsinfo_bitmap[1], hdr); | |
1da177e4 LT |
995 | } |
996 | ||
cf8cdbe5 | 997 | static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) |
830b8e33 | 998 | { |
cf8cdbe5 AA |
999 | encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], |
1000 | bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); | |
830b8e33 MN |
1001 | } |
1002 | ||
cf8cdbe5 | 1003 | static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
1da177e4 | 1004 | { |
8687b63a | 1005 | __be32 *p; |
1da177e4 | 1006 | |
13c65ce9 | 1007 | p = reserve_space(xdr, 4); |
34558513 | 1008 | *p = cpu_to_be32(OP_GETFH); |
d017931c | 1009 | hdr->nops++; |
dadf0c27 | 1010 | hdr->replen += decode_getfh_maxsz; |
1da177e4 LT |
1011 | } |
1012 | ||
cf8cdbe5 | 1013 | static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
1da177e4 | 1014 | { |
8687b63a | 1015 | __be32 *p; |
1da177e4 | 1016 | |
13c65ce9 | 1017 | p = reserve_space(xdr, 8 + name->len); |
e75bc1c8 | 1018 | *p++ = cpu_to_be32(OP_LINK); |
811652bd | 1019 | xdr_encode_opaque(p, name->name, name->len); |
d017931c | 1020 | hdr->nops++; |
dadf0c27 | 1021 | hdr->replen += decode_link_maxsz; |
1da177e4 LT |
1022 | } |
1023 | ||
911d1aaf TM |
1024 | static inline int nfs4_lock_type(struct file_lock *fl, int block) |
1025 | { | |
1026 | if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) | |
1027 | return block ? NFS4_READW_LT : NFS4_READ_LT; | |
1028 | return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; | |
1029 | } | |
1030 | ||
1031 | static inline uint64_t nfs4_lock_length(struct file_lock *fl) | |
1032 | { | |
1033 | if (fl->fl_end == OFFSET_MAX) | |
1034 | return ~(uint64_t)0; | |
1035 | return fl->fl_end - fl->fl_start + 1; | |
1036 | } | |
1037 | ||
1da177e4 LT |
1038 | /* |
1039 | * opcode,type,reclaim,offset,length,new_lock_owner = 32 | |
1040 | * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 | |
1041 | */ | |
cf8cdbe5 | 1042 | static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) |
1da177e4 | 1043 | { |
8687b63a | 1044 | __be32 *p; |
1da177e4 | 1045 | |
13c65ce9 | 1046 | p = reserve_space(xdr, 32); |
e75bc1c8 BH |
1047 | *p++ = cpu_to_be32(OP_LOCK); |
1048 | *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); | |
1049 | *p++ = cpu_to_be32(args->reclaim); | |
b95be5a9 BH |
1050 | p = xdr_encode_hyper(p, args->fl->fl_start); |
1051 | p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); | |
34558513 | 1052 | *p = cpu_to_be32(args->new_lock_owner); |
911d1aaf | 1053 | if (args->new_lock_owner){ |
13c65ce9 | 1054 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+32); |
e75bc1c8 | 1055 | *p++ = cpu_to_be32(args->open_seqid->sequence->counter); |
93f0cf25 | 1056 | p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE); |
e75bc1c8 | 1057 | *p++ = cpu_to_be32(args->lock_seqid->sequence->counter); |
b95be5a9 | 1058 | p = xdr_encode_hyper(p, args->lock_owner.clientid); |
e75bc1c8 | 1059 | *p++ = cpu_to_be32(16); |
93f0cf25 | 1060 | p = xdr_encode_opaque_fixed(p, "lock id:", 8); |
34558513 | 1061 | xdr_encode_hyper(p, args->lock_owner.id); |
1da177e4 LT |
1062 | } |
1063 | else { | |
13c65ce9 | 1064 | p = reserve_space(xdr, NFS4_STATEID_SIZE+4); |
93f0cf25 | 1065 | p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE); |
34558513 | 1066 | *p = cpu_to_be32(args->lock_seqid->sequence->counter); |
1da177e4 | 1067 | } |
d017931c | 1068 | hdr->nops++; |
dadf0c27 | 1069 | hdr->replen += decode_lock_maxsz; |
1da177e4 LT |
1070 | } |
1071 | ||
cf8cdbe5 | 1072 | static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) |
1da177e4 | 1073 | { |
8687b63a | 1074 | __be32 *p; |
1da177e4 | 1075 | |
13c65ce9 | 1076 | p = reserve_space(xdr, 52); |
e75bc1c8 BH |
1077 | *p++ = cpu_to_be32(OP_LOCKT); |
1078 | *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); | |
b95be5a9 BH |
1079 | p = xdr_encode_hyper(p, args->fl->fl_start); |
1080 | p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); | |
1081 | p = xdr_encode_hyper(p, args->lock_owner.clientid); | |
e75bc1c8 | 1082 | *p++ = cpu_to_be32(16); |
93f0cf25 | 1083 | p = xdr_encode_opaque_fixed(p, "lock id:", 8); |
34558513 | 1084 | xdr_encode_hyper(p, args->lock_owner.id); |
d017931c | 1085 | hdr->nops++; |
dadf0c27 | 1086 | hdr->replen += decode_lockt_maxsz; |
1da177e4 LT |
1087 | } |
1088 | ||
cf8cdbe5 | 1089 | static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) |
1da177e4 | 1090 | { |
8687b63a | 1091 | __be32 *p; |
1da177e4 | 1092 | |
13c65ce9 | 1093 | p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16); |
e75bc1c8 BH |
1094 | *p++ = cpu_to_be32(OP_LOCKU); |
1095 | *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); | |
1096 | *p++ = cpu_to_be32(args->seqid->sequence->counter); | |
93f0cf25 | 1097 | p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE); |
b95be5a9 | 1098 | p = xdr_encode_hyper(p, args->fl->fl_start); |
34558513 | 1099 | xdr_encode_hyper(p, nfs4_lock_length(args->fl)); |
d017931c | 1100 | hdr->nops++; |
dadf0c27 | 1101 | hdr->replen += decode_locku_maxsz; |
1da177e4 LT |
1102 | } |
1103 | ||
cf8cdbe5 | 1104 | static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
1da177e4 LT |
1105 | { |
1106 | int len = name->len; | |
8687b63a | 1107 | __be32 *p; |
1da177e4 | 1108 | |
13c65ce9 | 1109 | p = reserve_space(xdr, 8 + len); |
e75bc1c8 | 1110 | *p++ = cpu_to_be32(OP_LOOKUP); |
811652bd | 1111 | xdr_encode_opaque(p, name->name, len); |
d017931c | 1112 | hdr->nops++; |
dadf0c27 | 1113 | hdr->replen += decode_lookup_maxsz; |
1da177e4 LT |
1114 | } |
1115 | ||
dc0b027d | 1116 | static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) |
1da177e4 | 1117 | { |
8687b63a | 1118 | __be32 *p; |
1da177e4 | 1119 | |
13c65ce9 | 1120 | p = reserve_space(xdr, 8); |
dc0b027d | 1121 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
05d564fe | 1122 | case FMODE_READ: |
e75bc1c8 | 1123 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); |
05d564fe AA |
1124 | break; |
1125 | case FMODE_WRITE: | |
e75bc1c8 | 1126 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); |
05d564fe AA |
1127 | break; |
1128 | case FMODE_READ|FMODE_WRITE: | |
e75bc1c8 | 1129 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); |
05d564fe AA |
1130 | break; |
1131 | default: | |
e75bc1c8 | 1132 | *p++ = cpu_to_be32(0); |
1da177e4 | 1133 | } |
34558513 | 1134 | *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ |
1da177e4 LT |
1135 | } |
1136 | ||
1137 | static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
1138 | { | |
8687b63a | 1139 | __be32 *p; |
1da177e4 LT |
1140 | /* |
1141 | * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, | |
1142 | * owner 4 = 32 | |
1143 | */ | |
13c65ce9 | 1144 | p = reserve_space(xdr, 8); |
e75bc1c8 | 1145 | *p++ = cpu_to_be32(OP_OPEN); |
34558513 | 1146 | *p = cpu_to_be32(arg->seqid->sequence->counter); |
dc0b027d | 1147 | encode_share_access(xdr, arg->fmode); |
13c65ce9 | 1148 | p = reserve_space(xdr, 28); |
b95be5a9 | 1149 | p = xdr_encode_hyper(p, arg->clientid); |
e75bc1c8 | 1150 | *p++ = cpu_to_be32(16); |
93f0cf25 | 1151 | p = xdr_encode_opaque_fixed(p, "open id:", 8); |
34558513 | 1152 | xdr_encode_hyper(p, arg->id); |
1da177e4 LT |
1153 | } |
1154 | ||
1155 | static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
1156 | { | |
8687b63a | 1157 | __be32 *p; |
4882ef72 | 1158 | struct nfs_client *clp; |
1da177e4 | 1159 | |
13c65ce9 | 1160 | p = reserve_space(xdr, 4); |
1da177e4 | 1161 | switch(arg->open_flags & O_EXCL) { |
05d564fe | 1162 | case 0: |
34558513 | 1163 | *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); |
05d564fe AA |
1164 | encode_attrs(xdr, arg->u.attrs, arg->server); |
1165 | break; | |
1166 | default: | |
4882ef72 AB |
1167 | clp = arg->server->nfs_client; |
1168 | if (clp->cl_minorversion > 0) { | |
1169 | if (nfs4_has_persistent_session(clp)) { | |
1170 | *p = cpu_to_be32(NFS4_CREATE_GUARDED); | |
1171 | encode_attrs(xdr, arg->u.attrs, arg->server); | |
1172 | } else { | |
1173 | struct iattr dummy; | |
1174 | ||
1175 | *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); | |
1176 | encode_nfs4_verifier(xdr, &arg->u.verifier); | |
1177 | dummy.ia_valid = 0; | |
1178 | encode_attrs(xdr, &dummy, arg->server); | |
1179 | } | |
1180 | } else { | |
1181 | *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); | |
1182 | encode_nfs4_verifier(xdr, &arg->u.verifier); | |
1183 | } | |
1da177e4 LT |
1184 | } |
1185 | } | |
1186 | ||
1187 | static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) | |
1188 | { | |
8687b63a | 1189 | __be32 *p; |
1da177e4 | 1190 | |
13c65ce9 | 1191 | p = reserve_space(xdr, 4); |
1da177e4 | 1192 | switch (arg->open_flags & O_CREAT) { |
05d564fe | 1193 | case 0: |
34558513 | 1194 | *p = cpu_to_be32(NFS4_OPEN_NOCREATE); |
05d564fe AA |
1195 | break; |
1196 | default: | |
1197 | BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); | |
34558513 | 1198 | *p = cpu_to_be32(NFS4_OPEN_CREATE); |
05d564fe | 1199 | encode_createmode(xdr, arg); |
1da177e4 LT |
1200 | } |
1201 | } | |
1202 | ||
bd7bf9d5 | 1203 | static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) |
1da177e4 | 1204 | { |
8687b63a | 1205 | __be32 *p; |
1da177e4 | 1206 | |
13c65ce9 | 1207 | p = reserve_space(xdr, 4); |
1da177e4 | 1208 | switch (delegation_type) { |
05d564fe | 1209 | case 0: |
34558513 | 1210 | *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); |
05d564fe AA |
1211 | break; |
1212 | case FMODE_READ: | |
34558513 | 1213 | *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); |
05d564fe AA |
1214 | break; |
1215 | case FMODE_WRITE|FMODE_READ: | |
34558513 | 1216 | *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); |
05d564fe AA |
1217 | break; |
1218 | default: | |
1219 | BUG(); | |
1da177e4 LT |
1220 | } |
1221 | } | |
1222 | ||
1223 | static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) | |
1224 | { | |
8687b63a | 1225 | __be32 *p; |
1da177e4 | 1226 | |
13c65ce9 | 1227 | p = reserve_space(xdr, 4); |
34558513 | 1228 | *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); |
1da177e4 LT |
1229 | encode_string(xdr, name->len, name->name); |
1230 | } | |
1231 | ||
bd7bf9d5 | 1232 | static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) |
1da177e4 | 1233 | { |
8687b63a | 1234 | __be32 *p; |
1da177e4 | 1235 | |
13c65ce9 | 1236 | p = reserve_space(xdr, 4); |
34558513 | 1237 | *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); |
1da177e4 LT |
1238 | encode_delegation_type(xdr, type); |
1239 | } | |
1240 | ||
1241 | static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) | |
1242 | { | |
8687b63a | 1243 | __be32 *p; |
1da177e4 | 1244 | |
13c65ce9 | 1245 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
e75bc1c8 | 1246 | *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); |
34558513 | 1247 | xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); |
1da177e4 LT |
1248 | encode_string(xdr, name->len, name->name); |
1249 | } | |
1250 | ||
cf8cdbe5 | 1251 | static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) |
1da177e4 LT |
1252 | { |
1253 | encode_openhdr(xdr, arg); | |
1254 | encode_opentype(xdr, arg); | |
1255 | switch (arg->claim) { | |
05d564fe AA |
1256 | case NFS4_OPEN_CLAIM_NULL: |
1257 | encode_claim_null(xdr, arg->name); | |
1258 | break; | |
1259 | case NFS4_OPEN_CLAIM_PREVIOUS: | |
1260 | encode_claim_previous(xdr, arg->u.delegation_type); | |
1261 | break; | |
1262 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | |
1263 | encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); | |
1264 | break; | |
1265 | default: | |
1266 | BUG(); | |
1da177e4 | 1267 | } |
d017931c | 1268 | hdr->nops++; |
dadf0c27 | 1269 | hdr->replen += decode_open_maxsz; |
1da177e4 LT |
1270 | } |
1271 | ||
cf8cdbe5 | 1272 | static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) |
1da177e4 | 1273 | { |
8687b63a | 1274 | __be32 *p; |
1da177e4 | 1275 | |
13c65ce9 | 1276 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); |
e75bc1c8 | 1277 | *p++ = cpu_to_be32(OP_OPEN_CONFIRM); |
93f0cf25 | 1278 | p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); |
34558513 | 1279 | *p = cpu_to_be32(arg->seqid->sequence->counter); |
d017931c | 1280 | hdr->nops++; |
dadf0c27 | 1281 | hdr->replen += decode_open_confirm_maxsz; |
1da177e4 LT |
1282 | } |
1283 | ||
cf8cdbe5 | 1284 | static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) |
1da177e4 | 1285 | { |
8687b63a | 1286 | __be32 *p; |
1da177e4 | 1287 | |
13c65ce9 | 1288 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); |
e75bc1c8 | 1289 | *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE); |
93f0cf25 | 1290 | p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); |
34558513 | 1291 | *p = cpu_to_be32(arg->seqid->sequence->counter); |
dc0b027d | 1292 | encode_share_access(xdr, arg->fmode); |
d017931c | 1293 | hdr->nops++; |
dadf0c27 | 1294 | hdr->replen += decode_open_downgrade_maxsz; |
1da177e4 LT |
1295 | } |
1296 | ||
cf8cdbe5 | 1297 | static void |
d017931c | 1298 | encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) |
1da177e4 LT |
1299 | { |
1300 | int len = fh->size; | |
8687b63a | 1301 | __be32 *p; |
1da177e4 | 1302 | |
13c65ce9 | 1303 | p = reserve_space(xdr, 8 + len); |
e75bc1c8 | 1304 | *p++ = cpu_to_be32(OP_PUTFH); |
811652bd | 1305 | xdr_encode_opaque(p, fh->data, len); |
d017931c | 1306 | hdr->nops++; |
dadf0c27 | 1307 | hdr->replen += decode_putfh_maxsz; |
1da177e4 LT |
1308 | } |
1309 | ||
cf8cdbe5 | 1310 | static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
1da177e4 | 1311 | { |
05d564fe | 1312 | __be32 *p; |
6c0195a4 | 1313 | |
13c65ce9 | 1314 | p = reserve_space(xdr, 4); |
34558513 | 1315 | *p = cpu_to_be32(OP_PUTROOTFH); |
d017931c | 1316 | hdr->nops++; |
dadf0c27 | 1317 | hdr->replen += decode_putrootfh_maxsz; |
1da177e4 LT |
1318 | } |
1319 | ||
1320 | static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx) | |
1321 | { | |
1da177e4 | 1322 | nfs4_stateid stateid; |
8687b63a | 1323 | __be32 *p; |
1da177e4 | 1324 | |
13c65ce9 | 1325 | p = reserve_space(xdr, NFS4_STATEID_SIZE); |
1da177e4 LT |
1326 | if (ctx->state != NULL) { |
1327 | nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner); | |
34558513 | 1328 | xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE); |
1da177e4 | 1329 | } else |
34558513 | 1330 | xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); |
1da177e4 LT |
1331 | } |
1332 | ||
cf8cdbe5 | 1333 | static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) |
1da177e4 | 1334 | { |
8687b63a | 1335 | __be32 *p; |
1da177e4 | 1336 | |
13c65ce9 | 1337 | p = reserve_space(xdr, 4); |
34558513 | 1338 | *p = cpu_to_be32(OP_READ); |
1da177e4 LT |
1339 | |
1340 | encode_stateid(xdr, args->context); | |
1341 | ||
13c65ce9 | 1342 | p = reserve_space(xdr, 12); |
b95be5a9 | 1343 | p = xdr_encode_hyper(p, args->offset); |
34558513 | 1344 | *p = cpu_to_be32(args->count); |
d017931c | 1345 | hdr->nops++; |
dadf0c27 | 1346 | hdr->replen += decode_read_maxsz; |
1da177e4 LT |
1347 | } |
1348 | ||
cf8cdbe5 | 1349 | static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) |
1da177e4 | 1350 | { |
97d312d0 MN |
1351 | uint32_t attrs[2] = { |
1352 | FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID, | |
1353 | FATTR4_WORD1_MOUNTED_ON_FILEID, | |
1354 | }; | |
8687b63a | 1355 | __be32 *p; |
1da177e4 | 1356 | |
13c65ce9 | 1357 | p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20); |
e75bc1c8 | 1358 | *p++ = cpu_to_be32(OP_READDIR); |
b95be5a9 | 1359 | p = xdr_encode_hyper(p, readdir->cookie); |
93f0cf25 | 1360 | p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE); |
e75bc1c8 BH |
1361 | *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */ |
1362 | *p++ = cpu_to_be32(readdir->count); | |
1363 | *p++ = cpu_to_be32(2); | |
97d312d0 MN |
1364 | /* Switch to mounted_on_fileid if the server supports it */ |
1365 | if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) | |
1366 | attrs[0] &= ~FATTR4_WORD0_FILEID; | |
1367 | else | |
1368 | attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; | |
e75bc1c8 | 1369 | *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); |
34558513 | 1370 | *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); |
d017931c | 1371 | hdr->nops++; |
dadf0c27 | 1372 | hdr->replen += decode_readdir_maxsz; |
44109241 FI |
1373 | dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", |
1374 | __func__, | |
eadf4598 TM |
1375 | (unsigned long long)readdir->cookie, |
1376 | ((u32 *)readdir->verifier.data)[0], | |
1377 | ((u32 *)readdir->verifier.data)[1], | |
1378 | attrs[0] & readdir->bitmask[0], | |
1379 | attrs[1] & readdir->bitmask[1]); | |
1da177e4 LT |
1380 | } |
1381 | ||
cf8cdbe5 | 1382 | static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) |
1da177e4 | 1383 | { |
8687b63a | 1384 | __be32 *p; |
1da177e4 | 1385 | |
13c65ce9 | 1386 | p = reserve_space(xdr, 4); |
34558513 | 1387 | *p = cpu_to_be32(OP_READLINK); |
d017931c | 1388 | hdr->nops++; |
dadf0c27 | 1389 | hdr->replen += decode_readlink_maxsz; |
1da177e4 LT |
1390 | } |
1391 | ||
cf8cdbe5 | 1392 | static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) |
1da177e4 | 1393 | { |
8687b63a | 1394 | __be32 *p; |
1da177e4 | 1395 | |
13c65ce9 | 1396 | p = reserve_space(xdr, 8 + name->len); |
e75bc1c8 | 1397 | *p++ = cpu_to_be32(OP_REMOVE); |
811652bd | 1398 | xdr_encode_opaque(p, name->name, name->len); |
d017931c | 1399 | hdr->nops++; |
dadf0c27 | 1400 | hdr->replen += decode_remove_maxsz; |
1da177e4 LT |
1401 | } |
1402 | ||
cf8cdbe5 | 1403 | static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) |
1da177e4 | 1404 | { |
8687b63a | 1405 | __be32 *p; |
1da177e4 | 1406 | |
811652bd BH |
1407 | p = reserve_space(xdr, 4); |
1408 | *p = cpu_to_be32(OP_RENAME); | |
1409 | encode_string(xdr, oldname->len, oldname->name); | |
1410 | encode_string(xdr, newname->len, newname->name); | |
d017931c | 1411 | hdr->nops++; |
dadf0c27 | 1412 | hdr->replen += decode_rename_maxsz; |
1da177e4 LT |
1413 | } |
1414 | ||
cf8cdbe5 | 1415 | static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr) |
1da177e4 | 1416 | { |
8687b63a | 1417 | __be32 *p; |
1da177e4 | 1418 | |
13c65ce9 | 1419 | p = reserve_space(xdr, 12); |
e75bc1c8 | 1420 | *p++ = cpu_to_be32(OP_RENEW); |
34558513 | 1421 | xdr_encode_hyper(p, client_stateid->cl_clientid); |
d017931c | 1422 | hdr->nops++; |
dadf0c27 | 1423 | hdr->replen += decode_renew_maxsz; |
1da177e4 LT |
1424 | } |
1425 | ||
cf8cdbe5 | 1426 | static void |
d017931c | 1427 | encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
56ae19f3 | 1428 | { |
8687b63a | 1429 | __be32 *p; |
56ae19f3 | 1430 | |
13c65ce9 | 1431 | p = reserve_space(xdr, 4); |
34558513 | 1432 | *p = cpu_to_be32(OP_RESTOREFH); |
d017931c | 1433 | hdr->nops++; |
dadf0c27 | 1434 | hdr->replen += decode_restorefh_maxsz; |
56ae19f3 TM |
1435 | } |
1436 | ||
23ec6965 | 1437 | static int |
d017931c | 1438 | encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) |
23ec6965 | 1439 | { |
8687b63a | 1440 | __be32 *p; |
23ec6965 | 1441 | |
13c65ce9 | 1442 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
e75bc1c8 | 1443 | *p++ = cpu_to_be32(OP_SETATTR); |
34558513 | 1444 | xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); |
13c65ce9 | 1445 | p = reserve_space(xdr, 2*4); |
e75bc1c8 | 1446 | *p++ = cpu_to_be32(1); |
34558513 | 1447 | *p = cpu_to_be32(FATTR4_WORD0_ACL); |
23ec6965 BF |
1448 | if (arg->acl_len % 4) |
1449 | return -EINVAL; | |
13c65ce9 | 1450 | p = reserve_space(xdr, 4); |
34558513 | 1451 | *p = cpu_to_be32(arg->acl_len); |
23ec6965 | 1452 | xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); |
d017931c | 1453 | hdr->nops++; |
dadf0c27 | 1454 | hdr->replen += decode_setacl_maxsz; |
23ec6965 BF |
1455 | return 0; |
1456 | } | |
1457 | ||
cf8cdbe5 | 1458 | static void |
d017931c | 1459 | encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) |
1da177e4 | 1460 | { |
8687b63a | 1461 | __be32 *p; |
1da177e4 | 1462 | |
13c65ce9 | 1463 | p = reserve_space(xdr, 4); |
34558513 | 1464 | *p = cpu_to_be32(OP_SAVEFH); |
d017931c | 1465 | hdr->nops++; |
dadf0c27 | 1466 | hdr->replen += decode_savefh_maxsz; |
1da177e4 LT |
1467 | } |
1468 | ||
cf8cdbe5 | 1469 | static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) |
1da177e4 | 1470 | { |
8687b63a | 1471 | __be32 *p; |
6c0195a4 | 1472 | |
13c65ce9 | 1473 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
e75bc1c8 | 1474 | *p++ = cpu_to_be32(OP_SETATTR); |
34558513 | 1475 | xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE); |
d017931c | 1476 | hdr->nops++; |
dadf0c27 | 1477 | hdr->replen += decode_setattr_maxsz; |
cf8cdbe5 | 1478 | encode_attrs(xdr, arg->iap, server); |
1da177e4 LT |
1479 | } |
1480 | ||
cf8cdbe5 | 1481 | static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) |
1da177e4 | 1482 | { |
8687b63a | 1483 | __be32 *p; |
1da177e4 | 1484 | |
13c65ce9 | 1485 | p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE); |
e75bc1c8 | 1486 | *p++ = cpu_to_be32(OP_SETCLIENTID); |
34558513 | 1487 | xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE); |
1da177e4 LT |
1488 | |
1489 | encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); | |
13c65ce9 | 1490 | p = reserve_space(xdr, 4); |
34558513 | 1491 | *p = cpu_to_be32(setclientid->sc_prog); |
1da177e4 LT |
1492 | encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); |
1493 | encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); | |
13c65ce9 | 1494 | p = reserve_space(xdr, 4); |
34558513 | 1495 | *p = cpu_to_be32(setclientid->sc_cb_ident); |
d017931c | 1496 | hdr->nops++; |
dadf0c27 | 1497 | hdr->replen += decode_setclientid_maxsz; |
1da177e4 LT |
1498 | } |
1499 | ||
cf8cdbe5 | 1500 | static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr) |
1da177e4 | 1501 | { |
05d564fe | 1502 | __be32 *p; |
1da177e4 | 1503 | |
13c65ce9 | 1504 | p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE); |
e75bc1c8 | 1505 | *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM); |
b95be5a9 | 1506 | p = xdr_encode_hyper(p, client_state->cl_clientid); |
34558513 | 1507 | xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE); |
d017931c | 1508 | hdr->nops++; |
dadf0c27 | 1509 | hdr->replen += decode_setclientid_confirm_maxsz; |
1da177e4 LT |
1510 | } |
1511 | ||
cf8cdbe5 | 1512 | static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) |
1da177e4 | 1513 | { |
8687b63a | 1514 | __be32 *p; |
1da177e4 | 1515 | |
13c65ce9 | 1516 | p = reserve_space(xdr, 4); |
34558513 | 1517 | *p = cpu_to_be32(OP_WRITE); |
1da177e4 LT |
1518 | |
1519 | encode_stateid(xdr, args->context); | |
1520 | ||
13c65ce9 | 1521 | p = reserve_space(xdr, 16); |
b95be5a9 | 1522 | p = xdr_encode_hyper(p, args->offset); |
e75bc1c8 | 1523 | *p++ = cpu_to_be32(args->stable); |
34558513 | 1524 | *p = cpu_to_be32(args->count); |
1da177e4 LT |
1525 | |
1526 | xdr_write_pages(xdr, args->pages, args->pgbase, args->count); | |
d017931c | 1527 | hdr->nops++; |
dadf0c27 | 1528 | hdr->replen += decode_write_maxsz; |
1da177e4 LT |
1529 | } |
1530 | ||
cf8cdbe5 | 1531 | static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) |
1da177e4 | 1532 | { |
8687b63a | 1533 | __be32 *p; |
1da177e4 | 1534 | |
13c65ce9 | 1535 | p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); |
1da177e4 | 1536 | |
e75bc1c8 | 1537 | *p++ = cpu_to_be32(OP_DELEGRETURN); |
34558513 | 1538 | xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); |
d017931c | 1539 | hdr->nops++; |
dadf0c27 | 1540 | hdr->replen += decode_delegreturn_maxsz; |
1da177e4 | 1541 | } |
9b7b9fcc | 1542 | |
99fe60d0 | 1543 | #if defined(CONFIG_NFS_V4_1) |
9b7b9fcc | 1544 | /* NFSv4.1 operations */ |
99fe60d0 BH |
1545 | static void encode_exchange_id(struct xdr_stream *xdr, |
1546 | struct nfs41_exchange_id_args *args, | |
1547 | struct compound_hdr *hdr) | |
1548 | { | |
1549 | __be32 *p; | |
1550 | ||
13c65ce9 | 1551 | p = reserve_space(xdr, 4 + sizeof(args->verifier->data)); |
e75bc1c8 | 1552 | *p++ = cpu_to_be32(OP_EXCHANGE_ID); |
34558513 | 1553 | xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data)); |
99fe60d0 BH |
1554 | |
1555 | encode_string(xdr, args->id_len, args->id); | |
1556 | ||
13c65ce9 | 1557 | p = reserve_space(xdr, 12); |
e75bc1c8 BH |
1558 | *p++ = cpu_to_be32(args->flags); |
1559 | *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ | |
34558513 | 1560 | *p = cpu_to_be32(0); /* zero length implementation id array */ |
99fe60d0 BH |
1561 | hdr->nops++; |
1562 | hdr->replen += decode_exchange_id_maxsz; | |
1563 | } | |
fc931582 AA |
1564 | |
1565 | static void encode_create_session(struct xdr_stream *xdr, | |
1566 | struct nfs41_create_session_args *args, | |
1567 | struct compound_hdr *hdr) | |
1568 | { | |
1569 | __be32 *p; | |
1570 | char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; | |
1571 | uint32_t len; | |
1572 | struct nfs_client *clp = args->client; | |
1573 | ||
42edd698 BH |
1574 | len = scnprintf(machine_name, sizeof(machine_name), "%s", |
1575 | clp->cl_ipaddr); | |
fc931582 | 1576 | |
13c65ce9 | 1577 | p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12); |
42edd698 | 1578 | *p++ = cpu_to_be32(OP_CREATE_SESSION); |
b95be5a9 | 1579 | p = xdr_encode_hyper(p, clp->cl_ex_clid); |
e75bc1c8 BH |
1580 | *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ |
1581 | *p++ = cpu_to_be32(args->flags); /*flags */ | |
fc931582 | 1582 | |
fc931582 | 1583 | /* Fore Channel */ |
e75bc1c8 BH |
1584 | *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */ |
1585 | *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ | |
1586 | *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ | |
1587 | *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */ | |
1588 | *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ | |
1589 | *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ | |
1590 | *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ | |
fc931582 AA |
1591 | |
1592 | /* Back Channel */ | |
e75bc1c8 BH |
1593 | *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */ |
1594 | *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ | |
1595 | *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ | |
1596 | *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ | |
1597 | *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ | |
1598 | *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ | |
1599 | *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ | |
fc931582 | 1600 | |
e75bc1c8 | 1601 | *p++ = cpu_to_be32(args->cb_program); /* cb_program */ |
e75bc1c8 | 1602 | *p++ = cpu_to_be32(1); |
e75bc1c8 | 1603 | *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ |
fc931582 AA |
1604 | |
1605 | /* authsys_parms rfc1831 */ | |
e75bc1c8 | 1606 | *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ |
811652bd | 1607 | p = xdr_encode_opaque(p, machine_name, len); |
e75bc1c8 BH |
1608 | *p++ = cpu_to_be32(0); /* UID */ |
1609 | *p++ = cpu_to_be32(0); /* GID */ | |
34558513 | 1610 | *p = cpu_to_be32(0); /* No more gids */ |
fc931582 AA |
1611 | hdr->nops++; |
1612 | hdr->replen += decode_create_session_maxsz; | |
1613 | } | |
0f3e66c6 AA |
1614 | |
1615 | static void encode_destroy_session(struct xdr_stream *xdr, | |
1616 | struct nfs4_session *session, | |
1617 | struct compound_hdr *hdr) | |
1618 | { | |
1619 | __be32 *p; | |
13c65ce9 | 1620 | p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN); |
e75bc1c8 | 1621 | *p++ = cpu_to_be32(OP_DESTROY_SESSION); |
34558513 | 1622 | xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); |
0f3e66c6 AA |
1623 | hdr->nops++; |
1624 | hdr->replen += decode_destroy_session_maxsz; | |
1625 | } | |
99fe60d0 BH |
1626 | #endif /* CONFIG_NFS_V4_1 */ |
1627 | ||
9b7b9fcc AA |
1628 | static void encode_sequence(struct xdr_stream *xdr, |
1629 | const struct nfs4_sequence_args *args, | |
1630 | struct compound_hdr *hdr) | |
1631 | { | |
1632 | #if defined(CONFIG_NFS_V4_1) | |
1633 | struct nfs4_session *session = args->sa_session; | |
fc01cea9 AA |
1634 | struct nfs4_slot_table *tp; |
1635 | struct nfs4_slot *slot; | |
1636 | __be32 *p; | |
9b7b9fcc AA |
1637 | |
1638 | if (!session) | |
1639 | return; | |
1640 | ||
fc01cea9 AA |
1641 | tp = &session->fc_slot_table; |
1642 | ||
1643 | WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); | |
1644 | slot = tp->slots + args->sa_slotid; | |
1645 | ||
13c65ce9 | 1646 | p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16); |
e75bc1c8 | 1647 | *p++ = cpu_to_be32(OP_SEQUENCE); |
fc01cea9 AA |
1648 | |
1649 | /* | |
1650 | * Sessionid + seqid + slotid + max slotid + cache_this | |
1651 | */ | |
1652 | dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " | |
1653 | "max_slotid=%d cache_this=%d\n", | |
1654 | __func__, | |
1655 | ((u32 *)session->sess_id.data)[0], | |
1656 | ((u32 *)session->sess_id.data)[1], | |
1657 | ((u32 *)session->sess_id.data)[2], | |
1658 | ((u32 *)session->sess_id.data)[3], | |
1659 | slot->seq_nr, args->sa_slotid, | |
1660 | tp->highest_used_slotid, args->sa_cache_this); | |
93f0cf25 | 1661 | p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); |
e75bc1c8 BH |
1662 | *p++ = cpu_to_be32(slot->seq_nr); |
1663 | *p++ = cpu_to_be32(args->sa_slotid); | |
1664 | *p++ = cpu_to_be32(tp->highest_used_slotid); | |
34558513 | 1665 | *p = cpu_to_be32(args->sa_cache_this); |
9b7b9fcc AA |
1666 | hdr->nops++; |
1667 | hdr->replen += decode_sequence_maxsz; | |
1668 | #endif /* CONFIG_NFS_V4_1 */ | |
1669 | } | |
1670 | ||
1da177e4 LT |
1671 | /* |
1672 | * END OF "GENERIC" ENCODE ROUTINES. | |
1673 | */ | |
1674 | ||
66cc0429 BH |
1675 | static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) |
1676 | { | |
1677 | #if defined(CONFIG_NFS_V4_1) | |
1678 | if (args->sa_session) | |
1679 | return args->sa_session->clp->cl_minorversion; | |
1680 | #endif /* CONFIG_NFS_V4_1 */ | |
1681 | return 0; | |
1682 | } | |
1683 | ||
1da177e4 LT |
1684 | /* |
1685 | * Encode an ACCESS request | |
1686 | */ | |
8687b63a | 1687 | static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args) |
1da177e4 LT |
1688 | { |
1689 | struct xdr_stream xdr; | |
1690 | struct compound_hdr hdr = { | |
66cc0429 | 1691 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1692 | }; |
1da177e4 LT |
1693 | |
1694 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1695 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1696 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1697 | encode_putfh(&xdr, args->fh, &hdr); |
1698 | encode_access(&xdr, args->access, &hdr); | |
1699 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1700 | encode_nops(&hdr); |
cf8cdbe5 | 1701 | return 0; |
1da177e4 LT |
1702 | } |
1703 | ||
1704 | /* | |
1705 | * Encode LOOKUP request | |
1706 | */ | |
8687b63a | 1707 | static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args) |
1da177e4 LT |
1708 | { |
1709 | struct xdr_stream xdr; | |
1710 | struct compound_hdr hdr = { | |
66cc0429 | 1711 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1712 | }; |
1da177e4 LT |
1713 | |
1714 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1715 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1716 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1717 | encode_putfh(&xdr, args->dir_fh, &hdr); |
1718 | encode_lookup(&xdr, args->name, &hdr); | |
1719 | encode_getfh(&xdr, &hdr); | |
1720 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1721 | encode_nops(&hdr); |
cf8cdbe5 | 1722 | return 0; |
1da177e4 LT |
1723 | } |
1724 | ||
1725 | /* | |
1726 | * Encode LOOKUP_ROOT request | |
1727 | */ | |
8687b63a | 1728 | static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args) |
1da177e4 LT |
1729 | { |
1730 | struct xdr_stream xdr; | |
1731 | struct compound_hdr hdr = { | |
66cc0429 | 1732 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1733 | }; |
1da177e4 LT |
1734 | |
1735 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1736 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1737 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1738 | encode_putrootfh(&xdr, &hdr); |
1739 | encode_getfh(&xdr, &hdr); | |
1740 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1741 | encode_nops(&hdr); |
cf8cdbe5 | 1742 | return 0; |
1da177e4 LT |
1743 | } |
1744 | ||
1745 | /* | |
1746 | * Encode REMOVE request | |
1747 | */ | |
4fdc17b2 | 1748 | static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) |
1da177e4 LT |
1749 | { |
1750 | struct xdr_stream xdr; | |
1751 | struct compound_hdr hdr = { | |
66cc0429 | 1752 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1753 | }; |
1da177e4 LT |
1754 | |
1755 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1756 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1757 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1758 | encode_putfh(&xdr, args->fh, &hdr); |
1759 | encode_remove(&xdr, &args->name, &hdr); | |
1760 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1761 | encode_nops(&hdr); |
cf8cdbe5 | 1762 | return 0; |
1da177e4 LT |
1763 | } |
1764 | ||
1765 | /* | |
1766 | * Encode RENAME request | |
1767 | */ | |
8687b63a | 1768 | static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args) |
1da177e4 LT |
1769 | { |
1770 | struct xdr_stream xdr; | |
1771 | struct compound_hdr hdr = { | |
66cc0429 | 1772 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1773 | }; |
1da177e4 LT |
1774 | |
1775 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1776 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1777 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1778 | encode_putfh(&xdr, args->old_dir, &hdr); |
1779 | encode_savefh(&xdr, &hdr); | |
1780 | encode_putfh(&xdr, args->new_dir, &hdr); | |
1781 | encode_rename(&xdr, args->old_name, args->new_name, &hdr); | |
1782 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
1783 | encode_restorefh(&xdr, &hdr); | |
1784 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1785 | encode_nops(&hdr); |
cf8cdbe5 | 1786 | return 0; |
1da177e4 LT |
1787 | } |
1788 | ||
1789 | /* | |
1790 | * Encode LINK request | |
1791 | */ | |
8687b63a | 1792 | static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args) |
1da177e4 LT |
1793 | { |
1794 | struct xdr_stream xdr; | |
1795 | struct compound_hdr hdr = { | |
66cc0429 | 1796 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1797 | }; |
1da177e4 LT |
1798 | |
1799 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1800 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1801 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1802 | encode_putfh(&xdr, args->fh, &hdr); |
1803 | encode_savefh(&xdr, &hdr); | |
1804 | encode_putfh(&xdr, args->dir_fh, &hdr); | |
1805 | encode_link(&xdr, args->name, &hdr); | |
1806 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
1807 | encode_restorefh(&xdr, &hdr); | |
1808 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1809 | encode_nops(&hdr); |
cf8cdbe5 | 1810 | return 0; |
1da177e4 LT |
1811 | } |
1812 | ||
1813 | /* | |
1814 | * Encode CREATE request | |
1815 | */ | |
8687b63a | 1816 | static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) |
1da177e4 LT |
1817 | { |
1818 | struct xdr_stream xdr; | |
1819 | struct compound_hdr hdr = { | |
66cc0429 | 1820 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1821 | }; |
1da177e4 LT |
1822 | |
1823 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1824 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1825 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1826 | encode_putfh(&xdr, args->dir_fh, &hdr); |
1827 | encode_savefh(&xdr, &hdr); | |
1828 | encode_create(&xdr, args, &hdr); | |
1829 | encode_getfh(&xdr, &hdr); | |
1830 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
1831 | encode_restorefh(&xdr, &hdr); | |
1832 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1833 | encode_nops(&hdr); |
cf8cdbe5 | 1834 | return 0; |
1da177e4 LT |
1835 | } |
1836 | ||
1837 | /* | |
1838 | * Encode SYMLINK request | |
1839 | */ | |
8687b63a | 1840 | static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) |
1da177e4 LT |
1841 | { |
1842 | return nfs4_xdr_enc_create(req, p, args); | |
1843 | } | |
1844 | ||
1845 | /* | |
1846 | * Encode GETATTR request | |
1847 | */ | |
8687b63a | 1848 | static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args) |
1da177e4 LT |
1849 | { |
1850 | struct xdr_stream xdr; | |
1851 | struct compound_hdr hdr = { | |
66cc0429 | 1852 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1853 | }; |
1da177e4 LT |
1854 | |
1855 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1856 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1857 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1858 | encode_putfh(&xdr, args->fh, &hdr); |
1859 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1860 | encode_nops(&hdr); |
cf8cdbe5 | 1861 | return 0; |
1da177e4 LT |
1862 | } |
1863 | ||
1864 | /* | |
1865 | * Encode a CLOSE request | |
1866 | */ | |
8687b63a | 1867 | static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) |
1da177e4 | 1868 | { |
05d564fe AA |
1869 | struct xdr_stream xdr; |
1870 | struct compound_hdr hdr = { | |
66cc0429 | 1871 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
05d564fe | 1872 | }; |
05d564fe AA |
1873 | |
1874 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1875 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1876 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1877 | encode_putfh(&xdr, args->fh, &hdr); |
1878 | encode_close(&xdr, args, &hdr); | |
1879 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1880 | encode_nops(&hdr); |
cf8cdbe5 | 1881 | return 0; |
1da177e4 LT |
1882 | } |
1883 | ||
1884 | /* | |
1885 | * Encode an OPEN request | |
1886 | */ | |
8687b63a | 1887 | static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) |
1da177e4 LT |
1888 | { |
1889 | struct xdr_stream xdr; | |
1890 | struct compound_hdr hdr = { | |
66cc0429 | 1891 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1892 | }; |
1da177e4 LT |
1893 | |
1894 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1895 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1896 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1897 | encode_putfh(&xdr, args->fh, &hdr); |
1898 | encode_savefh(&xdr, &hdr); | |
1899 | encode_open(&xdr, args, &hdr); | |
1900 | encode_getfh(&xdr, &hdr); | |
1901 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
1902 | encode_restorefh(&xdr, &hdr); | |
1903 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1904 | encode_nops(&hdr); |
cf8cdbe5 | 1905 | return 0; |
1da177e4 LT |
1906 | } |
1907 | ||
1908 | /* | |
1909 | * Encode an OPEN_CONFIRM request | |
1910 | */ | |
8687b63a | 1911 | static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args) |
1da177e4 LT |
1912 | { |
1913 | struct xdr_stream xdr; | |
1914 | struct compound_hdr hdr = { | |
d017931c | 1915 | .nops = 0, |
1da177e4 | 1916 | }; |
1da177e4 LT |
1917 | |
1918 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1919 | encode_compound_hdr(&xdr, req, &hdr); |
cf8cdbe5 AA |
1920 | encode_putfh(&xdr, args->fh, &hdr); |
1921 | encode_open_confirm(&xdr, args, &hdr); | |
d017931c | 1922 | encode_nops(&hdr); |
cf8cdbe5 | 1923 | return 0; |
1da177e4 LT |
1924 | } |
1925 | ||
1926 | /* | |
1927 | * Encode an OPEN request with no attributes. | |
1928 | */ | |
8687b63a | 1929 | static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) |
1da177e4 LT |
1930 | { |
1931 | struct xdr_stream xdr; | |
1932 | struct compound_hdr hdr = { | |
66cc0429 | 1933 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1934 | }; |
1da177e4 LT |
1935 | |
1936 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1937 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1938 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1939 | encode_putfh(&xdr, args->fh, &hdr); |
1940 | encode_open(&xdr, args, &hdr); | |
1941 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1942 | encode_nops(&hdr); |
cf8cdbe5 | 1943 | return 0; |
1da177e4 LT |
1944 | } |
1945 | ||
1946 | /* | |
1947 | * Encode an OPEN_DOWNGRADE request | |
1948 | */ | |
8687b63a | 1949 | static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) |
1da177e4 LT |
1950 | { |
1951 | struct xdr_stream xdr; | |
1952 | struct compound_hdr hdr = { | |
66cc0429 | 1953 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1954 | }; |
1da177e4 LT |
1955 | |
1956 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1957 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1958 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1959 | encode_putfh(&xdr, args->fh, &hdr); |
1960 | encode_open_downgrade(&xdr, args, &hdr); | |
1961 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 1962 | encode_nops(&hdr); |
cf8cdbe5 | 1963 | return 0; |
1da177e4 LT |
1964 | } |
1965 | ||
1966 | /* | |
1967 | * Encode a LOCK request | |
1968 | */ | |
8687b63a | 1969 | static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args) |
1da177e4 LT |
1970 | { |
1971 | struct xdr_stream xdr; | |
1972 | struct compound_hdr hdr = { | |
66cc0429 | 1973 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1974 | }; |
1da177e4 LT |
1975 | |
1976 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1977 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1978 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1979 | encode_putfh(&xdr, args->fh, &hdr); |
1980 | encode_lock(&xdr, args, &hdr); | |
d017931c | 1981 | encode_nops(&hdr); |
cf8cdbe5 | 1982 | return 0; |
1da177e4 LT |
1983 | } |
1984 | ||
1985 | /* | |
1986 | * Encode a LOCKT request | |
1987 | */ | |
8687b63a | 1988 | static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args) |
1da177e4 LT |
1989 | { |
1990 | struct xdr_stream xdr; | |
1991 | struct compound_hdr hdr = { | |
66cc0429 | 1992 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 1993 | }; |
1da177e4 LT |
1994 | |
1995 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 1996 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 1997 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
1998 | encode_putfh(&xdr, args->fh, &hdr); |
1999 | encode_lockt(&xdr, args, &hdr); | |
d017931c | 2000 | encode_nops(&hdr); |
cf8cdbe5 | 2001 | return 0; |
1da177e4 LT |
2002 | } |
2003 | ||
2004 | /* | |
2005 | * Encode a LOCKU request | |
2006 | */ | |
8687b63a | 2007 | static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args) |
1da177e4 LT |
2008 | { |
2009 | struct xdr_stream xdr; | |
2010 | struct compound_hdr hdr = { | |
66cc0429 | 2011 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2012 | }; |
1da177e4 LT |
2013 | |
2014 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2015 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2016 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2017 | encode_putfh(&xdr, args->fh, &hdr); |
2018 | encode_locku(&xdr, args, &hdr); | |
d017931c | 2019 | encode_nops(&hdr); |
cf8cdbe5 | 2020 | return 0; |
1da177e4 LT |
2021 | } |
2022 | ||
2023 | /* | |
2024 | * Encode a READLINK request | |
2025 | */ | |
8687b63a | 2026 | static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args) |
1da177e4 LT |
2027 | { |
2028 | struct xdr_stream xdr; | |
2029 | struct compound_hdr hdr = { | |
66cc0429 | 2030 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2031 | }; |
1da177e4 LT |
2032 | |
2033 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2034 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2035 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2036 | encode_putfh(&xdr, args->fh, &hdr); |
2037 | encode_readlink(&xdr, args, req, &hdr); | |
e3a535e1 | 2038 | |
28f56694 | 2039 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
e3a535e1 | 2040 | args->pgbase, args->pglen); |
d017931c | 2041 | encode_nops(&hdr); |
cf8cdbe5 | 2042 | return 0; |
1da177e4 LT |
2043 | } |
2044 | ||
2045 | /* | |
2046 | * Encode a READDIR request | |
2047 | */ | |
8687b63a | 2048 | static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args) |
1da177e4 LT |
2049 | { |
2050 | struct xdr_stream xdr; | |
2051 | struct compound_hdr hdr = { | |
66cc0429 | 2052 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2053 | }; |
1da177e4 LT |
2054 | |
2055 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2056 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2057 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2058 | encode_putfh(&xdr, args->fh, &hdr); |
2059 | encode_readdir(&xdr, args, req, &hdr); | |
d6ac02df | 2060 | |
28f56694 | 2061 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
d6ac02df TM |
2062 | args->pgbase, args->count); |
2063 | dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", | |
28f56694 | 2064 | __func__, hdr.replen << 2, args->pages, |
d6ac02df | 2065 | args->pgbase, args->count); |
d017931c | 2066 | encode_nops(&hdr); |
cf8cdbe5 | 2067 | return 0; |
1da177e4 LT |
2068 | } |
2069 | ||
2070 | /* | |
2071 | * Encode a READ request | |
2072 | */ | |
8687b63a | 2073 | static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) |
1da177e4 | 2074 | { |
1da177e4 LT |
2075 | struct xdr_stream xdr; |
2076 | struct compound_hdr hdr = { | |
66cc0429 | 2077 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2078 | }; |
1da177e4 LT |
2079 | |
2080 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2081 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2082 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2083 | encode_putfh(&xdr, args->fh, &hdr); |
2084 | encode_read(&xdr, args, &hdr); | |
1da177e4 | 2085 | |
28f56694 | 2086 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, |
1da177e4 | 2087 | args->pages, args->pgbase, args->count); |
4f22ccc3 | 2088 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
d017931c | 2089 | encode_nops(&hdr); |
cf8cdbe5 | 2090 | return 0; |
1da177e4 LT |
2091 | } |
2092 | ||
2093 | /* | |
2094 | * Encode an SETATTR request | |
2095 | */ | |
8687b63a | 2096 | static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args) |
1da177e4 | 2097 | { |
05d564fe AA |
2098 | struct xdr_stream xdr; |
2099 | struct compound_hdr hdr = { | |
66cc0429 | 2100 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
05d564fe | 2101 | }; |
05d564fe AA |
2102 | |
2103 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2104 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2105 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2106 | encode_putfh(&xdr, args->fh, &hdr); |
2107 | encode_setattr(&xdr, args, args->server, &hdr); | |
2108 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 2109 | encode_nops(&hdr); |
cf8cdbe5 | 2110 | return 0; |
1da177e4 LT |
2111 | } |
2112 | ||
029d105e BF |
2113 | /* |
2114 | * Encode a GETACL request | |
2115 | */ | |
2116 | static int | |
8687b63a | 2117 | nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p, |
029d105e BF |
2118 | struct nfs_getaclargs *args) |
2119 | { | |
2120 | struct xdr_stream xdr; | |
029d105e | 2121 | struct compound_hdr hdr = { |
66cc0429 | 2122 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
029d105e | 2123 | }; |
28f56694 | 2124 | uint32_t replen; |
029d105e BF |
2125 | |
2126 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2127 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2128 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 | 2129 | encode_putfh(&xdr, args->fh, &hdr); |
d327cf74 | 2130 | replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1; |
cf8cdbe5 AA |
2131 | encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr); |
2132 | ||
28f56694 | 2133 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, |
029d105e | 2134 | args->acl_pages, args->acl_pgbase, args->acl_len); |
d017931c | 2135 | encode_nops(&hdr); |
cf8cdbe5 | 2136 | return 0; |
029d105e BF |
2137 | } |
2138 | ||
1da177e4 LT |
2139 | /* |
2140 | * Encode a WRITE request | |
2141 | */ | |
8687b63a | 2142 | static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) |
1da177e4 LT |
2143 | { |
2144 | struct xdr_stream xdr; | |
2145 | struct compound_hdr hdr = { | |
66cc0429 | 2146 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2147 | }; |
1da177e4 LT |
2148 | |
2149 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2150 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2151 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2152 | encode_putfh(&xdr, args->fh, &hdr); |
2153 | encode_write(&xdr, args, &hdr); | |
4f22ccc3 | 2154 | req->rq_snd_buf.flags |= XDRBUF_WRITE; |
cf8cdbe5 | 2155 | encode_getfattr(&xdr, args->bitmask, &hdr); |
d017931c | 2156 | encode_nops(&hdr); |
cf8cdbe5 | 2157 | return 0; |
1da177e4 LT |
2158 | } |
2159 | ||
2160 | /* | |
2161 | * a COMMIT request | |
2162 | */ | |
8687b63a | 2163 | static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) |
1da177e4 LT |
2164 | { |
2165 | struct xdr_stream xdr; | |
2166 | struct compound_hdr hdr = { | |
66cc0429 | 2167 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2168 | }; |
1da177e4 LT |
2169 | |
2170 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2171 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2172 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2173 | encode_putfh(&xdr, args->fh, &hdr); |
2174 | encode_commit(&xdr, args, &hdr); | |
2175 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 2176 | encode_nops(&hdr); |
cf8cdbe5 | 2177 | return 0; |
1da177e4 LT |
2178 | } |
2179 | ||
2180 | /* | |
2181 | * FSINFO request | |
2182 | */ | |
8687b63a | 2183 | static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args) |
1da177e4 LT |
2184 | { |
2185 | struct xdr_stream xdr; | |
2186 | struct compound_hdr hdr = { | |
66cc0429 | 2187 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2188 | }; |
1da177e4 LT |
2189 | |
2190 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2191 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2192 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2193 | encode_putfh(&xdr, args->fh, &hdr); |
2194 | encode_fsinfo(&xdr, args->bitmask, &hdr); | |
d017931c | 2195 | encode_nops(&hdr); |
cf8cdbe5 | 2196 | return 0; |
1da177e4 LT |
2197 | } |
2198 | ||
2199 | /* | |
2200 | * a PATHCONF request | |
2201 | */ | |
8687b63a | 2202 | static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args) |
1da177e4 | 2203 | { |
1da177e4 LT |
2204 | struct xdr_stream xdr; |
2205 | struct compound_hdr hdr = { | |
66cc0429 | 2206 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2207 | }; |
1da177e4 LT |
2208 | |
2209 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2210 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2211 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2212 | encode_putfh(&xdr, args->fh, &hdr); |
2213 | encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], | |
2214 | &hdr); | |
d017931c | 2215 | encode_nops(&hdr); |
cf8cdbe5 | 2216 | return 0; |
1da177e4 LT |
2217 | } |
2218 | ||
2219 | /* | |
2220 | * a STATFS request | |
2221 | */ | |
8687b63a | 2222 | static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args) |
1da177e4 | 2223 | { |
1da177e4 LT |
2224 | struct xdr_stream xdr; |
2225 | struct compound_hdr hdr = { | |
66cc0429 | 2226 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2227 | }; |
1da177e4 LT |
2228 | |
2229 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2230 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2231 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2232 | encode_putfh(&xdr, args->fh, &hdr); |
2233 | encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], | |
2234 | args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); | |
d017931c | 2235 | encode_nops(&hdr); |
cf8cdbe5 | 2236 | return 0; |
1da177e4 LT |
2237 | } |
2238 | ||
2239 | /* | |
2240 | * GETATTR_BITMAP request | |
2241 | */ | |
43652ad5 BH |
2242 | static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, |
2243 | struct nfs4_server_caps_arg *args) | |
1da177e4 LT |
2244 | { |
2245 | struct xdr_stream xdr; | |
2246 | struct compound_hdr hdr = { | |
66cc0429 | 2247 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2248 | }; |
1da177e4 LT |
2249 | |
2250 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2251 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2252 | encode_sequence(&xdr, &args->seq_args, &hdr); |
43652ad5 | 2253 | encode_putfh(&xdr, args->fhandle, &hdr); |
cf8cdbe5 AA |
2254 | encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS| |
2255 | FATTR4_WORD0_LINK_SUPPORT| | |
2256 | FATTR4_WORD0_SYMLINK_SUPPORT| | |
2257 | FATTR4_WORD0_ACLSUPPORT, &hdr); | |
d017931c | 2258 | encode_nops(&hdr); |
cf8cdbe5 | 2259 | return 0; |
1da177e4 LT |
2260 | } |
2261 | ||
2262 | /* | |
2263 | * a RENEW request | |
2264 | */ | |
8687b63a | 2265 | static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) |
1da177e4 LT |
2266 | { |
2267 | struct xdr_stream xdr; | |
2268 | struct compound_hdr hdr = { | |
d017931c | 2269 | .nops = 0, |
1da177e4 LT |
2270 | }; |
2271 | ||
2272 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2273 | encode_compound_hdr(&xdr, req, &hdr); |
cf8cdbe5 | 2274 | encode_renew(&xdr, clp, &hdr); |
d017931c | 2275 | encode_nops(&hdr); |
cf8cdbe5 | 2276 | return 0; |
1da177e4 LT |
2277 | } |
2278 | ||
2279 | /* | |
2280 | * a SETCLIENTID request | |
2281 | */ | |
8687b63a | 2282 | static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc) |
1da177e4 LT |
2283 | { |
2284 | struct xdr_stream xdr; | |
2285 | struct compound_hdr hdr = { | |
d017931c | 2286 | .nops = 0, |
1da177e4 LT |
2287 | }; |
2288 | ||
2289 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2290 | encode_compound_hdr(&xdr, req, &hdr); |
cf8cdbe5 | 2291 | encode_setclientid(&xdr, sc, &hdr); |
d017931c | 2292 | encode_nops(&hdr); |
cf8cdbe5 | 2293 | return 0; |
1da177e4 LT |
2294 | } |
2295 | ||
2296 | /* | |
2297 | * a SETCLIENTID_CONFIRM request | |
2298 | */ | |
8687b63a | 2299 | static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) |
1da177e4 LT |
2300 | { |
2301 | struct xdr_stream xdr; | |
2302 | struct compound_hdr hdr = { | |
d017931c | 2303 | .nops = 0, |
1da177e4 LT |
2304 | }; |
2305 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; | |
1da177e4 LT |
2306 | |
2307 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2308 | encode_compound_hdr(&xdr, req, &hdr); |
cf8cdbe5 AA |
2309 | encode_setclientid_confirm(&xdr, clp, &hdr); |
2310 | encode_putrootfh(&xdr, &hdr); | |
2311 | encode_fsinfo(&xdr, lease_bitmap, &hdr); | |
d017931c | 2312 | encode_nops(&hdr); |
cf8cdbe5 | 2313 | return 0; |
1da177e4 LT |
2314 | } |
2315 | ||
2316 | /* | |
2317 | * DELEGRETURN request | |
2318 | */ | |
8687b63a | 2319 | static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args) |
1da177e4 LT |
2320 | { |
2321 | struct xdr_stream xdr; | |
2322 | struct compound_hdr hdr = { | |
66cc0429 | 2323 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1da177e4 | 2324 | }; |
1da177e4 LT |
2325 | |
2326 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2327 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2328 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2329 | encode_putfh(&xdr, args->fhandle, &hdr); |
2330 | encode_delegreturn(&xdr, args->stateid, &hdr); | |
2331 | encode_getfattr(&xdr, args->bitmask, &hdr); | |
d017931c | 2332 | encode_nops(&hdr); |
cf8cdbe5 | 2333 | return 0; |
1da177e4 LT |
2334 | } |
2335 | ||
683b57b4 TM |
2336 | /* |
2337 | * Encode FS_LOCATIONS request | |
2338 | */ | |
8687b63a | 2339 | static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args) |
683b57b4 TM |
2340 | { |
2341 | struct xdr_stream xdr; | |
2342 | struct compound_hdr hdr = { | |
66cc0429 | 2343 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
683b57b4 | 2344 | }; |
28f56694 | 2345 | uint32_t replen; |
683b57b4 TM |
2346 | |
2347 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 2348 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 2349 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 AA |
2350 | encode_putfh(&xdr, args->dir_fh, &hdr); |
2351 | encode_lookup(&xdr, args->name, &hdr); | |
28f56694 | 2352 | replen = hdr.replen; /* get the attribute into args->page */ |
cf8cdbe5 AA |
2353 | encode_fs_locations(&xdr, args->bitmask, &hdr); |
2354 | ||
28f56694 | 2355 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, |
683b57b4 | 2356 | 0, PAGE_SIZE); |
d017931c | 2357 | encode_nops(&hdr); |
cf8cdbe5 | 2358 | return 0; |
683b57b4 TM |
2359 | } |
2360 | ||
99fe60d0 BH |
2361 | #if defined(CONFIG_NFS_V4_1) |
2362 | /* | |
2363 | * EXCHANGE_ID request | |
2364 | */ | |
2365 | static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p, | |
2366 | struct nfs41_exchange_id_args *args) | |
2367 | { | |
2368 | struct xdr_stream xdr; | |
2369 | struct compound_hdr hdr = { | |
2370 | .minorversion = args->client->cl_minorversion, | |
2371 | }; | |
2372 | ||
2373 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
2374 | encode_compound_hdr(&xdr, req, &hdr); | |
2375 | encode_exchange_id(&xdr, args, &hdr); | |
2376 | encode_nops(&hdr); | |
2377 | return 0; | |
2378 | } | |
2050f0cc | 2379 | |
fc931582 AA |
2380 | /* |
2381 | * a CREATE_SESSION request | |
2382 | */ | |
2383 | static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p, | |
2384 | struct nfs41_create_session_args *args) | |
2385 | { | |
2386 | struct xdr_stream xdr; | |
2387 | struct compound_hdr hdr = { | |
2388 | .minorversion = args->client->cl_minorversion, | |
2389 | }; | |
2390 | ||
2391 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
2392 | encode_compound_hdr(&xdr, req, &hdr); | |
2393 | encode_create_session(&xdr, args, &hdr); | |
2394 | encode_nops(&hdr); | |
2395 | return 0; | |
2396 | } | |
2397 | ||
0f3e66c6 AA |
2398 | /* |
2399 | * a DESTROY_SESSION request | |
2400 | */ | |
2401 | static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p, | |
2402 | struct nfs4_session *session) | |
2403 | { | |
2404 | struct xdr_stream xdr; | |
2405 | struct compound_hdr hdr = { | |
2406 | .minorversion = session->clp->cl_minorversion, | |
2407 | }; | |
2408 | ||
2409 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
2410 | encode_compound_hdr(&xdr, req, &hdr); | |
2411 | encode_destroy_session(&xdr, session, &hdr); | |
2412 | encode_nops(&hdr); | |
2413 | return 0; | |
2414 | } | |
2415 | ||
fc01cea9 AA |
2416 | /* |
2417 | * a SEQUENCE request | |
2418 | */ | |
2419 | static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p, | |
2420 | struct nfs4_sequence_args *args) | |
2421 | { | |
2422 | struct xdr_stream xdr; | |
2423 | struct compound_hdr hdr = { | |
2424 | .minorversion = nfs4_xdr_minorversion(args), | |
2425 | }; | |
2426 | ||
2427 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
2428 | encode_compound_hdr(&xdr, req, &hdr); | |
2429 | encode_sequence(&xdr, args, &hdr); | |
2430 | encode_nops(&hdr); | |
2431 | return 0; | |
2432 | } | |
2433 | ||
2050f0cc AA |
2434 | /* |
2435 | * a GET_LEASE_TIME request | |
2436 | */ | |
2437 | static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p, | |
2438 | struct nfs4_get_lease_time_args *args) | |
2439 | { | |
2440 | struct xdr_stream xdr; | |
2441 | struct compound_hdr hdr = { | |
2442 | .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), | |
2443 | }; | |
2444 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; | |
2445 | ||
2446 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
2447 | encode_compound_hdr(&xdr, req, &hdr); | |
2448 | encode_sequence(&xdr, &args->la_seq_args, &hdr); | |
2449 | encode_putrootfh(&xdr, &hdr); | |
2450 | encode_fsinfo(&xdr, lease_bitmap, &hdr); | |
2451 | encode_nops(&hdr); | |
2452 | return 0; | |
2453 | } | |
99fe60d0 BH |
2454 | #endif /* CONFIG_NFS_V4_1 */ |
2455 | ||
686841b3 BH |
2456 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) |
2457 | { | |
2458 | dprintk("nfs: %s: prematurely hit end of receive buffer. " | |
2459 | "Remaining buffer length is %tu words.\n", | |
2460 | func, xdr->end - xdr->p); | |
2461 | } | |
1da177e4 | 2462 | |
683b57b4 | 2463 | static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) |
1da177e4 | 2464 | { |
8687b63a | 2465 | __be32 *p; |
1da177e4 | 2466 | |
c0eae66e BH |
2467 | p = xdr_inline_decode(xdr, 4); |
2468 | if (unlikely(!p)) | |
2469 | goto out_overflow; | |
cccddf4f | 2470 | *len = be32_to_cpup(p); |
c0eae66e BH |
2471 | p = xdr_inline_decode(xdr, *len); |
2472 | if (unlikely(!p)) | |
2473 | goto out_overflow; | |
1da177e4 LT |
2474 | *string = (char *)p; |
2475 | return 0; | |
c0eae66e BH |
2476 | out_overflow: |
2477 | print_overflow_msg(__func__, xdr); | |
2478 | return -EIO; | |
1da177e4 LT |
2479 | } |
2480 | ||
2481 | static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) | |
2482 | { | |
8687b63a | 2483 | __be32 *p; |
1da177e4 | 2484 | |
c0eae66e BH |
2485 | p = xdr_inline_decode(xdr, 8); |
2486 | if (unlikely(!p)) | |
2487 | goto out_overflow; | |
6f723f77 | 2488 | hdr->status = be32_to_cpup(p++); |
cccddf4f | 2489 | hdr->taglen = be32_to_cpup(p); |
6c0195a4 | 2490 | |
c0eae66e BH |
2491 | p = xdr_inline_decode(xdr, hdr->taglen + 4); |
2492 | if (unlikely(!p)) | |
2493 | goto out_overflow; | |
1da177e4 LT |
2494 | hdr->tag = (char *)p; |
2495 | p += XDR_QUADLEN(hdr->taglen); | |
cccddf4f | 2496 | hdr->nops = be32_to_cpup(p); |
aadf6152 BH |
2497 | if (unlikely(hdr->nops < 1)) |
2498 | return nfs4_stat_to_errno(hdr->status); | |
1da177e4 | 2499 | return 0; |
c0eae66e BH |
2500 | out_overflow: |
2501 | print_overflow_msg(__func__, xdr); | |
2502 | return -EIO; | |
1da177e4 LT |
2503 | } |
2504 | ||
2505 | static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) | |
2506 | { | |
8687b63a | 2507 | __be32 *p; |
1da177e4 LT |
2508 | uint32_t opnum; |
2509 | int32_t nfserr; | |
2510 | ||
c0eae66e BH |
2511 | p = xdr_inline_decode(xdr, 8); |
2512 | if (unlikely(!p)) | |
2513 | goto out_overflow; | |
6f723f77 | 2514 | opnum = be32_to_cpup(p++); |
1da177e4 | 2515 | if (opnum != expected) { |
fe82a183 CL |
2516 | dprintk("nfs: Server returned operation" |
2517 | " %d but we issued a request for %d\n", | |
1da177e4 LT |
2518 | opnum, expected); |
2519 | return -EIO; | |
2520 | } | |
cccddf4f | 2521 | nfserr = be32_to_cpup(p); |
1da177e4 | 2522 | if (nfserr != NFS_OK) |
856dff3d | 2523 | return nfs4_stat_to_errno(nfserr); |
1da177e4 | 2524 | return 0; |
c0eae66e BH |
2525 | out_overflow: |
2526 | print_overflow_msg(__func__, xdr); | |
2527 | return -EIO; | |
1da177e4 LT |
2528 | } |
2529 | ||
2530 | /* Dummy routine */ | |
adfa6f98 | 2531 | static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) |
1da177e4 | 2532 | { |
8687b63a | 2533 | __be32 *p; |
683b57b4 | 2534 | unsigned int strlen; |
1da177e4 LT |
2535 | char *str; |
2536 | ||
c0eae66e BH |
2537 | p = xdr_inline_decode(xdr, 12); |
2538 | if (likely(p)) | |
2539 | return decode_opaque_inline(xdr, &strlen, &str); | |
2540 | print_overflow_msg(__func__, xdr); | |
2541 | return -EIO; | |
1da177e4 LT |
2542 | } |
2543 | ||
2544 | static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) | |
2545 | { | |
8687b63a AV |
2546 | uint32_t bmlen; |
2547 | __be32 *p; | |
1da177e4 | 2548 | |
c0eae66e BH |
2549 | p = xdr_inline_decode(xdr, 4); |
2550 | if (unlikely(!p)) | |
2551 | goto out_overflow; | |
cccddf4f | 2552 | bmlen = be32_to_cpup(p); |
1da177e4 LT |
2553 | |
2554 | bitmap[0] = bitmap[1] = 0; | |
c0eae66e BH |
2555 | p = xdr_inline_decode(xdr, (bmlen << 2)); |
2556 | if (unlikely(!p)) | |
2557 | goto out_overflow; | |
1da177e4 | 2558 | if (bmlen > 0) { |
6f723f77 | 2559 | bitmap[0] = be32_to_cpup(p++); |
1da177e4 | 2560 | if (bmlen > 1) |
cccddf4f | 2561 | bitmap[1] = be32_to_cpup(p); |
1da177e4 LT |
2562 | } |
2563 | return 0; | |
c0eae66e BH |
2564 | out_overflow: |
2565 | print_overflow_msg(__func__, xdr); | |
2566 | return -EIO; | |
1da177e4 LT |
2567 | } |
2568 | ||
8687b63a | 2569 | static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) |
1da177e4 | 2570 | { |
8687b63a | 2571 | __be32 *p; |
1da177e4 | 2572 | |
c0eae66e BH |
2573 | p = xdr_inline_decode(xdr, 4); |
2574 | if (unlikely(!p)) | |
2575 | goto out_overflow; | |
cccddf4f | 2576 | *attrlen = be32_to_cpup(p); |
1da177e4 LT |
2577 | *savep = xdr->p; |
2578 | return 0; | |
c0eae66e BH |
2579 | out_overflow: |
2580 | print_overflow_msg(__func__, xdr); | |
2581 | return -EIO; | |
1da177e4 LT |
2582 | } |
2583 | ||
2584 | static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) | |
2585 | { | |
2586 | if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { | |
2587 | decode_attr_bitmap(xdr, bitmask); | |
2588 | bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; | |
2589 | } else | |
2590 | bitmask[0] = bitmask[1] = 0; | |
44109241 | 2591 | dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]); |
1da177e4 LT |
2592 | return 0; |
2593 | } | |
2594 | ||
2595 | static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) | |
2596 | { | |
8687b63a | 2597 | __be32 *p; |
409924e4 | 2598 | int ret = 0; |
1da177e4 LT |
2599 | |
2600 | *type = 0; | |
2601 | if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) | |
2602 | return -EIO; | |
2603 | if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { | |
c0eae66e BH |
2604 | p = xdr_inline_decode(xdr, 4); |
2605 | if (unlikely(!p)) | |
2606 | goto out_overflow; | |
cccddf4f | 2607 | *type = be32_to_cpup(p); |
1da177e4 | 2608 | if (*type < NF4REG || *type > NF4NAMEDATTR) { |
3110ff80 | 2609 | dprintk("%s: bad type %d\n", __func__, *type); |
1da177e4 LT |
2610 | return -EIO; |
2611 | } | |
2612 | bitmap[0] &= ~FATTR4_WORD0_TYPE; | |
409924e4 | 2613 | ret = NFS_ATTR_FATTR_TYPE; |
1da177e4 | 2614 | } |
bca79478 | 2615 | dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); |
409924e4 | 2616 | return ret; |
c0eae66e BH |
2617 | out_overflow: |
2618 | print_overflow_msg(__func__, xdr); | |
2619 | return -EIO; | |
1da177e4 LT |
2620 | } |
2621 | ||
2622 | static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) | |
2623 | { | |
8687b63a | 2624 | __be32 *p; |
409924e4 | 2625 | int ret = 0; |
1da177e4 LT |
2626 | |
2627 | *change = 0; | |
2628 | if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) | |
2629 | return -EIO; | |
2630 | if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { | |
c0eae66e BH |
2631 | p = xdr_inline_decode(xdr, 8); |
2632 | if (unlikely(!p)) | |
2633 | goto out_overflow; | |
cccddf4f | 2634 | xdr_decode_hyper(p, change); |
1da177e4 | 2635 | bitmap[0] &= ~FATTR4_WORD0_CHANGE; |
409924e4 | 2636 | ret = NFS_ATTR_FATTR_CHANGE; |
1da177e4 | 2637 | } |
3110ff80 | 2638 | dprintk("%s: change attribute=%Lu\n", __func__, |
1da177e4 | 2639 | (unsigned long long)*change); |
409924e4 | 2640 | return ret; |
c0eae66e BH |
2641 | out_overflow: |
2642 | print_overflow_msg(__func__, xdr); | |
2643 | return -EIO; | |
1da177e4 LT |
2644 | } |
2645 | ||
2646 | static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) | |
2647 | { | |
8687b63a | 2648 | __be32 *p; |
409924e4 | 2649 | int ret = 0; |
1da177e4 LT |
2650 | |
2651 | *size = 0; | |
2652 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) | |
2653 | return -EIO; | |
2654 | if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { | |
c0eae66e BH |
2655 | p = xdr_inline_decode(xdr, 8); |
2656 | if (unlikely(!p)) | |
2657 | goto out_overflow; | |
cccddf4f | 2658 | xdr_decode_hyper(p, size); |
1da177e4 | 2659 | bitmap[0] &= ~FATTR4_WORD0_SIZE; |
409924e4 | 2660 | ret = NFS_ATTR_FATTR_SIZE; |
1da177e4 | 2661 | } |
3110ff80 | 2662 | dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); |
409924e4 | 2663 | return ret; |
c0eae66e BH |
2664 | out_overflow: |
2665 | print_overflow_msg(__func__, xdr); | |
2666 | return -EIO; | |
1da177e4 LT |
2667 | } |
2668 | ||
2669 | static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2670 | { | |
8687b63a | 2671 | __be32 *p; |
1da177e4 LT |
2672 | |
2673 | *res = 0; | |
2674 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) | |
2675 | return -EIO; | |
2676 | if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { | |
c0eae66e BH |
2677 | p = xdr_inline_decode(xdr, 4); |
2678 | if (unlikely(!p)) | |
2679 | goto out_overflow; | |
cccddf4f | 2680 | *res = be32_to_cpup(p); |
1da177e4 LT |
2681 | bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; |
2682 | } | |
3110ff80 | 2683 | dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); |
1da177e4 | 2684 | return 0; |
c0eae66e BH |
2685 | out_overflow: |
2686 | print_overflow_msg(__func__, xdr); | |
2687 | return -EIO; | |
1da177e4 LT |
2688 | } |
2689 | ||
2690 | static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2691 | { | |
8687b63a | 2692 | __be32 *p; |
1da177e4 LT |
2693 | |
2694 | *res = 0; | |
2695 | if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) | |
2696 | return -EIO; | |
2697 | if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { | |
c0eae66e BH |
2698 | p = xdr_inline_decode(xdr, 4); |
2699 | if (unlikely(!p)) | |
2700 | goto out_overflow; | |
cccddf4f | 2701 | *res = be32_to_cpup(p); |
1da177e4 LT |
2702 | bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; |
2703 | } | |
3110ff80 | 2704 | dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); |
1da177e4 | 2705 | return 0; |
c0eae66e BH |
2706 | out_overflow: |
2707 | print_overflow_msg(__func__, xdr); | |
2708 | return -EIO; | |
1da177e4 LT |
2709 | } |
2710 | ||
8b4bdcf8 | 2711 | static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) |
1da177e4 | 2712 | { |
8687b63a | 2713 | __be32 *p; |
409924e4 | 2714 | int ret = 0; |
1da177e4 LT |
2715 | |
2716 | fsid->major = 0; | |
2717 | fsid->minor = 0; | |
2718 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) | |
2719 | return -EIO; | |
2720 | if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { | |
c0eae66e BH |
2721 | p = xdr_inline_decode(xdr, 16); |
2722 | if (unlikely(!p)) | |
2723 | goto out_overflow; | |
3ceb4dbb | 2724 | p = xdr_decode_hyper(p, &fsid->major); |
cccddf4f | 2725 | xdr_decode_hyper(p, &fsid->minor); |
1da177e4 | 2726 | bitmap[0] &= ~FATTR4_WORD0_FSID; |
409924e4 | 2727 | ret = NFS_ATTR_FATTR_FSID; |
1da177e4 | 2728 | } |
3110ff80 | 2729 | dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, |
1da177e4 LT |
2730 | (unsigned long long)fsid->major, |
2731 | (unsigned long long)fsid->minor); | |
409924e4 | 2732 | return ret; |
c0eae66e BH |
2733 | out_overflow: |
2734 | print_overflow_msg(__func__, xdr); | |
2735 | return -EIO; | |
1da177e4 LT |
2736 | } |
2737 | ||
2738 | static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2739 | { | |
8687b63a | 2740 | __be32 *p; |
1da177e4 LT |
2741 | |
2742 | *res = 60; | |
2743 | if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) | |
2744 | return -EIO; | |
2745 | if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { | |
c0eae66e BH |
2746 | p = xdr_inline_decode(xdr, 4); |
2747 | if (unlikely(!p)) | |
2748 | goto out_overflow; | |
cccddf4f | 2749 | *res = be32_to_cpup(p); |
1da177e4 LT |
2750 | bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; |
2751 | } | |
3110ff80 | 2752 | dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); |
1da177e4 | 2753 | return 0; |
c0eae66e BH |
2754 | out_overflow: |
2755 | print_overflow_msg(__func__, xdr); | |
2756 | return -EIO; | |
1da177e4 LT |
2757 | } |
2758 | ||
2759 | static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
2760 | { | |
8687b63a | 2761 | __be32 *p; |
1da177e4 LT |
2762 | |
2763 | *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; | |
2764 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) | |
2765 | return -EIO; | |
2766 | if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { | |
c0eae66e BH |
2767 | p = xdr_inline_decode(xdr, 4); |
2768 | if (unlikely(!p)) | |
2769 | goto out_overflow; | |
cccddf4f | 2770 | *res = be32_to_cpup(p); |
1da177e4 LT |
2771 | bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; |
2772 | } | |
3110ff80 | 2773 | dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); |
1da177e4 | 2774 | return 0; |
c0eae66e BH |
2775 | out_overflow: |
2776 | print_overflow_msg(__func__, xdr); | |
2777 | return -EIO; | |
1da177e4 LT |
2778 | } |
2779 | ||
2780 | static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) | |
2781 | { | |
8687b63a | 2782 | __be32 *p; |
409924e4 | 2783 | int ret = 0; |
1da177e4 LT |
2784 | |
2785 | *fileid = 0; | |
2786 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) | |
2787 | return -EIO; | |
2788 | if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { | |
c0eae66e BH |
2789 | p = xdr_inline_decode(xdr, 8); |
2790 | if (unlikely(!p)) | |
2791 | goto out_overflow; | |
cccddf4f | 2792 | xdr_decode_hyper(p, fileid); |
1da177e4 | 2793 | bitmap[0] &= ~FATTR4_WORD0_FILEID; |
409924e4 | 2794 | ret = NFS_ATTR_FATTR_FILEID; |
1da177e4 | 2795 | } |
3110ff80 | 2796 | dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); |
409924e4 | 2797 | return ret; |
c0eae66e BH |
2798 | out_overflow: |
2799 | print_overflow_msg(__func__, xdr); | |
2800 | return -EIO; | |
1da177e4 LT |
2801 | } |
2802 | ||
99baf625 MN |
2803 | static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) |
2804 | { | |
8687b63a | 2805 | __be32 *p; |
409924e4 | 2806 | int ret = 0; |
99baf625 MN |
2807 | |
2808 | *fileid = 0; | |
2809 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) | |
2810 | return -EIO; | |
2811 | if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { | |
c0eae66e BH |
2812 | p = xdr_inline_decode(xdr, 8); |
2813 | if (unlikely(!p)) | |
2814 | goto out_overflow; | |
cccddf4f | 2815 | xdr_decode_hyper(p, fileid); |
99baf625 | 2816 | bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
409924e4 | 2817 | ret = NFS_ATTR_FATTR_FILEID; |
99baf625 | 2818 | } |
3110ff80 | 2819 | dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); |
409924e4 | 2820 | return ret; |
c0eae66e BH |
2821 | out_overflow: |
2822 | print_overflow_msg(__func__, xdr); | |
2823 | return -EIO; | |
99baf625 MN |
2824 | } |
2825 | ||
1da177e4 LT |
2826 | static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
2827 | { | |
8687b63a | 2828 | __be32 *p; |
1da177e4 LT |
2829 | int status = 0; |
2830 | ||
2831 | *res = 0; | |
2832 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) | |
2833 | return -EIO; | |
2834 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { | |
c0eae66e BH |
2835 | p = xdr_inline_decode(xdr, 8); |
2836 | if (unlikely(!p)) | |
2837 | goto out_overflow; | |
cccddf4f | 2838 | xdr_decode_hyper(p, res); |
1da177e4 LT |
2839 | bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; |
2840 | } | |
3110ff80 | 2841 | dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 2842 | return status; |
c0eae66e BH |
2843 | out_overflow: |
2844 | print_overflow_msg(__func__, xdr); | |
2845 | return -EIO; | |
1da177e4 LT |
2846 | } |
2847 | ||
2848 | static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2849 | { | |
8687b63a | 2850 | __be32 *p; |
1da177e4 LT |
2851 | int status = 0; |
2852 | ||
2853 | *res = 0; | |
2854 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) | |
2855 | return -EIO; | |
2856 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { | |
c0eae66e BH |
2857 | p = xdr_inline_decode(xdr, 8); |
2858 | if (unlikely(!p)) | |
2859 | goto out_overflow; | |
cccddf4f | 2860 | xdr_decode_hyper(p, res); |
1da177e4 LT |
2861 | bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; |
2862 | } | |
3110ff80 | 2863 | dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 2864 | return status; |
c0eae66e BH |
2865 | out_overflow: |
2866 | print_overflow_msg(__func__, xdr); | |
2867 | return -EIO; | |
1da177e4 LT |
2868 | } |
2869 | ||
2870 | static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
2871 | { | |
8687b63a | 2872 | __be32 *p; |
1da177e4 LT |
2873 | int status = 0; |
2874 | ||
2875 | *res = 0; | |
2876 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) | |
2877 | return -EIO; | |
2878 | if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { | |
c0eae66e BH |
2879 | p = xdr_inline_decode(xdr, 8); |
2880 | if (unlikely(!p)) | |
2881 | goto out_overflow; | |
cccddf4f | 2882 | xdr_decode_hyper(p, res); |
1da177e4 LT |
2883 | bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; |
2884 | } | |
3110ff80 | 2885 | dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 2886 | return status; |
c0eae66e BH |
2887 | out_overflow: |
2888 | print_overflow_msg(__func__, xdr); | |
2889 | return -EIO; | |
1da177e4 LT |
2890 | } |
2891 | ||
7aaa0b3b MN |
2892 | static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) |
2893 | { | |
464ad6b1 | 2894 | u32 n; |
8687b63a | 2895 | __be32 *p; |
7aaa0b3b MN |
2896 | int status = 0; |
2897 | ||
c0eae66e BH |
2898 | p = xdr_inline_decode(xdr, 4); |
2899 | if (unlikely(!p)) | |
2900 | goto out_overflow; | |
cccddf4f | 2901 | n = be32_to_cpup(p); |
33a43f28 AA |
2902 | if (n == 0) |
2903 | goto root_path; | |
7aaa0b3b MN |
2904 | dprintk("path "); |
2905 | path->ncomponents = 0; | |
2906 | while (path->ncomponents < n) { | |
2907 | struct nfs4_string *component = &path->components[path->ncomponents]; | |
2908 | status = decode_opaque_inline(xdr, &component->len, &component->data); | |
2909 | if (unlikely(status != 0)) | |
2910 | goto out_eio; | |
2911 | if (path->ncomponents != n) | |
2912 | dprintk("/"); | |
2913 | dprintk("%s", component->data); | |
2914 | if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) | |
2915 | path->ncomponents++; | |
2916 | else { | |
2917 | dprintk("cannot parse %d components in path\n", n); | |
2918 | goto out_eio; | |
2919 | } | |
2920 | } | |
2921 | out: | |
2922 | dprintk("\n"); | |
2923 | return status; | |
33a43f28 AA |
2924 | root_path: |
2925 | /* a root pathname is sent as a zero component4 */ | |
2926 | path->ncomponents = 1; | |
2927 | path->components[0].len=0; | |
2928 | path->components[0].data=NULL; | |
2929 | dprintk("path /\n"); | |
2930 | goto out; | |
7aaa0b3b MN |
2931 | out_eio: |
2932 | dprintk(" status %d", status); | |
2933 | status = -EIO; | |
2934 | goto out; | |
c0eae66e BH |
2935 | out_overflow: |
2936 | print_overflow_msg(__func__, xdr); | |
2937 | return -EIO; | |
7aaa0b3b MN |
2938 | } |
2939 | ||
2940 | static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) | |
683b57b4 TM |
2941 | { |
2942 | int n; | |
8687b63a | 2943 | __be32 *p; |
683b57b4 TM |
2944 | int status = -EIO; |
2945 | ||
2946 | if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) | |
2947 | goto out; | |
2948 | status = 0; | |
2949 | if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) | |
2950 | goto out; | |
3110ff80 | 2951 | dprintk("%s: fsroot ", __func__); |
7aaa0b3b | 2952 | status = decode_pathname(xdr, &res->fs_path); |
683b57b4 TM |
2953 | if (unlikely(status != 0)) |
2954 | goto out; | |
c0eae66e BH |
2955 | p = xdr_inline_decode(xdr, 4); |
2956 | if (unlikely(!p)) | |
2957 | goto out_overflow; | |
cccddf4f | 2958 | n = be32_to_cpup(p); |
683b57b4 TM |
2959 | if (n <= 0) |
2960 | goto out_eio; | |
2961 | res->nlocations = 0; | |
2962 | while (res->nlocations < n) { | |
464ad6b1 | 2963 | u32 m; |
7aaa0b3b | 2964 | struct nfs4_fs_location *loc = &res->locations[res->nlocations]; |
683b57b4 | 2965 | |
c0eae66e BH |
2966 | p = xdr_inline_decode(xdr, 4); |
2967 | if (unlikely(!p)) | |
2968 | goto out_overflow; | |
cccddf4f | 2969 | m = be32_to_cpup(p); |
7aaa0b3b MN |
2970 | |
2971 | loc->nservers = 0; | |
3110ff80 | 2972 | dprintk("%s: servers ", __func__); |
7aaa0b3b MN |
2973 | while (loc->nservers < m) { |
2974 | struct nfs4_string *server = &loc->servers[loc->nservers]; | |
2975 | status = decode_opaque_inline(xdr, &server->len, &server->data); | |
2976 | if (unlikely(status != 0)) | |
2977 | goto out_eio; | |
2978 | dprintk("%s ", server->data); | |
2979 | if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) | |
2980 | loc->nservers++; | |
2981 | else { | |
464ad6b1 CL |
2982 | unsigned int i; |
2983 | dprintk("%s: using first %u of %u servers " | |
2984 | "returned for location %u\n", | |
3110ff80 | 2985 | __func__, |
464ad6b1 CL |
2986 | NFS4_FS_LOCATION_MAXSERVERS, |
2987 | m, res->nlocations); | |
7aaa0b3b | 2988 | for (i = loc->nservers; i < m; i++) { |
2e42c3e2 | 2989 | unsigned int len; |
7aaa0b3b MN |
2990 | char *data; |
2991 | status = decode_opaque_inline(xdr, &len, &data); | |
2992 | if (unlikely(status != 0)) | |
2993 | goto out_eio; | |
2994 | } | |
2995 | } | |
2996 | } | |
2997 | status = decode_pathname(xdr, &loc->rootpath); | |
683b57b4 TM |
2998 | if (unlikely(status != 0)) |
2999 | goto out_eio; | |
7aaa0b3b | 3000 | if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) |
683b57b4 TM |
3001 | res->nlocations++; |
3002 | } | |
409924e4 TM |
3003 | if (res->nlocations != 0) |
3004 | status = NFS_ATTR_FATTR_V4_REFERRAL; | |
683b57b4 | 3005 | out: |
3110ff80 | 3006 | dprintk("%s: fs_locations done, error = %d\n", __func__, status); |
683b57b4 | 3007 | return status; |
c0eae66e BH |
3008 | out_overflow: |
3009 | print_overflow_msg(__func__, xdr); | |
683b57b4 TM |
3010 | out_eio: |
3011 | status = -EIO; | |
3012 | goto out; | |
3013 | } | |
3014 | ||
1da177e4 LT |
3015 | static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) |
3016 | { | |
8687b63a | 3017 | __be32 *p; |
1da177e4 LT |
3018 | int status = 0; |
3019 | ||
3020 | *res = 0; | |
3021 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) | |
3022 | return -EIO; | |
3023 | if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { | |
c0eae66e BH |
3024 | p = xdr_inline_decode(xdr, 8); |
3025 | if (unlikely(!p)) | |
3026 | goto out_overflow; | |
cccddf4f | 3027 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3028 | bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; |
3029 | } | |
3110ff80 | 3030 | dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3031 | return status; |
c0eae66e BH |
3032 | out_overflow: |
3033 | print_overflow_msg(__func__, xdr); | |
3034 | return -EIO; | |
1da177e4 LT |
3035 | } |
3036 | ||
3037 | static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) | |
3038 | { | |
8687b63a | 3039 | __be32 *p; |
1da177e4 LT |
3040 | int status = 0; |
3041 | ||
3042 | *maxlink = 1; | |
3043 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) | |
3044 | return -EIO; | |
3045 | if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { | |
c0eae66e BH |
3046 | p = xdr_inline_decode(xdr, 4); |
3047 | if (unlikely(!p)) | |
3048 | goto out_overflow; | |
cccddf4f | 3049 | *maxlink = be32_to_cpup(p); |
1da177e4 LT |
3050 | bitmap[0] &= ~FATTR4_WORD0_MAXLINK; |
3051 | } | |
3110ff80 | 3052 | dprintk("%s: maxlink=%u\n", __func__, *maxlink); |
1da177e4 | 3053 | return status; |
c0eae66e BH |
3054 | out_overflow: |
3055 | print_overflow_msg(__func__, xdr); | |
3056 | return -EIO; | |
1da177e4 LT |
3057 | } |
3058 | ||
3059 | static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) | |
3060 | { | |
8687b63a | 3061 | __be32 *p; |
1da177e4 LT |
3062 | int status = 0; |
3063 | ||
3064 | *maxname = 1024; | |
3065 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) | |
3066 | return -EIO; | |
3067 | if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { | |
c0eae66e BH |
3068 | p = xdr_inline_decode(xdr, 4); |
3069 | if (unlikely(!p)) | |
3070 | goto out_overflow; | |
cccddf4f | 3071 | *maxname = be32_to_cpup(p); |
1da177e4 LT |
3072 | bitmap[0] &= ~FATTR4_WORD0_MAXNAME; |
3073 | } | |
3110ff80 | 3074 | dprintk("%s: maxname=%u\n", __func__, *maxname); |
1da177e4 | 3075 | return status; |
c0eae66e BH |
3076 | out_overflow: |
3077 | print_overflow_msg(__func__, xdr); | |
3078 | return -EIO; | |
1da177e4 LT |
3079 | } |
3080 | ||
3081 | static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
3082 | { | |
8687b63a | 3083 | __be32 *p; |
1da177e4 LT |
3084 | int status = 0; |
3085 | ||
3086 | *res = 1024; | |
3087 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) | |
3088 | return -EIO; | |
3089 | if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { | |
3090 | uint64_t maxread; | |
c0eae66e BH |
3091 | p = xdr_inline_decode(xdr, 8); |
3092 | if (unlikely(!p)) | |
3093 | goto out_overflow; | |
cccddf4f | 3094 | xdr_decode_hyper(p, &maxread); |
1da177e4 LT |
3095 | if (maxread > 0x7FFFFFFF) |
3096 | maxread = 0x7FFFFFFF; | |
3097 | *res = (uint32_t)maxread; | |
3098 | bitmap[0] &= ~FATTR4_WORD0_MAXREAD; | |
3099 | } | |
3110ff80 | 3100 | dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); |
1da177e4 | 3101 | return status; |
c0eae66e BH |
3102 | out_overflow: |
3103 | print_overflow_msg(__func__, xdr); | |
3104 | return -EIO; | |
1da177e4 LT |
3105 | } |
3106 | ||
3107 | static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) | |
3108 | { | |
8687b63a | 3109 | __be32 *p; |
1da177e4 LT |
3110 | int status = 0; |
3111 | ||
3112 | *res = 1024; | |
3113 | if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) | |
3114 | return -EIO; | |
3115 | if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { | |
3116 | uint64_t maxwrite; | |
c0eae66e BH |
3117 | p = xdr_inline_decode(xdr, 8); |
3118 | if (unlikely(!p)) | |
3119 | goto out_overflow; | |
cccddf4f | 3120 | xdr_decode_hyper(p, &maxwrite); |
1da177e4 LT |
3121 | if (maxwrite > 0x7FFFFFFF) |
3122 | maxwrite = 0x7FFFFFFF; | |
3123 | *res = (uint32_t)maxwrite; | |
3124 | bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; | |
3125 | } | |
3110ff80 | 3126 | dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); |
1da177e4 | 3127 | return status; |
c0eae66e BH |
3128 | out_overflow: |
3129 | print_overflow_msg(__func__, xdr); | |
3130 | return -EIO; | |
1da177e4 LT |
3131 | } |
3132 | ||
bca79478 | 3133 | static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) |
1da177e4 | 3134 | { |
bca79478 | 3135 | uint32_t tmp; |
8687b63a | 3136 | __be32 *p; |
409924e4 | 3137 | int ret = 0; |
1da177e4 LT |
3138 | |
3139 | *mode = 0; | |
3140 | if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) | |
3141 | return -EIO; | |
3142 | if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { | |
c0eae66e BH |
3143 | p = xdr_inline_decode(xdr, 4); |
3144 | if (unlikely(!p)) | |
3145 | goto out_overflow; | |
cccddf4f | 3146 | tmp = be32_to_cpup(p); |
bca79478 | 3147 | *mode = tmp & ~S_IFMT; |
1da177e4 | 3148 | bitmap[1] &= ~FATTR4_WORD1_MODE; |
409924e4 | 3149 | ret = NFS_ATTR_FATTR_MODE; |
1da177e4 | 3150 | } |
3110ff80 | 3151 | dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); |
409924e4 | 3152 | return ret; |
c0eae66e BH |
3153 | out_overflow: |
3154 | print_overflow_msg(__func__, xdr); | |
3155 | return -EIO; | |
1da177e4 LT |
3156 | } |
3157 | ||
3158 | static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) | |
3159 | { | |
8687b63a | 3160 | __be32 *p; |
409924e4 | 3161 | int ret = 0; |
1da177e4 LT |
3162 | |
3163 | *nlink = 1; | |
3164 | if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) | |
3165 | return -EIO; | |
3166 | if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { | |
c0eae66e BH |
3167 | p = xdr_inline_decode(xdr, 4); |
3168 | if (unlikely(!p)) | |
3169 | goto out_overflow; | |
cccddf4f | 3170 | *nlink = be32_to_cpup(p); |
1da177e4 | 3171 | bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; |
409924e4 | 3172 | ret = NFS_ATTR_FATTR_NLINK; |
1da177e4 | 3173 | } |
3110ff80 | 3174 | dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); |
409924e4 | 3175 | return ret; |
c0eae66e BH |
3176 | out_overflow: |
3177 | print_overflow_msg(__func__, xdr); | |
3178 | return -EIO; | |
1da177e4 LT |
3179 | } |
3180 | ||
80e52ace TM |
3181 | static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, |
3182 | struct nfs_client *clp, uint32_t *uid, int may_sleep) | |
1da177e4 | 3183 | { |
8687b63a AV |
3184 | uint32_t len; |
3185 | __be32 *p; | |
409924e4 | 3186 | int ret = 0; |
1da177e4 LT |
3187 | |
3188 | *uid = -2; | |
3189 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) | |
3190 | return -EIO; | |
3191 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { | |
c0eae66e BH |
3192 | p = xdr_inline_decode(xdr, 4); |
3193 | if (unlikely(!p)) | |
3194 | goto out_overflow; | |
cccddf4f | 3195 | len = be32_to_cpup(p); |
c0eae66e BH |
3196 | p = xdr_inline_decode(xdr, len); |
3197 | if (unlikely(!p)) | |
3198 | goto out_overflow; | |
80e52ace TM |
3199 | if (!may_sleep) { |
3200 | /* do nothing */ | |
3201 | } else if (len < XDR_MAX_NETOBJ) { | |
409924e4 TM |
3202 | if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0) |
3203 | ret = NFS_ATTR_FATTR_OWNER; | |
3204 | else | |
1da177e4 | 3205 | dprintk("%s: nfs_map_name_to_uid failed!\n", |
3110ff80 | 3206 | __func__); |
1da177e4 | 3207 | } else |
fe82a183 | 3208 | dprintk("%s: name too long (%u)!\n", |
3110ff80 | 3209 | __func__, len); |
1da177e4 LT |
3210 | bitmap[1] &= ~FATTR4_WORD1_OWNER; |
3211 | } | |
3110ff80 | 3212 | dprintk("%s: uid=%d\n", __func__, (int)*uid); |
409924e4 | 3213 | return ret; |
c0eae66e BH |
3214 | out_overflow: |
3215 | print_overflow_msg(__func__, xdr); | |
3216 | return -EIO; | |
1da177e4 LT |
3217 | } |
3218 | ||
80e52ace TM |
3219 | static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, |
3220 | struct nfs_client *clp, uint32_t *gid, int may_sleep) | |
1da177e4 | 3221 | { |
8687b63a AV |
3222 | uint32_t len; |
3223 | __be32 *p; | |
409924e4 | 3224 | int ret = 0; |
1da177e4 LT |
3225 | |
3226 | *gid = -2; | |
3227 | if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) | |
3228 | return -EIO; | |
3229 | if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { | |
c0eae66e BH |
3230 | p = xdr_inline_decode(xdr, 4); |
3231 | if (unlikely(!p)) | |
3232 | goto out_overflow; | |
cccddf4f | 3233 | len = be32_to_cpup(p); |
c0eae66e BH |
3234 | p = xdr_inline_decode(xdr, len); |
3235 | if (unlikely(!p)) | |
3236 | goto out_overflow; | |
80e52ace TM |
3237 | if (!may_sleep) { |
3238 | /* do nothing */ | |
3239 | } else if (len < XDR_MAX_NETOBJ) { | |
409924e4 TM |
3240 | if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0) |
3241 | ret = NFS_ATTR_FATTR_GROUP; | |
3242 | else | |
1da177e4 | 3243 | dprintk("%s: nfs_map_group_to_gid failed!\n", |
3110ff80 | 3244 | __func__); |
1da177e4 | 3245 | } else |
fe82a183 | 3246 | dprintk("%s: name too long (%u)!\n", |
3110ff80 | 3247 | __func__, len); |
1da177e4 LT |
3248 | bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; |
3249 | } | |
3110ff80 | 3250 | dprintk("%s: gid=%d\n", __func__, (int)*gid); |
409924e4 | 3251 | return ret; |
c0eae66e BH |
3252 | out_overflow: |
3253 | print_overflow_msg(__func__, xdr); | |
3254 | return -EIO; | |
1da177e4 LT |
3255 | } |
3256 | ||
3257 | static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) | |
3258 | { | |
8687b63a AV |
3259 | uint32_t major = 0, minor = 0; |
3260 | __be32 *p; | |
409924e4 | 3261 | int ret = 0; |
1da177e4 LT |
3262 | |
3263 | *rdev = MKDEV(0,0); | |
3264 | if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) | |
3265 | return -EIO; | |
3266 | if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { | |
3267 | dev_t tmp; | |
3268 | ||
c0eae66e BH |
3269 | p = xdr_inline_decode(xdr, 8); |
3270 | if (unlikely(!p)) | |
3271 | goto out_overflow; | |
6f723f77 | 3272 | major = be32_to_cpup(p++); |
cccddf4f | 3273 | minor = be32_to_cpup(p); |
1da177e4 LT |
3274 | tmp = MKDEV(major, minor); |
3275 | if (MAJOR(tmp) == major && MINOR(tmp) == minor) | |
3276 | *rdev = tmp; | |
3277 | bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; | |
409924e4 | 3278 | ret = NFS_ATTR_FATTR_RDEV; |
1da177e4 | 3279 | } |
3110ff80 | 3280 | dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); |
409924e4 | 3281 | return ret; |
c0eae66e BH |
3282 | out_overflow: |
3283 | print_overflow_msg(__func__, xdr); | |
3284 | return -EIO; | |
1da177e4 LT |
3285 | } |
3286 | ||
3287 | static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3288 | { | |
8687b63a | 3289 | __be32 *p; |
1da177e4 LT |
3290 | int status = 0; |
3291 | ||
3292 | *res = 0; | |
3293 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) | |
3294 | return -EIO; | |
3295 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { | |
c0eae66e BH |
3296 | p = xdr_inline_decode(xdr, 8); |
3297 | if (unlikely(!p)) | |
3298 | goto out_overflow; | |
cccddf4f | 3299 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3300 | bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; |
3301 | } | |
3110ff80 | 3302 | dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3303 | return status; |
c0eae66e BH |
3304 | out_overflow: |
3305 | print_overflow_msg(__func__, xdr); | |
3306 | return -EIO; | |
1da177e4 LT |
3307 | } |
3308 | ||
3309 | static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3310 | { | |
8687b63a | 3311 | __be32 *p; |
1da177e4 LT |
3312 | int status = 0; |
3313 | ||
3314 | *res = 0; | |
3315 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) | |
3316 | return -EIO; | |
3317 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { | |
c0eae66e BH |
3318 | p = xdr_inline_decode(xdr, 8); |
3319 | if (unlikely(!p)) | |
3320 | goto out_overflow; | |
cccddf4f | 3321 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3322 | bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; |
3323 | } | |
3110ff80 | 3324 | dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3325 | return status; |
c0eae66e BH |
3326 | out_overflow: |
3327 | print_overflow_msg(__func__, xdr); | |
3328 | return -EIO; | |
1da177e4 LT |
3329 | } |
3330 | ||
3331 | static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) | |
3332 | { | |
8687b63a | 3333 | __be32 *p; |
1da177e4 LT |
3334 | int status = 0; |
3335 | ||
3336 | *res = 0; | |
3337 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) | |
3338 | return -EIO; | |
3339 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { | |
c0eae66e BH |
3340 | p = xdr_inline_decode(xdr, 8); |
3341 | if (unlikely(!p)) | |
3342 | goto out_overflow; | |
cccddf4f | 3343 | xdr_decode_hyper(p, res); |
1da177e4 LT |
3344 | bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; |
3345 | } | |
3110ff80 | 3346 | dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); |
1da177e4 | 3347 | return status; |
c0eae66e BH |
3348 | out_overflow: |
3349 | print_overflow_msg(__func__, xdr); | |
3350 | return -EIO; | |
1da177e4 LT |
3351 | } |
3352 | ||
3353 | static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) | |
3354 | { | |
8687b63a | 3355 | __be32 *p; |
409924e4 | 3356 | int ret = 0; |
1da177e4 LT |
3357 | |
3358 | *used = 0; | |
3359 | if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) | |
3360 | return -EIO; | |
3361 | if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { | |
c0eae66e BH |
3362 | p = xdr_inline_decode(xdr, 8); |
3363 | if (unlikely(!p)) | |
3364 | goto out_overflow; | |
cccddf4f | 3365 | xdr_decode_hyper(p, used); |
1da177e4 | 3366 | bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; |
409924e4 | 3367 | ret = NFS_ATTR_FATTR_SPACE_USED; |
1da177e4 | 3368 | } |
3110ff80 | 3369 | dprintk("%s: space used=%Lu\n", __func__, |
1da177e4 | 3370 | (unsigned long long)*used); |
409924e4 | 3371 | return ret; |
c0eae66e BH |
3372 | out_overflow: |
3373 | print_overflow_msg(__func__, xdr); | |
3374 | return -EIO; | |
1da177e4 LT |
3375 | } |
3376 | ||
3377 | static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) | |
3378 | { | |
8687b63a | 3379 | __be32 *p; |
1da177e4 LT |
3380 | uint64_t sec; |
3381 | uint32_t nsec; | |
3382 | ||
c0eae66e BH |
3383 | p = xdr_inline_decode(xdr, 12); |
3384 | if (unlikely(!p)) | |
3385 | goto out_overflow; | |
3ceb4dbb | 3386 | p = xdr_decode_hyper(p, &sec); |
cccddf4f | 3387 | nsec = be32_to_cpup(p); |
1da177e4 LT |
3388 | time->tv_sec = (time_t)sec; |
3389 | time->tv_nsec = (long)nsec; | |
3390 | return 0; | |
c0eae66e BH |
3391 | out_overflow: |
3392 | print_overflow_msg(__func__, xdr); | |
3393 | return -EIO; | |
1da177e4 LT |
3394 | } |
3395 | ||
3396 | static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
3397 | { | |
3398 | int status = 0; | |
3399 | ||
3400 | time->tv_sec = 0; | |
3401 | time->tv_nsec = 0; | |
3402 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) | |
3403 | return -EIO; | |
3404 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { | |
3405 | status = decode_attr_time(xdr, time); | |
409924e4 TM |
3406 | if (status == 0) |
3407 | status = NFS_ATTR_FATTR_ATIME; | |
1da177e4 LT |
3408 | bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; |
3409 | } | |
3110ff80 | 3410 | dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); |
1da177e4 LT |
3411 | return status; |
3412 | } | |
3413 | ||
3414 | static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
3415 | { | |
3416 | int status = 0; | |
3417 | ||
3418 | time->tv_sec = 0; | |
3419 | time->tv_nsec = 0; | |
3420 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) | |
3421 | return -EIO; | |
3422 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { | |
3423 | status = decode_attr_time(xdr, time); | |
409924e4 TM |
3424 | if (status == 0) |
3425 | status = NFS_ATTR_FATTR_CTIME; | |
1da177e4 LT |
3426 | bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; |
3427 | } | |
3110ff80 | 3428 | dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); |
1da177e4 LT |
3429 | return status; |
3430 | } | |
3431 | ||
3432 | static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) | |
3433 | { | |
3434 | int status = 0; | |
3435 | ||
3436 | time->tv_sec = 0; | |
3437 | time->tv_nsec = 0; | |
3438 | if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) | |
3439 | return -EIO; | |
3440 | if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { | |
3441 | status = decode_attr_time(xdr, time); | |
409924e4 TM |
3442 | if (status == 0) |
3443 | status = NFS_ATTR_FATTR_MTIME; | |
1da177e4 LT |
3444 | bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; |
3445 | } | |
3110ff80 | 3446 | dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); |
1da177e4 LT |
3447 | return status; |
3448 | } | |
3449 | ||
8687b63a | 3450 | static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) |
1da177e4 LT |
3451 | { |
3452 | unsigned int attrwords = XDR_QUADLEN(attrlen); | |
3453 | unsigned int nwords = xdr->p - savep; | |
3454 | ||
3455 | if (unlikely(attrwords != nwords)) { | |
fe82a183 CL |
3456 | dprintk("%s: server returned incorrect attribute length: " |
3457 | "%u %c %u\n", | |
3110ff80 | 3458 | __func__, |
1da177e4 LT |
3459 | attrwords << 2, |
3460 | (attrwords < nwords) ? '<' : '>', | |
3461 | nwords << 2); | |
3462 | return -EIO; | |
3463 | } | |
3464 | return 0; | |
3465 | } | |
3466 | ||
3467 | static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
3468 | { | |
8687b63a | 3469 | __be32 *p; |
1da177e4 | 3470 | |
c0eae66e BH |
3471 | p = xdr_inline_decode(xdr, 20); |
3472 | if (unlikely(!p)) | |
3473 | goto out_overflow; | |
6f723f77 | 3474 | cinfo->atomic = be32_to_cpup(p++); |
3ceb4dbb | 3475 | p = xdr_decode_hyper(p, &cinfo->before); |
cccddf4f | 3476 | xdr_decode_hyper(p, &cinfo->after); |
1da177e4 | 3477 | return 0; |
c0eae66e BH |
3478 | out_overflow: |
3479 | print_overflow_msg(__func__, xdr); | |
3480 | return -EIO; | |
1da177e4 LT |
3481 | } |
3482 | ||
3483 | static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) | |
3484 | { | |
8687b63a | 3485 | __be32 *p; |
1da177e4 LT |
3486 | uint32_t supp, acc; |
3487 | int status; | |
3488 | ||
3489 | status = decode_op_hdr(xdr, OP_ACCESS); | |
3490 | if (status) | |
3491 | return status; | |
c0eae66e BH |
3492 | p = xdr_inline_decode(xdr, 8); |
3493 | if (unlikely(!p)) | |
3494 | goto out_overflow; | |
6f723f77 | 3495 | supp = be32_to_cpup(p++); |
cccddf4f | 3496 | acc = be32_to_cpup(p); |
1da177e4 LT |
3497 | access->supported = supp; |
3498 | access->access = acc; | |
3499 | return 0; | |
c0eae66e BH |
3500 | out_overflow: |
3501 | print_overflow_msg(__func__, xdr); | |
3502 | return -EIO; | |
1da177e4 LT |
3503 | } |
3504 | ||
07d30434 | 3505 | static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) |
1da177e4 | 3506 | { |
8687b63a | 3507 | __be32 *p; |
07d30434 BH |
3508 | |
3509 | p = xdr_inline_decode(xdr, len); | |
3510 | if (likely(p)) { | |
3511 | memcpy(buf, p, len); | |
3512 | return 0; | |
3513 | } | |
3514 | print_overflow_msg(__func__, xdr); | |
3515 | return -EIO; | |
3516 | } | |
3517 | ||
3518 | static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) | |
3519 | { | |
3520 | return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE); | |
3521 | } | |
3522 | ||
3523 | static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) | |
3524 | { | |
1da177e4 LT |
3525 | int status; |
3526 | ||
3527 | status = decode_op_hdr(xdr, OP_CLOSE); | |
c1d51931 TM |
3528 | if (status != -EIO) |
3529 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
3530 | if (!status) |
3531 | status = decode_stateid(xdr, &res->stateid); | |
3532 | return status; | |
1da177e4 LT |
3533 | } |
3534 | ||
db942bbd BH |
3535 | static int decode_verifier(struct xdr_stream *xdr, void *verifier) |
3536 | { | |
3537 | return decode_opaque_fixed(xdr, verifier, 8); | |
1da177e4 LT |
3538 | } |
3539 | ||
3540 | static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) | |
3541 | { | |
1da177e4 LT |
3542 | int status; |
3543 | ||
3544 | status = decode_op_hdr(xdr, OP_COMMIT); | |
db942bbd BH |
3545 | if (!status) |
3546 | status = decode_verifier(xdr, res->verf->verifier); | |
3547 | return status; | |
1da177e4 LT |
3548 | } |
3549 | ||
3550 | static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
3551 | { | |
8687b63a | 3552 | __be32 *p; |
1da177e4 LT |
3553 | uint32_t bmlen; |
3554 | int status; | |
3555 | ||
3556 | status = decode_op_hdr(xdr, OP_CREATE); | |
3557 | if (status) | |
3558 | return status; | |
3559 | if ((status = decode_change_info(xdr, cinfo))) | |
3560 | return status; | |
c0eae66e BH |
3561 | p = xdr_inline_decode(xdr, 4); |
3562 | if (unlikely(!p)) | |
3563 | goto out_overflow; | |
cccddf4f | 3564 | bmlen = be32_to_cpup(p); |
c0eae66e BH |
3565 | p = xdr_inline_decode(xdr, bmlen << 2); |
3566 | if (likely(p)) | |
3567 | return 0; | |
3568 | out_overflow: | |
3569 | print_overflow_msg(__func__, xdr); | |
3570 | return -EIO; | |
1da177e4 LT |
3571 | } |
3572 | ||
3573 | static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) | |
3574 | { | |
8687b63a | 3575 | __be32 *savep; |
6c0195a4 | 3576 | uint32_t attrlen, bitmap[2] = {0}; |
1da177e4 LT |
3577 | int status; |
3578 | ||
3579 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
3580 | goto xdr_error; | |
3581 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
3582 | goto xdr_error; | |
3583 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
3584 | goto xdr_error; | |
3585 | if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) | |
3586 | goto xdr_error; | |
3587 | if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) | |
3588 | goto xdr_error; | |
3589 | if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) | |
3590 | goto xdr_error; | |
3591 | if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) | |
3592 | goto xdr_error; | |
3593 | status = verify_attr_len(xdr, savep, attrlen); | |
3594 | xdr_error: | |
3110ff80 | 3595 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
3596 | return status; |
3597 | } | |
6c0195a4 | 3598 | |
1da177e4 LT |
3599 | static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) |
3600 | { | |
8687b63a | 3601 | __be32 *savep; |
6c0195a4 | 3602 | uint32_t attrlen, bitmap[2] = {0}; |
1da177e4 | 3603 | int status; |
6c0195a4 | 3604 | |
1da177e4 LT |
3605 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
3606 | goto xdr_error; | |
3607 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
3608 | goto xdr_error; | |
3609 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
3610 | goto xdr_error; | |
3611 | ||
3612 | if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) | |
3613 | goto xdr_error; | |
3614 | if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) | |
3615 | goto xdr_error; | |
3616 | if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) | |
3617 | goto xdr_error; | |
3618 | if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) | |
3619 | goto xdr_error; | |
3620 | if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) | |
3621 | goto xdr_error; | |
3622 | if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) | |
3623 | goto xdr_error; | |
3624 | ||
3625 | status = verify_attr_len(xdr, savep, attrlen); | |
3626 | xdr_error: | |
3110ff80 | 3627 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
3628 | return status; |
3629 | } | |
3630 | ||
3631 | static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) | |
3632 | { | |
8687b63a | 3633 | __be32 *savep; |
6c0195a4 | 3634 | uint32_t attrlen, bitmap[2] = {0}; |
1da177e4 | 3635 | int status; |
6c0195a4 | 3636 | |
1da177e4 LT |
3637 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) |
3638 | goto xdr_error; | |
3639 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
3640 | goto xdr_error; | |
3641 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
3642 | goto xdr_error; | |
3643 | ||
3644 | if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) | |
3645 | goto xdr_error; | |
3646 | if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) | |
3647 | goto xdr_error; | |
3648 | ||
3649 | status = verify_attr_len(xdr, savep, attrlen); | |
3650 | xdr_error: | |
3110ff80 | 3651 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
3652 | return status; |
3653 | } | |
3654 | ||
80e52ace TM |
3655 | static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, |
3656 | const struct nfs_server *server, int may_sleep) | |
1da177e4 | 3657 | { |
8687b63a | 3658 | __be32 *savep; |
1da177e4 LT |
3659 | uint32_t attrlen, |
3660 | bitmap[2] = {0}, | |
3661 | type; | |
bca79478 TM |
3662 | int status; |
3663 | umode_t fmode = 0; | |
99baf625 | 3664 | uint64_t fileid; |
1da177e4 | 3665 | |
f26c7a78 TM |
3666 | status = decode_op_hdr(xdr, OP_GETATTR); |
3667 | if (status < 0) | |
1da177e4 | 3668 | goto xdr_error; |
f26c7a78 TM |
3669 | |
3670 | status = decode_attr_bitmap(xdr, bitmap); | |
3671 | if (status < 0) | |
1da177e4 LT |
3672 | goto xdr_error; |
3673 | ||
f26c7a78 TM |
3674 | status = decode_attr_length(xdr, &attrlen, &savep); |
3675 | if (status < 0) | |
1da177e4 LT |
3676 | goto xdr_error; |
3677 | ||
3678 | ||
f26c7a78 TM |
3679 | status = decode_attr_type(xdr, bitmap, &type); |
3680 | if (status < 0) | |
1da177e4 | 3681 | goto xdr_error; |
409924e4 TM |
3682 | fattr->mode = 0; |
3683 | if (status != 0) { | |
3684 | fattr->mode |= nfs_type2fmt[type]; | |
3685 | fattr->valid |= status; | |
3686 | } | |
1da177e4 | 3687 | |
f26c7a78 TM |
3688 | status = decode_attr_change(xdr, bitmap, &fattr->change_attr); |
3689 | if (status < 0) | |
1da177e4 | 3690 | goto xdr_error; |
409924e4 | 3691 | fattr->valid |= status; |
f26c7a78 TM |
3692 | |
3693 | status = decode_attr_size(xdr, bitmap, &fattr->size); | |
3694 | if (status < 0) | |
1da177e4 | 3695 | goto xdr_error; |
409924e4 | 3696 | fattr->valid |= status; |
f26c7a78 TM |
3697 | |
3698 | status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); | |
3699 | if (status < 0) | |
1da177e4 | 3700 | goto xdr_error; |
409924e4 | 3701 | fattr->valid |= status; |
f26c7a78 TM |
3702 | |
3703 | status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); | |
3704 | if (status < 0) | |
1da177e4 | 3705 | goto xdr_error; |
409924e4 | 3706 | fattr->valid |= status; |
f26c7a78 TM |
3707 | |
3708 | status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, | |
7aaa0b3b | 3709 | struct nfs4_fs_locations, |
f26c7a78 TM |
3710 | fattr)); |
3711 | if (status < 0) | |
683b57b4 | 3712 | goto xdr_error; |
409924e4 | 3713 | fattr->valid |= status; |
f26c7a78 TM |
3714 | |
3715 | status = decode_attr_mode(xdr, bitmap, &fmode); | |
3716 | if (status < 0) | |
1da177e4 | 3717 | goto xdr_error; |
409924e4 TM |
3718 | if (status != 0) { |
3719 | fattr->mode |= fmode; | |
3720 | fattr->valid |= status; | |
3721 | } | |
f26c7a78 TM |
3722 | |
3723 | status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); | |
3724 | if (status < 0) | |
1da177e4 | 3725 | goto xdr_error; |
409924e4 | 3726 | fattr->valid |= status; |
f26c7a78 | 3727 | |
80e52ace TM |
3728 | status = decode_attr_owner(xdr, bitmap, server->nfs_client, |
3729 | &fattr->uid, may_sleep); | |
f26c7a78 | 3730 | if (status < 0) |
1da177e4 | 3731 | goto xdr_error; |
409924e4 | 3732 | fattr->valid |= status; |
f26c7a78 | 3733 | |
80e52ace TM |
3734 | status = decode_attr_group(xdr, bitmap, server->nfs_client, |
3735 | &fattr->gid, may_sleep); | |
f26c7a78 | 3736 | if (status < 0) |
1da177e4 | 3737 | goto xdr_error; |
409924e4 | 3738 | fattr->valid |= status; |
f26c7a78 TM |
3739 | |
3740 | status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); | |
3741 | if (status < 0) | |
1da177e4 | 3742 | goto xdr_error; |
409924e4 | 3743 | fattr->valid |= status; |
f26c7a78 TM |
3744 | |
3745 | status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); | |
3746 | if (status < 0) | |
1da177e4 | 3747 | goto xdr_error; |
409924e4 | 3748 | fattr->valid |= status; |
f26c7a78 TM |
3749 | |
3750 | status = decode_attr_time_access(xdr, bitmap, &fattr->atime); | |
3751 | if (status < 0) | |
1da177e4 | 3752 | goto xdr_error; |
409924e4 | 3753 | fattr->valid |= status; |
f26c7a78 TM |
3754 | |
3755 | status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); | |
3756 | if (status < 0) | |
1da177e4 | 3757 | goto xdr_error; |
409924e4 | 3758 | fattr->valid |= status; |
f26c7a78 TM |
3759 | |
3760 | status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); | |
3761 | if (status < 0) | |
1da177e4 | 3762 | goto xdr_error; |
409924e4 | 3763 | fattr->valid |= status; |
f26c7a78 TM |
3764 | |
3765 | status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid); | |
3766 | if (status < 0) | |
99baf625 | 3767 | goto xdr_error; |
409924e4 | 3768 | if (status != 0 && !(fattr->valid & status)) { |
99baf625 | 3769 | fattr->fileid = fileid; |
409924e4 TM |
3770 | fattr->valid |= status; |
3771 | } | |
f26c7a78 TM |
3772 | |
3773 | status = verify_attr_len(xdr, savep, attrlen); | |
1da177e4 | 3774 | xdr_error: |
3110ff80 | 3775 | dprintk("%s: xdr returned %d\n", __func__, -status); |
1da177e4 LT |
3776 | return status; |
3777 | } | |
3778 | ||
3779 | ||
3780 | static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) | |
3781 | { | |
8687b63a | 3782 | __be32 *savep; |
1da177e4 LT |
3783 | uint32_t attrlen, bitmap[2]; |
3784 | int status; | |
3785 | ||
3786 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
3787 | goto xdr_error; | |
3788 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
3789 | goto xdr_error; | |
3790 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
3791 | goto xdr_error; | |
3792 | ||
3793 | fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ | |
3794 | ||
3795 | if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) | |
3796 | goto xdr_error; | |
3797 | if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) | |
3798 | goto xdr_error; | |
3799 | if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) | |
3800 | goto xdr_error; | |
3801 | fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; | |
3802 | if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) | |
3803 | goto xdr_error; | |
3804 | fsinfo->wtpref = fsinfo->wtmax; | |
3805 | ||
3806 | status = verify_attr_len(xdr, savep, attrlen); | |
3807 | xdr_error: | |
3110ff80 | 3808 | dprintk("%s: xdr returned %d!\n", __func__, -status); |
1da177e4 LT |
3809 | return status; |
3810 | } | |
3811 | ||
3812 | static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) | |
3813 | { | |
8687b63a | 3814 | __be32 *p; |
1da177e4 LT |
3815 | uint32_t len; |
3816 | int status; | |
3817 | ||
9936781d TM |
3818 | /* Zero handle first to allow comparisons */ |
3819 | memset(fh, 0, sizeof(*fh)); | |
3820 | ||
1da177e4 LT |
3821 | status = decode_op_hdr(xdr, OP_GETFH); |
3822 | if (status) | |
3823 | return status; | |
1da177e4 | 3824 | |
c0eae66e BH |
3825 | p = xdr_inline_decode(xdr, 4); |
3826 | if (unlikely(!p)) | |
3827 | goto out_overflow; | |
cccddf4f | 3828 | len = be32_to_cpup(p); |
1da177e4 LT |
3829 | if (len > NFS4_FHSIZE) |
3830 | return -EIO; | |
3831 | fh->size = len; | |
c0eae66e BH |
3832 | p = xdr_inline_decode(xdr, len); |
3833 | if (unlikely(!p)) | |
3834 | goto out_overflow; | |
99398d06 | 3835 | memcpy(fh->data, p, len); |
1da177e4 | 3836 | return 0; |
c0eae66e BH |
3837 | out_overflow: |
3838 | print_overflow_msg(__func__, xdr); | |
3839 | return -EIO; | |
1da177e4 LT |
3840 | } |
3841 | ||
3842 | static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
3843 | { | |
3844 | int status; | |
6c0195a4 | 3845 | |
1da177e4 LT |
3846 | status = decode_op_hdr(xdr, OP_LINK); |
3847 | if (status) | |
3848 | return status; | |
3849 | return decode_change_info(xdr, cinfo); | |
3850 | } | |
3851 | ||
3852 | /* | |
3853 | * We create the owner, so we know a proper owner.id length is 4. | |
3854 | */ | |
911d1aaf | 3855 | static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) |
1da177e4 | 3856 | { |
911d1aaf | 3857 | uint64_t offset, length, clientid; |
8687b63a | 3858 | __be32 *p; |
911d1aaf | 3859 | uint32_t namelen, type; |
1da177e4 | 3860 | |
c0eae66e BH |
3861 | p = xdr_inline_decode(xdr, 32); |
3862 | if (unlikely(!p)) | |
3863 | goto out_overflow; | |
3ceb4dbb BH |
3864 | p = xdr_decode_hyper(p, &offset); |
3865 | p = xdr_decode_hyper(p, &length); | |
6f723f77 | 3866 | type = be32_to_cpup(p++); |
911d1aaf TM |
3867 | if (fl != NULL) { |
3868 | fl->fl_start = (loff_t)offset; | |
3869 | fl->fl_end = fl->fl_start + (loff_t)length - 1; | |
3870 | if (length == ~(uint64_t)0) | |
3871 | fl->fl_end = OFFSET_MAX; | |
3872 | fl->fl_type = F_WRLCK; | |
3873 | if (type & 1) | |
3874 | fl->fl_type = F_RDLCK; | |
3875 | fl->fl_pid = 0; | |
3876 | } | |
3ceb4dbb | 3877 | p = xdr_decode_hyper(p, &clientid); |
cccddf4f | 3878 | namelen = be32_to_cpup(p); |
c0eae66e BH |
3879 | p = xdr_inline_decode(xdr, namelen); |
3880 | if (likely(p)) | |
3881 | return -NFS4ERR_DENIED; | |
3882 | out_overflow: | |
3883 | print_overflow_msg(__func__, xdr); | |
3884 | return -EIO; | |
1da177e4 LT |
3885 | } |
3886 | ||
911d1aaf | 3887 | static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) |
1da177e4 | 3888 | { |
1da177e4 LT |
3889 | int status; |
3890 | ||
3891 | status = decode_op_hdr(xdr, OP_LOCK); | |
c1d51931 TM |
3892 | if (status == -EIO) |
3893 | goto out; | |
1da177e4 | 3894 | if (status == 0) { |
07d30434 BH |
3895 | status = decode_stateid(xdr, &res->stateid); |
3896 | if (unlikely(status)) | |
3897 | goto out; | |
1da177e4 | 3898 | } else if (status == -NFS4ERR_DENIED) |
c1d51931 TM |
3899 | status = decode_lock_denied(xdr, NULL); |
3900 | if (res->open_seqid != NULL) | |
3901 | nfs_increment_open_seqid(status, res->open_seqid); | |
3902 | nfs_increment_lock_seqid(status, res->lock_seqid); | |
3903 | out: | |
1da177e4 LT |
3904 | return status; |
3905 | } | |
3906 | ||
911d1aaf | 3907 | static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) |
1da177e4 LT |
3908 | { |
3909 | int status; | |
3910 | status = decode_op_hdr(xdr, OP_LOCKT); | |
3911 | if (status == -NFS4ERR_DENIED) | |
911d1aaf | 3912 | return decode_lock_denied(xdr, res->denied); |
1da177e4 LT |
3913 | return status; |
3914 | } | |
3915 | ||
911d1aaf | 3916 | static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) |
1da177e4 | 3917 | { |
1da177e4 LT |
3918 | int status; |
3919 | ||
3920 | status = decode_op_hdr(xdr, OP_LOCKU); | |
c1d51931 TM |
3921 | if (status != -EIO) |
3922 | nfs_increment_lock_seqid(status, res->seqid); | |
07d30434 BH |
3923 | if (status == 0) |
3924 | status = decode_stateid(xdr, &res->stateid); | |
1da177e4 LT |
3925 | return status; |
3926 | } | |
3927 | ||
3928 | static int decode_lookup(struct xdr_stream *xdr) | |
3929 | { | |
3930 | return decode_op_hdr(xdr, OP_LOOKUP); | |
3931 | } | |
3932 | ||
3933 | /* This is too sick! */ | |
3934 | static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) | |
3935 | { | |
05d564fe | 3936 | __be32 *p; |
1da177e4 LT |
3937 | uint32_t limit_type, nblocks, blocksize; |
3938 | ||
c0eae66e BH |
3939 | p = xdr_inline_decode(xdr, 12); |
3940 | if (unlikely(!p)) | |
3941 | goto out_overflow; | |
6f723f77 | 3942 | limit_type = be32_to_cpup(p++); |
1da177e4 | 3943 | switch (limit_type) { |
05d564fe | 3944 | case 1: |
cccddf4f | 3945 | xdr_decode_hyper(p, maxsize); |
05d564fe AA |
3946 | break; |
3947 | case 2: | |
6f723f77 | 3948 | nblocks = be32_to_cpup(p++); |
cccddf4f | 3949 | blocksize = be32_to_cpup(p); |
05d564fe | 3950 | *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; |
1da177e4 LT |
3951 | } |
3952 | return 0; | |
c0eae66e BH |
3953 | out_overflow: |
3954 | print_overflow_msg(__func__, xdr); | |
3955 | return -EIO; | |
1da177e4 LT |
3956 | } |
3957 | ||
3958 | static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) | |
3959 | { | |
05d564fe AA |
3960 | __be32 *p; |
3961 | uint32_t delegation_type; | |
07d30434 | 3962 | int status; |
1da177e4 | 3963 | |
c0eae66e BH |
3964 | p = xdr_inline_decode(xdr, 4); |
3965 | if (unlikely(!p)) | |
3966 | goto out_overflow; | |
cccddf4f | 3967 | delegation_type = be32_to_cpup(p); |
1da177e4 LT |
3968 | if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { |
3969 | res->delegation_type = 0; | |
3970 | return 0; | |
3971 | } | |
07d30434 BH |
3972 | status = decode_stateid(xdr, &res->delegation); |
3973 | if (unlikely(status)) | |
3974 | return status; | |
c0eae66e BH |
3975 | p = xdr_inline_decode(xdr, 4); |
3976 | if (unlikely(!p)) | |
3977 | goto out_overflow; | |
cccddf4f | 3978 | res->do_recall = be32_to_cpup(p); |
05d564fe | 3979 | |
1da177e4 | 3980 | switch (delegation_type) { |
05d564fe AA |
3981 | case NFS4_OPEN_DELEGATE_READ: |
3982 | res->delegation_type = FMODE_READ; | |
3983 | break; | |
3984 | case NFS4_OPEN_DELEGATE_WRITE: | |
3985 | res->delegation_type = FMODE_WRITE|FMODE_READ; | |
3986 | if (decode_space_limit(xdr, &res->maxsize) < 0) | |
1da177e4 LT |
3987 | return -EIO; |
3988 | } | |
7539bbab | 3989 | return decode_ace(xdr, NULL, res->server->nfs_client); |
c0eae66e BH |
3990 | out_overflow: |
3991 | print_overflow_msg(__func__, xdr); | |
3992 | return -EIO; | |
1da177e4 LT |
3993 | } |
3994 | ||
3995 | static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) | |
3996 | { | |
05d564fe | 3997 | __be32 *p; |
aa53ed54 | 3998 | uint32_t savewords, bmlen, i; |
05d564fe | 3999 | int status; |
1da177e4 | 4000 | |
05d564fe | 4001 | status = decode_op_hdr(xdr, OP_OPEN); |
c1d51931 TM |
4002 | if (status != -EIO) |
4003 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
4004 | if (!status) |
4005 | status = decode_stateid(xdr, &res->stateid); | |
4006 | if (unlikely(status)) | |
05d564fe | 4007 | return status; |
1da177e4 | 4008 | |
05d564fe | 4009 | decode_change_info(xdr, &res->cinfo); |
1da177e4 | 4010 | |
c0eae66e BH |
4011 | p = xdr_inline_decode(xdr, 8); |
4012 | if (unlikely(!p)) | |
4013 | goto out_overflow; | |
6f723f77 | 4014 | res->rflags = be32_to_cpup(p++); |
cccddf4f | 4015 | bmlen = be32_to_cpup(p); |
05d564fe AA |
4016 | if (bmlen > 10) |
4017 | goto xdr_error; | |
1da177e4 | 4018 | |
c0eae66e BH |
4019 | p = xdr_inline_decode(xdr, bmlen << 2); |
4020 | if (unlikely(!p)) | |
4021 | goto out_overflow; | |
aa53ed54 JL |
4022 | savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); |
4023 | for (i = 0; i < savewords; ++i) | |
6f723f77 | 4024 | res->attrset[i] = be32_to_cpup(p++); |
aa53ed54 JL |
4025 | for (; i < NFS4_BITMAP_SIZE; i++) |
4026 | res->attrset[i] = 0; | |
4027 | ||
1da177e4 LT |
4028 | return decode_delegation(xdr, res); |
4029 | xdr_error: | |
3110ff80 | 4030 | dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); |
1da177e4 | 4031 | return -EIO; |
c0eae66e BH |
4032 | out_overflow: |
4033 | print_overflow_msg(__func__, xdr); | |
4034 | return -EIO; | |
1da177e4 LT |
4035 | } |
4036 | ||
4037 | static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) | |
4038 | { | |
1da177e4 LT |
4039 | int status; |
4040 | ||
05d564fe | 4041 | status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); |
c1d51931 TM |
4042 | if (status != -EIO) |
4043 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
4044 | if (!status) |
4045 | status = decode_stateid(xdr, &res->stateid); | |
4046 | return status; | |
1da177e4 LT |
4047 | } |
4048 | ||
4049 | static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) | |
4050 | { | |
1da177e4 LT |
4051 | int status; |
4052 | ||
4053 | status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); | |
c1d51931 TM |
4054 | if (status != -EIO) |
4055 | nfs_increment_open_seqid(status, res->seqid); | |
07d30434 BH |
4056 | if (!status) |
4057 | status = decode_stateid(xdr, &res->stateid); | |
4058 | return status; | |
1da177e4 LT |
4059 | } |
4060 | ||
4061 | static int decode_putfh(struct xdr_stream *xdr) | |
4062 | { | |
4063 | return decode_op_hdr(xdr, OP_PUTFH); | |
4064 | } | |
4065 | ||
4066 | static int decode_putrootfh(struct xdr_stream *xdr) | |
4067 | { | |
4068 | return decode_op_hdr(xdr, OP_PUTROOTFH); | |
4069 | } | |
4070 | ||
4071 | static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) | |
4072 | { | |
4073 | struct kvec *iov = req->rq_rcv_buf.head; | |
8687b63a | 4074 | __be32 *p; |
1da177e4 LT |
4075 | uint32_t count, eof, recvd, hdrlen; |
4076 | int status; | |
4077 | ||
4078 | status = decode_op_hdr(xdr, OP_READ); | |
4079 | if (status) | |
4080 | return status; | |
c0eae66e BH |
4081 | p = xdr_inline_decode(xdr, 8); |
4082 | if (unlikely(!p)) | |
4083 | goto out_overflow; | |
6f723f77 | 4084 | eof = be32_to_cpup(p++); |
cccddf4f | 4085 | count = be32_to_cpup(p); |
1da177e4 LT |
4086 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; |
4087 | recvd = req->rq_rcv_buf.len - hdrlen; | |
4088 | if (count > recvd) { | |
fe82a183 | 4089 | dprintk("NFS: server cheating in read reply: " |
1da177e4 LT |
4090 | "count %u > recvd %u\n", count, recvd); |
4091 | count = recvd; | |
4092 | eof = 0; | |
4093 | } | |
4094 | xdr_read_pages(xdr, count); | |
4095 | res->eof = eof; | |
4096 | res->count = count; | |
4097 | return 0; | |
c0eae66e BH |
4098 | out_overflow: |
4099 | print_overflow_msg(__func__, xdr); | |
4100 | return -EIO; | |
1da177e4 LT |
4101 | } |
4102 | ||
4103 | static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) | |
4104 | { | |
4105 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | |
4106 | struct page *page = *rcvbuf->pages; | |
4107 | struct kvec *iov = rcvbuf->head; | |
bcecff77 CL |
4108 | size_t hdrlen; |
4109 | u32 recvd, pglen = rcvbuf->page_len; | |
8687b63a | 4110 | __be32 *end, *entry, *p, *kaddr; |
7bda2cdf | 4111 | unsigned int nr = 0; |
bcecff77 | 4112 | int status; |
1da177e4 LT |
4113 | |
4114 | status = decode_op_hdr(xdr, OP_READDIR); | |
db942bbd BH |
4115 | if (!status) |
4116 | status = decode_verifier(xdr, readdir->verifier.data); | |
4117 | if (unlikely(status)) | |
1da177e4 | 4118 | return status; |
44109241 FI |
4119 | dprintk("%s: verifier = %08x:%08x\n", |
4120 | __func__, | |
eadf4598 TM |
4121 | ((u32 *)readdir->verifier.data)[0], |
4122 | ((u32 *)readdir->verifier.data)[1]); | |
4123 | ||
1da177e4 | 4124 | |
db942bbd | 4125 | hdrlen = (char *) xdr->p - (char *) iov->iov_base; |
1da177e4 LT |
4126 | recvd = rcvbuf->len - hdrlen; |
4127 | if (pglen > recvd) | |
4128 | pglen = recvd; | |
4129 | xdr_read_pages(xdr, pglen); | |
4130 | ||
4131 | BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE); | |
8687b63a | 4132 | kaddr = p = kmap_atomic(page, KM_USER0); |
e8896495 | 4133 | end = p + ((pglen + readdir->pgbase) >> 2); |
1da177e4 | 4134 | entry = p; |
7bda2cdf JL |
4135 | |
4136 | /* Make sure the packet actually has a value_follows and EOF entry */ | |
4137 | if ((entry + 1) > end) | |
4138 | goto short_pkt; | |
4139 | ||
4140 | for (; *p++; nr++) { | |
bcecff77 | 4141 | u32 len, attrlen, xlen; |
e8896495 | 4142 | if (end - p < 3) |
1da177e4 | 4143 | goto short_pkt; |
eadf4598 | 4144 | dprintk("cookie = %Lu, ", *((unsigned long long *)p)); |
1da177e4 LT |
4145 | p += 2; /* cookie */ |
4146 | len = ntohl(*p++); /* filename length */ | |
4147 | if (len > NFS4_MAXNAMLEN) { | |
fe82a183 CL |
4148 | dprintk("NFS: giant filename in readdir (len 0x%x)\n", |
4149 | len); | |
1da177e4 LT |
4150 | goto err_unmap; |
4151 | } | |
e8896495 DH |
4152 | xlen = XDR_QUADLEN(len); |
4153 | if (end - p < xlen + 1) | |
1da177e4 | 4154 | goto short_pkt; |
e8896495 DH |
4155 | dprintk("filename = %*s\n", len, (char *)p); |
4156 | p += xlen; | |
1da177e4 | 4157 | len = ntohl(*p++); /* bitmap length */ |
e8896495 | 4158 | if (end - p < len + 1) |
1da177e4 | 4159 | goto short_pkt; |
e8896495 | 4160 | p += len; |
1da177e4 | 4161 | attrlen = XDR_QUADLEN(ntohl(*p++)); |
e8896495 | 4162 | if (end - p < attrlen + 2) |
1da177e4 | 4163 | goto short_pkt; |
e8896495 | 4164 | p += attrlen; /* attributes */ |
1da177e4 LT |
4165 | entry = p; |
4166 | } | |
7bda2cdf JL |
4167 | /* |
4168 | * Apparently some server sends responses that are a valid size, but | |
4169 | * contain no entries, and have value_follows==0 and EOF==0. For | |
4170 | * those, just set the EOF marker. | |
4171 | */ | |
4172 | if (!nr && entry[1] == 0) { | |
4173 | dprintk("NFS: readdir reply truncated!\n"); | |
4174 | entry[1] = 1; | |
4175 | } | |
6c0195a4 | 4176 | out: |
1da177e4 LT |
4177 | kunmap_atomic(kaddr, KM_USER0); |
4178 | return 0; | |
4179 | short_pkt: | |
7bda2cdf JL |
4180 | /* |
4181 | * When we get a short packet there are 2 possibilities. We can | |
4182 | * return an error, or fix up the response to look like a valid | |
4183 | * response and return what we have so far. If there are no | |
4184 | * entries and the packet was short, then return -EIO. If there | |
4185 | * are valid entries in the response, return them and pretend that | |
4186 | * the call was successful, but incomplete. The caller can retry the | |
4187 | * readdir starting at the last cookie. | |
4188 | */ | |
3110ff80 | 4189 | dprintk("%s: short packet at entry %d\n", __func__, nr); |
1da177e4 | 4190 | entry[0] = entry[1] = 0; |
7bda2cdf JL |
4191 | if (nr) |
4192 | goto out; | |
1da177e4 LT |
4193 | err_unmap: |
4194 | kunmap_atomic(kaddr, KM_USER0); | |
4195 | return -errno_NFSERR_IO; | |
4196 | } | |
4197 | ||
4198 | static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) | |
4199 | { | |
4200 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | |
4201 | struct kvec *iov = rcvbuf->head; | |
bcecff77 CL |
4202 | size_t hdrlen; |
4203 | u32 len, recvd; | |
8687b63a | 4204 | __be32 *p; |
1da177e4 LT |
4205 | char *kaddr; |
4206 | int status; | |
4207 | ||
4208 | status = decode_op_hdr(xdr, OP_READLINK); | |
4209 | if (status) | |
4210 | return status; | |
4211 | ||
4212 | /* Convert length of symlink */ | |
c0eae66e BH |
4213 | p = xdr_inline_decode(xdr, 4); |
4214 | if (unlikely(!p)) | |
4215 | goto out_overflow; | |
cccddf4f | 4216 | len = be32_to_cpup(p); |
1da177e4 | 4217 | if (len >= rcvbuf->page_len || len <= 0) { |
fe82a183 | 4218 | dprintk("nfs: server returned giant symlink!\n"); |
1da177e4 LT |
4219 | return -ENAMETOOLONG; |
4220 | } | |
4221 | hdrlen = (char *) xdr->p - (char *) iov->iov_base; | |
4222 | recvd = req->rq_rcv_buf.len - hdrlen; | |
4223 | if (recvd < len) { | |
fe82a183 | 4224 | dprintk("NFS: server cheating in readlink reply: " |
1da177e4 LT |
4225 | "count %u > recvd %u\n", len, recvd); |
4226 | return -EIO; | |
4227 | } | |
4228 | xdr_read_pages(xdr, len); | |
4229 | /* | |
4230 | * The XDR encode routine has set things up so that | |
4231 | * the link text will be copied directly into the | |
4232 | * buffer. We just have to do overflow-checking, | |
4233 | * and and null-terminate the text (the VFS expects | |
4234 | * null-termination). | |
4235 | */ | |
4236 | kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); | |
4237 | kaddr[len+rcvbuf->page_base] = '\0'; | |
4238 | kunmap_atomic(kaddr, KM_USER0); | |
4239 | return 0; | |
c0eae66e BH |
4240 | out_overflow: |
4241 | print_overflow_msg(__func__, xdr); | |
4242 | return -EIO; | |
1da177e4 LT |
4243 | } |
4244 | ||
4245 | static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) | |
4246 | { | |
4247 | int status; | |
4248 | ||
4249 | status = decode_op_hdr(xdr, OP_REMOVE); | |
4250 | if (status) | |
4251 | goto out; | |
4252 | status = decode_change_info(xdr, cinfo); | |
4253 | out: | |
4254 | return status; | |
4255 | } | |
4256 | ||
4257 | static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, | |
4258 | struct nfs4_change_info *new_cinfo) | |
4259 | { | |
4260 | int status; | |
4261 | ||
4262 | status = decode_op_hdr(xdr, OP_RENAME); | |
4263 | if (status) | |
4264 | goto out; | |
4265 | if ((status = decode_change_info(xdr, old_cinfo))) | |
4266 | goto out; | |
4267 | status = decode_change_info(xdr, new_cinfo); | |
4268 | out: | |
4269 | return status; | |
4270 | } | |
4271 | ||
4272 | static int decode_renew(struct xdr_stream *xdr) | |
4273 | { | |
4274 | return decode_op_hdr(xdr, OP_RENEW); | |
4275 | } | |
4276 | ||
56ae19f3 TM |
4277 | static int |
4278 | decode_restorefh(struct xdr_stream *xdr) | |
4279 | { | |
4280 | return decode_op_hdr(xdr, OP_RESTOREFH); | |
4281 | } | |
4282 | ||
029d105e BF |
4283 | static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, |
4284 | size_t *acl_len) | |
4285 | { | |
8687b63a | 4286 | __be32 *savep; |
029d105e BF |
4287 | uint32_t attrlen, |
4288 | bitmap[2] = {0}; | |
4289 | struct kvec *iov = req->rq_rcv_buf.head; | |
4290 | int status; | |
4291 | ||
4292 | *acl_len = 0; | |
4293 | if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) | |
4294 | goto out; | |
4295 | if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) | |
4296 | goto out; | |
4297 | if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) | |
4298 | goto out; | |
4299 | ||
4300 | if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) | |
4301 | return -EIO; | |
4302 | if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { | |
bcecff77 CL |
4303 | size_t hdrlen; |
4304 | u32 recvd; | |
029d105e BF |
4305 | |
4306 | /* We ignore &savep and don't do consistency checks on | |
4307 | * the attr length. Let userspace figure it out.... */ | |
4308 | hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; | |
4309 | recvd = req->rq_rcv_buf.len - hdrlen; | |
4310 | if (attrlen > recvd) { | |
fe82a183 | 4311 | dprintk("NFS: server cheating in getattr" |
029d105e BF |
4312 | " acl reply: attrlen %u > recvd %u\n", |
4313 | attrlen, recvd); | |
4314 | return -EINVAL; | |
4315 | } | |
c04871e6 | 4316 | xdr_read_pages(xdr, attrlen); |
029d105e | 4317 | *acl_len = attrlen; |
8c233cf9 BF |
4318 | } else |
4319 | status = -EOPNOTSUPP; | |
029d105e BF |
4320 | |
4321 | out: | |
4322 | return status; | |
4323 | } | |
4324 | ||
1da177e4 LT |
4325 | static int |
4326 | decode_savefh(struct xdr_stream *xdr) | |
4327 | { | |
4328 | return decode_op_hdr(xdr, OP_SAVEFH); | |
4329 | } | |
4330 | ||
9e9ecc03 | 4331 | static int decode_setattr(struct xdr_stream *xdr) |
1da177e4 | 4332 | { |
8687b63a | 4333 | __be32 *p; |
1da177e4 LT |
4334 | uint32_t bmlen; |
4335 | int status; | |
4336 | ||
1da177e4 LT |
4337 | status = decode_op_hdr(xdr, OP_SETATTR); |
4338 | if (status) | |
4339 | return status; | |
c0eae66e BH |
4340 | p = xdr_inline_decode(xdr, 4); |
4341 | if (unlikely(!p)) | |
4342 | goto out_overflow; | |
cccddf4f | 4343 | bmlen = be32_to_cpup(p); |
c0eae66e BH |
4344 | p = xdr_inline_decode(xdr, bmlen << 2); |
4345 | if (likely(p)) | |
4346 | return 0; | |
4347 | out_overflow: | |
4348 | print_overflow_msg(__func__, xdr); | |
4349 | return -EIO; | |
1da177e4 LT |
4350 | } |
4351 | ||
adfa6f98 | 4352 | static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp) |
1da177e4 | 4353 | { |
8687b63a | 4354 | __be32 *p; |
1da177e4 LT |
4355 | uint32_t opnum; |
4356 | int32_t nfserr; | |
4357 | ||
c0eae66e BH |
4358 | p = xdr_inline_decode(xdr, 8); |
4359 | if (unlikely(!p)) | |
4360 | goto out_overflow; | |
6f723f77 | 4361 | opnum = be32_to_cpup(p++); |
1da177e4 | 4362 | if (opnum != OP_SETCLIENTID) { |
fe82a183 | 4363 | dprintk("nfs: decode_setclientid: Server returned operation" |
6c0195a4 | 4364 | " %d\n", opnum); |
1da177e4 LT |
4365 | return -EIO; |
4366 | } | |
cccddf4f | 4367 | nfserr = be32_to_cpup(p); |
1da177e4 | 4368 | if (nfserr == NFS_OK) { |
c0eae66e BH |
4369 | p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); |
4370 | if (unlikely(!p)) | |
4371 | goto out_overflow; | |
3ceb4dbb | 4372 | p = xdr_decode_hyper(p, &clp->cl_clientid); |
99398d06 | 4373 | memcpy(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE); |
1da177e4 LT |
4374 | } else if (nfserr == NFSERR_CLID_INUSE) { |
4375 | uint32_t len; | |
4376 | ||
4377 | /* skip netid string */ | |
c0eae66e BH |
4378 | p = xdr_inline_decode(xdr, 4); |
4379 | if (unlikely(!p)) | |
4380 | goto out_overflow; | |
cccddf4f | 4381 | len = be32_to_cpup(p); |
c0eae66e BH |
4382 | p = xdr_inline_decode(xdr, len); |
4383 | if (unlikely(!p)) | |
4384 | goto out_overflow; | |
1da177e4 LT |
4385 | |
4386 | /* skip uaddr string */ | |
c0eae66e BH |
4387 | p = xdr_inline_decode(xdr, 4); |
4388 | if (unlikely(!p)) | |
4389 | goto out_overflow; | |
cccddf4f | 4390 | len = be32_to_cpup(p); |
c0eae66e BH |
4391 | p = xdr_inline_decode(xdr, len); |
4392 | if (unlikely(!p)) | |
4393 | goto out_overflow; | |
1da177e4 LT |
4394 | return -NFSERR_CLID_INUSE; |
4395 | } else | |
856dff3d | 4396 | return nfs4_stat_to_errno(nfserr); |
1da177e4 LT |
4397 | |
4398 | return 0; | |
c0eae66e BH |
4399 | out_overflow: |
4400 | print_overflow_msg(__func__, xdr); | |
4401 | return -EIO; | |
1da177e4 LT |
4402 | } |
4403 | ||
4404 | static int decode_setclientid_confirm(struct xdr_stream *xdr) | |
4405 | { | |
4406 | return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); | |
4407 | } | |
4408 | ||
4409 | static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) | |
4410 | { | |
8687b63a | 4411 | __be32 *p; |
1da177e4 LT |
4412 | int status; |
4413 | ||
4414 | status = decode_op_hdr(xdr, OP_WRITE); | |
4415 | if (status) | |
4416 | return status; | |
4417 | ||
c0eae66e BH |
4418 | p = xdr_inline_decode(xdr, 16); |
4419 | if (unlikely(!p)) | |
4420 | goto out_overflow; | |
6f723f77 BH |
4421 | res->count = be32_to_cpup(p++); |
4422 | res->verf->committed = be32_to_cpup(p++); | |
99398d06 | 4423 | memcpy(res->verf->verifier, p, 8); |
1da177e4 | 4424 | return 0; |
c0eae66e BH |
4425 | out_overflow: |
4426 | print_overflow_msg(__func__, xdr); | |
4427 | return -EIO; | |
1da177e4 LT |
4428 | } |
4429 | ||
4430 | static int decode_delegreturn(struct xdr_stream *xdr) | |
4431 | { | |
4432 | return decode_op_hdr(xdr, OP_DELEGRETURN); | |
4433 | } | |
4434 | ||
99fe60d0 BH |
4435 | #if defined(CONFIG_NFS_V4_1) |
4436 | static int decode_exchange_id(struct xdr_stream *xdr, | |
4437 | struct nfs41_exchange_id_res *res) | |
4438 | { | |
4439 | __be32 *p; | |
4440 | uint32_t dummy; | |
2460ba57 | 4441 | char *dummy_str; |
99fe60d0 BH |
4442 | int status; |
4443 | struct nfs_client *clp = res->client; | |
4444 | ||
4445 | status = decode_op_hdr(xdr, OP_EXCHANGE_ID); | |
4446 | if (status) | |
4447 | return status; | |
4448 | ||
c0eae66e BH |
4449 | p = xdr_inline_decode(xdr, 8); |
4450 | if (unlikely(!p)) | |
4451 | goto out_overflow; | |
cccddf4f | 4452 | xdr_decode_hyper(p, &clp->cl_ex_clid); |
c0eae66e BH |
4453 | p = xdr_inline_decode(xdr, 12); |
4454 | if (unlikely(!p)) | |
4455 | goto out_overflow; | |
6f723f77 BH |
4456 | clp->cl_seqid = be32_to_cpup(p++); |
4457 | clp->cl_exchange_flags = be32_to_cpup(p++); | |
99fe60d0 BH |
4458 | |
4459 | /* We ask for SP4_NONE */ | |
cccddf4f | 4460 | dummy = be32_to_cpup(p); |
99fe60d0 BH |
4461 | if (dummy != SP4_NONE) |
4462 | return -EIO; | |
4463 | ||
4464 | /* Throw away minor_id */ | |
c0eae66e BH |
4465 | p = xdr_inline_decode(xdr, 8); |
4466 | if (unlikely(!p)) | |
4467 | goto out_overflow; | |
99fe60d0 BH |
4468 | |
4469 | /* Throw away Major id */ | |
2460ba57 BH |
4470 | status = decode_opaque_inline(xdr, &dummy, &dummy_str); |
4471 | if (unlikely(status)) | |
4472 | return status; | |
99fe60d0 BH |
4473 | |
4474 | /* Throw away server_scope */ | |
2460ba57 BH |
4475 | status = decode_opaque_inline(xdr, &dummy, &dummy_str); |
4476 | if (unlikely(status)) | |
4477 | return status; | |
99fe60d0 BH |
4478 | |
4479 | /* Throw away Implementation id array */ | |
2460ba57 BH |
4480 | status = decode_opaque_inline(xdr, &dummy, &dummy_str); |
4481 | if (unlikely(status)) | |
4482 | return status; | |
99fe60d0 BH |
4483 | |
4484 | return 0; | |
c0eae66e BH |
4485 | out_overflow: |
4486 | print_overflow_msg(__func__, xdr); | |
4487 | return -EIO; | |
99fe60d0 | 4488 | } |
fc931582 AA |
4489 | |
4490 | static int decode_chan_attrs(struct xdr_stream *xdr, | |
4491 | struct nfs4_channel_attrs *attrs) | |
4492 | { | |
4493 | __be32 *p; | |
4494 | u32 nr_attrs; | |
4495 | ||
c0eae66e BH |
4496 | p = xdr_inline_decode(xdr, 28); |
4497 | if (unlikely(!p)) | |
4498 | goto out_overflow; | |
6f723f77 BH |
4499 | attrs->headerpadsz = be32_to_cpup(p++); |
4500 | attrs->max_rqst_sz = be32_to_cpup(p++); | |
4501 | attrs->max_resp_sz = be32_to_cpup(p++); | |
4502 | attrs->max_resp_sz_cached = be32_to_cpup(p++); | |
4503 | attrs->max_ops = be32_to_cpup(p++); | |
4504 | attrs->max_reqs = be32_to_cpup(p++); | |
cccddf4f | 4505 | nr_attrs = be32_to_cpup(p); |
fc931582 AA |
4506 | if (unlikely(nr_attrs > 1)) { |
4507 | printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n", | |
4508 | __func__, nr_attrs); | |
4509 | return -EINVAL; | |
4510 | } | |
c0eae66e BH |
4511 | if (nr_attrs == 1) { |
4512 | p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ | |
4513 | if (unlikely(!p)) | |
4514 | goto out_overflow; | |
4515 | } | |
fc931582 | 4516 | return 0; |
c0eae66e BH |
4517 | out_overflow: |
4518 | print_overflow_msg(__func__, xdr); | |
4519 | return -EIO; | |
fc931582 AA |
4520 | } |
4521 | ||
e78291e4 BH |
4522 | static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) |
4523 | { | |
4524 | return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); | |
fc931582 AA |
4525 | } |
4526 | ||
4527 | static int decode_create_session(struct xdr_stream *xdr, | |
4528 | struct nfs41_create_session_res *res) | |
4529 | { | |
4530 | __be32 *p; | |
4531 | int status; | |
4532 | struct nfs_client *clp = res->client; | |
4533 | struct nfs4_session *session = clp->cl_session; | |
4534 | ||
4535 | status = decode_op_hdr(xdr, OP_CREATE_SESSION); | |
e78291e4 BH |
4536 | if (!status) |
4537 | status = decode_sessionid(xdr, &session->sess_id); | |
4538 | if (unlikely(status)) | |
fc931582 AA |
4539 | return status; |
4540 | ||
fc931582 | 4541 | /* seqid, flags */ |
c0eae66e BH |
4542 | p = xdr_inline_decode(xdr, 8); |
4543 | if (unlikely(!p)) | |
4544 | goto out_overflow; | |
6f723f77 | 4545 | clp->cl_seqid = be32_to_cpup(p++); |
cccddf4f | 4546 | session->flags = be32_to_cpup(p); |
fc931582 AA |
4547 | |
4548 | /* Channel attributes */ | |
4549 | status = decode_chan_attrs(xdr, &session->fc_attrs); | |
4550 | if (!status) | |
4551 | status = decode_chan_attrs(xdr, &session->bc_attrs); | |
4552 | return status; | |
c0eae66e BH |
4553 | out_overflow: |
4554 | print_overflow_msg(__func__, xdr); | |
4555 | return -EIO; | |
fc931582 | 4556 | } |
0f3e66c6 AA |
4557 | |
4558 | static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) | |
4559 | { | |
4560 | return decode_op_hdr(xdr, OP_DESTROY_SESSION); | |
4561 | } | |
99fe60d0 BH |
4562 | #endif /* CONFIG_NFS_V4_1 */ |
4563 | ||
9b7b9fcc AA |
4564 | static int decode_sequence(struct xdr_stream *xdr, |
4565 | struct nfs4_sequence_res *res, | |
4566 | struct rpc_rqst *rqstp) | |
4567 | { | |
4568 | #if defined(CONFIG_NFS_V4_1) | |
fc01cea9 AA |
4569 | struct nfs4_slot *slot; |
4570 | struct nfs4_sessionid id; | |
4571 | u32 dummy; | |
4572 | int status; | |
4573 | __be32 *p; | |
4574 | ||
9b7b9fcc AA |
4575 | if (!res->sr_session) |
4576 | return 0; | |
4577 | ||
fc01cea9 | 4578 | status = decode_op_hdr(xdr, OP_SEQUENCE); |
e78291e4 BH |
4579 | if (!status) |
4580 | status = decode_sessionid(xdr, &id); | |
4581 | if (unlikely(status)) | |
fc01cea9 | 4582 | goto out_err; |
9b7b9fcc | 4583 | |
fc01cea9 AA |
4584 | /* |
4585 | * If the server returns different values for sessionID, slotID or | |
4586 | * sequence number, the server is looney tunes. | |
4587 | */ | |
4588 | status = -ESERVERFAULT; | |
4589 | ||
fc01cea9 AA |
4590 | if (memcmp(id.data, res->sr_session->sess_id.data, |
4591 | NFS4_MAX_SESSIONID_LEN)) { | |
4592 | dprintk("%s Invalid session id\n", __func__); | |
4593 | goto out_err; | |
4594 | } | |
e78291e4 | 4595 | |
c0eae66e BH |
4596 | p = xdr_inline_decode(xdr, 20); |
4597 | if (unlikely(!p)) | |
4598 | goto out_overflow; | |
e78291e4 | 4599 | |
fc01cea9 | 4600 | /* seqid */ |
e78291e4 | 4601 | slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid]; |
6f723f77 | 4602 | dummy = be32_to_cpup(p++); |
fc01cea9 AA |
4603 | if (dummy != slot->seq_nr) { |
4604 | dprintk("%s Invalid sequence number\n", __func__); | |
4605 | goto out_err; | |
4606 | } | |
4607 | /* slot id */ | |
6f723f77 | 4608 | dummy = be32_to_cpup(p++); |
fc01cea9 AA |
4609 | if (dummy != res->sr_slotid) { |
4610 | dprintk("%s Invalid slot id\n", __func__); | |
4611 | goto out_err; | |
4612 | } | |
4613 | /* highest slot id - currently not processed */ | |
6f723f77 | 4614 | dummy = be32_to_cpup(p++); |
fc01cea9 | 4615 | /* target highest slot id - currently not processed */ |
6f723f77 | 4616 | dummy = be32_to_cpup(p++); |
0629e370 AB |
4617 | /* result flags */ |
4618 | res->sr_status_flags = be32_to_cpup(p); | |
fc01cea9 AA |
4619 | status = 0; |
4620 | out_err: | |
4621 | res->sr_status = status; | |
4622 | return status; | |
c0eae66e BH |
4623 | out_overflow: |
4624 | print_overflow_msg(__func__, xdr); | |
4625 | status = -EIO; | |
4626 | goto out_err; | |
fc01cea9 | 4627 | #else /* CONFIG_NFS_V4_1 */ |
9b7b9fcc | 4628 | return 0; |
fc01cea9 | 4629 | #endif /* CONFIG_NFS_V4_1 */ |
9b7b9fcc AA |
4630 | } |
4631 | ||
49c2559e BH |
4632 | /* |
4633 | * END OF "GENERIC" DECODE ROUTINES. | |
4634 | */ | |
4635 | ||
1da177e4 LT |
4636 | /* |
4637 | * Decode OPEN_DOWNGRADE response | |
4638 | */ | |
8687b63a | 4639 | static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) |
1da177e4 | 4640 | { |
05d564fe AA |
4641 | struct xdr_stream xdr; |
4642 | struct compound_hdr hdr; | |
4643 | int status; | |
4644 | ||
4645 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4646 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
4647 | if (status) |
4648 | goto out; | |
4649 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
05d564fe AA |
4650 | if (status) |
4651 | goto out; | |
4652 | status = decode_putfh(&xdr); | |
4653 | if (status) | |
4654 | goto out; | |
4655 | status = decode_open_downgrade(&xdr, res); | |
516a6af6 TM |
4656 | if (status != 0) |
4657 | goto out; | |
80e52ace TM |
4658 | decode_getfattr(&xdr, res->fattr, res->server, |
4659 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 | 4660 | out: |
05d564fe | 4661 | return status; |
1da177e4 LT |
4662 | } |
4663 | ||
1da177e4 LT |
4664 | /* |
4665 | * Decode ACCESS response | |
4666 | */ | |
8687b63a | 4667 | static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res) |
1da177e4 LT |
4668 | { |
4669 | struct xdr_stream xdr; | |
4670 | struct compound_hdr hdr; | |
4671 | int status; | |
6c0195a4 | 4672 | |
1da177e4 | 4673 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
9b7b9fcc AA |
4674 | status = decode_compound_hdr(&xdr, &hdr); |
4675 | if (status) | |
4676 | goto out; | |
4677 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
4678 | if (status) | |
1da177e4 | 4679 | goto out; |
76b32999 TM |
4680 | status = decode_putfh(&xdr); |
4681 | if (status != 0) | |
4682 | goto out; | |
4683 | status = decode_access(&xdr, res); | |
4684 | if (status != 0) | |
4685 | goto out; | |
80e52ace TM |
4686 | decode_getfattr(&xdr, res->fattr, res->server, |
4687 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4688 | out: |
4689 | return status; | |
4690 | } | |
4691 | ||
4692 | /* | |
4693 | * Decode LOOKUP response | |
4694 | */ | |
8687b63a | 4695 | static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) |
1da177e4 LT |
4696 | { |
4697 | struct xdr_stream xdr; | |
4698 | struct compound_hdr hdr; | |
4699 | int status; | |
6c0195a4 | 4700 | |
1da177e4 | 4701 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
9b7b9fcc AA |
4702 | status = decode_compound_hdr(&xdr, &hdr); |
4703 | if (status) | |
4704 | goto out; | |
4705 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
4706 | if (status) | |
1da177e4 LT |
4707 | goto out; |
4708 | if ((status = decode_putfh(&xdr)) != 0) | |
4709 | goto out; | |
4710 | if ((status = decode_lookup(&xdr)) != 0) | |
4711 | goto out; | |
4712 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | |
4713 | goto out; | |
80e52ace TM |
4714 | status = decode_getfattr(&xdr, res->fattr, res->server |
4715 | ,!RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4716 | out: |
4717 | return status; | |
4718 | } | |
4719 | ||
4720 | /* | |
4721 | * Decode LOOKUP_ROOT response | |
4722 | */ | |
8687b63a | 4723 | static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) |
1da177e4 LT |
4724 | { |
4725 | struct xdr_stream xdr; | |
4726 | struct compound_hdr hdr; | |
4727 | int status; | |
6c0195a4 | 4728 | |
1da177e4 | 4729 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
9b7b9fcc AA |
4730 | status = decode_compound_hdr(&xdr, &hdr); |
4731 | if (status) | |
4732 | goto out; | |
4733 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
4734 | if (status) | |
1da177e4 LT |
4735 | goto out; |
4736 | if ((status = decode_putrootfh(&xdr)) != 0) | |
4737 | goto out; | |
4738 | if ((status = decode_getfh(&xdr, res->fh)) == 0) | |
80e52ace TM |
4739 | status = decode_getfattr(&xdr, res->fattr, res->server, |
4740 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4741 | out: |
4742 | return status; | |
4743 | } | |
4744 | ||
4745 | /* | |
4746 | * Decode REMOVE response | |
4747 | */ | |
4fdc17b2 | 4748 | static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res) |
1da177e4 LT |
4749 | { |
4750 | struct xdr_stream xdr; | |
4751 | struct compound_hdr hdr; | |
4752 | int status; | |
6c0195a4 | 4753 | |
1da177e4 | 4754 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
9b7b9fcc AA |
4755 | status = decode_compound_hdr(&xdr, &hdr); |
4756 | if (status) | |
4757 | goto out; | |
4758 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
4759 | if (status) | |
1da177e4 | 4760 | goto out; |
16e42959 TM |
4761 | if ((status = decode_putfh(&xdr)) != 0) |
4762 | goto out; | |
4763 | if ((status = decode_remove(&xdr, &res->cinfo)) != 0) | |
4764 | goto out; | |
80e52ace TM |
4765 | decode_getfattr(&xdr, &res->dir_attr, res->server, |
4766 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4767 | out: |
4768 | return status; | |
4769 | } | |
4770 | ||
4771 | /* | |
4772 | * Decode RENAME response | |
4773 | */ | |
8687b63a | 4774 | static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res) |
1da177e4 LT |
4775 | { |
4776 | struct xdr_stream xdr; | |
4777 | struct compound_hdr hdr; | |
4778 | int status; | |
6c0195a4 | 4779 | |
1da177e4 | 4780 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
9b7b9fcc AA |
4781 | status = decode_compound_hdr(&xdr, &hdr); |
4782 | if (status) | |
4783 | goto out; | |
4784 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
4785 | if (status) | |
1da177e4 LT |
4786 | goto out; |
4787 | if ((status = decode_putfh(&xdr)) != 0) | |
4788 | goto out; | |
4789 | if ((status = decode_savefh(&xdr)) != 0) | |
4790 | goto out; | |
4791 | if ((status = decode_putfh(&xdr)) != 0) | |
4792 | goto out; | |
6caf2c82 TM |
4793 | if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) |
4794 | goto out; | |
4795 | /* Current FH is target directory */ | |
80e52ace TM |
4796 | if (decode_getfattr(&xdr, res->new_fattr, res->server, |
4797 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | |
6caf2c82 TM |
4798 | goto out; |
4799 | if ((status = decode_restorefh(&xdr)) != 0) | |
4800 | goto out; | |
80e52ace TM |
4801 | decode_getfattr(&xdr, res->old_fattr, res->server, |
4802 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4803 | out: |
4804 | return status; | |
4805 | } | |
4806 | ||
4807 | /* | |
4808 | * Decode LINK response | |
4809 | */ | |
8687b63a | 4810 | static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res) |
1da177e4 LT |
4811 | { |
4812 | struct xdr_stream xdr; | |
4813 | struct compound_hdr hdr; | |
4814 | int status; | |
6c0195a4 | 4815 | |
1da177e4 | 4816 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
9b7b9fcc AA |
4817 | status = decode_compound_hdr(&xdr, &hdr); |
4818 | if (status) | |
4819 | goto out; | |
4820 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
4821 | if (status) | |
1da177e4 LT |
4822 | goto out; |
4823 | if ((status = decode_putfh(&xdr)) != 0) | |
4824 | goto out; | |
4825 | if ((status = decode_savefh(&xdr)) != 0) | |
4826 | goto out; | |
4827 | if ((status = decode_putfh(&xdr)) != 0) | |
4828 | goto out; | |
91ba2eee TM |
4829 | if ((status = decode_link(&xdr, &res->cinfo)) != 0) |
4830 | goto out; | |
4831 | /* | |
4832 | * Note order: OP_LINK leaves the directory as the current | |
4833 | * filehandle. | |
4834 | */ | |
80e52ace TM |
4835 | if (decode_getfattr(&xdr, res->dir_attr, res->server, |
4836 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | |
91ba2eee TM |
4837 | goto out; |
4838 | if ((status = decode_restorefh(&xdr)) != 0) | |
4839 | goto out; | |
80e52ace TM |
4840 | decode_getfattr(&xdr, res->fattr, res->server, |
4841 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4842 | out: |
4843 | return status; | |
4844 | } | |
4845 | ||
4846 | /* | |
4847 | * Decode CREATE response | |
4848 | */ | |
8687b63a | 4849 | static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) |
1da177e4 LT |
4850 | { |
4851 | struct xdr_stream xdr; | |
4852 | struct compound_hdr hdr; | |
4853 | int status; | |
6c0195a4 | 4854 | |
1da177e4 | 4855 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
9b7b9fcc AA |
4856 | status = decode_compound_hdr(&xdr, &hdr); |
4857 | if (status) | |
4858 | goto out; | |
4859 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
4860 | if (status) | |
1da177e4 LT |
4861 | goto out; |
4862 | if ((status = decode_putfh(&xdr)) != 0) | |
4863 | goto out; | |
56ae19f3 TM |
4864 | if ((status = decode_savefh(&xdr)) != 0) |
4865 | goto out; | |
1da177e4 LT |
4866 | if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) |
4867 | goto out; | |
4868 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | |
4869 | goto out; | |
80e52ace TM |
4870 | if (decode_getfattr(&xdr, res->fattr, res->server, |
4871 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | |
56ae19f3 TM |
4872 | goto out; |
4873 | if ((status = decode_restorefh(&xdr)) != 0) | |
4874 | goto out; | |
80e52ace TM |
4875 | decode_getfattr(&xdr, res->dir_fattr, res->server, |
4876 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4877 | out: |
4878 | return status; | |
4879 | } | |
4880 | ||
4881 | /* | |
4882 | * Decode SYMLINK response | |
4883 | */ | |
8687b63a | 4884 | static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) |
1da177e4 LT |
4885 | { |
4886 | return nfs4_xdr_dec_create(rqstp, p, res); | |
4887 | } | |
4888 | ||
4889 | /* | |
4890 | * Decode GETATTR response | |
4891 | */ | |
8687b63a | 4892 | static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res) |
1da177e4 LT |
4893 | { |
4894 | struct xdr_stream xdr; | |
4895 | struct compound_hdr hdr; | |
4896 | int status; | |
6c0195a4 | 4897 | |
1da177e4 LT |
4898 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
4899 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
4900 | if (status) |
4901 | goto out; | |
4902 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
4903 | if (status) |
4904 | goto out; | |
4905 | status = decode_putfh(&xdr); | |
4906 | if (status) | |
4907 | goto out; | |
80e52ace TM |
4908 | status = decode_getfattr(&xdr, res->fattr, res->server, |
4909 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
4910 | out: |
4911 | return status; | |
1da177e4 LT |
4912 | } |
4913 | ||
23ec6965 BF |
4914 | /* |
4915 | * Encode an SETACL request | |
4916 | */ | |
4917 | static int | |
8687b63a | 4918 | nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args) |
23ec6965 | 4919 | { |
05d564fe AA |
4920 | struct xdr_stream xdr; |
4921 | struct compound_hdr hdr = { | |
66cc0429 | 4922 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
05d564fe AA |
4923 | }; |
4924 | int status; | |
4925 | ||
4926 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
0c4e8c18 | 4927 | encode_compound_hdr(&xdr, req, &hdr); |
9b7b9fcc | 4928 | encode_sequence(&xdr, &args->seq_args, &hdr); |
cf8cdbe5 | 4929 | encode_putfh(&xdr, args->fh, &hdr); |
d017931c | 4930 | status = encode_setacl(&xdr, args, &hdr); |
d017931c | 4931 | encode_nops(&hdr); |
05d564fe | 4932 | return status; |
23ec6965 | 4933 | } |
05d564fe | 4934 | |
23ec6965 BF |
4935 | /* |
4936 | * Decode SETACL response | |
4937 | */ | |
4938 | static int | |
73c403a9 BH |
4939 | nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, |
4940 | struct nfs_setaclres *res) | |
23ec6965 BF |
4941 | { |
4942 | struct xdr_stream xdr; | |
4943 | struct compound_hdr hdr; | |
4944 | int status; | |
4945 | ||
4946 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4947 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
4948 | if (status) |
4949 | goto out; | |
4950 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
23ec6965 BF |
4951 | if (status) |
4952 | goto out; | |
4953 | status = decode_putfh(&xdr); | |
4954 | if (status) | |
4955 | goto out; | |
9e9ecc03 | 4956 | status = decode_setattr(&xdr); |
23ec6965 BF |
4957 | out: |
4958 | return status; | |
4959 | } | |
1da177e4 | 4960 | |
029d105e BF |
4961 | /* |
4962 | * Decode GETACL response | |
4963 | */ | |
4964 | static int | |
663c79b3 BH |
4965 | nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, |
4966 | struct nfs_getaclres *res) | |
029d105e BF |
4967 | { |
4968 | struct xdr_stream xdr; | |
4969 | struct compound_hdr hdr; | |
4970 | int status; | |
4971 | ||
4972 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4973 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
4974 | if (status) |
4975 | goto out; | |
4976 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
029d105e BF |
4977 | if (status) |
4978 | goto out; | |
4979 | status = decode_putfh(&xdr); | |
4980 | if (status) | |
4981 | goto out; | |
663c79b3 | 4982 | status = decode_getacl(&xdr, rqstp, &res->acl_len); |
029d105e BF |
4983 | |
4984 | out: | |
4985 | return status; | |
4986 | } | |
4987 | ||
1da177e4 LT |
4988 | /* |
4989 | * Decode CLOSE response | |
4990 | */ | |
8687b63a | 4991 | static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) |
1da177e4 | 4992 | { |
05d564fe AA |
4993 | struct xdr_stream xdr; |
4994 | struct compound_hdr hdr; | |
4995 | int status; | |
4996 | ||
4997 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
4998 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
4999 | if (status) |
5000 | goto out; | |
5001 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
05d564fe AA |
5002 | if (status) |
5003 | goto out; | |
5004 | status = decode_putfh(&xdr); | |
5005 | if (status) | |
5006 | goto out; | |
5007 | status = decode_close(&xdr, res); | |
516a6af6 TM |
5008 | if (status != 0) |
5009 | goto out; | |
5010 | /* | |
5011 | * Note: Server may do delete on close for this file | |
5012 | * in which case the getattr call will fail with | |
5013 | * an ESTALE error. Shouldn't be a problem, | |
5014 | * though, since fattr->valid will remain unset. | |
5015 | */ | |
80e52ace TM |
5016 | decode_getfattr(&xdr, res->fattr, res->server, |
5017 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 | 5018 | out: |
05d564fe | 5019 | return status; |
1da177e4 LT |
5020 | } |
5021 | ||
5022 | /* | |
5023 | * Decode OPEN response | |
5024 | */ | |
8687b63a | 5025 | static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) |
1da177e4 | 5026 | { |
05d564fe AA |
5027 | struct xdr_stream xdr; |
5028 | struct compound_hdr hdr; | |
5029 | int status; | |
5030 | ||
5031 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5032 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5033 | if (status) |
5034 | goto out; | |
5035 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
05d564fe AA |
5036 | if (status) |
5037 | goto out; | |
5038 | status = decode_putfh(&xdr); | |
5039 | if (status) | |
5040 | goto out; | |
5041 | status = decode_savefh(&xdr); | |
5042 | if (status) | |
5043 | goto out; | |
5044 | status = decode_open(&xdr, res); | |
56ae19f3 TM |
5045 | if (status) |
5046 | goto out; | |
9936781d | 5047 | if (decode_getfh(&xdr, &res->fh) != 0) |
1da177e4 | 5048 | goto out; |
80e52ace TM |
5049 | if (decode_getfattr(&xdr, res->f_attr, res->server, |
5050 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | |
56ae19f3 | 5051 | goto out; |
365c8f58 | 5052 | if (decode_restorefh(&xdr) != 0) |
56ae19f3 | 5053 | goto out; |
80e52ace TM |
5054 | decode_getfattr(&xdr, res->dir_attr, res->server, |
5055 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 | 5056 | out: |
05d564fe | 5057 | return status; |
1da177e4 LT |
5058 | } |
5059 | ||
5060 | /* | |
5061 | * Decode OPEN_CONFIRM response | |
5062 | */ | |
8687b63a | 5063 | static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res) |
1da177e4 | 5064 | { |
05d564fe AA |
5065 | struct xdr_stream xdr; |
5066 | struct compound_hdr hdr; | |
5067 | int status; | |
5068 | ||
5069 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5070 | status = decode_compound_hdr(&xdr, &hdr); | |
5071 | if (status) | |
5072 | goto out; | |
5073 | status = decode_putfh(&xdr); | |
5074 | if (status) | |
5075 | goto out; | |
5076 | status = decode_open_confirm(&xdr, res); | |
1da177e4 | 5077 | out: |
05d564fe | 5078 | return status; |
1da177e4 LT |
5079 | } |
5080 | ||
5081 | /* | |
5082 | * Decode OPEN response | |
5083 | */ | |
8687b63a | 5084 | static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) |
1da177e4 | 5085 | { |
05d564fe AA |
5086 | struct xdr_stream xdr; |
5087 | struct compound_hdr hdr; | |
5088 | int status; | |
5089 | ||
5090 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5091 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5092 | if (status) |
5093 | goto out; | |
5094 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
05d564fe AA |
5095 | if (status) |
5096 | goto out; | |
5097 | status = decode_putfh(&xdr); | |
5098 | if (status) | |
5099 | goto out; | |
5100 | status = decode_open(&xdr, res); | |
5101 | if (status) | |
5102 | goto out; | |
80e52ace TM |
5103 | decode_getfattr(&xdr, res->f_attr, res->server, |
5104 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 | 5105 | out: |
05d564fe | 5106 | return status; |
1da177e4 LT |
5107 | } |
5108 | ||
5109 | /* | |
5110 | * Decode SETATTR response | |
5111 | */ | |
8687b63a | 5112 | static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res) |
1da177e4 | 5113 | { |
05d564fe AA |
5114 | struct xdr_stream xdr; |
5115 | struct compound_hdr hdr; | |
5116 | int status; | |
5117 | ||
5118 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5119 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5120 | if (status) |
5121 | goto out; | |
5122 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
05d564fe AA |
5123 | if (status) |
5124 | goto out; | |
5125 | status = decode_putfh(&xdr); | |
5126 | if (status) | |
5127 | goto out; | |
9e9ecc03 | 5128 | status = decode_setattr(&xdr); |
05d564fe AA |
5129 | if (status) |
5130 | goto out; | |
80e52ace TM |
5131 | decode_getfattr(&xdr, res->fattr, res->server, |
5132 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 | 5133 | out: |
05d564fe | 5134 | return status; |
1da177e4 LT |
5135 | } |
5136 | ||
5137 | /* | |
5138 | * Decode LOCK response | |
5139 | */ | |
8687b63a | 5140 | static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res) |
1da177e4 LT |
5141 | { |
5142 | struct xdr_stream xdr; | |
5143 | struct compound_hdr hdr; | |
5144 | int status; | |
5145 | ||
5146 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5147 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5148 | if (status) |
5149 | goto out; | |
5150 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5151 | if (status) |
5152 | goto out; | |
5153 | status = decode_putfh(&xdr); | |
5154 | if (status) | |
5155 | goto out; | |
5156 | status = decode_lock(&xdr, res); | |
5157 | out: | |
5158 | return status; | |
5159 | } | |
5160 | ||
5161 | /* | |
5162 | * Decode LOCKT response | |
5163 | */ | |
8687b63a | 5164 | static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res) |
1da177e4 LT |
5165 | { |
5166 | struct xdr_stream xdr; | |
5167 | struct compound_hdr hdr; | |
5168 | int status; | |
5169 | ||
5170 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5171 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5172 | if (status) |
5173 | goto out; | |
5174 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5175 | if (status) |
5176 | goto out; | |
5177 | status = decode_putfh(&xdr); | |
5178 | if (status) | |
5179 | goto out; | |
5180 | status = decode_lockt(&xdr, res); | |
5181 | out: | |
5182 | return status; | |
5183 | } | |
5184 | ||
5185 | /* | |
5186 | * Decode LOCKU response | |
5187 | */ | |
8687b63a | 5188 | static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res) |
1da177e4 LT |
5189 | { |
5190 | struct xdr_stream xdr; | |
5191 | struct compound_hdr hdr; | |
5192 | int status; | |
5193 | ||
5194 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5195 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5196 | if (status) |
5197 | goto out; | |
5198 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5199 | if (status) |
5200 | goto out; | |
5201 | status = decode_putfh(&xdr); | |
5202 | if (status) | |
5203 | goto out; | |
5204 | status = decode_locku(&xdr, res); | |
5205 | out: | |
5206 | return status; | |
5207 | } | |
5208 | ||
5209 | /* | |
5210 | * Decode READLINK response | |
5211 | */ | |
f50c7000 BH |
5212 | static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, |
5213 | struct nfs4_readlink_res *res) | |
1da177e4 LT |
5214 | { |
5215 | struct xdr_stream xdr; | |
5216 | struct compound_hdr hdr; | |
5217 | int status; | |
5218 | ||
5219 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5220 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5221 | if (status) |
5222 | goto out; | |
5223 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5224 | if (status) |
5225 | goto out; | |
5226 | status = decode_putfh(&xdr); | |
5227 | if (status) | |
5228 | goto out; | |
5229 | status = decode_readlink(&xdr, rqstp); | |
5230 | out: | |
5231 | return status; | |
5232 | } | |
5233 | ||
5234 | /* | |
5235 | * Decode READDIR response | |
5236 | */ | |
8687b63a | 5237 | static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res) |
1da177e4 LT |
5238 | { |
5239 | struct xdr_stream xdr; | |
5240 | struct compound_hdr hdr; | |
5241 | int status; | |
5242 | ||
5243 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5244 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5245 | if (status) |
5246 | goto out; | |
5247 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5248 | if (status) |
5249 | goto out; | |
5250 | status = decode_putfh(&xdr); | |
5251 | if (status) | |
5252 | goto out; | |
5253 | status = decode_readdir(&xdr, rqstp, res); | |
5254 | out: | |
5255 | return status; | |
5256 | } | |
5257 | ||
5258 | /* | |
5259 | * Decode Read response | |
5260 | */ | |
8687b63a | 5261 | static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res) |
1da177e4 LT |
5262 | { |
5263 | struct xdr_stream xdr; | |
5264 | struct compound_hdr hdr; | |
5265 | int status; | |
5266 | ||
5267 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5268 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5269 | if (status) |
5270 | goto out; | |
5271 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5272 | if (status) |
5273 | goto out; | |
5274 | status = decode_putfh(&xdr); | |
5275 | if (status) | |
5276 | goto out; | |
5277 | status = decode_read(&xdr, rqstp, res); | |
5278 | if (!status) | |
5279 | status = res->count; | |
5280 | out: | |
5281 | return status; | |
5282 | } | |
5283 | ||
5284 | /* | |
5285 | * Decode WRITE response | |
5286 | */ | |
8687b63a | 5287 | static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) |
1da177e4 LT |
5288 | { |
5289 | struct xdr_stream xdr; | |
5290 | struct compound_hdr hdr; | |
5291 | int status; | |
5292 | ||
5293 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5294 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5295 | if (status) |
5296 | goto out; | |
5297 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5298 | if (status) |
5299 | goto out; | |
5300 | status = decode_putfh(&xdr); | |
5301 | if (status) | |
5302 | goto out; | |
5303 | status = decode_write(&xdr, res); | |
4f9838c7 TM |
5304 | if (status) |
5305 | goto out; | |
80e52ace TM |
5306 | decode_getfattr(&xdr, res->fattr, res->server, |
5307 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
5308 | if (!status) |
5309 | status = res->count; | |
5310 | out: | |
5311 | return status; | |
5312 | } | |
5313 | ||
5314 | /* | |
5315 | * Decode COMMIT response | |
5316 | */ | |
8687b63a | 5317 | static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) |
1da177e4 LT |
5318 | { |
5319 | struct xdr_stream xdr; | |
5320 | struct compound_hdr hdr; | |
5321 | int status; | |
5322 | ||
5323 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5324 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5325 | if (status) |
5326 | goto out; | |
5327 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
1da177e4 LT |
5328 | if (status) |
5329 | goto out; | |
5330 | status = decode_putfh(&xdr); | |
5331 | if (status) | |
5332 | goto out; | |
5333 | status = decode_commit(&xdr, res); | |
4f9838c7 TM |
5334 | if (status) |
5335 | goto out; | |
80e52ace TM |
5336 | decode_getfattr(&xdr, res->fattr, res->server, |
5337 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
1da177e4 LT |
5338 | out: |
5339 | return status; | |
5340 | } | |
5341 | ||
5342 | /* | |
5343 | * FSINFO request | |
5344 | */ | |
3dda5e43 BH |
5345 | static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, |
5346 | struct nfs4_fsinfo_res *res) | |
1da177e4 LT |
5347 | { |
5348 | struct xdr_stream xdr; | |
5349 | struct compound_hdr hdr; | |
5350 | int status; | |
5351 | ||
5352 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
5353 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5354 | if (!status) |
5355 | status = decode_sequence(&xdr, &res->seq_res, req); | |
1da177e4 LT |
5356 | if (!status) |
5357 | status = decode_putfh(&xdr); | |
5358 | if (!status) | |
3dda5e43 | 5359 | status = decode_fsinfo(&xdr, res->fsinfo); |
1da177e4 LT |
5360 | return status; |
5361 | } | |
5362 | ||
5363 | /* | |
5364 | * PATHCONF request | |
5365 | */ | |
d45b2989 BH |
5366 | static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, |
5367 | struct nfs4_pathconf_res *res) | |
1da177e4 LT |
5368 | { |
5369 | struct xdr_stream xdr; | |
5370 | struct compound_hdr hdr; | |
5371 | int status; | |
5372 | ||
5373 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
5374 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5375 | if (!status) |
5376 | status = decode_sequence(&xdr, &res->seq_res, req); | |
1da177e4 LT |
5377 | if (!status) |
5378 | status = decode_putfh(&xdr); | |
5379 | if (!status) | |
d45b2989 | 5380 | status = decode_pathconf(&xdr, res->pathconf); |
1da177e4 LT |
5381 | return status; |
5382 | } | |
5383 | ||
5384 | /* | |
5385 | * STATFS request | |
5386 | */ | |
24ad148a BH |
5387 | static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, |
5388 | struct nfs4_statfs_res *res) | |
1da177e4 LT |
5389 | { |
5390 | struct xdr_stream xdr; | |
5391 | struct compound_hdr hdr; | |
5392 | int status; | |
5393 | ||
5394 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
5395 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5396 | if (!status) |
5397 | status = decode_sequence(&xdr, &res->seq_res, req); | |
1da177e4 LT |
5398 | if (!status) |
5399 | status = decode_putfh(&xdr); | |
5400 | if (!status) | |
24ad148a | 5401 | status = decode_statfs(&xdr, res->fsstat); |
1da177e4 LT |
5402 | return status; |
5403 | } | |
5404 | ||
5405 | /* | |
5406 | * GETATTR_BITMAP request | |
5407 | */ | |
8687b63a | 5408 | static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res) |
1da177e4 LT |
5409 | { |
5410 | struct xdr_stream xdr; | |
5411 | struct compound_hdr hdr; | |
5412 | int status; | |
5413 | ||
5414 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
9b7b9fcc AA |
5415 | status = decode_compound_hdr(&xdr, &hdr); |
5416 | if (status) | |
5417 | goto out; | |
5418 | status = decode_sequence(&xdr, &res->seq_res, req); | |
5419 | if (status) | |
1da177e4 LT |
5420 | goto out; |
5421 | if ((status = decode_putfh(&xdr)) != 0) | |
5422 | goto out; | |
5423 | status = decode_server_caps(&xdr, res); | |
5424 | out: | |
5425 | return status; | |
5426 | } | |
5427 | ||
5428 | /* | |
5429 | * Decode RENEW response | |
5430 | */ | |
8687b63a | 5431 | static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy) |
1da177e4 LT |
5432 | { |
5433 | struct xdr_stream xdr; | |
5434 | struct compound_hdr hdr; | |
5435 | int status; | |
5436 | ||
5437 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5438 | status = decode_compound_hdr(&xdr, &hdr); | |
5439 | if (!status) | |
5440 | status = decode_renew(&xdr); | |
5441 | return status; | |
5442 | } | |
5443 | ||
5444 | /* | |
5445 | * a SETCLIENTID request | |
5446 | */ | |
8687b63a | 5447 | static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p, |
adfa6f98 | 5448 | struct nfs_client *clp) |
1da177e4 LT |
5449 | { |
5450 | struct xdr_stream xdr; | |
5451 | struct compound_hdr hdr; | |
5452 | int status; | |
5453 | ||
5454 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
5455 | status = decode_compound_hdr(&xdr, &hdr); | |
5456 | if (!status) | |
5457 | status = decode_setclientid(&xdr, clp); | |
1da177e4 LT |
5458 | return status; |
5459 | } | |
5460 | ||
5461 | /* | |
5462 | * a SETCLIENTID_CONFIRM request | |
5463 | */ | |
8687b63a | 5464 | static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo) |
1da177e4 LT |
5465 | { |
5466 | struct xdr_stream xdr; | |
5467 | struct compound_hdr hdr; | |
5468 | int status; | |
5469 | ||
5470 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
5471 | status = decode_compound_hdr(&xdr, &hdr); | |
5472 | if (!status) | |
5473 | status = decode_setclientid_confirm(&xdr); | |
5474 | if (!status) | |
5475 | status = decode_putrootfh(&xdr); | |
5476 | if (!status) | |
5477 | status = decode_fsinfo(&xdr, fsinfo); | |
1da177e4 LT |
5478 | return status; |
5479 | } | |
5480 | ||
5481 | /* | |
5482 | * DELEGRETURN request | |
5483 | */ | |
8687b63a | 5484 | static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res) |
1da177e4 LT |
5485 | { |
5486 | struct xdr_stream xdr; | |
5487 | struct compound_hdr hdr; | |
5488 | int status; | |
5489 | ||
5490 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5491 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5492 | if (status) |
5493 | goto out; | |
5494 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | |
5495 | if (status) | |
fa178f29 TM |
5496 | goto out; |
5497 | status = decode_putfh(&xdr); | |
5498 | if (status != 0) | |
5499 | goto out; | |
5500 | status = decode_delegreturn(&xdr); | |
80e52ace TM |
5501 | decode_getfattr(&xdr, res->fattr, res->server, |
5502 | !RPC_IS_ASYNC(rqstp->rq_task)); | |
fa178f29 | 5503 | out: |
1da177e4 LT |
5504 | return status; |
5505 | } | |
5506 | ||
683b57b4 TM |
5507 | /* |
5508 | * FS_LOCATIONS request | |
5509 | */ | |
22958463 BH |
5510 | static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, |
5511 | struct nfs4_fs_locations_res *res) | |
683b57b4 TM |
5512 | { |
5513 | struct xdr_stream xdr; | |
5514 | struct compound_hdr hdr; | |
5515 | int status; | |
5516 | ||
5517 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
5518 | status = decode_compound_hdr(&xdr, &hdr); | |
9b7b9fcc AA |
5519 | if (status) |
5520 | goto out; | |
5521 | status = decode_sequence(&xdr, &res->seq_res, req); | |
5522 | if (status) | |
683b57b4 TM |
5523 | goto out; |
5524 | if ((status = decode_putfh(&xdr)) != 0) | |
5525 | goto out; | |
5526 | if ((status = decode_lookup(&xdr)) != 0) | |
5527 | goto out; | |
5528 | xdr_enter_page(&xdr, PAGE_SIZE); | |
22958463 | 5529 | status = decode_getfattr(&xdr, &res->fs_locations->fattr, |
80e52ace TM |
5530 | res->fs_locations->server, |
5531 | !RPC_IS_ASYNC(req->rq_task)); | |
683b57b4 TM |
5532 | out: |
5533 | return status; | |
5534 | } | |
5535 | ||
99fe60d0 BH |
5536 | #if defined(CONFIG_NFS_V4_1) |
5537 | /* | |
5538 | * EXCHANGE_ID request | |
5539 | */ | |
5540 | static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p, | |
5541 | void *res) | |
5542 | { | |
5543 | struct xdr_stream xdr; | |
5544 | struct compound_hdr hdr; | |
5545 | int status; | |
5546 | ||
5547 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5548 | status = decode_compound_hdr(&xdr, &hdr); | |
5549 | if (!status) | |
5550 | status = decode_exchange_id(&xdr, res); | |
5551 | return status; | |
5552 | } | |
2050f0cc | 5553 | |
fc931582 AA |
5554 | /* |
5555 | * a CREATE_SESSION request | |
5556 | */ | |
5557 | static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p, | |
5558 | struct nfs41_create_session_res *res) | |
5559 | { | |
5560 | struct xdr_stream xdr; | |
5561 | struct compound_hdr hdr; | |
5562 | int status; | |
5563 | ||
5564 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5565 | status = decode_compound_hdr(&xdr, &hdr); | |
5566 | if (!status) | |
5567 | status = decode_create_session(&xdr, res); | |
5568 | return status; | |
5569 | } | |
5570 | ||
0f3e66c6 AA |
5571 | /* |
5572 | * a DESTROY_SESSION request | |
5573 | */ | |
5574 | static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p, | |
5575 | void *dummy) | |
5576 | { | |
5577 | struct xdr_stream xdr; | |
5578 | struct compound_hdr hdr; | |
5579 | int status; | |
5580 | ||
5581 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5582 | status = decode_compound_hdr(&xdr, &hdr); | |
5583 | if (!status) | |
5584 | status = decode_destroy_session(&xdr, dummy); | |
5585 | return status; | |
5586 | } | |
5587 | ||
fc01cea9 AA |
5588 | /* |
5589 | * a SEQUENCE request | |
5590 | */ | |
5591 | static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p, | |
5592 | struct nfs4_sequence_res *res) | |
5593 | { | |
5594 | struct xdr_stream xdr; | |
5595 | struct compound_hdr hdr; | |
5596 | int status; | |
5597 | ||
5598 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5599 | status = decode_compound_hdr(&xdr, &hdr); | |
5600 | if (!status) | |
5601 | status = decode_sequence(&xdr, res, rqstp); | |
5602 | return status; | |
5603 | } | |
5604 | ||
2050f0cc AA |
5605 | /* |
5606 | * a GET_LEASE_TIME request | |
5607 | */ | |
5608 | static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p, | |
5609 | struct nfs4_get_lease_time_res *res) | |
5610 | { | |
5611 | struct xdr_stream xdr; | |
5612 | struct compound_hdr hdr; | |
5613 | int status; | |
5614 | ||
5615 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
5616 | status = decode_compound_hdr(&xdr, &hdr); | |
5617 | if (!status) | |
5618 | status = decode_sequence(&xdr, &res->lr_seq_res, rqstp); | |
5619 | if (!status) | |
5620 | status = decode_putrootfh(&xdr); | |
5621 | if (!status) | |
5622 | status = decode_fsinfo(&xdr, res->lr_fsinfo); | |
5623 | return status; | |
5624 | } | |
99fe60d0 BH |
5625 | #endif /* CONFIG_NFS_V4_1 */ |
5626 | ||
0dbb4c67 | 5627 | __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus) |
1da177e4 LT |
5628 | { |
5629 | uint32_t bitmap[2] = {0}; | |
5630 | uint32_t len; | |
5631 | ||
5632 | if (!*p++) { | |
5633 | if (!*p) | |
5634 | return ERR_PTR(-EAGAIN); | |
5635 | entry->eof = 1; | |
5636 | return ERR_PTR(-EBADCOOKIE); | |
5637 | } | |
5638 | ||
5639 | entry->prev_cookie = entry->cookie; | |
5640 | p = xdr_decode_hyper(p, &entry->cookie); | |
5641 | entry->len = ntohl(*p++); | |
5642 | entry->name = (const char *) p; | |
5643 | p += XDR_QUADLEN(entry->len); | |
5644 | ||
5645 | /* | |
5646 | * In case the server doesn't return an inode number, | |
5647 | * we fake one here. (We don't use inode number 0, | |
5648 | * since glibc seems to choke on it...) | |
5649 | */ | |
5650 | entry->ino = 1; | |
5651 | ||
5652 | len = ntohl(*p++); /* bitmap length */ | |
5653 | if (len-- > 0) { | |
5654 | bitmap[0] = ntohl(*p++); | |
5655 | if (len-- > 0) { | |
5656 | bitmap[1] = ntohl(*p++); | |
5657 | p += len; | |
5658 | } | |
5659 | } | |
5660 | len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */ | |
5661 | if (len > 0) { | |
97d312d0 MN |
5662 | if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) { |
5663 | bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; | |
5664 | /* Ignore the return value of rdattr_error for now */ | |
5665 | p++; | |
5666 | len--; | |
5667 | } | |
1da177e4 LT |
5668 | if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID) |
5669 | xdr_decode_hyper(p, &entry->ino); | |
5670 | else if (bitmap[0] == FATTR4_WORD0_FILEID) | |
5671 | xdr_decode_hyper(p, &entry->ino); | |
5672 | p += len; | |
5673 | } | |
5674 | ||
5675 | entry->eof = !p[0] && p[1]; | |
5676 | return p; | |
5677 | } | |
5678 | ||
5679 | /* | |
5680 | * We need to translate between nfs status return values and | |
5681 | * the local errno values which may not be the same. | |
5682 | */ | |
5683 | static struct { | |
5684 | int stat; | |
5685 | int errno; | |
5686 | } nfs_errtbl[] = { | |
5687 | { NFS4_OK, 0 }, | |
856dff3d BH |
5688 | { NFS4ERR_PERM, -EPERM }, |
5689 | { NFS4ERR_NOENT, -ENOENT }, | |
5690 | { NFS4ERR_IO, -errno_NFSERR_IO}, | |
5691 | { NFS4ERR_NXIO, -ENXIO }, | |
5692 | { NFS4ERR_ACCESS, -EACCES }, | |
5693 | { NFS4ERR_EXIST, -EEXIST }, | |
5694 | { NFS4ERR_XDEV, -EXDEV }, | |
5695 | { NFS4ERR_NOTDIR, -ENOTDIR }, | |
5696 | { NFS4ERR_ISDIR, -EISDIR }, | |
5697 | { NFS4ERR_INVAL, -EINVAL }, | |
5698 | { NFS4ERR_FBIG, -EFBIG }, | |
5699 | { NFS4ERR_NOSPC, -ENOSPC }, | |
5700 | { NFS4ERR_ROFS, -EROFS }, | |
5701 | { NFS4ERR_MLINK, -EMLINK }, | |
5702 | { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, | |
5703 | { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, | |
5704 | { NFS4ERR_DQUOT, -EDQUOT }, | |
5705 | { NFS4ERR_STALE, -ESTALE }, | |
5706 | { NFS4ERR_BADHANDLE, -EBADHANDLE }, | |
5707 | { NFS4ERR_BADOWNER, -EINVAL }, | |
5708 | { NFS4ERR_BADNAME, -EINVAL }, | |
5709 | { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, | |
5710 | { NFS4ERR_NOTSUPP, -ENOTSUPP }, | |
5711 | { NFS4ERR_TOOSMALL, -ETOOSMALL }, | |
5712 | { NFS4ERR_SERVERFAULT, -ESERVERFAULT }, | |
5713 | { NFS4ERR_BADTYPE, -EBADTYPE }, | |
5714 | { NFS4ERR_LOCKED, -EAGAIN }, | |
856dff3d BH |
5715 | { NFS4ERR_SYMLINK, -ELOOP }, |
5716 | { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, | |
5717 | { NFS4ERR_DEADLOCK, -EDEADLK }, | |
5718 | { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs | |
1da177e4 LT |
5719 | * to be handled by a |
5720 | * middle-layer. | |
5721 | */ | |
856dff3d | 5722 | { -1, -EIO } |
1da177e4 LT |
5723 | }; |
5724 | ||
5725 | /* | |
5726 | * Convert an NFS error code to a local one. | |
5727 | * This one is used jointly by NFSv2 and NFSv3. | |
5728 | */ | |
5729 | static int | |
0a8ea437 | 5730 | nfs4_stat_to_errno(int stat) |
1da177e4 LT |
5731 | { |
5732 | int i; | |
5733 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { | |
5734 | if (nfs_errtbl[i].stat == stat) | |
5735 | return nfs_errtbl[i].errno; | |
5736 | } | |
5737 | if (stat <= 10000 || stat > 10100) { | |
5738 | /* The server is looney tunes. */ | |
856dff3d | 5739 | return -ESERVERFAULT; |
1da177e4 LT |
5740 | } |
5741 | /* If we cannot translate the error, the recovery routines should | |
5742 | * handle it. | |
5743 | * Note: remaining NFSv4 error codes have values > 10000, so should | |
5744 | * not conflict with native Linux error codes. | |
5745 | */ | |
856dff3d | 5746 | return -stat; |
1da177e4 LT |
5747 | } |
5748 | ||
1da177e4 LT |
5749 | #define PROC(proc, argtype, restype) \ |
5750 | [NFSPROC4_CLNT_##proc] = { \ | |
5751 | .p_proc = NFSPROC4_COMPOUND, \ | |
5752 | .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ | |
5753 | .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ | |
2bea90d4 CL |
5754 | .p_arglen = NFS4_##argtype##_sz, \ |
5755 | .p_replen = NFS4_##restype##_sz, \ | |
cc0175c1 CL |
5756 | .p_statidx = NFSPROC4_CLNT_##proc, \ |
5757 | .p_name = #proc, \ | |
05d564fe | 5758 | } |
1da177e4 LT |
5759 | |
5760 | struct rpc_procinfo nfs4_procedures[] = { | |
5761 | PROC(READ, enc_read, dec_read), | |
5762 | PROC(WRITE, enc_write, dec_write), | |
5763 | PROC(COMMIT, enc_commit, dec_commit), | |
5764 | PROC(OPEN, enc_open, dec_open), | |
5765 | PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), | |
5766 | PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), | |
5767 | PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), | |
5768 | PROC(CLOSE, enc_close, dec_close), | |
5769 | PROC(SETATTR, enc_setattr, dec_setattr), | |
5770 | PROC(FSINFO, enc_fsinfo, dec_fsinfo), | |
5771 | PROC(RENEW, enc_renew, dec_renew), | |
5772 | PROC(SETCLIENTID, enc_setclientid, dec_setclientid), | |
5773 | PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), | |
5774 | PROC(LOCK, enc_lock, dec_lock), | |
5775 | PROC(LOCKT, enc_lockt, dec_lockt), | |
5776 | PROC(LOCKU, enc_locku, dec_locku), | |
5777 | PROC(ACCESS, enc_access, dec_access), | |
5778 | PROC(GETATTR, enc_getattr, dec_getattr), | |
5779 | PROC(LOOKUP, enc_lookup, dec_lookup), | |
5780 | PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), | |
5781 | PROC(REMOVE, enc_remove, dec_remove), | |
5782 | PROC(RENAME, enc_rename, dec_rename), | |
5783 | PROC(LINK, enc_link, dec_link), | |
5784 | PROC(SYMLINK, enc_symlink, dec_symlink), | |
5785 | PROC(CREATE, enc_create, dec_create), | |
5786 | PROC(PATHCONF, enc_pathconf, dec_pathconf), | |
5787 | PROC(STATFS, enc_statfs, dec_statfs), | |
5788 | PROC(READLINK, enc_readlink, dec_readlink), | |
5789 | PROC(READDIR, enc_readdir, dec_readdir), | |
5790 | PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), | |
5791 | PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), | |
029d105e | 5792 | PROC(GETACL, enc_getacl, dec_getacl), |
23ec6965 | 5793 | PROC(SETACL, enc_setacl, dec_setacl), |
683b57b4 | 5794 | PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), |
99fe60d0 BH |
5795 | #if defined(CONFIG_NFS_V4_1) |
5796 | PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), | |
fc931582 | 5797 | PROC(CREATE_SESSION, enc_create_session, dec_create_session), |
0f3e66c6 | 5798 | PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), |
fc01cea9 | 5799 | PROC(SEQUENCE, enc_sequence, dec_sequence), |
2050f0cc | 5800 | PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), |
99fe60d0 | 5801 | #endif /* CONFIG_NFS_V4_1 */ |
1da177e4 LT |
5802 | }; |
5803 | ||
5804 | struct rpc_version nfs_version4 = { | |
5805 | .number = 4, | |
e8c96f8c | 5806 | .nrprocs = ARRAY_SIZE(nfs4_procedures), |
1da177e4 LT |
5807 | .procs = nfs4_procedures |
5808 | }; | |
5809 | ||
5810 | /* | |
5811 | * Local variables: | |
5812 | * c-basic-offset: 8 | |
5813 | * End: | |
5814 | */ |