NFS: Micro-optimize nfs4_decode_dirent()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / nfs / nfs4xdr.c
blob009aef9e12bc3d5a5cef83b659da8f67251983b0
1 /*
2 * fs/nfs/nfs4xdr.c
4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
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.
38 #include <linux/param.h>
39 #include <linux/time.h>
40 #include <linux/mm.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/in.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/sunrpc/clnt.h>
48 #include <linux/sunrpc/msg_prot.h>
49 #include <linux/nfs.h>
50 #include <linux/nfs4.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/nfs_idmap.h>
53 #include "nfs4_fs.h"
54 #include "internal.h"
55 #include "pnfs.h"
57 #define NFSDBG_FACILITY NFSDBG_XDR
59 /* Mapping from NFS error code to "errno" error code. */
60 #define errno_NFSERR_IO EIO
62 static int nfs4_stat_to_errno(int);
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
71 /* lock,open owner id:
72 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
74 #define open_owner_id_maxsz (1 + 1 + 4)
75 #define lock_owner_id_maxsz (1 + 1 + 4)
76 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
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)
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))
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))
93 #define nfs4_fattr_bitmap_maxsz 3
94 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
95 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
96 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
97 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
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 + \
101 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
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)
105 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
106 1 + 2 + 1 + \
107 nfs4_owner_maxsz + \
108 nfs4_group_maxsz + \
109 4 + 4)
110 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
111 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
112 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
113 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
114 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
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 + \
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 */
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)
135 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
136 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
137 #define encode_share_access_maxsz \
139 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
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)
148 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 decode_ace_maxsz)
150 #define decode_change_info_maxsz (5)
151 #define decode_open_maxsz (op_decode_hdr_maxsz + \
152 decode_stateid_maxsz + \
153 decode_change_info_maxsz + 1 + \
154 nfs4_fattr_bitmap_maxsz + \
155 decode_delegation_maxsz)
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)
194 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 nfs4_name_maxsz)
196 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
197 decode_change_info_maxsz)
198 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 2 * nfs4_name_maxsz)
200 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
201 decode_change_info_maxsz + \
202 decode_change_info_maxsz)
203 #define encode_link_maxsz (op_encode_hdr_maxsz + \
204 nfs4_name_maxsz)
205 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
206 #define encode_lockowner_maxsz (7)
207 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
208 7 + \
209 1 + encode_stateid_maxsz + 1 + \
210 encode_lockowner_maxsz)
211 #define decode_lock_denied_maxsz \
212 (8 + decode_lockowner_maxsz)
213 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
216 encode_lockowner_maxsz)
217 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
218 decode_lock_denied_maxsz)
219 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
220 encode_stateid_maxsz + \
222 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
223 decode_stateid_maxsz)
224 #define encode_release_lockowner_maxsz \
225 (op_encode_hdr_maxsz + \
226 encode_lockowner_maxsz)
227 #define decode_release_lockowner_maxsz \
228 (op_decode_hdr_maxsz)
229 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
230 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
231 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
232 1 + nfs4_name_maxsz + \
233 1 + \
234 nfs4_fattr_maxsz)
235 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
236 #define encode_create_maxsz (op_encode_hdr_maxsz + \
237 1 + 2 + nfs4_name_maxsz + \
238 encode_attrs_maxsz)
239 #define decode_create_maxsz (op_decode_hdr_maxsz + \
240 decode_change_info_maxsz + \
241 nfs4_fattr_bitmap_maxsz)
242 #define encode_statfs_maxsz (encode_getattr_maxsz)
243 #define decode_statfs_maxsz (decode_getattr_maxsz)
244 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
245 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
246 #define encode_getacl_maxsz (encode_getattr_maxsz)
247 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
248 nfs4_fattr_bitmap_maxsz + 1)
249 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
250 encode_stateid_maxsz + 3)
251 #define decode_setacl_maxsz (decode_setattr_maxsz)
252 #define encode_fs_locations_maxsz \
253 (encode_getattr_maxsz)
254 #define decode_fs_locations_maxsz \
257 #if defined(CONFIG_NFS_V4_1)
258 #define NFS4_MAX_MACHINE_NAME_LEN (64)
260 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
261 encode_verifier_maxsz + \
262 1 /* co_ownerid.len */ + \
263 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
264 1 /* flags */ + \
265 1 /* spa_how */ + \
266 0 /* SP4_NONE (for now) */ + \
267 1 /* zero implemetation id array */)
268 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
269 2 /* eir_clientid */ + \
270 1 /* eir_sequenceid */ + \
271 1 /* eir_flags */ + \
272 1 /* spr_how */ + \
273 0 /* SP4_NONE (for now) */ + \
274 2 /* eir_server_owner.so_minor_id */ + \
275 /* eir_server_owner.so_major_id<> */ \
276 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
277 /* eir_server_scope<> */ \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
279 1 /* eir_server_impl_id array length */ + \
280 0 /* ignored eir_server_impl_id contents */)
281 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
282 #define decode_channel_attrs_maxsz (6 + \
283 1 /* ca_rdma_ird.len */ + \
284 1 /* ca_rdma_ird */)
285 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
286 2 /* csa_clientid */ + \
287 1 /* csa_sequence */ + \
288 1 /* csa_flags */ + \
289 encode_channel_attrs_maxsz + \
290 encode_channel_attrs_maxsz + \
291 1 /* csa_cb_program */ + \
292 1 /* csa_sec_parms.len (1) */ + \
293 1 /* cb_secflavor (AUTH_SYS) */ + \
294 1 /* stamp */ + \
295 1 /* machinename.len */ + \
296 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
297 1 /* uid */ + \
298 1 /* gid */ + \
299 1 /* gids.len (0) */)
300 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
302 1 /* csr_sequence */ + \
303 1 /* csr_flags */ + \
304 decode_channel_attrs_maxsz + \
305 decode_channel_attrs_maxsz)
306 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
307 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
308 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
309 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
310 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
311 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
312 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
313 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
314 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
315 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
316 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
317 1 /* layout type */ + \
318 1 /* opaque devaddr4 length */ + \
319 /* devaddr4 payload is read into page */ \
320 1 /* notification bitmap length */ + \
321 1 /* notification bitmap */)
322 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
323 encode_stateid_maxsz)
324 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
325 decode_stateid_maxsz + \
326 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
327 #else /* CONFIG_NFS_V4_1 */
328 #define encode_sequence_maxsz 0
329 #define decode_sequence_maxsz 0
330 #endif /* CONFIG_NFS_V4_1 */
332 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
333 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
334 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
335 encode_sequence_maxsz + \
336 encode_putfh_maxsz + \
337 encode_read_maxsz)
338 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
339 decode_sequence_maxsz + \
340 decode_putfh_maxsz + \
341 decode_read_maxsz)
342 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
343 encode_sequence_maxsz + \
344 encode_putfh_maxsz + \
345 encode_readlink_maxsz)
346 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
347 decode_sequence_maxsz + \
348 decode_putfh_maxsz + \
349 decode_readlink_maxsz)
350 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
351 encode_sequence_maxsz + \
352 encode_putfh_maxsz + \
353 encode_readdir_maxsz)
354 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
355 decode_sequence_maxsz + \
356 decode_putfh_maxsz + \
357 decode_readdir_maxsz)
358 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
359 encode_sequence_maxsz + \
360 encode_putfh_maxsz + \
361 encode_write_maxsz + \
362 encode_getattr_maxsz)
363 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
364 decode_sequence_maxsz + \
365 decode_putfh_maxsz + \
366 decode_write_maxsz + \
367 decode_getattr_maxsz)
368 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
369 encode_sequence_maxsz + \
370 encode_putfh_maxsz + \
371 encode_commit_maxsz + \
372 encode_getattr_maxsz)
373 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
374 decode_sequence_maxsz + \
375 decode_putfh_maxsz + \
376 decode_commit_maxsz + \
377 decode_getattr_maxsz)
378 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
379 encode_sequence_maxsz + \
380 encode_putfh_maxsz + \
381 encode_savefh_maxsz + \
382 encode_open_maxsz + \
383 encode_getfh_maxsz + \
384 encode_getattr_maxsz + \
385 encode_restorefh_maxsz + \
386 encode_getattr_maxsz)
387 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
388 decode_sequence_maxsz + \
389 decode_putfh_maxsz + \
390 decode_savefh_maxsz + \
391 decode_open_maxsz + \
392 decode_getfh_maxsz + \
393 decode_getattr_maxsz + \
394 decode_restorefh_maxsz + \
395 decode_getattr_maxsz)
396 #define NFS4_enc_open_confirm_sz \
397 (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_open_confirm_maxsz)
400 #define NFS4_dec_open_confirm_sz \
401 (compound_decode_hdr_maxsz + \
402 decode_putfh_maxsz + \
403 decode_open_confirm_maxsz)
404 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
405 encode_sequence_maxsz + \
406 encode_putfh_maxsz + \
407 encode_open_maxsz + \
408 encode_getattr_maxsz)
409 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
410 decode_sequence_maxsz + \
411 decode_putfh_maxsz + \
412 decode_open_maxsz + \
413 decode_getattr_maxsz)
414 #define NFS4_enc_open_downgrade_sz \
415 (compound_encode_hdr_maxsz + \
416 encode_sequence_maxsz + \
417 encode_putfh_maxsz + \
418 encode_open_downgrade_maxsz + \
419 encode_getattr_maxsz)
420 #define NFS4_dec_open_downgrade_sz \
421 (compound_decode_hdr_maxsz + \
422 decode_sequence_maxsz + \
423 decode_putfh_maxsz + \
424 decode_open_downgrade_maxsz + \
425 decode_getattr_maxsz)
426 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
427 encode_sequence_maxsz + \
428 encode_putfh_maxsz + \
429 encode_close_maxsz + \
430 encode_getattr_maxsz)
431 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
432 decode_sequence_maxsz + \
433 decode_putfh_maxsz + \
434 decode_close_maxsz + \
435 decode_getattr_maxsz)
436 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
437 encode_sequence_maxsz + \
438 encode_putfh_maxsz + \
439 encode_setattr_maxsz + \
440 encode_getattr_maxsz)
441 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
442 decode_sequence_maxsz + \
443 decode_putfh_maxsz + \
444 decode_setattr_maxsz + \
445 decode_getattr_maxsz)
446 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
447 encode_sequence_maxsz + \
448 encode_putfh_maxsz + \
449 encode_fsinfo_maxsz)
450 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
451 decode_sequence_maxsz + \
452 decode_putfh_maxsz + \
453 decode_fsinfo_maxsz)
454 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
455 encode_renew_maxsz)
456 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
457 decode_renew_maxsz)
458 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
459 encode_setclientid_maxsz)
460 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
461 decode_setclientid_maxsz)
462 #define NFS4_enc_setclientid_confirm_sz \
463 (compound_encode_hdr_maxsz + \
464 encode_setclientid_confirm_maxsz + \
465 encode_putrootfh_maxsz + \
466 encode_fsinfo_maxsz)
467 #define NFS4_dec_setclientid_confirm_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_setclientid_confirm_maxsz + \
470 decode_putrootfh_maxsz + \
471 decode_fsinfo_maxsz)
472 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
473 encode_sequence_maxsz + \
474 encode_putfh_maxsz + \
475 encode_lock_maxsz)
476 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
477 decode_sequence_maxsz + \
478 decode_putfh_maxsz + \
479 decode_lock_maxsz)
480 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
481 encode_sequence_maxsz + \
482 encode_putfh_maxsz + \
483 encode_lockt_maxsz)
484 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
485 decode_sequence_maxsz + \
486 decode_putfh_maxsz + \
487 decode_lockt_maxsz)
488 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
489 encode_sequence_maxsz + \
490 encode_putfh_maxsz + \
491 encode_locku_maxsz)
492 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
493 decode_sequence_maxsz + \
494 decode_putfh_maxsz + \
495 decode_locku_maxsz)
496 #define NFS4_enc_release_lockowner_sz \
497 (compound_encode_hdr_maxsz + \
498 encode_lockowner_maxsz)
499 #define NFS4_dec_release_lockowner_sz \
500 (compound_decode_hdr_maxsz + \
501 decode_lockowner_maxsz)
502 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
503 encode_sequence_maxsz + \
504 encode_putfh_maxsz + \
505 encode_access_maxsz + \
506 encode_getattr_maxsz)
507 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
508 decode_sequence_maxsz + \
509 decode_putfh_maxsz + \
510 decode_access_maxsz + \
511 decode_getattr_maxsz)
512 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
513 encode_sequence_maxsz + \
514 encode_putfh_maxsz + \
515 encode_getattr_maxsz)
516 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
517 decode_sequence_maxsz + \
518 decode_putfh_maxsz + \
519 decode_getattr_maxsz)
520 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
521 encode_sequence_maxsz + \
522 encode_putfh_maxsz + \
523 encode_lookup_maxsz + \
524 encode_getattr_maxsz + \
525 encode_getfh_maxsz)
526 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
527 decode_sequence_maxsz + \
528 decode_putfh_maxsz + \
529 decode_lookup_maxsz + \
530 decode_getattr_maxsz + \
531 decode_getfh_maxsz)
532 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
533 encode_sequence_maxsz + \
534 encode_putrootfh_maxsz + \
535 encode_getattr_maxsz + \
536 encode_getfh_maxsz)
537 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
538 decode_sequence_maxsz + \
539 decode_putrootfh_maxsz + \
540 decode_getattr_maxsz + \
541 decode_getfh_maxsz)
542 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
543 encode_sequence_maxsz + \
544 encode_putfh_maxsz + \
545 encode_remove_maxsz + \
546 encode_getattr_maxsz)
547 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
548 decode_sequence_maxsz + \
549 decode_putfh_maxsz + \
550 decode_remove_maxsz + \
551 decode_getattr_maxsz)
552 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
553 encode_sequence_maxsz + \
554 encode_putfh_maxsz + \
555 encode_savefh_maxsz + \
556 encode_putfh_maxsz + \
557 encode_rename_maxsz + \
558 encode_getattr_maxsz + \
559 encode_restorefh_maxsz + \
560 encode_getattr_maxsz)
561 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
562 decode_sequence_maxsz + \
563 decode_putfh_maxsz + \
564 decode_savefh_maxsz + \
565 decode_putfh_maxsz + \
566 decode_rename_maxsz + \
567 decode_getattr_maxsz + \
568 decode_restorefh_maxsz + \
569 decode_getattr_maxsz)
570 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
571 encode_sequence_maxsz + \
572 encode_putfh_maxsz + \
573 encode_savefh_maxsz + \
574 encode_putfh_maxsz + \
575 encode_link_maxsz + \
576 decode_getattr_maxsz + \
577 encode_restorefh_maxsz + \
578 decode_getattr_maxsz)
579 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
580 decode_sequence_maxsz + \
581 decode_putfh_maxsz + \
582 decode_savefh_maxsz + \
583 decode_putfh_maxsz + \
584 decode_link_maxsz + \
585 decode_getattr_maxsz + \
586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
588 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
589 encode_sequence_maxsz + \
590 encode_putfh_maxsz + \
591 encode_symlink_maxsz + \
592 encode_getattr_maxsz + \
593 encode_getfh_maxsz)
594 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
595 decode_sequence_maxsz + \
596 decode_putfh_maxsz + \
597 decode_symlink_maxsz + \
598 decode_getattr_maxsz + \
599 decode_getfh_maxsz)
600 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
601 encode_sequence_maxsz + \
602 encode_putfh_maxsz + \
603 encode_savefh_maxsz + \
604 encode_create_maxsz + \
605 encode_getfh_maxsz + \
606 encode_getattr_maxsz + \
607 encode_restorefh_maxsz + \
608 encode_getattr_maxsz)
609 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
610 decode_sequence_maxsz + \
611 decode_putfh_maxsz + \
612 decode_savefh_maxsz + \
613 decode_create_maxsz + \
614 decode_getfh_maxsz + \
615 decode_getattr_maxsz + \
616 decode_restorefh_maxsz + \
617 decode_getattr_maxsz)
618 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
619 encode_sequence_maxsz + \
620 encode_putfh_maxsz + \
621 encode_getattr_maxsz)
622 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
623 decode_sequence_maxsz + \
624 decode_putfh_maxsz + \
625 decode_getattr_maxsz)
626 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
627 encode_sequence_maxsz + \
628 encode_putfh_maxsz + \
629 encode_statfs_maxsz)
630 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
631 decode_sequence_maxsz + \
632 decode_putfh_maxsz + \
633 decode_statfs_maxsz)
634 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
635 encode_sequence_maxsz + \
636 encode_putfh_maxsz + \
637 encode_getattr_maxsz)
638 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
639 decode_sequence_maxsz + \
640 decode_putfh_maxsz + \
641 decode_getattr_maxsz)
642 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
643 encode_sequence_maxsz + \
644 encode_putfh_maxsz + \
645 encode_delegreturn_maxsz + \
646 encode_getattr_maxsz)
647 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
648 decode_sequence_maxsz + \
649 decode_delegreturn_maxsz + \
650 decode_getattr_maxsz)
651 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
652 encode_sequence_maxsz + \
653 encode_putfh_maxsz + \
654 encode_getacl_maxsz)
655 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
656 decode_sequence_maxsz + \
657 decode_putfh_maxsz + \
658 decode_getacl_maxsz)
659 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
660 encode_sequence_maxsz + \
661 encode_putfh_maxsz + \
662 encode_setacl_maxsz)
663 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
664 decode_sequence_maxsz + \
665 decode_putfh_maxsz + \
666 decode_setacl_maxsz)
667 #define NFS4_enc_fs_locations_sz \
668 (compound_encode_hdr_maxsz + \
669 encode_sequence_maxsz + \
670 encode_putfh_maxsz + \
671 encode_lookup_maxsz + \
672 encode_fs_locations_maxsz)
673 #define NFS4_dec_fs_locations_sz \
674 (compound_decode_hdr_maxsz + \
675 decode_sequence_maxsz + \
676 decode_putfh_maxsz + \
677 decode_lookup_maxsz + \
678 decode_fs_locations_maxsz)
679 #if defined(CONFIG_NFS_V4_1)
680 #define NFS4_enc_exchange_id_sz \
681 (compound_encode_hdr_maxsz + \
682 encode_exchange_id_maxsz)
683 #define NFS4_dec_exchange_id_sz \
684 (compound_decode_hdr_maxsz + \
685 decode_exchange_id_maxsz)
686 #define NFS4_enc_create_session_sz \
687 (compound_encode_hdr_maxsz + \
688 encode_create_session_maxsz)
689 #define NFS4_dec_create_session_sz \
690 (compound_decode_hdr_maxsz + \
691 decode_create_session_maxsz)
692 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
693 encode_destroy_session_maxsz)
694 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
695 decode_destroy_session_maxsz)
696 #define NFS4_enc_sequence_sz \
697 (compound_decode_hdr_maxsz + \
698 encode_sequence_maxsz)
699 #define NFS4_dec_sequence_sz \
700 (compound_decode_hdr_maxsz + \
701 decode_sequence_maxsz)
702 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
703 encode_sequence_maxsz + \
704 encode_putrootfh_maxsz + \
705 encode_fsinfo_maxsz)
706 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
707 decode_sequence_maxsz + \
708 decode_putrootfh_maxsz + \
709 decode_fsinfo_maxsz)
710 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_reclaim_complete_maxsz)
713 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
714 decode_sequence_maxsz + \
715 decode_reclaim_complete_maxsz)
716 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
717 encode_sequence_maxsz +\
718 encode_getdeviceinfo_maxsz)
719 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
720 decode_sequence_maxsz + \
721 decode_getdeviceinfo_maxsz)
722 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_putfh_maxsz + \
725 encode_layoutget_maxsz)
726 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
727 decode_sequence_maxsz + \
728 decode_putfh_maxsz + \
729 decode_layoutget_maxsz)
731 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
732 compound_encode_hdr_maxsz +
733 encode_sequence_maxsz +
734 encode_putfh_maxsz +
735 encode_getattr_maxsz) *
736 XDR_UNIT);
738 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
739 compound_decode_hdr_maxsz +
740 decode_sequence_maxsz +
741 decode_putfh_maxsz) *
742 XDR_UNIT);
743 #endif /* CONFIG_NFS_V4_1 */
745 static const umode_t nfs_type2fmt[] = {
746 [NF4BAD] = 0,
747 [NF4REG] = S_IFREG,
748 [NF4DIR] = S_IFDIR,
749 [NF4BLK] = S_IFBLK,
750 [NF4CHR] = S_IFCHR,
751 [NF4LNK] = S_IFLNK,
752 [NF4SOCK] = S_IFSOCK,
753 [NF4FIFO] = S_IFIFO,
754 [NF4ATTRDIR] = 0,
755 [NF4NAMEDATTR] = 0,
758 struct compound_hdr {
759 int32_t status;
760 uint32_t nops;
761 __be32 * nops_p;
762 uint32_t taglen;
763 char * tag;
764 uint32_t replen; /* expected reply words */
765 u32 minorversion;
768 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
770 __be32 *p = xdr_reserve_space(xdr, nbytes);
771 BUG_ON(!p);
772 return p;
775 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
777 __be32 *p;
779 p = xdr_reserve_space(xdr, 4 + len);
780 BUG_ON(p == NULL);
781 xdr_encode_opaque(p, str, len);
784 static void encode_compound_hdr(struct xdr_stream *xdr,
785 struct rpc_rqst *req,
786 struct compound_hdr *hdr)
788 __be32 *p;
789 struct rpc_auth *auth = req->rq_cred->cr_auth;
791 /* initialize running count of expected bytes in reply.
792 * NOTE: the replied tag SHOULD be the same is the one sent,
793 * but this is not required as a MUST for the server to do so. */
794 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
796 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
797 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
798 p = reserve_space(xdr, 4 + hdr->taglen + 8);
799 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
800 *p++ = cpu_to_be32(hdr->minorversion);
801 hdr->nops_p = p;
802 *p = cpu_to_be32(hdr->nops);
805 static void encode_nops(struct compound_hdr *hdr)
807 BUG_ON(hdr->nops > NFS4_MAX_OPS);
808 *hdr->nops_p = htonl(hdr->nops);
811 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
813 __be32 *p;
815 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
816 BUG_ON(p == NULL);
817 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
820 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
822 char owner_name[IDMAP_NAMESZ];
823 char owner_group[IDMAP_NAMESZ];
824 int owner_namelen = 0;
825 int owner_grouplen = 0;
826 __be32 *p;
827 __be32 *q;
828 int len;
829 uint32_t bmval0 = 0;
830 uint32_t bmval1 = 0;
833 * We reserve enough space to write the entire attribute buffer at once.
834 * In the worst-case, this would be
835 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
836 * = 36 bytes, plus any contribution from variable-length fields
837 * such as owner/group.
839 len = 16;
841 /* Sigh */
842 if (iap->ia_valid & ATTR_SIZE)
843 len += 8;
844 if (iap->ia_valid & ATTR_MODE)
845 len += 4;
846 if (iap->ia_valid & ATTR_UID) {
847 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
848 if (owner_namelen < 0) {
849 dprintk("nfs: couldn't resolve uid %d to string\n",
850 iap->ia_uid);
851 /* XXX */
852 strcpy(owner_name, "nobody");
853 owner_namelen = sizeof("nobody") - 1;
854 /* goto out; */
856 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
858 if (iap->ia_valid & ATTR_GID) {
859 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
860 if (owner_grouplen < 0) {
861 dprintk("nfs: couldn't resolve gid %d to string\n",
862 iap->ia_gid);
863 strcpy(owner_group, "nobody");
864 owner_grouplen = sizeof("nobody") - 1;
865 /* goto out; */
867 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
869 if (iap->ia_valid & ATTR_ATIME_SET)
870 len += 16;
871 else if (iap->ia_valid & ATTR_ATIME)
872 len += 4;
873 if (iap->ia_valid & ATTR_MTIME_SET)
874 len += 16;
875 else if (iap->ia_valid & ATTR_MTIME)
876 len += 4;
877 p = reserve_space(xdr, len);
880 * We write the bitmap length now, but leave the bitmap and the attribute
881 * buffer length to be backfilled at the end of this routine.
883 *p++ = cpu_to_be32(2);
884 q = p;
885 p += 3;
887 if (iap->ia_valid & ATTR_SIZE) {
888 bmval0 |= FATTR4_WORD0_SIZE;
889 p = xdr_encode_hyper(p, iap->ia_size);
891 if (iap->ia_valid & ATTR_MODE) {
892 bmval1 |= FATTR4_WORD1_MODE;
893 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
895 if (iap->ia_valid & ATTR_UID) {
896 bmval1 |= FATTR4_WORD1_OWNER;
897 p = xdr_encode_opaque(p, owner_name, owner_namelen);
899 if (iap->ia_valid & ATTR_GID) {
900 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
901 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
903 if (iap->ia_valid & ATTR_ATIME_SET) {
904 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
905 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
906 *p++ = cpu_to_be32(0);
907 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
908 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
910 else if (iap->ia_valid & ATTR_ATIME) {
911 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
912 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
914 if (iap->ia_valid & ATTR_MTIME_SET) {
915 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
916 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
917 *p++ = cpu_to_be32(0);
918 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
919 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
921 else if (iap->ia_valid & ATTR_MTIME) {
922 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
923 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
927 * Now we backfill the bitmap and the attribute buffer length.
929 if (len != ((char *)p - (char *)q) + 4) {
930 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
931 len, ((char *)p - (char *)q) + 4);
932 BUG();
934 len = (char *)p - (char *)q - 12;
935 *q++ = htonl(bmval0);
936 *q++ = htonl(bmval1);
937 *q = htonl(len);
939 /* out: */
942 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
944 __be32 *p;
946 p = reserve_space(xdr, 8);
947 *p++ = cpu_to_be32(OP_ACCESS);
948 *p = cpu_to_be32(access);
949 hdr->nops++;
950 hdr->replen += decode_access_maxsz;
953 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
955 __be32 *p;
957 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
958 *p++ = cpu_to_be32(OP_CLOSE);
959 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
960 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
961 hdr->nops++;
962 hdr->replen += decode_close_maxsz;
965 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
967 __be32 *p;
969 p = reserve_space(xdr, 16);
970 *p++ = cpu_to_be32(OP_COMMIT);
971 p = xdr_encode_hyper(p, args->offset);
972 *p = cpu_to_be32(args->count);
973 hdr->nops++;
974 hdr->replen += decode_commit_maxsz;
977 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
979 __be32 *p;
981 p = reserve_space(xdr, 8);
982 *p++ = cpu_to_be32(OP_CREATE);
983 *p = cpu_to_be32(create->ftype);
985 switch (create->ftype) {
986 case NF4LNK:
987 p = reserve_space(xdr, 4);
988 *p = cpu_to_be32(create->u.symlink.len);
989 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
990 break;
992 case NF4BLK: case NF4CHR:
993 p = reserve_space(xdr, 8);
994 *p++ = cpu_to_be32(create->u.device.specdata1);
995 *p = cpu_to_be32(create->u.device.specdata2);
996 break;
998 default:
999 break;
1002 encode_string(xdr, create->name->len, create->name->name);
1003 hdr->nops++;
1004 hdr->replen += decode_create_maxsz;
1006 encode_attrs(xdr, create->attrs, create->server);
1009 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1011 __be32 *p;
1013 p = reserve_space(xdr, 12);
1014 *p++ = cpu_to_be32(OP_GETATTR);
1015 *p++ = cpu_to_be32(1);
1016 *p = cpu_to_be32(bitmap);
1017 hdr->nops++;
1018 hdr->replen += decode_getattr_maxsz;
1021 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1023 __be32 *p;
1025 p = reserve_space(xdr, 16);
1026 *p++ = cpu_to_be32(OP_GETATTR);
1027 *p++ = cpu_to_be32(2);
1028 *p++ = cpu_to_be32(bm0);
1029 *p = cpu_to_be32(bm1);
1030 hdr->nops++;
1031 hdr->replen += decode_getattr_maxsz;
1034 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1036 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1037 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1040 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1042 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1043 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1046 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1048 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1049 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1052 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1054 __be32 *p;
1056 p = reserve_space(xdr, 4);
1057 *p = cpu_to_be32(OP_GETFH);
1058 hdr->nops++;
1059 hdr->replen += decode_getfh_maxsz;
1062 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1064 __be32 *p;
1066 p = reserve_space(xdr, 8 + name->len);
1067 *p++ = cpu_to_be32(OP_LINK);
1068 xdr_encode_opaque(p, name->name, name->len);
1069 hdr->nops++;
1070 hdr->replen += decode_link_maxsz;
1073 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1075 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1076 return block ? NFS4_READW_LT : NFS4_READ_LT;
1077 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1080 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1082 if (fl->fl_end == OFFSET_MAX)
1083 return ~(uint64_t)0;
1084 return fl->fl_end - fl->fl_start + 1;
1087 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1089 __be32 *p;
1091 p = reserve_space(xdr, 32);
1092 p = xdr_encode_hyper(p, lowner->clientid);
1093 *p++ = cpu_to_be32(20);
1094 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1095 *p++ = cpu_to_be32(lowner->s_dev);
1096 xdr_encode_hyper(p, lowner->id);
1100 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1101 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1103 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1105 __be32 *p;
1107 p = reserve_space(xdr, 32);
1108 *p++ = cpu_to_be32(OP_LOCK);
1109 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1110 *p++ = cpu_to_be32(args->reclaim);
1111 p = xdr_encode_hyper(p, args->fl->fl_start);
1112 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1113 *p = cpu_to_be32(args->new_lock_owner);
1114 if (args->new_lock_owner){
1115 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1116 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1117 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1118 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1119 encode_lockowner(xdr, &args->lock_owner);
1121 else {
1122 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1123 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1124 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1126 hdr->nops++;
1127 hdr->replen += decode_lock_maxsz;
1130 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1132 __be32 *p;
1134 p = reserve_space(xdr, 24);
1135 *p++ = cpu_to_be32(OP_LOCKT);
1136 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1137 p = xdr_encode_hyper(p, args->fl->fl_start);
1138 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1139 encode_lockowner(xdr, &args->lock_owner);
1140 hdr->nops++;
1141 hdr->replen += decode_lockt_maxsz;
1144 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1146 __be32 *p;
1148 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1149 *p++ = cpu_to_be32(OP_LOCKU);
1150 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1151 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1152 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1153 p = xdr_encode_hyper(p, args->fl->fl_start);
1154 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1155 hdr->nops++;
1156 hdr->replen += decode_locku_maxsz;
1159 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1161 __be32 *p;
1163 p = reserve_space(xdr, 4);
1164 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1165 encode_lockowner(xdr, lowner);
1166 hdr->nops++;
1167 hdr->replen += decode_release_lockowner_maxsz;
1170 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1172 int len = name->len;
1173 __be32 *p;
1175 p = reserve_space(xdr, 8 + len);
1176 *p++ = cpu_to_be32(OP_LOOKUP);
1177 xdr_encode_opaque(p, name->name, len);
1178 hdr->nops++;
1179 hdr->replen += decode_lookup_maxsz;
1182 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1184 __be32 *p;
1186 p = reserve_space(xdr, 8);
1187 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1188 case FMODE_READ:
1189 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1190 break;
1191 case FMODE_WRITE:
1192 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1193 break;
1194 case FMODE_READ|FMODE_WRITE:
1195 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1196 break;
1197 default:
1198 *p++ = cpu_to_be32(0);
1200 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1203 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1205 __be32 *p;
1207 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1208 * owner 4 = 32
1210 p = reserve_space(xdr, 8);
1211 *p++ = cpu_to_be32(OP_OPEN);
1212 *p = cpu_to_be32(arg->seqid->sequence->counter);
1213 encode_share_access(xdr, arg->fmode);
1214 p = reserve_space(xdr, 32);
1215 p = xdr_encode_hyper(p, arg->clientid);
1216 *p++ = cpu_to_be32(20);
1217 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1218 *p++ = cpu_to_be32(arg->server->s_dev);
1219 xdr_encode_hyper(p, arg->id);
1222 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1224 __be32 *p;
1225 struct nfs_client *clp;
1227 p = reserve_space(xdr, 4);
1228 switch(arg->open_flags & O_EXCL) {
1229 case 0:
1230 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1231 encode_attrs(xdr, arg->u.attrs, arg->server);
1232 break;
1233 default:
1234 clp = arg->server->nfs_client;
1235 if (clp->cl_mvops->minor_version > 0) {
1236 if (nfs4_has_persistent_session(clp)) {
1237 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1238 encode_attrs(xdr, arg->u.attrs, arg->server);
1239 } else {
1240 struct iattr dummy;
1242 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1243 encode_nfs4_verifier(xdr, &arg->u.verifier);
1244 dummy.ia_valid = 0;
1245 encode_attrs(xdr, &dummy, arg->server);
1247 } else {
1248 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1249 encode_nfs4_verifier(xdr, &arg->u.verifier);
1254 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1256 __be32 *p;
1258 p = reserve_space(xdr, 4);
1259 switch (arg->open_flags & O_CREAT) {
1260 case 0:
1261 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1262 break;
1263 default:
1264 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1265 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1266 encode_createmode(xdr, arg);
1270 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1272 __be32 *p;
1274 p = reserve_space(xdr, 4);
1275 switch (delegation_type) {
1276 case 0:
1277 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1278 break;
1279 case FMODE_READ:
1280 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1281 break;
1282 case FMODE_WRITE|FMODE_READ:
1283 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1284 break;
1285 default:
1286 BUG();
1290 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1292 __be32 *p;
1294 p = reserve_space(xdr, 4);
1295 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1296 encode_string(xdr, name->len, name->name);
1299 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1301 __be32 *p;
1303 p = reserve_space(xdr, 4);
1304 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1305 encode_delegation_type(xdr, type);
1308 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1310 __be32 *p;
1312 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1313 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1314 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1315 encode_string(xdr, name->len, name->name);
1318 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1320 encode_openhdr(xdr, arg);
1321 encode_opentype(xdr, arg);
1322 switch (arg->claim) {
1323 case NFS4_OPEN_CLAIM_NULL:
1324 encode_claim_null(xdr, arg->name);
1325 break;
1326 case NFS4_OPEN_CLAIM_PREVIOUS:
1327 encode_claim_previous(xdr, arg->u.delegation_type);
1328 break;
1329 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1330 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1331 break;
1332 default:
1333 BUG();
1335 hdr->nops++;
1336 hdr->replen += decode_open_maxsz;
1339 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1341 __be32 *p;
1343 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1344 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1345 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1346 *p = cpu_to_be32(arg->seqid->sequence->counter);
1347 hdr->nops++;
1348 hdr->replen += decode_open_confirm_maxsz;
1351 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1353 __be32 *p;
1355 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1356 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1357 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1358 *p = cpu_to_be32(arg->seqid->sequence->counter);
1359 encode_share_access(xdr, arg->fmode);
1360 hdr->nops++;
1361 hdr->replen += decode_open_downgrade_maxsz;
1364 static void
1365 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1367 int len = fh->size;
1368 __be32 *p;
1370 p = reserve_space(xdr, 8 + len);
1371 *p++ = cpu_to_be32(OP_PUTFH);
1372 xdr_encode_opaque(p, fh->data, len);
1373 hdr->nops++;
1374 hdr->replen += decode_putfh_maxsz;
1377 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1379 __be32 *p;
1381 p = reserve_space(xdr, 4);
1382 *p = cpu_to_be32(OP_PUTROOTFH);
1383 hdr->nops++;
1384 hdr->replen += decode_putrootfh_maxsz;
1387 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx)
1389 nfs4_stateid stateid;
1390 __be32 *p;
1392 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1393 if (ctx->state != NULL) {
1394 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1395 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1396 } else
1397 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1400 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1402 __be32 *p;
1404 p = reserve_space(xdr, 4);
1405 *p = cpu_to_be32(OP_READ);
1407 encode_stateid(xdr, args->context, args->lock_context);
1409 p = reserve_space(xdr, 12);
1410 p = xdr_encode_hyper(p, args->offset);
1411 *p = cpu_to_be32(args->count);
1412 hdr->nops++;
1413 hdr->replen += decode_read_maxsz;
1416 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1418 uint32_t attrs[2] = {0, 0};
1419 uint32_t dircount = readdir->count >> 1;
1420 __be32 *p;
1422 if (readdir->plus) {
1423 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1424 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1425 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1426 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1427 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1428 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1429 dircount >>= 1;
1431 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1432 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
1433 /* Switch to mounted_on_fileid if the server supports it */
1434 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1435 attrs[0] &= ~FATTR4_WORD0_FILEID;
1436 else
1437 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1439 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1440 *p++ = cpu_to_be32(OP_READDIR);
1441 p = xdr_encode_hyper(p, readdir->cookie);
1442 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1443 *p++ = cpu_to_be32(dircount);
1444 *p++ = cpu_to_be32(readdir->count);
1445 *p++ = cpu_to_be32(2);
1447 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1448 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1449 hdr->nops++;
1450 hdr->replen += decode_readdir_maxsz;
1451 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1452 __func__,
1453 (unsigned long long)readdir->cookie,
1454 ((u32 *)readdir->verifier.data)[0],
1455 ((u32 *)readdir->verifier.data)[1],
1456 attrs[0] & readdir->bitmask[0],
1457 attrs[1] & readdir->bitmask[1]);
1460 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1462 __be32 *p;
1464 p = reserve_space(xdr, 4);
1465 *p = cpu_to_be32(OP_READLINK);
1466 hdr->nops++;
1467 hdr->replen += decode_readlink_maxsz;
1470 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1472 __be32 *p;
1474 p = reserve_space(xdr, 8 + name->len);
1475 *p++ = cpu_to_be32(OP_REMOVE);
1476 xdr_encode_opaque(p, name->name, name->len);
1477 hdr->nops++;
1478 hdr->replen += decode_remove_maxsz;
1481 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1483 __be32 *p;
1485 p = reserve_space(xdr, 4);
1486 *p = cpu_to_be32(OP_RENAME);
1487 encode_string(xdr, oldname->len, oldname->name);
1488 encode_string(xdr, newname->len, newname->name);
1489 hdr->nops++;
1490 hdr->replen += decode_rename_maxsz;
1493 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1495 __be32 *p;
1497 p = reserve_space(xdr, 12);
1498 *p++ = cpu_to_be32(OP_RENEW);
1499 xdr_encode_hyper(p, client_stateid->cl_clientid);
1500 hdr->nops++;
1501 hdr->replen += decode_renew_maxsz;
1504 static void
1505 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1507 __be32 *p;
1509 p = reserve_space(xdr, 4);
1510 *p = cpu_to_be32(OP_RESTOREFH);
1511 hdr->nops++;
1512 hdr->replen += decode_restorefh_maxsz;
1515 static void
1516 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1518 __be32 *p;
1520 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1521 *p++ = cpu_to_be32(OP_SETATTR);
1522 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1523 p = reserve_space(xdr, 2*4);
1524 *p++ = cpu_to_be32(1);
1525 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1526 BUG_ON(arg->acl_len % 4);
1527 p = reserve_space(xdr, 4);
1528 *p = cpu_to_be32(arg->acl_len);
1529 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1530 hdr->nops++;
1531 hdr->replen += decode_setacl_maxsz;
1534 static void
1535 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1537 __be32 *p;
1539 p = reserve_space(xdr, 4);
1540 *p = cpu_to_be32(OP_SAVEFH);
1541 hdr->nops++;
1542 hdr->replen += decode_savefh_maxsz;
1545 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1547 __be32 *p;
1549 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1550 *p++ = cpu_to_be32(OP_SETATTR);
1551 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1552 hdr->nops++;
1553 hdr->replen += decode_setattr_maxsz;
1554 encode_attrs(xdr, arg->iap, server);
1557 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1559 __be32 *p;
1561 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1562 *p++ = cpu_to_be32(OP_SETCLIENTID);
1563 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1565 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1566 p = reserve_space(xdr, 4);
1567 *p = cpu_to_be32(setclientid->sc_prog);
1568 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1569 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1570 p = reserve_space(xdr, 4);
1571 *p = cpu_to_be32(setclientid->sc_cb_ident);
1572 hdr->nops++;
1573 hdr->replen += decode_setclientid_maxsz;
1576 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1578 __be32 *p;
1580 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1581 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1582 p = xdr_encode_hyper(p, arg->clientid);
1583 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1584 hdr->nops++;
1585 hdr->replen += decode_setclientid_confirm_maxsz;
1588 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1590 __be32 *p;
1592 p = reserve_space(xdr, 4);
1593 *p = cpu_to_be32(OP_WRITE);
1595 encode_stateid(xdr, args->context, args->lock_context);
1597 p = reserve_space(xdr, 16);
1598 p = xdr_encode_hyper(p, args->offset);
1599 *p++ = cpu_to_be32(args->stable);
1600 *p = cpu_to_be32(args->count);
1602 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1603 hdr->nops++;
1604 hdr->replen += decode_write_maxsz;
1607 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1609 __be32 *p;
1611 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1613 *p++ = cpu_to_be32(OP_DELEGRETURN);
1614 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1615 hdr->nops++;
1616 hdr->replen += decode_delegreturn_maxsz;
1619 #if defined(CONFIG_NFS_V4_1)
1620 /* NFSv4.1 operations */
1621 static void encode_exchange_id(struct xdr_stream *xdr,
1622 struct nfs41_exchange_id_args *args,
1623 struct compound_hdr *hdr)
1625 __be32 *p;
1627 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1628 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1629 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1631 encode_string(xdr, args->id_len, args->id);
1633 p = reserve_space(xdr, 12);
1634 *p++ = cpu_to_be32(args->flags);
1635 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1636 *p = cpu_to_be32(0); /* zero length implementation id array */
1637 hdr->nops++;
1638 hdr->replen += decode_exchange_id_maxsz;
1641 static void encode_create_session(struct xdr_stream *xdr,
1642 struct nfs41_create_session_args *args,
1643 struct compound_hdr *hdr)
1645 __be32 *p;
1646 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1647 uint32_t len;
1648 struct nfs_client *clp = args->client;
1649 u32 max_resp_sz_cached;
1652 * Assumes OPEN is the biggest non-idempotent compound.
1653 * 2 is the verifier.
1655 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1656 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1658 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1659 clp->cl_ipaddr);
1661 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1662 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1663 p = xdr_encode_hyper(p, clp->cl_ex_clid);
1664 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1665 *p++ = cpu_to_be32(args->flags); /*flags */
1667 /* Fore Channel */
1668 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1669 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1670 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1671 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1672 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1673 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1674 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1676 /* Back Channel */
1677 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1678 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1679 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1680 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1681 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1682 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1683 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1685 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1686 *p++ = cpu_to_be32(1);
1687 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1689 /* authsys_parms rfc1831 */
1690 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1691 p = xdr_encode_opaque(p, machine_name, len);
1692 *p++ = cpu_to_be32(0); /* UID */
1693 *p++ = cpu_to_be32(0); /* GID */
1694 *p = cpu_to_be32(0); /* No more gids */
1695 hdr->nops++;
1696 hdr->replen += decode_create_session_maxsz;
1699 static void encode_destroy_session(struct xdr_stream *xdr,
1700 struct nfs4_session *session,
1701 struct compound_hdr *hdr)
1703 __be32 *p;
1704 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1705 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1706 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1707 hdr->nops++;
1708 hdr->replen += decode_destroy_session_maxsz;
1711 static void encode_reclaim_complete(struct xdr_stream *xdr,
1712 struct nfs41_reclaim_complete_args *args,
1713 struct compound_hdr *hdr)
1715 __be32 *p;
1717 p = reserve_space(xdr, 8);
1718 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1719 *p++ = cpu_to_be32(args->one_fs);
1720 hdr->nops++;
1721 hdr->replen += decode_reclaim_complete_maxsz;
1723 #endif /* CONFIG_NFS_V4_1 */
1725 static void encode_sequence(struct xdr_stream *xdr,
1726 const struct nfs4_sequence_args *args,
1727 struct compound_hdr *hdr)
1729 #if defined(CONFIG_NFS_V4_1)
1730 struct nfs4_session *session = args->sa_session;
1731 struct nfs4_slot_table *tp;
1732 struct nfs4_slot *slot;
1733 __be32 *p;
1735 if (!session)
1736 return;
1738 tp = &session->fc_slot_table;
1740 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1741 slot = tp->slots + args->sa_slotid;
1743 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1744 *p++ = cpu_to_be32(OP_SEQUENCE);
1747 * Sessionid + seqid + slotid + max slotid + cache_this
1749 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1750 "max_slotid=%d cache_this=%d\n",
1751 __func__,
1752 ((u32 *)session->sess_id.data)[0],
1753 ((u32 *)session->sess_id.data)[1],
1754 ((u32 *)session->sess_id.data)[2],
1755 ((u32 *)session->sess_id.data)[3],
1756 slot->seq_nr, args->sa_slotid,
1757 tp->highest_used_slotid, args->sa_cache_this);
1758 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1759 *p++ = cpu_to_be32(slot->seq_nr);
1760 *p++ = cpu_to_be32(args->sa_slotid);
1761 *p++ = cpu_to_be32(tp->highest_used_slotid);
1762 *p = cpu_to_be32(args->sa_cache_this);
1763 hdr->nops++;
1764 hdr->replen += decode_sequence_maxsz;
1765 #endif /* CONFIG_NFS_V4_1 */
1768 #ifdef CONFIG_NFS_V4_1
1769 static void
1770 encode_getdeviceinfo(struct xdr_stream *xdr,
1771 const struct nfs4_getdeviceinfo_args *args,
1772 struct compound_hdr *hdr)
1774 __be32 *p;
1776 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1777 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1778 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1779 NFS4_DEVICEID4_SIZE);
1780 *p++ = cpu_to_be32(args->pdev->layout_type);
1781 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1782 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1783 hdr->nops++;
1784 hdr->replen += decode_getdeviceinfo_maxsz;
1787 static void
1788 encode_layoutget(struct xdr_stream *xdr,
1789 const struct nfs4_layoutget_args *args,
1790 struct compound_hdr *hdr)
1792 __be32 *p;
1794 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1795 *p++ = cpu_to_be32(OP_LAYOUTGET);
1796 *p++ = cpu_to_be32(0); /* Signal layout available */
1797 *p++ = cpu_to_be32(args->type);
1798 *p++ = cpu_to_be32(args->range.iomode);
1799 p = xdr_encode_hyper(p, args->range.offset);
1800 p = xdr_encode_hyper(p, args->range.length);
1801 p = xdr_encode_hyper(p, args->minlength);
1802 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1803 *p = cpu_to_be32(args->maxcount);
1805 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1806 __func__,
1807 args->type,
1808 args->range.iomode,
1809 (unsigned long)args->range.offset,
1810 (unsigned long)args->range.length,
1811 args->maxcount);
1812 hdr->nops++;
1813 hdr->replen += decode_layoutget_maxsz;
1815 #endif /* CONFIG_NFS_V4_1 */
1818 * END OF "GENERIC" ENCODE ROUTINES.
1821 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1823 #if defined(CONFIG_NFS_V4_1)
1824 if (args->sa_session)
1825 return args->sa_session->clp->cl_mvops->minor_version;
1826 #endif /* CONFIG_NFS_V4_1 */
1827 return 0;
1831 * Encode an ACCESS request
1833 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1834 const struct nfs4_accessargs *args)
1836 struct compound_hdr hdr = {
1837 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1840 encode_compound_hdr(xdr, req, &hdr);
1841 encode_sequence(xdr, &args->seq_args, &hdr);
1842 encode_putfh(xdr, args->fh, &hdr);
1843 encode_access(xdr, args->access, &hdr);
1844 encode_getfattr(xdr, args->bitmask, &hdr);
1845 encode_nops(&hdr);
1849 * Encode LOOKUP request
1851 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1852 const struct nfs4_lookup_arg *args)
1854 struct compound_hdr hdr = {
1855 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1858 encode_compound_hdr(xdr, req, &hdr);
1859 encode_sequence(xdr, &args->seq_args, &hdr);
1860 encode_putfh(xdr, args->dir_fh, &hdr);
1861 encode_lookup(xdr, args->name, &hdr);
1862 encode_getfh(xdr, &hdr);
1863 encode_getfattr(xdr, args->bitmask, &hdr);
1864 encode_nops(&hdr);
1868 * Encode LOOKUP_ROOT request
1870 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1871 struct xdr_stream *xdr,
1872 const struct nfs4_lookup_root_arg *args)
1874 struct compound_hdr hdr = {
1875 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1878 encode_compound_hdr(xdr, req, &hdr);
1879 encode_sequence(xdr, &args->seq_args, &hdr);
1880 encode_putrootfh(xdr, &hdr);
1881 encode_getfh(xdr, &hdr);
1882 encode_getfattr(xdr, args->bitmask, &hdr);
1883 encode_nops(&hdr);
1887 * Encode REMOVE request
1889 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1890 const struct nfs_removeargs *args)
1892 struct compound_hdr hdr = {
1893 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1896 encode_compound_hdr(xdr, req, &hdr);
1897 encode_sequence(xdr, &args->seq_args, &hdr);
1898 encode_putfh(xdr, args->fh, &hdr);
1899 encode_remove(xdr, &args->name, &hdr);
1900 encode_getfattr(xdr, args->bitmask, &hdr);
1901 encode_nops(&hdr);
1905 * Encode RENAME request
1907 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1908 const struct nfs_renameargs *args)
1910 struct compound_hdr hdr = {
1911 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1914 encode_compound_hdr(xdr, req, &hdr);
1915 encode_sequence(xdr, &args->seq_args, &hdr);
1916 encode_putfh(xdr, args->old_dir, &hdr);
1917 encode_savefh(xdr, &hdr);
1918 encode_putfh(xdr, args->new_dir, &hdr);
1919 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1920 encode_getfattr(xdr, args->bitmask, &hdr);
1921 encode_restorefh(xdr, &hdr);
1922 encode_getfattr(xdr, args->bitmask, &hdr);
1923 encode_nops(&hdr);
1927 * Encode LINK request
1929 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1930 const struct nfs4_link_arg *args)
1932 struct compound_hdr hdr = {
1933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1936 encode_compound_hdr(xdr, req, &hdr);
1937 encode_sequence(xdr, &args->seq_args, &hdr);
1938 encode_putfh(xdr, args->fh, &hdr);
1939 encode_savefh(xdr, &hdr);
1940 encode_putfh(xdr, args->dir_fh, &hdr);
1941 encode_link(xdr, args->name, &hdr);
1942 encode_getfattr(xdr, args->bitmask, &hdr);
1943 encode_restorefh(xdr, &hdr);
1944 encode_getfattr(xdr, args->bitmask, &hdr);
1945 encode_nops(&hdr);
1949 * Encode CREATE request
1951 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
1952 const struct nfs4_create_arg *args)
1954 struct compound_hdr hdr = {
1955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1958 encode_compound_hdr(xdr, req, &hdr);
1959 encode_sequence(xdr, &args->seq_args, &hdr);
1960 encode_putfh(xdr, args->dir_fh, &hdr);
1961 encode_savefh(xdr, &hdr);
1962 encode_create(xdr, args, &hdr);
1963 encode_getfh(xdr, &hdr);
1964 encode_getfattr(xdr, args->bitmask, &hdr);
1965 encode_restorefh(xdr, &hdr);
1966 encode_getfattr(xdr, args->bitmask, &hdr);
1967 encode_nops(&hdr);
1971 * Encode SYMLINK request
1973 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
1974 const struct nfs4_create_arg *args)
1976 nfs4_xdr_enc_create(req, xdr, args);
1980 * Encode GETATTR request
1982 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1983 const struct nfs4_getattr_arg *args)
1985 struct compound_hdr hdr = {
1986 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1989 encode_compound_hdr(xdr, req, &hdr);
1990 encode_sequence(xdr, &args->seq_args, &hdr);
1991 encode_putfh(xdr, args->fh, &hdr);
1992 encode_getfattr(xdr, args->bitmask, &hdr);
1993 encode_nops(&hdr);
1997 * Encode a CLOSE request
1999 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2000 struct nfs_closeargs *args)
2002 struct compound_hdr hdr = {
2003 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2006 encode_compound_hdr(xdr, req, &hdr);
2007 encode_sequence(xdr, &args->seq_args, &hdr);
2008 encode_putfh(xdr, args->fh, &hdr);
2009 encode_close(xdr, args, &hdr);
2010 encode_getfattr(xdr, args->bitmask, &hdr);
2011 encode_nops(&hdr);
2015 * Encode an OPEN request
2017 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2018 struct nfs_openargs *args)
2020 struct compound_hdr hdr = {
2021 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2024 encode_compound_hdr(xdr, req, &hdr);
2025 encode_sequence(xdr, &args->seq_args, &hdr);
2026 encode_putfh(xdr, args->fh, &hdr);
2027 encode_savefh(xdr, &hdr);
2028 encode_open(xdr, args, &hdr);
2029 encode_getfh(xdr, &hdr);
2030 encode_getfattr(xdr, args->bitmask, &hdr);
2031 encode_restorefh(xdr, &hdr);
2032 encode_getfattr(xdr, args->bitmask, &hdr);
2033 encode_nops(&hdr);
2037 * Encode an OPEN_CONFIRM request
2039 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2040 struct xdr_stream *xdr,
2041 struct nfs_open_confirmargs *args)
2043 struct compound_hdr hdr = {
2044 .nops = 0,
2047 encode_compound_hdr(xdr, req, &hdr);
2048 encode_putfh(xdr, args->fh, &hdr);
2049 encode_open_confirm(xdr, args, &hdr);
2050 encode_nops(&hdr);
2054 * Encode an OPEN request with no attributes.
2056 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2057 struct xdr_stream *xdr,
2058 struct nfs_openargs *args)
2060 struct compound_hdr hdr = {
2061 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2064 encode_compound_hdr(xdr, req, &hdr);
2065 encode_sequence(xdr, &args->seq_args, &hdr);
2066 encode_putfh(xdr, args->fh, &hdr);
2067 encode_open(xdr, args, &hdr);
2068 encode_getfattr(xdr, args->bitmask, &hdr);
2069 encode_nops(&hdr);
2073 * Encode an OPEN_DOWNGRADE request
2075 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2076 struct xdr_stream *xdr,
2077 struct nfs_closeargs *args)
2079 struct compound_hdr hdr = {
2080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2083 encode_compound_hdr(xdr, req, &hdr);
2084 encode_sequence(xdr, &args->seq_args, &hdr);
2085 encode_putfh(xdr, args->fh, &hdr);
2086 encode_open_downgrade(xdr, args, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
2088 encode_nops(&hdr);
2092 * Encode a LOCK request
2094 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2095 struct nfs_lock_args *args)
2097 struct compound_hdr hdr = {
2098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2101 encode_compound_hdr(xdr, req, &hdr);
2102 encode_sequence(xdr, &args->seq_args, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_lock(xdr, args, &hdr);
2105 encode_nops(&hdr);
2109 * Encode a LOCKT request
2111 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 struct nfs_lockt_args *args)
2114 struct compound_hdr hdr = {
2115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->fh, &hdr);
2121 encode_lockt(xdr, args, &hdr);
2122 encode_nops(&hdr);
2126 * Encode a LOCKU request
2128 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2129 struct nfs_locku_args *args)
2131 struct compound_hdr hdr = {
2132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2135 encode_compound_hdr(xdr, req, &hdr);
2136 encode_sequence(xdr, &args->seq_args, &hdr);
2137 encode_putfh(xdr, args->fh, &hdr);
2138 encode_locku(xdr, args, &hdr);
2139 encode_nops(&hdr);
2142 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2143 struct xdr_stream *xdr,
2144 struct nfs_release_lockowner_args *args)
2146 struct compound_hdr hdr = {
2147 .minorversion = 0,
2150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2152 encode_nops(&hdr);
2156 * Encode a READLINK request
2158 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs4_readlink *args)
2161 struct compound_hdr hdr = {
2162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_readlink(xdr, args, req, &hdr);
2170 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2171 args->pgbase, args->pglen);
2172 encode_nops(&hdr);
2176 * Encode a READDIR request
2178 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 const struct nfs4_readdir_arg *args)
2181 struct compound_hdr hdr = {
2182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->fh, &hdr);
2188 encode_readdir(xdr, args, req, &hdr);
2190 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2191 args->pgbase, args->count);
2192 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2193 __func__, hdr.replen << 2, args->pages,
2194 args->pgbase, args->count);
2195 encode_nops(&hdr);
2199 * Encode a READ request
2201 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2202 struct nfs_readargs *args)
2204 struct compound_hdr hdr = {
2205 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2208 encode_compound_hdr(xdr, req, &hdr);
2209 encode_sequence(xdr, &args->seq_args, &hdr);
2210 encode_putfh(xdr, args->fh, &hdr);
2211 encode_read(xdr, args, &hdr);
2213 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2214 args->pages, args->pgbase, args->count);
2215 req->rq_rcv_buf.flags |= XDRBUF_READ;
2216 encode_nops(&hdr);
2220 * Encode an SETATTR request
2222 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2223 struct nfs_setattrargs *args)
2225 struct compound_hdr hdr = {
2226 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2229 encode_compound_hdr(xdr, req, &hdr);
2230 encode_sequence(xdr, &args->seq_args, &hdr);
2231 encode_putfh(xdr, args->fh, &hdr);
2232 encode_setattr(xdr, args, args->server, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
2234 encode_nops(&hdr);
2238 * Encode a GETACL request
2240 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2241 struct nfs_getaclargs *args)
2243 struct compound_hdr hdr = {
2244 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2246 uint32_t replen;
2248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
2251 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2252 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2254 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2255 args->acl_pages, args->acl_pgbase, args->acl_len);
2256 encode_nops(&hdr);
2260 * Encode a WRITE request
2262 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2263 struct nfs_writeargs *args)
2265 struct compound_hdr hdr = {
2266 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2269 encode_compound_hdr(xdr, req, &hdr);
2270 encode_sequence(xdr, &args->seq_args, &hdr);
2271 encode_putfh(xdr, args->fh, &hdr);
2272 encode_write(xdr, args, &hdr);
2273 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2274 encode_getfattr(xdr, args->bitmask, &hdr);
2275 encode_nops(&hdr);
2279 * a COMMIT request
2281 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2282 struct nfs_writeargs *args)
2284 struct compound_hdr hdr = {
2285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_sequence(xdr, &args->seq_args, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
2291 encode_commit(xdr, args, &hdr);
2292 encode_getfattr(xdr, args->bitmask, &hdr);
2293 encode_nops(&hdr);
2297 * FSINFO request
2299 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2300 struct nfs4_fsinfo_arg *args)
2302 struct compound_hdr hdr = {
2303 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2306 encode_compound_hdr(xdr, req, &hdr);
2307 encode_sequence(xdr, &args->seq_args, &hdr);
2308 encode_putfh(xdr, args->fh, &hdr);
2309 encode_fsinfo(xdr, args->bitmask, &hdr);
2310 encode_nops(&hdr);
2314 * a PATHCONF request
2316 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2317 const struct nfs4_pathconf_arg *args)
2319 struct compound_hdr hdr = {
2320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_sequence(xdr, &args->seq_args, &hdr);
2325 encode_putfh(xdr, args->fh, &hdr);
2326 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2327 &hdr);
2328 encode_nops(&hdr);
2332 * a STATFS request
2334 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2335 const struct nfs4_statfs_arg *args)
2337 struct compound_hdr hdr = {
2338 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2341 encode_compound_hdr(xdr, req, &hdr);
2342 encode_sequence(xdr, &args->seq_args, &hdr);
2343 encode_putfh(xdr, args->fh, &hdr);
2344 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2345 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2346 encode_nops(&hdr);
2350 * GETATTR_BITMAP request
2352 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2353 struct xdr_stream *xdr,
2354 struct nfs4_server_caps_arg *args)
2356 struct compound_hdr hdr = {
2357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2360 encode_compound_hdr(xdr, req, &hdr);
2361 encode_sequence(xdr, &args->seq_args, &hdr);
2362 encode_putfh(xdr, args->fhandle, &hdr);
2363 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2364 FATTR4_WORD0_LINK_SUPPORT|
2365 FATTR4_WORD0_SYMLINK_SUPPORT|
2366 FATTR4_WORD0_ACLSUPPORT, &hdr);
2367 encode_nops(&hdr);
2371 * a RENEW request
2373 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2374 struct nfs_client *clp)
2376 struct compound_hdr hdr = {
2377 .nops = 0,
2380 encode_compound_hdr(xdr, req, &hdr);
2381 encode_renew(xdr, clp, &hdr);
2382 encode_nops(&hdr);
2386 * a SETCLIENTID request
2388 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2389 struct xdr_stream *xdr,
2390 struct nfs4_setclientid *sc)
2392 struct compound_hdr hdr = {
2393 .nops = 0,
2396 encode_compound_hdr(xdr, req, &hdr);
2397 encode_setclientid(xdr, sc, &hdr);
2398 encode_nops(&hdr);
2402 * a SETCLIENTID_CONFIRM request
2404 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2405 struct xdr_stream *xdr,
2406 struct nfs4_setclientid_res *arg)
2408 struct compound_hdr hdr = {
2409 .nops = 0,
2411 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2413 encode_compound_hdr(xdr, req, &hdr);
2414 encode_setclientid_confirm(xdr, arg, &hdr);
2415 encode_putrootfh(xdr, &hdr);
2416 encode_fsinfo(xdr, lease_bitmap, &hdr);
2417 encode_nops(&hdr);
2421 * DELEGRETURN request
2423 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2424 struct xdr_stream *xdr,
2425 const struct nfs4_delegreturnargs *args)
2427 struct compound_hdr hdr = {
2428 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2431 encode_compound_hdr(xdr, req, &hdr);
2432 encode_sequence(xdr, &args->seq_args, &hdr);
2433 encode_putfh(xdr, args->fhandle, &hdr);
2434 encode_delegreturn(xdr, args->stateid, &hdr);
2435 encode_getfattr(xdr, args->bitmask, &hdr);
2436 encode_nops(&hdr);
2440 * Encode FS_LOCATIONS request
2442 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2443 struct xdr_stream *xdr,
2444 struct nfs4_fs_locations_arg *args)
2446 struct compound_hdr hdr = {
2447 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2449 uint32_t replen;
2451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->dir_fh, &hdr);
2454 encode_lookup(xdr, args->name, &hdr);
2455 replen = hdr.replen; /* get the attribute into args->page */
2456 encode_fs_locations(xdr, args->bitmask, &hdr);
2458 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2459 0, PAGE_SIZE);
2460 encode_nops(&hdr);
2463 #if defined(CONFIG_NFS_V4_1)
2465 * EXCHANGE_ID request
2467 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2468 struct xdr_stream *xdr,
2469 struct nfs41_exchange_id_args *args)
2471 struct compound_hdr hdr = {
2472 .minorversion = args->client->cl_mvops->minor_version,
2475 encode_compound_hdr(xdr, req, &hdr);
2476 encode_exchange_id(xdr, args, &hdr);
2477 encode_nops(&hdr);
2481 * a CREATE_SESSION request
2483 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2484 struct xdr_stream *xdr,
2485 struct nfs41_create_session_args *args)
2487 struct compound_hdr hdr = {
2488 .minorversion = args->client->cl_mvops->minor_version,
2491 encode_compound_hdr(xdr, req, &hdr);
2492 encode_create_session(xdr, args, &hdr);
2493 encode_nops(&hdr);
2497 * a DESTROY_SESSION request
2499 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2500 struct xdr_stream *xdr,
2501 struct nfs4_session *session)
2503 struct compound_hdr hdr = {
2504 .minorversion = session->clp->cl_mvops->minor_version,
2507 encode_compound_hdr(xdr, req, &hdr);
2508 encode_destroy_session(xdr, session, &hdr);
2509 encode_nops(&hdr);
2513 * a SEQUENCE request
2515 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 struct nfs4_sequence_args *args)
2518 struct compound_hdr hdr = {
2519 .minorversion = nfs4_xdr_minorversion(args),
2522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, args, &hdr);
2524 encode_nops(&hdr);
2528 * a GET_LEASE_TIME request
2530 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2531 struct xdr_stream *xdr,
2532 struct nfs4_get_lease_time_args *args)
2534 struct compound_hdr hdr = {
2535 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2537 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2539 encode_compound_hdr(xdr, req, &hdr);
2540 encode_sequence(xdr, &args->la_seq_args, &hdr);
2541 encode_putrootfh(xdr, &hdr);
2542 encode_fsinfo(xdr, lease_bitmap, &hdr);
2543 encode_nops(&hdr);
2547 * a RECLAIM_COMPLETE request
2549 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2550 struct xdr_stream *xdr,
2551 struct nfs41_reclaim_complete_args *args)
2553 struct compound_hdr hdr = {
2554 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2557 encode_compound_hdr(xdr, req, &hdr);
2558 encode_sequence(xdr, &args->seq_args, &hdr);
2559 encode_reclaim_complete(xdr, args, &hdr);
2560 encode_nops(&hdr);
2564 * Encode GETDEVICEINFO request
2566 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2567 struct xdr_stream *xdr,
2568 struct nfs4_getdeviceinfo_args *args)
2570 struct compound_hdr hdr = {
2571 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2574 encode_compound_hdr(xdr, req, &hdr);
2575 encode_sequence(xdr, &args->seq_args, &hdr);
2576 encode_getdeviceinfo(xdr, args, &hdr);
2578 /* set up reply kvec. Subtract notification bitmap max size (2)
2579 * so that notification bitmap is put in xdr_buf tail */
2580 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2581 args->pdev->pages, args->pdev->pgbase,
2582 args->pdev->pglen);
2584 encode_nops(&hdr);
2588 * Encode LAYOUTGET request
2590 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2591 struct xdr_stream *xdr,
2592 struct nfs4_layoutget_args *args)
2594 struct compound_hdr hdr = {
2595 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2598 encode_compound_hdr(xdr, req, &hdr);
2599 encode_sequence(xdr, &args->seq_args, &hdr);
2600 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2601 encode_layoutget(xdr, args, &hdr);
2602 encode_nops(&hdr);
2604 #endif /* CONFIG_NFS_V4_1 */
2606 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2608 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2609 "Remaining buffer length is %tu words.\n",
2610 func, xdr->end - xdr->p);
2613 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2615 __be32 *p;
2617 p = xdr_inline_decode(xdr, 4);
2618 if (unlikely(!p))
2619 goto out_overflow;
2620 *len = be32_to_cpup(p);
2621 p = xdr_inline_decode(xdr, *len);
2622 if (unlikely(!p))
2623 goto out_overflow;
2624 *string = (char *)p;
2625 return 0;
2626 out_overflow:
2627 print_overflow_msg(__func__, xdr);
2628 return -EIO;
2631 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2633 __be32 *p;
2635 p = xdr_inline_decode(xdr, 8);
2636 if (unlikely(!p))
2637 goto out_overflow;
2638 hdr->status = be32_to_cpup(p++);
2639 hdr->taglen = be32_to_cpup(p);
2641 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2642 if (unlikely(!p))
2643 goto out_overflow;
2644 hdr->tag = (char *)p;
2645 p += XDR_QUADLEN(hdr->taglen);
2646 hdr->nops = be32_to_cpup(p);
2647 if (unlikely(hdr->nops < 1))
2648 return nfs4_stat_to_errno(hdr->status);
2649 return 0;
2650 out_overflow:
2651 print_overflow_msg(__func__, xdr);
2652 return -EIO;
2655 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2657 __be32 *p;
2658 uint32_t opnum;
2659 int32_t nfserr;
2661 p = xdr_inline_decode(xdr, 8);
2662 if (unlikely(!p))
2663 goto out_overflow;
2664 opnum = be32_to_cpup(p++);
2665 if (opnum != expected) {
2666 dprintk("nfs: Server returned operation"
2667 " %d but we issued a request for %d\n",
2668 opnum, expected);
2669 return -EIO;
2671 nfserr = be32_to_cpup(p);
2672 if (nfserr != NFS_OK)
2673 return nfs4_stat_to_errno(nfserr);
2674 return 0;
2675 out_overflow:
2676 print_overflow_msg(__func__, xdr);
2677 return -EIO;
2680 /* Dummy routine */
2681 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2683 __be32 *p;
2684 unsigned int strlen;
2685 char *str;
2687 p = xdr_inline_decode(xdr, 12);
2688 if (likely(p))
2689 return decode_opaque_inline(xdr, &strlen, &str);
2690 print_overflow_msg(__func__, xdr);
2691 return -EIO;
2694 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2696 uint32_t bmlen;
2697 __be32 *p;
2699 p = xdr_inline_decode(xdr, 4);
2700 if (unlikely(!p))
2701 goto out_overflow;
2702 bmlen = be32_to_cpup(p);
2704 bitmap[0] = bitmap[1] = 0;
2705 p = xdr_inline_decode(xdr, (bmlen << 2));
2706 if (unlikely(!p))
2707 goto out_overflow;
2708 if (bmlen > 0) {
2709 bitmap[0] = be32_to_cpup(p++);
2710 if (bmlen > 1)
2711 bitmap[1] = be32_to_cpup(p);
2713 return 0;
2714 out_overflow:
2715 print_overflow_msg(__func__, xdr);
2716 return -EIO;
2719 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2721 __be32 *p;
2723 p = xdr_inline_decode(xdr, 4);
2724 if (unlikely(!p))
2725 goto out_overflow;
2726 *attrlen = be32_to_cpup(p);
2727 *savep = xdr->p;
2728 return 0;
2729 out_overflow:
2730 print_overflow_msg(__func__, xdr);
2731 return -EIO;
2734 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2736 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2737 int ret;
2738 ret = decode_attr_bitmap(xdr, bitmask);
2739 if (unlikely(ret < 0))
2740 return ret;
2741 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2742 } else
2743 bitmask[0] = bitmask[1] = 0;
2744 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2745 return 0;
2748 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2750 __be32 *p;
2751 int ret = 0;
2753 *type = 0;
2754 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2755 return -EIO;
2756 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2757 p = xdr_inline_decode(xdr, 4);
2758 if (unlikely(!p))
2759 goto out_overflow;
2760 *type = be32_to_cpup(p);
2761 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2762 dprintk("%s: bad type %d\n", __func__, *type);
2763 return -EIO;
2765 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2766 ret = NFS_ATTR_FATTR_TYPE;
2768 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2769 return ret;
2770 out_overflow:
2771 print_overflow_msg(__func__, xdr);
2772 return -EIO;
2775 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2777 __be32 *p;
2778 int ret = 0;
2780 *change = 0;
2781 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2782 return -EIO;
2783 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2784 p = xdr_inline_decode(xdr, 8);
2785 if (unlikely(!p))
2786 goto out_overflow;
2787 xdr_decode_hyper(p, change);
2788 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2789 ret = NFS_ATTR_FATTR_CHANGE;
2791 dprintk("%s: change attribute=%Lu\n", __func__,
2792 (unsigned long long)*change);
2793 return ret;
2794 out_overflow:
2795 print_overflow_msg(__func__, xdr);
2796 return -EIO;
2799 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2801 __be32 *p;
2802 int ret = 0;
2804 *size = 0;
2805 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2806 return -EIO;
2807 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2808 p = xdr_inline_decode(xdr, 8);
2809 if (unlikely(!p))
2810 goto out_overflow;
2811 xdr_decode_hyper(p, size);
2812 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2813 ret = NFS_ATTR_FATTR_SIZE;
2815 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2816 return ret;
2817 out_overflow:
2818 print_overflow_msg(__func__, xdr);
2819 return -EIO;
2822 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2824 __be32 *p;
2826 *res = 0;
2827 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2828 return -EIO;
2829 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2830 p = xdr_inline_decode(xdr, 4);
2831 if (unlikely(!p))
2832 goto out_overflow;
2833 *res = be32_to_cpup(p);
2834 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2836 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2837 return 0;
2838 out_overflow:
2839 print_overflow_msg(__func__, xdr);
2840 return -EIO;
2843 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2845 __be32 *p;
2847 *res = 0;
2848 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2849 return -EIO;
2850 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2851 p = xdr_inline_decode(xdr, 4);
2852 if (unlikely(!p))
2853 goto out_overflow;
2854 *res = be32_to_cpup(p);
2855 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2857 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2858 return 0;
2859 out_overflow:
2860 print_overflow_msg(__func__, xdr);
2861 return -EIO;
2864 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2866 __be32 *p;
2867 int ret = 0;
2869 fsid->major = 0;
2870 fsid->minor = 0;
2871 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2872 return -EIO;
2873 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2874 p = xdr_inline_decode(xdr, 16);
2875 if (unlikely(!p))
2876 goto out_overflow;
2877 p = xdr_decode_hyper(p, &fsid->major);
2878 xdr_decode_hyper(p, &fsid->minor);
2879 bitmap[0] &= ~FATTR4_WORD0_FSID;
2880 ret = NFS_ATTR_FATTR_FSID;
2882 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2883 (unsigned long long)fsid->major,
2884 (unsigned long long)fsid->minor);
2885 return ret;
2886 out_overflow:
2887 print_overflow_msg(__func__, xdr);
2888 return -EIO;
2891 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2893 __be32 *p;
2895 *res = 60;
2896 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2897 return -EIO;
2898 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2899 p = xdr_inline_decode(xdr, 4);
2900 if (unlikely(!p))
2901 goto out_overflow;
2902 *res = be32_to_cpup(p);
2903 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2905 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2906 return 0;
2907 out_overflow:
2908 print_overflow_msg(__func__, xdr);
2909 return -EIO;
2912 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2914 __be32 *p;
2916 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2917 return -EIO;
2918 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2919 p = xdr_inline_decode(xdr, 4);
2920 if (unlikely(!p))
2921 goto out_overflow;
2922 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
2924 return 0;
2925 out_overflow:
2926 print_overflow_msg(__func__, xdr);
2927 return -EIO;
2930 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2932 __be32 *p;
2933 int len;
2935 if (fh != NULL)
2936 memset(fh, 0, sizeof(*fh));
2938 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2939 return -EIO;
2940 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2941 p = xdr_inline_decode(xdr, 4);
2942 if (unlikely(!p))
2943 goto out_overflow;
2944 len = be32_to_cpup(p);
2945 if (len > NFS4_FHSIZE)
2946 return -EIO;
2947 p = xdr_inline_decode(xdr, len);
2948 if (unlikely(!p))
2949 goto out_overflow;
2950 if (fh != NULL) {
2951 memcpy(fh->data, p, len);
2952 fh->size = len;
2954 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
2956 return 0;
2957 out_overflow:
2958 print_overflow_msg(__func__, xdr);
2959 return -EIO;
2962 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2964 __be32 *p;
2966 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2967 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2968 return -EIO;
2969 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2970 p = xdr_inline_decode(xdr, 4);
2971 if (unlikely(!p))
2972 goto out_overflow;
2973 *res = be32_to_cpup(p);
2974 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2976 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2977 return 0;
2978 out_overflow:
2979 print_overflow_msg(__func__, xdr);
2980 return -EIO;
2983 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2985 __be32 *p;
2986 int ret = 0;
2988 *fileid = 0;
2989 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2990 return -EIO;
2991 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2992 p = xdr_inline_decode(xdr, 8);
2993 if (unlikely(!p))
2994 goto out_overflow;
2995 xdr_decode_hyper(p, fileid);
2996 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2997 ret = NFS_ATTR_FATTR_FILEID;
2999 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3000 return ret;
3001 out_overflow:
3002 print_overflow_msg(__func__, xdr);
3003 return -EIO;
3006 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3008 __be32 *p;
3009 int ret = 0;
3011 *fileid = 0;
3012 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3013 return -EIO;
3014 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3015 p = xdr_inline_decode(xdr, 8);
3016 if (unlikely(!p))
3017 goto out_overflow;
3018 xdr_decode_hyper(p, fileid);
3019 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3020 ret = NFS_ATTR_FATTR_FILEID;
3022 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3023 return ret;
3024 out_overflow:
3025 print_overflow_msg(__func__, xdr);
3026 return -EIO;
3029 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3031 __be32 *p;
3032 int status = 0;
3034 *res = 0;
3035 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3036 return -EIO;
3037 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3038 p = xdr_inline_decode(xdr, 8);
3039 if (unlikely(!p))
3040 goto out_overflow;
3041 xdr_decode_hyper(p, res);
3042 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3044 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3045 return status;
3046 out_overflow:
3047 print_overflow_msg(__func__, xdr);
3048 return -EIO;
3051 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3053 __be32 *p;
3054 int status = 0;
3056 *res = 0;
3057 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3058 return -EIO;
3059 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3060 p = xdr_inline_decode(xdr, 8);
3061 if (unlikely(!p))
3062 goto out_overflow;
3063 xdr_decode_hyper(p, res);
3064 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3066 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3067 return status;
3068 out_overflow:
3069 print_overflow_msg(__func__, xdr);
3070 return -EIO;
3073 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3075 __be32 *p;
3076 int status = 0;
3078 *res = 0;
3079 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3080 return -EIO;
3081 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3082 p = xdr_inline_decode(xdr, 8);
3083 if (unlikely(!p))
3084 goto out_overflow;
3085 xdr_decode_hyper(p, res);
3086 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3088 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3089 return status;
3090 out_overflow:
3091 print_overflow_msg(__func__, xdr);
3092 return -EIO;
3095 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3097 u32 n;
3098 __be32 *p;
3099 int status = 0;
3101 p = xdr_inline_decode(xdr, 4);
3102 if (unlikely(!p))
3103 goto out_overflow;
3104 n = be32_to_cpup(p);
3105 if (n == 0)
3106 goto root_path;
3107 dprintk("path ");
3108 path->ncomponents = 0;
3109 while (path->ncomponents < n) {
3110 struct nfs4_string *component = &path->components[path->ncomponents];
3111 status = decode_opaque_inline(xdr, &component->len, &component->data);
3112 if (unlikely(status != 0))
3113 goto out_eio;
3114 if (path->ncomponents != n)
3115 dprintk("/");
3116 dprintk("%s", component->data);
3117 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3118 path->ncomponents++;
3119 else {
3120 dprintk("cannot parse %d components in path\n", n);
3121 goto out_eio;
3124 out:
3125 dprintk("\n");
3126 return status;
3127 root_path:
3128 /* a root pathname is sent as a zero component4 */
3129 path->ncomponents = 1;
3130 path->components[0].len=0;
3131 path->components[0].data=NULL;
3132 dprintk("path /\n");
3133 goto out;
3134 out_eio:
3135 dprintk(" status %d", status);
3136 status = -EIO;
3137 goto out;
3138 out_overflow:
3139 print_overflow_msg(__func__, xdr);
3140 return -EIO;
3143 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3145 int n;
3146 __be32 *p;
3147 int status = -EIO;
3149 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3150 goto out;
3151 status = 0;
3152 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3153 goto out;
3154 dprintk("%s: fsroot ", __func__);
3155 status = decode_pathname(xdr, &res->fs_path);
3156 if (unlikely(status != 0))
3157 goto out;
3158 p = xdr_inline_decode(xdr, 4);
3159 if (unlikely(!p))
3160 goto out_overflow;
3161 n = be32_to_cpup(p);
3162 if (n <= 0)
3163 goto out_eio;
3164 res->nlocations = 0;
3165 while (res->nlocations < n) {
3166 u32 m;
3167 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3169 p = xdr_inline_decode(xdr, 4);
3170 if (unlikely(!p))
3171 goto out_overflow;
3172 m = be32_to_cpup(p);
3174 loc->nservers = 0;
3175 dprintk("%s: servers ", __func__);
3176 while (loc->nservers < m) {
3177 struct nfs4_string *server = &loc->servers[loc->nservers];
3178 status = decode_opaque_inline(xdr, &server->len, &server->data);
3179 if (unlikely(status != 0))
3180 goto out_eio;
3181 dprintk("%s ", server->data);
3182 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3183 loc->nservers++;
3184 else {
3185 unsigned int i;
3186 dprintk("%s: using first %u of %u servers "
3187 "returned for location %u\n",
3188 __func__,
3189 NFS4_FS_LOCATION_MAXSERVERS,
3190 m, res->nlocations);
3191 for (i = loc->nservers; i < m; i++) {
3192 unsigned int len;
3193 char *data;
3194 status = decode_opaque_inline(xdr, &len, &data);
3195 if (unlikely(status != 0))
3196 goto out_eio;
3200 status = decode_pathname(xdr, &loc->rootpath);
3201 if (unlikely(status != 0))
3202 goto out_eio;
3203 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3204 res->nlocations++;
3206 if (res->nlocations != 0)
3207 status = NFS_ATTR_FATTR_V4_REFERRAL;
3208 out:
3209 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3210 return status;
3211 out_overflow:
3212 print_overflow_msg(__func__, xdr);
3213 out_eio:
3214 status = -EIO;
3215 goto out;
3218 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3220 __be32 *p;
3221 int status = 0;
3223 *res = 0;
3224 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3225 return -EIO;
3226 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3227 p = xdr_inline_decode(xdr, 8);
3228 if (unlikely(!p))
3229 goto out_overflow;
3230 xdr_decode_hyper(p, res);
3231 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3233 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3234 return status;
3235 out_overflow:
3236 print_overflow_msg(__func__, xdr);
3237 return -EIO;
3240 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3242 __be32 *p;
3243 int status = 0;
3245 *maxlink = 1;
3246 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3247 return -EIO;
3248 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3249 p = xdr_inline_decode(xdr, 4);
3250 if (unlikely(!p))
3251 goto out_overflow;
3252 *maxlink = be32_to_cpup(p);
3253 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3255 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3256 return status;
3257 out_overflow:
3258 print_overflow_msg(__func__, xdr);
3259 return -EIO;
3262 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3264 __be32 *p;
3265 int status = 0;
3267 *maxname = 1024;
3268 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3269 return -EIO;
3270 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3271 p = xdr_inline_decode(xdr, 4);
3272 if (unlikely(!p))
3273 goto out_overflow;
3274 *maxname = be32_to_cpup(p);
3275 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3277 dprintk("%s: maxname=%u\n", __func__, *maxname);
3278 return status;
3279 out_overflow:
3280 print_overflow_msg(__func__, xdr);
3281 return -EIO;
3284 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3286 __be32 *p;
3287 int status = 0;
3289 *res = 1024;
3290 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3291 return -EIO;
3292 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3293 uint64_t maxread;
3294 p = xdr_inline_decode(xdr, 8);
3295 if (unlikely(!p))
3296 goto out_overflow;
3297 xdr_decode_hyper(p, &maxread);
3298 if (maxread > 0x7FFFFFFF)
3299 maxread = 0x7FFFFFFF;
3300 *res = (uint32_t)maxread;
3301 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3303 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3304 return status;
3305 out_overflow:
3306 print_overflow_msg(__func__, xdr);
3307 return -EIO;
3310 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3312 __be32 *p;
3313 int status = 0;
3315 *res = 1024;
3316 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3317 return -EIO;
3318 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3319 uint64_t maxwrite;
3320 p = xdr_inline_decode(xdr, 8);
3321 if (unlikely(!p))
3322 goto out_overflow;
3323 xdr_decode_hyper(p, &maxwrite);
3324 if (maxwrite > 0x7FFFFFFF)
3325 maxwrite = 0x7FFFFFFF;
3326 *res = (uint32_t)maxwrite;
3327 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3329 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3330 return status;
3331 out_overflow:
3332 print_overflow_msg(__func__, xdr);
3333 return -EIO;
3336 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3338 uint32_t tmp;
3339 __be32 *p;
3340 int ret = 0;
3342 *mode = 0;
3343 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3346 p = xdr_inline_decode(xdr, 4);
3347 if (unlikely(!p))
3348 goto out_overflow;
3349 tmp = be32_to_cpup(p);
3350 *mode = tmp & ~S_IFMT;
3351 bitmap[1] &= ~FATTR4_WORD1_MODE;
3352 ret = NFS_ATTR_FATTR_MODE;
3354 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3355 return ret;
3356 out_overflow:
3357 print_overflow_msg(__func__, xdr);
3358 return -EIO;
3361 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3363 __be32 *p;
3364 int ret = 0;
3366 *nlink = 1;
3367 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3368 return -EIO;
3369 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3370 p = xdr_inline_decode(xdr, 4);
3371 if (unlikely(!p))
3372 goto out_overflow;
3373 *nlink = be32_to_cpup(p);
3374 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3375 ret = NFS_ATTR_FATTR_NLINK;
3377 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3378 return ret;
3379 out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
3384 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3385 struct nfs_client *clp, uint32_t *uid, int may_sleep)
3387 uint32_t len;
3388 __be32 *p;
3389 int ret = 0;
3391 *uid = -2;
3392 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3393 return -EIO;
3394 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3395 p = xdr_inline_decode(xdr, 4);
3396 if (unlikely(!p))
3397 goto out_overflow;
3398 len = be32_to_cpup(p);
3399 p = xdr_inline_decode(xdr, len);
3400 if (unlikely(!p))
3401 goto out_overflow;
3402 if (!may_sleep) {
3403 /* do nothing */
3404 } else if (len < XDR_MAX_NETOBJ) {
3405 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3406 ret = NFS_ATTR_FATTR_OWNER;
3407 else
3408 dprintk("%s: nfs_map_name_to_uid failed!\n",
3409 __func__);
3410 } else
3411 dprintk("%s: name too long (%u)!\n",
3412 __func__, len);
3413 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3415 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3416 return ret;
3417 out_overflow:
3418 print_overflow_msg(__func__, xdr);
3419 return -EIO;
3422 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3423 struct nfs_client *clp, uint32_t *gid, int may_sleep)
3425 uint32_t len;
3426 __be32 *p;
3427 int ret = 0;
3429 *gid = -2;
3430 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3431 return -EIO;
3432 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3433 p = xdr_inline_decode(xdr, 4);
3434 if (unlikely(!p))
3435 goto out_overflow;
3436 len = be32_to_cpup(p);
3437 p = xdr_inline_decode(xdr, len);
3438 if (unlikely(!p))
3439 goto out_overflow;
3440 if (!may_sleep) {
3441 /* do nothing */
3442 } else if (len < XDR_MAX_NETOBJ) {
3443 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3444 ret = NFS_ATTR_FATTR_GROUP;
3445 else
3446 dprintk("%s: nfs_map_group_to_gid failed!\n",
3447 __func__);
3448 } else
3449 dprintk("%s: name too long (%u)!\n",
3450 __func__, len);
3451 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3453 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3454 return ret;
3455 out_overflow:
3456 print_overflow_msg(__func__, xdr);
3457 return -EIO;
3460 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3462 uint32_t major = 0, minor = 0;
3463 __be32 *p;
3464 int ret = 0;
3466 *rdev = MKDEV(0,0);
3467 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3468 return -EIO;
3469 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3470 dev_t tmp;
3472 p = xdr_inline_decode(xdr, 8);
3473 if (unlikely(!p))
3474 goto out_overflow;
3475 major = be32_to_cpup(p++);
3476 minor = be32_to_cpup(p);
3477 tmp = MKDEV(major, minor);
3478 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3479 *rdev = tmp;
3480 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3481 ret = NFS_ATTR_FATTR_RDEV;
3483 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3484 return ret;
3485 out_overflow:
3486 print_overflow_msg(__func__, xdr);
3487 return -EIO;
3490 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3492 __be32 *p;
3493 int status = 0;
3495 *res = 0;
3496 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3497 return -EIO;
3498 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3499 p = xdr_inline_decode(xdr, 8);
3500 if (unlikely(!p))
3501 goto out_overflow;
3502 xdr_decode_hyper(p, res);
3503 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3505 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3506 return status;
3507 out_overflow:
3508 print_overflow_msg(__func__, xdr);
3509 return -EIO;
3512 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3514 __be32 *p;
3515 int status = 0;
3517 *res = 0;
3518 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3519 return -EIO;
3520 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3521 p = xdr_inline_decode(xdr, 8);
3522 if (unlikely(!p))
3523 goto out_overflow;
3524 xdr_decode_hyper(p, res);
3525 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3527 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3528 return status;
3529 out_overflow:
3530 print_overflow_msg(__func__, xdr);
3531 return -EIO;
3534 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3536 __be32 *p;
3537 int status = 0;
3539 *res = 0;
3540 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3541 return -EIO;
3542 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3543 p = xdr_inline_decode(xdr, 8);
3544 if (unlikely(!p))
3545 goto out_overflow;
3546 xdr_decode_hyper(p, res);
3547 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3549 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3550 return status;
3551 out_overflow:
3552 print_overflow_msg(__func__, xdr);
3553 return -EIO;
3556 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3558 __be32 *p;
3559 int ret = 0;
3561 *used = 0;
3562 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3563 return -EIO;
3564 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3565 p = xdr_inline_decode(xdr, 8);
3566 if (unlikely(!p))
3567 goto out_overflow;
3568 xdr_decode_hyper(p, used);
3569 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3570 ret = NFS_ATTR_FATTR_SPACE_USED;
3572 dprintk("%s: space used=%Lu\n", __func__,
3573 (unsigned long long)*used);
3574 return ret;
3575 out_overflow:
3576 print_overflow_msg(__func__, xdr);
3577 return -EIO;
3580 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3582 __be32 *p;
3583 uint64_t sec;
3584 uint32_t nsec;
3586 p = xdr_inline_decode(xdr, 12);
3587 if (unlikely(!p))
3588 goto out_overflow;
3589 p = xdr_decode_hyper(p, &sec);
3590 nsec = be32_to_cpup(p);
3591 time->tv_sec = (time_t)sec;
3592 time->tv_nsec = (long)nsec;
3593 return 0;
3594 out_overflow:
3595 print_overflow_msg(__func__, xdr);
3596 return -EIO;
3599 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3601 int status = 0;
3603 time->tv_sec = 0;
3604 time->tv_nsec = 0;
3605 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3606 return -EIO;
3607 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3608 status = decode_attr_time(xdr, time);
3609 if (status == 0)
3610 status = NFS_ATTR_FATTR_ATIME;
3611 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3613 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3614 return status;
3617 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3619 int status = 0;
3621 time->tv_sec = 0;
3622 time->tv_nsec = 0;
3623 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3624 return -EIO;
3625 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3626 status = decode_attr_time(xdr, time);
3627 if (status == 0)
3628 status = NFS_ATTR_FATTR_CTIME;
3629 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3631 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3632 return status;
3635 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3636 struct timespec *time)
3638 int status = 0;
3640 time->tv_sec = 0;
3641 time->tv_nsec = 0;
3642 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3643 return -EIO;
3644 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3645 status = decode_attr_time(xdr, time);
3646 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3648 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3649 (long)time->tv_nsec);
3650 return status;
3653 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3655 int status = 0;
3657 time->tv_sec = 0;
3658 time->tv_nsec = 0;
3659 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3660 return -EIO;
3661 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3662 status = decode_attr_time(xdr, time);
3663 if (status == 0)
3664 status = NFS_ATTR_FATTR_MTIME;
3665 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3667 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3668 return status;
3671 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3673 unsigned int attrwords = XDR_QUADLEN(attrlen);
3674 unsigned int nwords = xdr->p - savep;
3676 if (unlikely(attrwords != nwords)) {
3677 dprintk("%s: server returned incorrect attribute length: "
3678 "%u %c %u\n",
3679 __func__,
3680 attrwords << 2,
3681 (attrwords < nwords) ? '<' : '>',
3682 nwords << 2);
3683 return -EIO;
3685 return 0;
3688 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3690 __be32 *p;
3692 p = xdr_inline_decode(xdr, 20);
3693 if (unlikely(!p))
3694 goto out_overflow;
3695 cinfo->atomic = be32_to_cpup(p++);
3696 p = xdr_decode_hyper(p, &cinfo->before);
3697 xdr_decode_hyper(p, &cinfo->after);
3698 return 0;
3699 out_overflow:
3700 print_overflow_msg(__func__, xdr);
3701 return -EIO;
3704 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3706 __be32 *p;
3707 uint32_t supp, acc;
3708 int status;
3710 status = decode_op_hdr(xdr, OP_ACCESS);
3711 if (status)
3712 return status;
3713 p = xdr_inline_decode(xdr, 8);
3714 if (unlikely(!p))
3715 goto out_overflow;
3716 supp = be32_to_cpup(p++);
3717 acc = be32_to_cpup(p);
3718 access->supported = supp;
3719 access->access = acc;
3720 return 0;
3721 out_overflow:
3722 print_overflow_msg(__func__, xdr);
3723 return -EIO;
3726 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
3728 __be32 *p;
3730 p = xdr_inline_decode(xdr, len);
3731 if (likely(p)) {
3732 memcpy(buf, p, len);
3733 return 0;
3735 print_overflow_msg(__func__, xdr);
3736 return -EIO;
3739 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3741 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
3744 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3746 int status;
3748 status = decode_op_hdr(xdr, OP_CLOSE);
3749 if (status != -EIO)
3750 nfs_increment_open_seqid(status, res->seqid);
3751 if (!status)
3752 status = decode_stateid(xdr, &res->stateid);
3753 return status;
3756 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3758 return decode_opaque_fixed(xdr, verifier, 8);
3761 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3763 int status;
3765 status = decode_op_hdr(xdr, OP_COMMIT);
3766 if (!status)
3767 status = decode_verifier(xdr, res->verf->verifier);
3768 return status;
3771 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3773 __be32 *p;
3774 uint32_t bmlen;
3775 int status;
3777 status = decode_op_hdr(xdr, OP_CREATE);
3778 if (status)
3779 return status;
3780 if ((status = decode_change_info(xdr, cinfo)))
3781 return status;
3782 p = xdr_inline_decode(xdr, 4);
3783 if (unlikely(!p))
3784 goto out_overflow;
3785 bmlen = be32_to_cpup(p);
3786 p = xdr_inline_decode(xdr, bmlen << 2);
3787 if (likely(p))
3788 return 0;
3789 out_overflow:
3790 print_overflow_msg(__func__, xdr);
3791 return -EIO;
3794 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3796 __be32 *savep;
3797 uint32_t attrlen, bitmap[2] = {0};
3798 int status;
3800 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3801 goto xdr_error;
3802 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3803 goto xdr_error;
3804 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3805 goto xdr_error;
3806 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3807 goto xdr_error;
3808 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3809 goto xdr_error;
3810 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3811 goto xdr_error;
3812 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3813 goto xdr_error;
3814 status = verify_attr_len(xdr, savep, attrlen);
3815 xdr_error:
3816 dprintk("%s: xdr returned %d!\n", __func__, -status);
3817 return status;
3820 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3822 __be32 *savep;
3823 uint32_t attrlen, bitmap[2] = {0};
3824 int status;
3826 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3827 goto xdr_error;
3828 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3829 goto xdr_error;
3830 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3831 goto xdr_error;
3833 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3834 goto xdr_error;
3835 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3836 goto xdr_error;
3837 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3838 goto xdr_error;
3839 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3840 goto xdr_error;
3841 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3842 goto xdr_error;
3843 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3844 goto xdr_error;
3846 status = verify_attr_len(xdr, savep, attrlen);
3847 xdr_error:
3848 dprintk("%s: xdr returned %d!\n", __func__, -status);
3849 return status;
3852 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3854 __be32 *savep;
3855 uint32_t attrlen, bitmap[2] = {0};
3856 int status;
3858 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3859 goto xdr_error;
3860 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3861 goto xdr_error;
3862 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3863 goto xdr_error;
3865 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3866 goto xdr_error;
3867 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3868 goto xdr_error;
3870 status = verify_attr_len(xdr, savep, attrlen);
3871 xdr_error:
3872 dprintk("%s: xdr returned %d!\n", __func__, -status);
3873 return status;
3876 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3877 struct nfs_fattr *fattr, struct nfs_fh *fh,
3878 const struct nfs_server *server, int may_sleep)
3880 int status;
3881 umode_t fmode = 0;
3882 uint64_t fileid;
3883 uint32_t type;
3885 status = decode_attr_type(xdr, bitmap, &type);
3886 if (status < 0)
3887 goto xdr_error;
3888 fattr->mode = 0;
3889 if (status != 0) {
3890 fattr->mode |= nfs_type2fmt[type];
3891 fattr->valid |= status;
3894 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3895 if (status < 0)
3896 goto xdr_error;
3897 fattr->valid |= status;
3899 status = decode_attr_size(xdr, bitmap, &fattr->size);
3900 if (status < 0)
3901 goto xdr_error;
3902 fattr->valid |= status;
3904 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3905 if (status < 0)
3906 goto xdr_error;
3907 fattr->valid |= status;
3909 status = decode_attr_error(xdr, bitmap);
3910 if (status < 0)
3911 goto xdr_error;
3913 status = decode_attr_filehandle(xdr, bitmap, fh);
3914 if (status < 0)
3915 goto xdr_error;
3917 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3918 if (status < 0)
3919 goto xdr_error;
3920 fattr->valid |= status;
3922 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3923 struct nfs4_fs_locations,
3924 fattr));
3925 if (status < 0)
3926 goto xdr_error;
3927 fattr->valid |= status;
3929 status = decode_attr_mode(xdr, bitmap, &fmode);
3930 if (status < 0)
3931 goto xdr_error;
3932 if (status != 0) {
3933 fattr->mode |= fmode;
3934 fattr->valid |= status;
3937 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3938 if (status < 0)
3939 goto xdr_error;
3940 fattr->valid |= status;
3942 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3943 &fattr->uid, may_sleep);
3944 if (status < 0)
3945 goto xdr_error;
3946 fattr->valid |= status;
3948 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3949 &fattr->gid, may_sleep);
3950 if (status < 0)
3951 goto xdr_error;
3952 fattr->valid |= status;
3954 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3955 if (status < 0)
3956 goto xdr_error;
3957 fattr->valid |= status;
3959 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3960 if (status < 0)
3961 goto xdr_error;
3962 fattr->valid |= status;
3964 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3965 if (status < 0)
3966 goto xdr_error;
3967 fattr->valid |= status;
3969 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3970 if (status < 0)
3971 goto xdr_error;
3972 fattr->valid |= status;
3974 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3975 if (status < 0)
3976 goto xdr_error;
3977 fattr->valid |= status;
3979 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3980 if (status < 0)
3981 goto xdr_error;
3982 if (status != 0 && !(fattr->valid & status)) {
3983 fattr->fileid = fileid;
3984 fattr->valid |= status;
3987 xdr_error:
3988 dprintk("%s: xdr returned %d\n", __func__, -status);
3989 return status;
3992 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3993 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
3995 __be32 *savep;
3996 uint32_t attrlen,
3997 bitmap[2] = {0};
3998 int status;
4000 status = decode_op_hdr(xdr, OP_GETATTR);
4001 if (status < 0)
4002 goto xdr_error;
4004 status = decode_attr_bitmap(xdr, bitmap);
4005 if (status < 0)
4006 goto xdr_error;
4008 status = decode_attr_length(xdr, &attrlen, &savep);
4009 if (status < 0)
4010 goto xdr_error;
4012 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4013 if (status < 0)
4014 goto xdr_error;
4016 status = verify_attr_len(xdr, savep, attrlen);
4017 xdr_error:
4018 dprintk("%s: xdr returned %d\n", __func__, -status);
4019 return status;
4022 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4023 const struct nfs_server *server, int may_sleep)
4025 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4029 * Decode potentially multiple layout types. Currently we only support
4030 * one layout driver per file system.
4032 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4033 uint32_t *layouttype)
4035 uint32_t *p;
4036 int num;
4038 p = xdr_inline_decode(xdr, 4);
4039 if (unlikely(!p))
4040 goto out_overflow;
4041 num = be32_to_cpup(p);
4043 /* pNFS is not supported by the underlying file system */
4044 if (num == 0) {
4045 *layouttype = 0;
4046 return 0;
4048 if (num > 1)
4049 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4050 "per filesystem not supported\n", __func__);
4052 /* Decode and set first layout type, move xdr->p past unused types */
4053 p = xdr_inline_decode(xdr, num * 4);
4054 if (unlikely(!p))
4055 goto out_overflow;
4056 *layouttype = be32_to_cpup(p);
4057 return 0;
4058 out_overflow:
4059 print_overflow_msg(__func__, xdr);
4060 return -EIO;
4064 * The type of file system exported.
4065 * Note we must ensure that layouttype is set in any non-error case.
4067 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4068 uint32_t *layouttype)
4070 int status = 0;
4072 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4073 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4074 return -EIO;
4075 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4076 status = decode_first_pnfs_layout_type(xdr, layouttype);
4077 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4078 } else
4079 *layouttype = 0;
4080 return status;
4083 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4085 __be32 *savep;
4086 uint32_t attrlen, bitmap[2];
4087 int status;
4089 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4090 goto xdr_error;
4091 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4092 goto xdr_error;
4093 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4094 goto xdr_error;
4096 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4098 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4099 goto xdr_error;
4100 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4101 goto xdr_error;
4102 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4103 goto xdr_error;
4104 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4105 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4106 goto xdr_error;
4107 fsinfo->wtpref = fsinfo->wtmax;
4108 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4109 if (status != 0)
4110 goto xdr_error;
4111 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4112 if (status != 0)
4113 goto xdr_error;
4115 status = verify_attr_len(xdr, savep, attrlen);
4116 xdr_error:
4117 dprintk("%s: xdr returned %d!\n", __func__, -status);
4118 return status;
4121 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4123 __be32 *p;
4124 uint32_t len;
4125 int status;
4127 /* Zero handle first to allow comparisons */
4128 memset(fh, 0, sizeof(*fh));
4130 status = decode_op_hdr(xdr, OP_GETFH);
4131 if (status)
4132 return status;
4134 p = xdr_inline_decode(xdr, 4);
4135 if (unlikely(!p))
4136 goto out_overflow;
4137 len = be32_to_cpup(p);
4138 if (len > NFS4_FHSIZE)
4139 return -EIO;
4140 fh->size = len;
4141 p = xdr_inline_decode(xdr, len);
4142 if (unlikely(!p))
4143 goto out_overflow;
4144 memcpy(fh->data, p, len);
4145 return 0;
4146 out_overflow:
4147 print_overflow_msg(__func__, xdr);
4148 return -EIO;
4151 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4153 int status;
4155 status = decode_op_hdr(xdr, OP_LINK);
4156 if (status)
4157 return status;
4158 return decode_change_info(xdr, cinfo);
4162 * We create the owner, so we know a proper owner.id length is 4.
4164 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4166 uint64_t offset, length, clientid;
4167 __be32 *p;
4168 uint32_t namelen, type;
4170 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4171 if (unlikely(!p))
4172 goto out_overflow;
4173 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4174 p = xdr_decode_hyper(p, &length);
4175 type = be32_to_cpup(p++); /* 4 byte read */
4176 if (fl != NULL) { /* manipulate file lock */
4177 fl->fl_start = (loff_t)offset;
4178 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4179 if (length == ~(uint64_t)0)
4180 fl->fl_end = OFFSET_MAX;
4181 fl->fl_type = F_WRLCK;
4182 if (type & 1)
4183 fl->fl_type = F_RDLCK;
4184 fl->fl_pid = 0;
4186 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4187 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4188 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4189 if (likely(p))
4190 return -NFS4ERR_DENIED;
4191 out_overflow:
4192 print_overflow_msg(__func__, xdr);
4193 return -EIO;
4196 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4198 int status;
4200 status = decode_op_hdr(xdr, OP_LOCK);
4201 if (status == -EIO)
4202 goto out;
4203 if (status == 0) {
4204 status = decode_stateid(xdr, &res->stateid);
4205 if (unlikely(status))
4206 goto out;
4207 } else if (status == -NFS4ERR_DENIED)
4208 status = decode_lock_denied(xdr, NULL);
4209 if (res->open_seqid != NULL)
4210 nfs_increment_open_seqid(status, res->open_seqid);
4211 nfs_increment_lock_seqid(status, res->lock_seqid);
4212 out:
4213 return status;
4216 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4218 int status;
4219 status = decode_op_hdr(xdr, OP_LOCKT);
4220 if (status == -NFS4ERR_DENIED)
4221 return decode_lock_denied(xdr, res->denied);
4222 return status;
4225 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4227 int status;
4229 status = decode_op_hdr(xdr, OP_LOCKU);
4230 if (status != -EIO)
4231 nfs_increment_lock_seqid(status, res->seqid);
4232 if (status == 0)
4233 status = decode_stateid(xdr, &res->stateid);
4234 return status;
4237 static int decode_release_lockowner(struct xdr_stream *xdr)
4239 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4242 static int decode_lookup(struct xdr_stream *xdr)
4244 return decode_op_hdr(xdr, OP_LOOKUP);
4247 /* This is too sick! */
4248 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4250 __be32 *p;
4251 uint32_t limit_type, nblocks, blocksize;
4253 p = xdr_inline_decode(xdr, 12);
4254 if (unlikely(!p))
4255 goto out_overflow;
4256 limit_type = be32_to_cpup(p++);
4257 switch (limit_type) {
4258 case 1:
4259 xdr_decode_hyper(p, maxsize);
4260 break;
4261 case 2:
4262 nblocks = be32_to_cpup(p++);
4263 blocksize = be32_to_cpup(p);
4264 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4266 return 0;
4267 out_overflow:
4268 print_overflow_msg(__func__, xdr);
4269 return -EIO;
4272 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4274 __be32 *p;
4275 uint32_t delegation_type;
4276 int status;
4278 p = xdr_inline_decode(xdr, 4);
4279 if (unlikely(!p))
4280 goto out_overflow;
4281 delegation_type = be32_to_cpup(p);
4282 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4283 res->delegation_type = 0;
4284 return 0;
4286 status = decode_stateid(xdr, &res->delegation);
4287 if (unlikely(status))
4288 return status;
4289 p = xdr_inline_decode(xdr, 4);
4290 if (unlikely(!p))
4291 goto out_overflow;
4292 res->do_recall = be32_to_cpup(p);
4294 switch (delegation_type) {
4295 case NFS4_OPEN_DELEGATE_READ:
4296 res->delegation_type = FMODE_READ;
4297 break;
4298 case NFS4_OPEN_DELEGATE_WRITE:
4299 res->delegation_type = FMODE_WRITE|FMODE_READ;
4300 if (decode_space_limit(xdr, &res->maxsize) < 0)
4301 return -EIO;
4303 return decode_ace(xdr, NULL, res->server->nfs_client);
4304 out_overflow:
4305 print_overflow_msg(__func__, xdr);
4306 return -EIO;
4309 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4311 __be32 *p;
4312 uint32_t savewords, bmlen, i;
4313 int status;
4315 status = decode_op_hdr(xdr, OP_OPEN);
4316 if (status != -EIO)
4317 nfs_increment_open_seqid(status, res->seqid);
4318 if (!status)
4319 status = decode_stateid(xdr, &res->stateid);
4320 if (unlikely(status))
4321 return status;
4323 decode_change_info(xdr, &res->cinfo);
4325 p = xdr_inline_decode(xdr, 8);
4326 if (unlikely(!p))
4327 goto out_overflow;
4328 res->rflags = be32_to_cpup(p++);
4329 bmlen = be32_to_cpup(p);
4330 if (bmlen > 10)
4331 goto xdr_error;
4333 p = xdr_inline_decode(xdr, bmlen << 2);
4334 if (unlikely(!p))
4335 goto out_overflow;
4336 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4337 for (i = 0; i < savewords; ++i)
4338 res->attrset[i] = be32_to_cpup(p++);
4339 for (; i < NFS4_BITMAP_SIZE; i++)
4340 res->attrset[i] = 0;
4342 return decode_delegation(xdr, res);
4343 xdr_error:
4344 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4345 return -EIO;
4346 out_overflow:
4347 print_overflow_msg(__func__, xdr);
4348 return -EIO;
4351 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4353 int status;
4355 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4356 if (status != -EIO)
4357 nfs_increment_open_seqid(status, res->seqid);
4358 if (!status)
4359 status = decode_stateid(xdr, &res->stateid);
4360 return status;
4363 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4365 int status;
4367 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4368 if (status != -EIO)
4369 nfs_increment_open_seqid(status, res->seqid);
4370 if (!status)
4371 status = decode_stateid(xdr, &res->stateid);
4372 return status;
4375 static int decode_putfh(struct xdr_stream *xdr)
4377 return decode_op_hdr(xdr, OP_PUTFH);
4380 static int decode_putrootfh(struct xdr_stream *xdr)
4382 return decode_op_hdr(xdr, OP_PUTROOTFH);
4385 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4387 struct kvec *iov = req->rq_rcv_buf.head;
4388 __be32 *p;
4389 uint32_t count, eof, recvd, hdrlen;
4390 int status;
4392 status = decode_op_hdr(xdr, OP_READ);
4393 if (status)
4394 return status;
4395 p = xdr_inline_decode(xdr, 8);
4396 if (unlikely(!p))
4397 goto out_overflow;
4398 eof = be32_to_cpup(p++);
4399 count = be32_to_cpup(p);
4400 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4401 recvd = req->rq_rcv_buf.len - hdrlen;
4402 if (count > recvd) {
4403 dprintk("NFS: server cheating in read reply: "
4404 "count %u > recvd %u\n", count, recvd);
4405 count = recvd;
4406 eof = 0;
4408 xdr_read_pages(xdr, count);
4409 res->eof = eof;
4410 res->count = count;
4411 return 0;
4412 out_overflow:
4413 print_overflow_msg(__func__, xdr);
4414 return -EIO;
4417 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4419 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4420 struct kvec *iov = rcvbuf->head;
4421 size_t hdrlen;
4422 u32 recvd, pglen = rcvbuf->page_len;
4423 int status;
4425 status = decode_op_hdr(xdr, OP_READDIR);
4426 if (!status)
4427 status = decode_verifier(xdr, readdir->verifier.data);
4428 if (unlikely(status))
4429 return status;
4430 dprintk("%s: verifier = %08x:%08x\n",
4431 __func__,
4432 ((u32 *)readdir->verifier.data)[0],
4433 ((u32 *)readdir->verifier.data)[1]);
4436 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4437 recvd = rcvbuf->len - hdrlen;
4438 if (pglen > recvd)
4439 pglen = recvd;
4440 xdr_read_pages(xdr, pglen);
4443 return pglen;
4446 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4448 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4449 struct kvec *iov = rcvbuf->head;
4450 size_t hdrlen;
4451 u32 len, recvd;
4452 __be32 *p;
4453 int status;
4455 status = decode_op_hdr(xdr, OP_READLINK);
4456 if (status)
4457 return status;
4459 /* Convert length of symlink */
4460 p = xdr_inline_decode(xdr, 4);
4461 if (unlikely(!p))
4462 goto out_overflow;
4463 len = be32_to_cpup(p);
4464 if (len >= rcvbuf->page_len || len <= 0) {
4465 dprintk("nfs: server returned giant symlink!\n");
4466 return -ENAMETOOLONG;
4468 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4469 recvd = req->rq_rcv_buf.len - hdrlen;
4470 if (recvd < len) {
4471 dprintk("NFS: server cheating in readlink reply: "
4472 "count %u > recvd %u\n", len, recvd);
4473 return -EIO;
4475 xdr_read_pages(xdr, len);
4477 * The XDR encode routine has set things up so that
4478 * the link text will be copied directly into the
4479 * buffer. We just have to do overflow-checking,
4480 * and and null-terminate the text (the VFS expects
4481 * null-termination).
4483 xdr_terminate_string(rcvbuf, len);
4484 return 0;
4485 out_overflow:
4486 print_overflow_msg(__func__, xdr);
4487 return -EIO;
4490 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4492 int status;
4494 status = decode_op_hdr(xdr, OP_REMOVE);
4495 if (status)
4496 goto out;
4497 status = decode_change_info(xdr, cinfo);
4498 out:
4499 return status;
4502 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4503 struct nfs4_change_info *new_cinfo)
4505 int status;
4507 status = decode_op_hdr(xdr, OP_RENAME);
4508 if (status)
4509 goto out;
4510 if ((status = decode_change_info(xdr, old_cinfo)))
4511 goto out;
4512 status = decode_change_info(xdr, new_cinfo);
4513 out:
4514 return status;
4517 static int decode_renew(struct xdr_stream *xdr)
4519 return decode_op_hdr(xdr, OP_RENEW);
4522 static int
4523 decode_restorefh(struct xdr_stream *xdr)
4525 return decode_op_hdr(xdr, OP_RESTOREFH);
4528 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4529 size_t *acl_len)
4531 __be32 *savep;
4532 uint32_t attrlen,
4533 bitmap[2] = {0};
4534 struct kvec *iov = req->rq_rcv_buf.head;
4535 int status;
4537 *acl_len = 0;
4538 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4539 goto out;
4540 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4541 goto out;
4542 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4543 goto out;
4545 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4546 return -EIO;
4547 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4548 size_t hdrlen;
4549 u32 recvd;
4551 /* We ignore &savep and don't do consistency checks on
4552 * the attr length. Let userspace figure it out.... */
4553 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4554 recvd = req->rq_rcv_buf.len - hdrlen;
4555 if (attrlen > recvd) {
4556 dprintk("NFS: server cheating in getattr"
4557 " acl reply: attrlen %u > recvd %u\n",
4558 attrlen, recvd);
4559 return -EINVAL;
4561 xdr_read_pages(xdr, attrlen);
4562 *acl_len = attrlen;
4563 } else
4564 status = -EOPNOTSUPP;
4566 out:
4567 return status;
4570 static int
4571 decode_savefh(struct xdr_stream *xdr)
4573 return decode_op_hdr(xdr, OP_SAVEFH);
4576 static int decode_setattr(struct xdr_stream *xdr)
4578 __be32 *p;
4579 uint32_t bmlen;
4580 int status;
4582 status = decode_op_hdr(xdr, OP_SETATTR);
4583 if (status)
4584 return status;
4585 p = xdr_inline_decode(xdr, 4);
4586 if (unlikely(!p))
4587 goto out_overflow;
4588 bmlen = be32_to_cpup(p);
4589 p = xdr_inline_decode(xdr, bmlen << 2);
4590 if (likely(p))
4591 return 0;
4592 out_overflow:
4593 print_overflow_msg(__func__, xdr);
4594 return -EIO;
4597 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
4599 __be32 *p;
4600 uint32_t opnum;
4601 int32_t nfserr;
4603 p = xdr_inline_decode(xdr, 8);
4604 if (unlikely(!p))
4605 goto out_overflow;
4606 opnum = be32_to_cpup(p++);
4607 if (opnum != OP_SETCLIENTID) {
4608 dprintk("nfs: decode_setclientid: Server returned operation"
4609 " %d\n", opnum);
4610 return -EIO;
4612 nfserr = be32_to_cpup(p);
4613 if (nfserr == NFS_OK) {
4614 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4615 if (unlikely(!p))
4616 goto out_overflow;
4617 p = xdr_decode_hyper(p, &res->clientid);
4618 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
4619 } else if (nfserr == NFSERR_CLID_INUSE) {
4620 uint32_t len;
4622 /* skip netid string */
4623 p = xdr_inline_decode(xdr, 4);
4624 if (unlikely(!p))
4625 goto out_overflow;
4626 len = be32_to_cpup(p);
4627 p = xdr_inline_decode(xdr, len);
4628 if (unlikely(!p))
4629 goto out_overflow;
4631 /* skip uaddr string */
4632 p = xdr_inline_decode(xdr, 4);
4633 if (unlikely(!p))
4634 goto out_overflow;
4635 len = be32_to_cpup(p);
4636 p = xdr_inline_decode(xdr, len);
4637 if (unlikely(!p))
4638 goto out_overflow;
4639 return -NFSERR_CLID_INUSE;
4640 } else
4641 return nfs4_stat_to_errno(nfserr);
4643 return 0;
4644 out_overflow:
4645 print_overflow_msg(__func__, xdr);
4646 return -EIO;
4649 static int decode_setclientid_confirm(struct xdr_stream *xdr)
4651 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4654 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4656 __be32 *p;
4657 int status;
4659 status = decode_op_hdr(xdr, OP_WRITE);
4660 if (status)
4661 return status;
4663 p = xdr_inline_decode(xdr, 16);
4664 if (unlikely(!p))
4665 goto out_overflow;
4666 res->count = be32_to_cpup(p++);
4667 res->verf->committed = be32_to_cpup(p++);
4668 memcpy(res->verf->verifier, p, 8);
4669 return 0;
4670 out_overflow:
4671 print_overflow_msg(__func__, xdr);
4672 return -EIO;
4675 static int decode_delegreturn(struct xdr_stream *xdr)
4677 return decode_op_hdr(xdr, OP_DELEGRETURN);
4680 #if defined(CONFIG_NFS_V4_1)
4681 static int decode_exchange_id(struct xdr_stream *xdr,
4682 struct nfs41_exchange_id_res *res)
4684 __be32 *p;
4685 uint32_t dummy;
4686 char *dummy_str;
4687 int status;
4688 struct nfs_client *clp = res->client;
4690 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4691 if (status)
4692 return status;
4694 p = xdr_inline_decode(xdr, 8);
4695 if (unlikely(!p))
4696 goto out_overflow;
4697 xdr_decode_hyper(p, &clp->cl_ex_clid);
4698 p = xdr_inline_decode(xdr, 12);
4699 if (unlikely(!p))
4700 goto out_overflow;
4701 clp->cl_seqid = be32_to_cpup(p++);
4702 clp->cl_exchange_flags = be32_to_cpup(p++);
4704 /* We ask for SP4_NONE */
4705 dummy = be32_to_cpup(p);
4706 if (dummy != SP4_NONE)
4707 return -EIO;
4709 /* Throw away minor_id */
4710 p = xdr_inline_decode(xdr, 8);
4711 if (unlikely(!p))
4712 goto out_overflow;
4714 /* Throw away Major id */
4715 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4716 if (unlikely(status))
4717 return status;
4719 /* Throw away server_scope */
4720 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4721 if (unlikely(status))
4722 return status;
4724 /* Throw away Implementation id array */
4725 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4726 if (unlikely(status))
4727 return status;
4729 return 0;
4730 out_overflow:
4731 print_overflow_msg(__func__, xdr);
4732 return -EIO;
4735 static int decode_chan_attrs(struct xdr_stream *xdr,
4736 struct nfs4_channel_attrs *attrs)
4738 __be32 *p;
4739 u32 nr_attrs;
4741 p = xdr_inline_decode(xdr, 28);
4742 if (unlikely(!p))
4743 goto out_overflow;
4744 attrs->headerpadsz = be32_to_cpup(p++);
4745 attrs->max_rqst_sz = be32_to_cpup(p++);
4746 attrs->max_resp_sz = be32_to_cpup(p++);
4747 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4748 attrs->max_ops = be32_to_cpup(p++);
4749 attrs->max_reqs = be32_to_cpup(p++);
4750 nr_attrs = be32_to_cpup(p);
4751 if (unlikely(nr_attrs > 1)) {
4752 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4753 __func__, nr_attrs);
4754 return -EINVAL;
4756 if (nr_attrs == 1) {
4757 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4758 if (unlikely(!p))
4759 goto out_overflow;
4761 return 0;
4762 out_overflow:
4763 print_overflow_msg(__func__, xdr);
4764 return -EIO;
4767 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4769 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
4772 static int decode_create_session(struct xdr_stream *xdr,
4773 struct nfs41_create_session_res *res)
4775 __be32 *p;
4776 int status;
4777 struct nfs_client *clp = res->client;
4778 struct nfs4_session *session = clp->cl_session;
4780 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4781 if (!status)
4782 status = decode_sessionid(xdr, &session->sess_id);
4783 if (unlikely(status))
4784 return status;
4786 /* seqid, flags */
4787 p = xdr_inline_decode(xdr, 8);
4788 if (unlikely(!p))
4789 goto out_overflow;
4790 clp->cl_seqid = be32_to_cpup(p++);
4791 session->flags = be32_to_cpup(p);
4793 /* Channel attributes */
4794 status = decode_chan_attrs(xdr, &session->fc_attrs);
4795 if (!status)
4796 status = decode_chan_attrs(xdr, &session->bc_attrs);
4797 return status;
4798 out_overflow:
4799 print_overflow_msg(__func__, xdr);
4800 return -EIO;
4803 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4805 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4808 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4810 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4812 #endif /* CONFIG_NFS_V4_1 */
4814 static int decode_sequence(struct xdr_stream *xdr,
4815 struct nfs4_sequence_res *res,
4816 struct rpc_rqst *rqstp)
4818 #if defined(CONFIG_NFS_V4_1)
4819 struct nfs4_sessionid id;
4820 u32 dummy;
4821 int status;
4822 __be32 *p;
4824 if (!res->sr_session)
4825 return 0;
4827 status = decode_op_hdr(xdr, OP_SEQUENCE);
4828 if (!status)
4829 status = decode_sessionid(xdr, &id);
4830 if (unlikely(status))
4831 goto out_err;
4834 * If the server returns different values for sessionID, slotID or
4835 * sequence number, the server is looney tunes.
4837 status = -EREMOTEIO;
4839 if (memcmp(id.data, res->sr_session->sess_id.data,
4840 NFS4_MAX_SESSIONID_LEN)) {
4841 dprintk("%s Invalid session id\n", __func__);
4842 goto out_err;
4845 p = xdr_inline_decode(xdr, 20);
4846 if (unlikely(!p))
4847 goto out_overflow;
4849 /* seqid */
4850 dummy = be32_to_cpup(p++);
4851 if (dummy != res->sr_slot->seq_nr) {
4852 dprintk("%s Invalid sequence number\n", __func__);
4853 goto out_err;
4855 /* slot id */
4856 dummy = be32_to_cpup(p++);
4857 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
4858 dprintk("%s Invalid slot id\n", __func__);
4859 goto out_err;
4861 /* highest slot id - currently not processed */
4862 dummy = be32_to_cpup(p++);
4863 /* target highest slot id - currently not processed */
4864 dummy = be32_to_cpup(p++);
4865 /* result flags */
4866 res->sr_status_flags = be32_to_cpup(p);
4867 status = 0;
4868 out_err:
4869 res->sr_status = status;
4870 return status;
4871 out_overflow:
4872 print_overflow_msg(__func__, xdr);
4873 status = -EIO;
4874 goto out_err;
4875 #else /* CONFIG_NFS_V4_1 */
4876 return 0;
4877 #endif /* CONFIG_NFS_V4_1 */
4880 #if defined(CONFIG_NFS_V4_1)
4882 static int decode_getdeviceinfo(struct xdr_stream *xdr,
4883 struct pnfs_device *pdev)
4885 __be32 *p;
4886 uint32_t len, type;
4887 int status;
4889 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
4890 if (status) {
4891 if (status == -ETOOSMALL) {
4892 p = xdr_inline_decode(xdr, 4);
4893 if (unlikely(!p))
4894 goto out_overflow;
4895 pdev->mincount = be32_to_cpup(p);
4896 dprintk("%s: Min count too small. mincnt = %u\n",
4897 __func__, pdev->mincount);
4899 return status;
4902 p = xdr_inline_decode(xdr, 8);
4903 if (unlikely(!p))
4904 goto out_overflow;
4905 type = be32_to_cpup(p++);
4906 if (type != pdev->layout_type) {
4907 dprintk("%s: layout mismatch req: %u pdev: %u\n",
4908 __func__, pdev->layout_type, type);
4909 return -EINVAL;
4912 * Get the length of the opaque device_addr4. xdr_read_pages places
4913 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
4914 * and places the remaining xdr data in xdr_buf->tail
4916 pdev->mincount = be32_to_cpup(p);
4917 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
4919 /* Parse notification bitmap, verifying that it is zero. */
4920 p = xdr_inline_decode(xdr, 4);
4921 if (unlikely(!p))
4922 goto out_overflow;
4923 len = be32_to_cpup(p);
4924 if (len) {
4925 uint32_t i;
4927 p = xdr_inline_decode(xdr, 4 * len);
4928 if (unlikely(!p))
4929 goto out_overflow;
4930 for (i = 0; i < len; i++, p++) {
4931 if (be32_to_cpup(p)) {
4932 dprintk("%s: notifications not supported\n",
4933 __func__);
4934 return -EIO;
4938 return 0;
4939 out_overflow:
4940 print_overflow_msg(__func__, xdr);
4941 return -EIO;
4944 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
4945 struct nfs4_layoutget_res *res)
4947 __be32 *p;
4948 int status;
4949 u32 layout_count;
4951 status = decode_op_hdr(xdr, OP_LAYOUTGET);
4952 if (status)
4953 return status;
4954 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
4955 if (unlikely(!p))
4956 goto out_overflow;
4957 res->return_on_close = be32_to_cpup(p++);
4958 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
4959 layout_count = be32_to_cpup(p);
4960 if (!layout_count) {
4961 dprintk("%s: server responded with empty layout array\n",
4962 __func__);
4963 return -EINVAL;
4966 p = xdr_inline_decode(xdr, 24);
4967 if (unlikely(!p))
4968 goto out_overflow;
4969 p = xdr_decode_hyper(p, &res->range.offset);
4970 p = xdr_decode_hyper(p, &res->range.length);
4971 res->range.iomode = be32_to_cpup(p++);
4972 res->type = be32_to_cpup(p++);
4974 status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
4975 if (unlikely(status))
4976 return status;
4978 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
4979 __func__,
4980 (unsigned long)res->range.offset,
4981 (unsigned long)res->range.length,
4982 res->range.iomode,
4983 res->type,
4984 res->layout.len);
4986 /* nfs4_proc_layoutget allocated a single page */
4987 if (res->layout.len > PAGE_SIZE)
4988 return -ENOMEM;
4989 memcpy(res->layout.buf, p, res->layout.len);
4991 if (layout_count > 1) {
4992 /* We only handle a length one array at the moment. Any
4993 * further entries are just ignored. Note that this means
4994 * the client may see a response that is less than the
4995 * minimum it requested.
4997 dprintk("%s: server responded with %d layouts, dropping tail\n",
4998 __func__, layout_count);
5001 return 0;
5002 out_overflow:
5003 print_overflow_msg(__func__, xdr);
5004 return -EIO;
5006 #endif /* CONFIG_NFS_V4_1 */
5009 * END OF "GENERIC" DECODE ROUTINES.
5013 * Decode OPEN_DOWNGRADE response
5015 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5016 struct xdr_stream *xdr,
5017 struct nfs_closeres *res)
5019 struct compound_hdr hdr;
5020 int status;
5022 status = decode_compound_hdr(xdr, &hdr);
5023 if (status)
5024 goto out;
5025 status = decode_sequence(xdr, &res->seq_res, rqstp);
5026 if (status)
5027 goto out;
5028 status = decode_putfh(xdr);
5029 if (status)
5030 goto out;
5031 status = decode_open_downgrade(xdr, res);
5032 if (status != 0)
5033 goto out;
5034 decode_getfattr(xdr, res->fattr, res->server,
5035 !RPC_IS_ASYNC(rqstp->rq_task));
5036 out:
5037 return status;
5041 * Decode ACCESS response
5043 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5044 struct nfs4_accessres *res)
5046 struct compound_hdr hdr;
5047 int status;
5049 status = decode_compound_hdr(xdr, &hdr);
5050 if (status)
5051 goto out;
5052 status = decode_sequence(xdr, &res->seq_res, rqstp);
5053 if (status)
5054 goto out;
5055 status = decode_putfh(xdr);
5056 if (status != 0)
5057 goto out;
5058 status = decode_access(xdr, res);
5059 if (status != 0)
5060 goto out;
5061 decode_getfattr(xdr, res->fattr, res->server,
5062 !RPC_IS_ASYNC(rqstp->rq_task));
5063 out:
5064 return status;
5068 * Decode LOOKUP response
5070 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5071 struct nfs4_lookup_res *res)
5073 struct compound_hdr hdr;
5074 int status;
5076 status = decode_compound_hdr(xdr, &hdr);
5077 if (status)
5078 goto out;
5079 status = decode_sequence(xdr, &res->seq_res, rqstp);
5080 if (status)
5081 goto out;
5082 status = decode_putfh(xdr);
5083 if (status)
5084 goto out;
5085 status = decode_lookup(xdr);
5086 if (status)
5087 goto out;
5088 status = decode_getfh(xdr, res->fh);
5089 if (status)
5090 goto out;
5091 status = decode_getfattr(xdr, res->fattr, res->server
5092 ,!RPC_IS_ASYNC(rqstp->rq_task));
5093 out:
5094 return status;
5098 * Decode LOOKUP_ROOT response
5100 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5101 struct xdr_stream *xdr,
5102 struct nfs4_lookup_res *res)
5104 struct compound_hdr hdr;
5105 int status;
5107 status = decode_compound_hdr(xdr, &hdr);
5108 if (status)
5109 goto out;
5110 status = decode_sequence(xdr, &res->seq_res, rqstp);
5111 if (status)
5112 goto out;
5113 status = decode_putrootfh(xdr);
5114 if (status)
5115 goto out;
5116 status = decode_getfh(xdr, res->fh);
5117 if (status == 0)
5118 status = decode_getfattr(xdr, res->fattr, res->server,
5119 !RPC_IS_ASYNC(rqstp->rq_task));
5120 out:
5121 return status;
5125 * Decode REMOVE response
5127 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5128 struct nfs_removeres *res)
5130 struct compound_hdr hdr;
5131 int status;
5133 status = decode_compound_hdr(xdr, &hdr);
5134 if (status)
5135 goto out;
5136 status = decode_sequence(xdr, &res->seq_res, rqstp);
5137 if (status)
5138 goto out;
5139 status = decode_putfh(xdr);
5140 if (status)
5141 goto out;
5142 status = decode_remove(xdr, &res->cinfo);
5143 if (status)
5144 goto out;
5145 decode_getfattr(xdr, res->dir_attr, res->server,
5146 !RPC_IS_ASYNC(rqstp->rq_task));
5147 out:
5148 return status;
5152 * Decode RENAME response
5154 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5155 struct nfs_renameres *res)
5157 struct compound_hdr hdr;
5158 int status;
5160 status = decode_compound_hdr(xdr, &hdr);
5161 if (status)
5162 goto out;
5163 status = decode_sequence(xdr, &res->seq_res, rqstp);
5164 if (status)
5165 goto out;
5166 status = decode_putfh(xdr);
5167 if (status)
5168 goto out;
5169 status = decode_savefh(xdr);
5170 if (status)
5171 goto out;
5172 status = decode_putfh(xdr);
5173 if (status)
5174 goto out;
5175 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5176 if (status)
5177 goto out;
5178 /* Current FH is target directory */
5179 if (decode_getfattr(xdr, res->new_fattr, res->server,
5180 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5181 goto out;
5182 status = decode_restorefh(xdr);
5183 if (status)
5184 goto out;
5185 decode_getfattr(xdr, res->old_fattr, res->server,
5186 !RPC_IS_ASYNC(rqstp->rq_task));
5187 out:
5188 return status;
5192 * Decode LINK response
5194 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5195 struct nfs4_link_res *res)
5197 struct compound_hdr hdr;
5198 int status;
5200 status = decode_compound_hdr(xdr, &hdr);
5201 if (status)
5202 goto out;
5203 status = decode_sequence(xdr, &res->seq_res, rqstp);
5204 if (status)
5205 goto out;
5206 status = decode_putfh(xdr);
5207 if (status)
5208 goto out;
5209 status = decode_savefh(xdr);
5210 if (status)
5211 goto out;
5212 status = decode_putfh(xdr);
5213 if (status)
5214 goto out;
5215 status = decode_link(xdr, &res->cinfo);
5216 if (status)
5217 goto out;
5219 * Note order: OP_LINK leaves the directory as the current
5220 * filehandle.
5222 if (decode_getfattr(xdr, res->dir_attr, res->server,
5223 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5224 goto out;
5225 status = decode_restorefh(xdr);
5226 if (status)
5227 goto out;
5228 decode_getfattr(xdr, res->fattr, res->server,
5229 !RPC_IS_ASYNC(rqstp->rq_task));
5230 out:
5231 return status;
5235 * Decode CREATE response
5237 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5238 struct nfs4_create_res *res)
5240 struct compound_hdr hdr;
5241 int status;
5243 status = decode_compound_hdr(xdr, &hdr);
5244 if (status)
5245 goto out;
5246 status = decode_sequence(xdr, &res->seq_res, rqstp);
5247 if (status)
5248 goto out;
5249 status = decode_putfh(xdr);
5250 if (status)
5251 goto out;
5252 status = decode_savefh(xdr);
5253 if (status)
5254 goto out;
5255 status = decode_create(xdr, &res->dir_cinfo);
5256 if (status)
5257 goto out;
5258 status = decode_getfh(xdr, res->fh);
5259 if (status)
5260 goto out;
5261 if (decode_getfattr(xdr, res->fattr, res->server,
5262 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5263 goto out;
5264 status = decode_restorefh(xdr);
5265 if (status)
5266 goto out;
5267 decode_getfattr(xdr, res->dir_fattr, res->server,
5268 !RPC_IS_ASYNC(rqstp->rq_task));
5269 out:
5270 return status;
5274 * Decode SYMLINK response
5276 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5277 struct nfs4_create_res *res)
5279 return nfs4_xdr_dec_create(rqstp, xdr, res);
5283 * Decode GETATTR response
5285 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5286 struct nfs4_getattr_res *res)
5288 struct compound_hdr hdr;
5289 int status;
5291 status = decode_compound_hdr(xdr, &hdr);
5292 if (status)
5293 goto out;
5294 status = decode_sequence(xdr, &res->seq_res, rqstp);
5295 if (status)
5296 goto out;
5297 status = decode_putfh(xdr);
5298 if (status)
5299 goto out;
5300 status = decode_getfattr(xdr, res->fattr, res->server,
5301 !RPC_IS_ASYNC(rqstp->rq_task));
5302 out:
5303 return status;
5307 * Encode an SETACL request
5309 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5310 struct nfs_setaclargs *args)
5312 struct compound_hdr hdr = {
5313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
5316 encode_compound_hdr(xdr, req, &hdr);
5317 encode_sequence(xdr, &args->seq_args, &hdr);
5318 encode_putfh(xdr, args->fh, &hdr);
5319 encode_setacl(xdr, args, &hdr);
5320 encode_nops(&hdr);
5324 * Decode SETACL response
5326 static int
5327 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5328 struct nfs_setaclres *res)
5330 struct compound_hdr hdr;
5331 int status;
5333 status = decode_compound_hdr(xdr, &hdr);
5334 if (status)
5335 goto out;
5336 status = decode_sequence(xdr, &res->seq_res, rqstp);
5337 if (status)
5338 goto out;
5339 status = decode_putfh(xdr);
5340 if (status)
5341 goto out;
5342 status = decode_setattr(xdr);
5343 out:
5344 return status;
5348 * Decode GETACL response
5350 static int
5351 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5352 struct nfs_getaclres *res)
5354 struct compound_hdr hdr;
5355 int status;
5357 status = decode_compound_hdr(xdr, &hdr);
5358 if (status)
5359 goto out;
5360 status = decode_sequence(xdr, &res->seq_res, rqstp);
5361 if (status)
5362 goto out;
5363 status = decode_putfh(xdr);
5364 if (status)
5365 goto out;
5366 status = decode_getacl(xdr, rqstp, &res->acl_len);
5368 out:
5369 return status;
5373 * Decode CLOSE response
5375 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5376 struct nfs_closeres *res)
5378 struct compound_hdr hdr;
5379 int status;
5381 status = decode_compound_hdr(xdr, &hdr);
5382 if (status)
5383 goto out;
5384 status = decode_sequence(xdr, &res->seq_res, rqstp);
5385 if (status)
5386 goto out;
5387 status = decode_putfh(xdr);
5388 if (status)
5389 goto out;
5390 status = decode_close(xdr, res);
5391 if (status != 0)
5392 goto out;
5394 * Note: Server may do delete on close for this file
5395 * in which case the getattr call will fail with
5396 * an ESTALE error. Shouldn't be a problem,
5397 * though, since fattr->valid will remain unset.
5399 decode_getfattr(xdr, res->fattr, res->server,
5400 !RPC_IS_ASYNC(rqstp->rq_task));
5401 out:
5402 return status;
5406 * Decode OPEN response
5408 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5409 struct nfs_openres *res)
5411 struct compound_hdr hdr;
5412 int status;
5414 status = decode_compound_hdr(xdr, &hdr);
5415 if (status)
5416 goto out;
5417 status = decode_sequence(xdr, &res->seq_res, rqstp);
5418 if (status)
5419 goto out;
5420 status = decode_putfh(xdr);
5421 if (status)
5422 goto out;
5423 status = decode_savefh(xdr);
5424 if (status)
5425 goto out;
5426 status = decode_open(xdr, res);
5427 if (status)
5428 goto out;
5429 if (decode_getfh(xdr, &res->fh) != 0)
5430 goto out;
5431 if (decode_getfattr(xdr, res->f_attr, res->server,
5432 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5433 goto out;
5434 if (decode_restorefh(xdr) != 0)
5435 goto out;
5436 decode_getfattr(xdr, res->dir_attr, res->server,
5437 !RPC_IS_ASYNC(rqstp->rq_task));
5438 out:
5439 return status;
5443 * Decode OPEN_CONFIRM response
5445 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5446 struct xdr_stream *xdr,
5447 struct nfs_open_confirmres *res)
5449 struct compound_hdr hdr;
5450 int status;
5452 status = decode_compound_hdr(xdr, &hdr);
5453 if (status)
5454 goto out;
5455 status = decode_putfh(xdr);
5456 if (status)
5457 goto out;
5458 status = decode_open_confirm(xdr, res);
5459 out:
5460 return status;
5464 * Decode OPEN response
5466 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5467 struct xdr_stream *xdr,
5468 struct nfs_openres *res)
5470 struct compound_hdr hdr;
5471 int status;
5473 status = decode_compound_hdr(xdr, &hdr);
5474 if (status)
5475 goto out;
5476 status = decode_sequence(xdr, &res->seq_res, rqstp);
5477 if (status)
5478 goto out;
5479 status = decode_putfh(xdr);
5480 if (status)
5481 goto out;
5482 status = decode_open(xdr, res);
5483 if (status)
5484 goto out;
5485 decode_getfattr(xdr, res->f_attr, res->server,
5486 !RPC_IS_ASYNC(rqstp->rq_task));
5487 out:
5488 return status;
5492 * Decode SETATTR response
5494 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5495 struct xdr_stream *xdr,
5496 struct nfs_setattrres *res)
5498 struct compound_hdr hdr;
5499 int status;
5501 status = decode_compound_hdr(xdr, &hdr);
5502 if (status)
5503 goto out;
5504 status = decode_sequence(xdr, &res->seq_res, rqstp);
5505 if (status)
5506 goto out;
5507 status = decode_putfh(xdr);
5508 if (status)
5509 goto out;
5510 status = decode_setattr(xdr);
5511 if (status)
5512 goto out;
5513 decode_getfattr(xdr, res->fattr, res->server,
5514 !RPC_IS_ASYNC(rqstp->rq_task));
5515 out:
5516 return status;
5520 * Decode LOCK response
5522 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5523 struct nfs_lock_res *res)
5525 struct compound_hdr hdr;
5526 int status;
5528 status = decode_compound_hdr(xdr, &hdr);
5529 if (status)
5530 goto out;
5531 status = decode_sequence(xdr, &res->seq_res, rqstp);
5532 if (status)
5533 goto out;
5534 status = decode_putfh(xdr);
5535 if (status)
5536 goto out;
5537 status = decode_lock(xdr, res);
5538 out:
5539 return status;
5543 * Decode LOCKT response
5545 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5546 struct nfs_lockt_res *res)
5548 struct compound_hdr hdr;
5549 int status;
5551 status = decode_compound_hdr(xdr, &hdr);
5552 if (status)
5553 goto out;
5554 status = decode_sequence(xdr, &res->seq_res, rqstp);
5555 if (status)
5556 goto out;
5557 status = decode_putfh(xdr);
5558 if (status)
5559 goto out;
5560 status = decode_lockt(xdr, res);
5561 out:
5562 return status;
5566 * Decode LOCKU response
5568 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5569 struct nfs_locku_res *res)
5571 struct compound_hdr hdr;
5572 int status;
5574 status = decode_compound_hdr(xdr, &hdr);
5575 if (status)
5576 goto out;
5577 status = decode_sequence(xdr, &res->seq_res, rqstp);
5578 if (status)
5579 goto out;
5580 status = decode_putfh(xdr);
5581 if (status)
5582 goto out;
5583 status = decode_locku(xdr, res);
5584 out:
5585 return status;
5588 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5589 struct xdr_stream *xdr, void *dummy)
5591 struct compound_hdr hdr;
5592 int status;
5594 status = decode_compound_hdr(xdr, &hdr);
5595 if (!status)
5596 status = decode_release_lockowner(xdr);
5597 return status;
5601 * Decode READLINK response
5603 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5604 struct xdr_stream *xdr,
5605 struct nfs4_readlink_res *res)
5607 struct compound_hdr hdr;
5608 int status;
5610 status = decode_compound_hdr(xdr, &hdr);
5611 if (status)
5612 goto out;
5613 status = decode_sequence(xdr, &res->seq_res, rqstp);
5614 if (status)
5615 goto out;
5616 status = decode_putfh(xdr);
5617 if (status)
5618 goto out;
5619 status = decode_readlink(xdr, rqstp);
5620 out:
5621 return status;
5625 * Decode READDIR response
5627 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5628 struct nfs4_readdir_res *res)
5630 struct compound_hdr hdr;
5631 int status;
5633 status = decode_compound_hdr(xdr, &hdr);
5634 if (status)
5635 goto out;
5636 status = decode_sequence(xdr, &res->seq_res, rqstp);
5637 if (status)
5638 goto out;
5639 status = decode_putfh(xdr);
5640 if (status)
5641 goto out;
5642 status = decode_readdir(xdr, rqstp, res);
5643 out:
5644 return status;
5648 * Decode Read response
5650 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5651 struct nfs_readres *res)
5653 struct compound_hdr hdr;
5654 int status;
5656 status = decode_compound_hdr(xdr, &hdr);
5657 if (status)
5658 goto out;
5659 status = decode_sequence(xdr, &res->seq_res, rqstp);
5660 if (status)
5661 goto out;
5662 status = decode_putfh(xdr);
5663 if (status)
5664 goto out;
5665 status = decode_read(xdr, rqstp, res);
5666 if (!status)
5667 status = res->count;
5668 out:
5669 return status;
5673 * Decode WRITE response
5675 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5676 struct nfs_writeres *res)
5678 struct compound_hdr hdr;
5679 int status;
5681 status = decode_compound_hdr(xdr, &hdr);
5682 if (status)
5683 goto out;
5684 status = decode_sequence(xdr, &res->seq_res, rqstp);
5685 if (status)
5686 goto out;
5687 status = decode_putfh(xdr);
5688 if (status)
5689 goto out;
5690 status = decode_write(xdr, res);
5691 if (status)
5692 goto out;
5693 decode_getfattr(xdr, res->fattr, res->server,
5694 !RPC_IS_ASYNC(rqstp->rq_task));
5695 if (!status)
5696 status = res->count;
5697 out:
5698 return status;
5702 * Decode COMMIT response
5704 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5705 struct nfs_writeres *res)
5707 struct compound_hdr hdr;
5708 int status;
5710 status = decode_compound_hdr(xdr, &hdr);
5711 if (status)
5712 goto out;
5713 status = decode_sequence(xdr, &res->seq_res, rqstp);
5714 if (status)
5715 goto out;
5716 status = decode_putfh(xdr);
5717 if (status)
5718 goto out;
5719 status = decode_commit(xdr, res);
5720 if (status)
5721 goto out;
5722 decode_getfattr(xdr, res->fattr, res->server,
5723 !RPC_IS_ASYNC(rqstp->rq_task));
5724 out:
5725 return status;
5729 * Decode FSINFO response
5731 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
5732 struct nfs4_fsinfo_res *res)
5734 struct compound_hdr hdr;
5735 int status;
5737 status = decode_compound_hdr(xdr, &hdr);
5738 if (!status)
5739 status = decode_sequence(xdr, &res->seq_res, req);
5740 if (!status)
5741 status = decode_putfh(xdr);
5742 if (!status)
5743 status = decode_fsinfo(xdr, res->fsinfo);
5744 return status;
5748 * Decode PATHCONF response
5750 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
5751 struct nfs4_pathconf_res *res)
5753 struct compound_hdr hdr;
5754 int status;
5756 status = decode_compound_hdr(xdr, &hdr);
5757 if (!status)
5758 status = decode_sequence(xdr, &res->seq_res, req);
5759 if (!status)
5760 status = decode_putfh(xdr);
5761 if (!status)
5762 status = decode_pathconf(xdr, res->pathconf);
5763 return status;
5767 * Decode STATFS response
5769 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
5770 struct nfs4_statfs_res *res)
5772 struct compound_hdr hdr;
5773 int status;
5775 status = decode_compound_hdr(xdr, &hdr);
5776 if (!status)
5777 status = decode_sequence(xdr, &res->seq_res, req);
5778 if (!status)
5779 status = decode_putfh(xdr);
5780 if (!status)
5781 status = decode_statfs(xdr, res->fsstat);
5782 return status;
5786 * Decode GETATTR_BITMAP response
5788 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5789 struct xdr_stream *xdr,
5790 struct nfs4_server_caps_res *res)
5792 struct compound_hdr hdr;
5793 int status;
5795 status = decode_compound_hdr(xdr, &hdr);
5796 if (status)
5797 goto out;
5798 status = decode_sequence(xdr, &res->seq_res, req);
5799 if (status)
5800 goto out;
5801 status = decode_putfh(xdr);
5802 if (status)
5803 goto out;
5804 status = decode_server_caps(xdr, res);
5805 out:
5806 return status;
5810 * Decode RENEW response
5812 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5813 void *__unused)
5815 struct compound_hdr hdr;
5816 int status;
5818 status = decode_compound_hdr(xdr, &hdr);
5819 if (!status)
5820 status = decode_renew(xdr);
5821 return status;
5825 * Decode SETCLIENTID response
5827 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5828 struct xdr_stream *xdr,
5829 struct nfs4_setclientid_res *res)
5831 struct compound_hdr hdr;
5832 int status;
5834 status = decode_compound_hdr(xdr, &hdr);
5835 if (!status)
5836 status = decode_setclientid(xdr, res);
5837 return status;
5841 * Decode SETCLIENTID_CONFIRM response
5843 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5844 struct xdr_stream *xdr,
5845 struct nfs_fsinfo *fsinfo)
5847 struct compound_hdr hdr;
5848 int status;
5850 status = decode_compound_hdr(xdr, &hdr);
5851 if (!status)
5852 status = decode_setclientid_confirm(xdr);
5853 if (!status)
5854 status = decode_putrootfh(xdr);
5855 if (!status)
5856 status = decode_fsinfo(xdr, fsinfo);
5857 return status;
5861 * Decode DELEGRETURN response
5863 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5864 struct xdr_stream *xdr,
5865 struct nfs4_delegreturnres *res)
5867 struct compound_hdr hdr;
5868 int status;
5870 status = decode_compound_hdr(xdr, &hdr);
5871 if (status)
5872 goto out;
5873 status = decode_sequence(xdr, &res->seq_res, rqstp);
5874 if (status)
5875 goto out;
5876 status = decode_putfh(xdr);
5877 if (status != 0)
5878 goto out;
5879 status = decode_delegreturn(xdr);
5880 if (status != 0)
5881 goto out;
5882 decode_getfattr(xdr, res->fattr, res->server,
5883 !RPC_IS_ASYNC(rqstp->rq_task));
5884 out:
5885 return status;
5889 * Decode FS_LOCATIONS response
5891 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
5892 struct xdr_stream *xdr,
5893 struct nfs4_fs_locations_res *res)
5895 struct compound_hdr hdr;
5896 int status;
5898 status = decode_compound_hdr(xdr, &hdr);
5899 if (status)
5900 goto out;
5901 status = decode_sequence(xdr, &res->seq_res, req);
5902 if (status)
5903 goto out;
5904 status = decode_putfh(xdr);
5905 if (status)
5906 goto out;
5907 status = decode_lookup(xdr);
5908 if (status)
5909 goto out;
5910 xdr_enter_page(xdr, PAGE_SIZE);
5911 status = decode_getfattr(xdr, &res->fs_locations->fattr,
5912 res->fs_locations->server,
5913 !RPC_IS_ASYNC(req->rq_task));
5914 out:
5915 return status;
5918 #if defined(CONFIG_NFS_V4_1)
5920 * Decode EXCHANGE_ID response
5922 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
5923 struct xdr_stream *xdr,
5924 void *res)
5926 struct compound_hdr hdr;
5927 int status;
5929 status = decode_compound_hdr(xdr, &hdr);
5930 if (!status)
5931 status = decode_exchange_id(xdr, res);
5932 return status;
5936 * Decode CREATE_SESSION response
5938 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
5939 struct xdr_stream *xdr,
5940 struct nfs41_create_session_res *res)
5942 struct compound_hdr hdr;
5943 int status;
5945 status = decode_compound_hdr(xdr, &hdr);
5946 if (!status)
5947 status = decode_create_session(xdr, res);
5948 return status;
5952 * Decode DESTROY_SESSION response
5954 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
5955 struct xdr_stream *xdr,
5956 void *res)
5958 struct compound_hdr hdr;
5959 int status;
5961 status = decode_compound_hdr(xdr, &hdr);
5962 if (!status)
5963 status = decode_destroy_session(xdr, res);
5964 return status;
5968 * Decode SEQUENCE response
5970 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
5971 struct xdr_stream *xdr,
5972 struct nfs4_sequence_res *res)
5974 struct compound_hdr hdr;
5975 int status;
5977 status = decode_compound_hdr(xdr, &hdr);
5978 if (!status)
5979 status = decode_sequence(xdr, res, rqstp);
5980 return status;
5984 * Decode GET_LEASE_TIME response
5986 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
5987 struct xdr_stream *xdr,
5988 struct nfs4_get_lease_time_res *res)
5990 struct compound_hdr hdr;
5991 int status;
5993 status = decode_compound_hdr(xdr, &hdr);
5994 if (!status)
5995 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
5996 if (!status)
5997 status = decode_putrootfh(xdr);
5998 if (!status)
5999 status = decode_fsinfo(xdr, res->lr_fsinfo);
6000 return status;
6004 * Decode RECLAIM_COMPLETE response
6006 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6007 struct xdr_stream *xdr,
6008 struct nfs41_reclaim_complete_res *res)
6010 struct compound_hdr hdr;
6011 int status;
6013 status = decode_compound_hdr(xdr, &hdr);
6014 if (!status)
6015 status = decode_sequence(xdr, &res->seq_res, rqstp);
6016 if (!status)
6017 status = decode_reclaim_complete(xdr, (void *)NULL);
6018 return status;
6022 * Decode GETDEVINFO response
6024 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6025 struct xdr_stream *xdr,
6026 struct nfs4_getdeviceinfo_res *res)
6028 struct compound_hdr hdr;
6029 int status;
6031 status = decode_compound_hdr(xdr, &hdr);
6032 if (status != 0)
6033 goto out;
6034 status = decode_sequence(xdr, &res->seq_res, rqstp);
6035 if (status != 0)
6036 goto out;
6037 status = decode_getdeviceinfo(xdr, res->pdev);
6038 out:
6039 return status;
6043 * Decode LAYOUTGET response
6045 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6046 struct xdr_stream *xdr,
6047 struct nfs4_layoutget_res *res)
6049 struct compound_hdr hdr;
6050 int status;
6052 status = decode_compound_hdr(xdr, &hdr);
6053 if (status)
6054 goto out;
6055 status = decode_sequence(xdr, &res->seq_res, rqstp);
6056 if (status)
6057 goto out;
6058 status = decode_putfh(xdr);
6059 if (status)
6060 goto out;
6061 status = decode_layoutget(xdr, rqstp, res);
6062 out:
6063 return status;
6065 #endif /* CONFIG_NFS_V4_1 */
6068 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6069 * the local page cache.
6070 * @xdr: XDR stream where entry resides
6071 * @entry: buffer to fill in with entry data
6072 * @plus: boolean indicating whether this should be a readdirplus entry
6074 * Returns zero if successful, otherwise a negative errno value is
6075 * returned.
6077 * This function is not invoked during READDIR reply decoding, but
6078 * rather whenever an application invokes the getdents(2) system call
6079 * on a directory already in our cache.
6081 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6082 int plus)
6084 uint32_t bitmap[2] = {0};
6085 uint32_t len;
6086 __be32 *p = xdr_inline_decode(xdr, 4);
6087 if (unlikely(!p))
6088 goto out_overflow;
6089 if (*p == xdr_zero) {
6090 p = xdr_inline_decode(xdr, 4);
6091 if (unlikely(!p))
6092 goto out_overflow;
6093 if (*p == xdr_zero)
6094 return -EAGAIN;
6095 entry->eof = 1;
6096 return -EBADCOOKIE;
6099 p = xdr_inline_decode(xdr, 12);
6100 if (unlikely(!p))
6101 goto out_overflow;
6102 entry->prev_cookie = entry->cookie;
6103 p = xdr_decode_hyper(p, &entry->cookie);
6104 entry->len = be32_to_cpup(p);
6106 p = xdr_inline_decode(xdr, entry->len);
6107 if (unlikely(!p))
6108 goto out_overflow;
6109 entry->name = (const char *) p;
6112 * In case the server doesn't return an inode number,
6113 * we fake one here. (We don't use inode number 0,
6114 * since glibc seems to choke on it...)
6116 entry->ino = 1;
6117 entry->fattr->valid = 0;
6119 if (decode_attr_bitmap(xdr, bitmap) < 0)
6120 goto out_overflow;
6122 if (decode_attr_length(xdr, &len, &p) < 0)
6123 goto out_overflow;
6125 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6126 entry->server, 1) < 0)
6127 goto out_overflow;
6128 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6129 entry->ino = entry->fattr->fileid;
6131 entry->d_type = DT_UNKNOWN;
6132 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6133 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6135 if (verify_attr_len(xdr, p, len) < 0)
6136 goto out_overflow;
6138 return 0;
6140 out_overflow:
6141 print_overflow_msg(__func__, xdr);
6142 return -EAGAIN;
6146 * We need to translate between nfs status return values and
6147 * the local errno values which may not be the same.
6149 static struct {
6150 int stat;
6151 int errno;
6152 } nfs_errtbl[] = {
6153 { NFS4_OK, 0 },
6154 { NFS4ERR_PERM, -EPERM },
6155 { NFS4ERR_NOENT, -ENOENT },
6156 { NFS4ERR_IO, -errno_NFSERR_IO},
6157 { NFS4ERR_NXIO, -ENXIO },
6158 { NFS4ERR_ACCESS, -EACCES },
6159 { NFS4ERR_EXIST, -EEXIST },
6160 { NFS4ERR_XDEV, -EXDEV },
6161 { NFS4ERR_NOTDIR, -ENOTDIR },
6162 { NFS4ERR_ISDIR, -EISDIR },
6163 { NFS4ERR_INVAL, -EINVAL },
6164 { NFS4ERR_FBIG, -EFBIG },
6165 { NFS4ERR_NOSPC, -ENOSPC },
6166 { NFS4ERR_ROFS, -EROFS },
6167 { NFS4ERR_MLINK, -EMLINK },
6168 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6169 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6170 { NFS4ERR_DQUOT, -EDQUOT },
6171 { NFS4ERR_STALE, -ESTALE },
6172 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6173 { NFS4ERR_BADOWNER, -EINVAL },
6174 { NFS4ERR_BADNAME, -EINVAL },
6175 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6176 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6177 { NFS4ERR_TOOSMALL, -ETOOSMALL },
6178 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
6179 { NFS4ERR_BADTYPE, -EBADTYPE },
6180 { NFS4ERR_LOCKED, -EAGAIN },
6181 { NFS4ERR_SYMLINK, -ELOOP },
6182 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6183 { NFS4ERR_DEADLOCK, -EDEADLK },
6184 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
6185 * to be handled by a
6186 * middle-layer.
6188 { -1, -EIO }
6192 * Convert an NFS error code to a local one.
6193 * This one is used jointly by NFSv2 and NFSv3.
6195 static int
6196 nfs4_stat_to_errno(int stat)
6198 int i;
6199 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6200 if (nfs_errtbl[i].stat == stat)
6201 return nfs_errtbl[i].errno;
6203 if (stat <= 10000 || stat > 10100) {
6204 /* The server is looney tunes. */
6205 return -EREMOTEIO;
6207 /* If we cannot translate the error, the recovery routines should
6208 * handle it.
6209 * Note: remaining NFSv4 error codes have values > 10000, so should
6210 * not conflict with native Linux error codes.
6212 return -stat;
6215 #define PROC(proc, argtype, restype) \
6216 [NFSPROC4_CLNT_##proc] = { \
6217 .p_proc = NFSPROC4_COMPOUND, \
6218 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6219 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6220 .p_arglen = NFS4_##argtype##_sz, \
6221 .p_replen = NFS4_##restype##_sz, \
6222 .p_statidx = NFSPROC4_CLNT_##proc, \
6223 .p_name = #proc, \
6226 struct rpc_procinfo nfs4_procedures[] = {
6227 PROC(READ, enc_read, dec_read),
6228 PROC(WRITE, enc_write, dec_write),
6229 PROC(COMMIT, enc_commit, dec_commit),
6230 PROC(OPEN, enc_open, dec_open),
6231 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6232 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6233 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6234 PROC(CLOSE, enc_close, dec_close),
6235 PROC(SETATTR, enc_setattr, dec_setattr),
6236 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6237 PROC(RENEW, enc_renew, dec_renew),
6238 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6239 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6240 PROC(LOCK, enc_lock, dec_lock),
6241 PROC(LOCKT, enc_lockt, dec_lockt),
6242 PROC(LOCKU, enc_locku, dec_locku),
6243 PROC(ACCESS, enc_access, dec_access),
6244 PROC(GETATTR, enc_getattr, dec_getattr),
6245 PROC(LOOKUP, enc_lookup, dec_lookup),
6246 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6247 PROC(REMOVE, enc_remove, dec_remove),
6248 PROC(RENAME, enc_rename, dec_rename),
6249 PROC(LINK, enc_link, dec_link),
6250 PROC(SYMLINK, enc_symlink, dec_symlink),
6251 PROC(CREATE, enc_create, dec_create),
6252 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6253 PROC(STATFS, enc_statfs, dec_statfs),
6254 PROC(READLINK, enc_readlink, dec_readlink),
6255 PROC(READDIR, enc_readdir, dec_readdir),
6256 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6257 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6258 PROC(GETACL, enc_getacl, dec_getacl),
6259 PROC(SETACL, enc_setacl, dec_setacl),
6260 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6261 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
6262 #if defined(CONFIG_NFS_V4_1)
6263 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6264 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6265 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6266 PROC(SEQUENCE, enc_sequence, dec_sequence),
6267 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6268 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6269 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6270 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
6271 #endif /* CONFIG_NFS_V4_1 */
6274 struct rpc_version nfs_version4 = {
6275 .number = 4,
6276 .nrprocs = ARRAY_SIZE(nfs4_procedures),
6277 .procs = nfs4_procedures
6281 * Local variables:
6282 * c-basic-offset: 8
6283 * End: