4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
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
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>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
197 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
202 #define encode_link_maxsz (op_encode_hdr_maxsz + \
204 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
205 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 1 + encode_stateid_maxsz + 8)
208 #define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
218 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
222 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
226 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227 #define encode_create_maxsz (op_encode_hdr_maxsz + \
228 1 + 2 + nfs4_name_maxsz + \
230 #define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
233 #define encode_statfs_maxsz (encode_getattr_maxsz)
234 #define decode_statfs_maxsz (decode_getattr_maxsz)
235 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
237 #define encode_getacl_maxsz (encode_getattr_maxsz)
238 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242 #define decode_setacl_maxsz (decode_setattr_maxsz)
243 #define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245 #define decode_fs_locations_maxsz \
248 #if defined(CONFIG_NFS_V4_1)
249 #define NFS4_MAX_MACHINE_NAME_LEN (64)
251 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
252 encode_verifier_maxsz + \
253 1 /* co_ownerid.len */ + \
254 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
257 0 /* SP4_NONE (for now) */ + \
258 1 /* zero implemetation id array */)
259 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
260 2 /* eir_clientid */ + \
261 1 /* eir_sequenceid */ + \
262 1 /* eir_flags */ + \
264 0 /* SP4_NONE (for now) */ + \
265 2 /* eir_server_owner.so_minor_id */ + \
266 /* eir_server_owner.so_major_id<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 /* eir_server_scope<> */ \
269 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
270 1 /* eir_server_impl_id array length */ + \
271 0 /* ignored eir_server_impl_id contents */)
272 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
273 #define decode_channel_attrs_maxsz (6 + \
274 1 /* ca_rdma_ird.len */ + \
276 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
277 2 /* csa_clientid */ + \
278 1 /* csa_sequence */ + \
279 1 /* csa_flags */ + \
280 encode_channel_attrs_maxsz + \
281 encode_channel_attrs_maxsz + \
282 1 /* csa_cb_program */ + \
283 1 /* csa_sec_parms.len (1) */ + \
284 1 /* cb_secflavor (AUTH_SYS) */ + \
286 1 /* machinename.len */ + \
287 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
290 1 /* gids.len (0) */)
291 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
292 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
293 1 /* csr_sequence */ + \
294 1 /* csr_flags */ + \
295 decode_channel_attrs_maxsz + \
296 decode_channel_attrs_maxsz)
297 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
298 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
299 #define encode_sequence_maxsz 0 /* stub */
300 #define decode_sequence_maxsz 0 /* stub */
301 #else /* CONFIG_NFS_V4_1 */
302 #define encode_sequence_maxsz 0
303 #define decode_sequence_maxsz 0
304 #endif /* CONFIG_NFS_V4_1 */
306 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
307 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
308 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
309 encode_sequence_maxsz + \
310 encode_putfh_maxsz + \
312 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
313 decode_sequence_maxsz + \
314 decode_putfh_maxsz + \
316 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
317 encode_sequence_maxsz + \
318 encode_putfh_maxsz + \
319 encode_readlink_maxsz)
320 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
321 decode_sequence_maxsz + \
322 decode_putfh_maxsz + \
323 decode_readlink_maxsz)
324 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
325 encode_sequence_maxsz + \
326 encode_putfh_maxsz + \
327 encode_readdir_maxsz)
328 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
329 decode_sequence_maxsz + \
330 decode_putfh_maxsz + \
331 decode_readdir_maxsz)
332 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
333 encode_sequence_maxsz + \
334 encode_putfh_maxsz + \
335 encode_write_maxsz + \
336 encode_getattr_maxsz)
337 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
338 decode_sequence_maxsz + \
339 decode_putfh_maxsz + \
340 decode_write_maxsz + \
341 decode_getattr_maxsz)
342 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
343 encode_sequence_maxsz + \
344 encode_putfh_maxsz + \
345 encode_commit_maxsz + \
346 encode_getattr_maxsz)
347 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
348 decode_sequence_maxsz + \
349 decode_putfh_maxsz + \
350 decode_commit_maxsz + \
351 decode_getattr_maxsz)
352 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
353 encode_sequence_maxsz + \
354 encode_putfh_maxsz + \
355 encode_savefh_maxsz + \
356 encode_open_maxsz + \
357 encode_getfh_maxsz + \
358 encode_getattr_maxsz + \
359 encode_restorefh_maxsz + \
360 encode_getattr_maxsz)
361 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
362 decode_sequence_maxsz + \
363 decode_putfh_maxsz + \
364 decode_savefh_maxsz + \
365 decode_open_maxsz + \
366 decode_getfh_maxsz + \
367 decode_getattr_maxsz + \
368 decode_restorefh_maxsz + \
369 decode_getattr_maxsz)
370 #define NFS4_enc_open_confirm_sz \
371 (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
373 encode_open_confirm_maxsz)
374 #define NFS4_dec_open_confirm_sz \
375 (compound_decode_hdr_maxsz + \
376 decode_putfh_maxsz + \
377 decode_open_confirm_maxsz)
378 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
379 encode_sequence_maxsz + \
380 encode_putfh_maxsz + \
381 encode_open_maxsz + \
382 encode_getattr_maxsz)
383 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
384 decode_sequence_maxsz + \
385 decode_putfh_maxsz + \
386 decode_open_maxsz + \
387 decode_getattr_maxsz)
388 #define NFS4_enc_open_downgrade_sz \
389 (compound_encode_hdr_maxsz + \
390 encode_sequence_maxsz + \
391 encode_putfh_maxsz + \
392 encode_open_downgrade_maxsz + \
393 encode_getattr_maxsz)
394 #define NFS4_dec_open_downgrade_sz \
395 (compound_decode_hdr_maxsz + \
396 decode_sequence_maxsz + \
397 decode_putfh_maxsz + \
398 decode_open_downgrade_maxsz + \
399 decode_getattr_maxsz)
400 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
401 encode_sequence_maxsz + \
402 encode_putfh_maxsz + \
403 encode_close_maxsz + \
404 encode_getattr_maxsz)
405 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
406 decode_sequence_maxsz + \
407 decode_putfh_maxsz + \
408 decode_close_maxsz + \
409 decode_getattr_maxsz)
410 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
411 encode_sequence_maxsz + \
412 encode_putfh_maxsz + \
413 encode_setattr_maxsz + \
414 encode_getattr_maxsz)
415 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
416 decode_sequence_maxsz + \
417 decode_putfh_maxsz + \
418 decode_setattr_maxsz + \
419 decode_getattr_maxsz)
420 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
421 encode_sequence_maxsz + \
422 encode_putfh_maxsz + \
424 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
425 decode_sequence_maxsz + \
426 decode_putfh_maxsz + \
428 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
430 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
432 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
433 encode_setclientid_maxsz)
434 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
435 decode_setclientid_maxsz)
436 #define NFS4_enc_setclientid_confirm_sz \
437 (compound_encode_hdr_maxsz + \
438 encode_setclientid_confirm_maxsz + \
439 encode_putrootfh_maxsz + \
441 #define NFS4_dec_setclientid_confirm_sz \
442 (compound_decode_hdr_maxsz + \
443 decode_setclientid_confirm_maxsz + \
444 decode_putrootfh_maxsz + \
446 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
447 encode_sequence_maxsz + \
448 encode_putfh_maxsz + \
450 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
451 decode_sequence_maxsz + \
452 decode_putfh_maxsz + \
454 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
455 encode_sequence_maxsz + \
456 encode_putfh_maxsz + \
458 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
459 decode_sequence_maxsz + \
460 decode_putfh_maxsz + \
462 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
463 encode_sequence_maxsz + \
464 encode_putfh_maxsz + \
466 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
467 decode_sequence_maxsz + \
468 decode_putfh_maxsz + \
470 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
471 encode_sequence_maxsz + \
472 encode_putfh_maxsz + \
473 encode_access_maxsz + \
474 encode_getattr_maxsz)
475 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
476 decode_sequence_maxsz + \
477 decode_putfh_maxsz + \
478 decode_access_maxsz + \
479 decode_getattr_maxsz)
480 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
481 encode_sequence_maxsz + \
482 encode_putfh_maxsz + \
483 encode_getattr_maxsz)
484 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
485 decode_sequence_maxsz + \
486 decode_putfh_maxsz + \
487 decode_getattr_maxsz)
488 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
489 encode_sequence_maxsz + \
490 encode_putfh_maxsz + \
491 encode_lookup_maxsz + \
492 encode_getattr_maxsz + \
494 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
495 decode_sequence_maxsz + \
496 decode_putfh_maxsz + \
497 decode_lookup_maxsz + \
498 decode_getattr_maxsz + \
500 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
501 encode_sequence_maxsz + \
502 encode_putrootfh_maxsz + \
503 encode_getattr_maxsz + \
505 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
506 decode_sequence_maxsz + \
507 decode_putrootfh_maxsz + \
508 decode_getattr_maxsz + \
510 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
511 encode_sequence_maxsz + \
512 encode_putfh_maxsz + \
513 encode_remove_maxsz + \
514 encode_getattr_maxsz)
515 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
516 decode_sequence_maxsz + \
517 decode_putfh_maxsz + \
518 decode_remove_maxsz + \
519 decode_getattr_maxsz)
520 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
521 encode_sequence_maxsz + \
522 encode_putfh_maxsz + \
523 encode_savefh_maxsz + \
524 encode_putfh_maxsz + \
525 encode_rename_maxsz + \
526 encode_getattr_maxsz + \
527 encode_restorefh_maxsz + \
528 encode_getattr_maxsz)
529 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
530 decode_sequence_maxsz + \
531 decode_putfh_maxsz + \
532 decode_savefh_maxsz + \
533 decode_putfh_maxsz + \
534 decode_rename_maxsz + \
535 decode_getattr_maxsz + \
536 decode_restorefh_maxsz + \
537 decode_getattr_maxsz)
538 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
539 encode_sequence_maxsz + \
540 encode_putfh_maxsz + \
541 encode_savefh_maxsz + \
542 encode_putfh_maxsz + \
543 encode_link_maxsz + \
544 decode_getattr_maxsz + \
545 encode_restorefh_maxsz + \
546 decode_getattr_maxsz)
547 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
548 decode_sequence_maxsz + \
549 decode_putfh_maxsz + \
550 decode_savefh_maxsz + \
551 decode_putfh_maxsz + \
552 decode_link_maxsz + \
553 decode_getattr_maxsz + \
554 decode_restorefh_maxsz + \
555 decode_getattr_maxsz)
556 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
557 encode_sequence_maxsz + \
558 encode_putfh_maxsz + \
559 encode_symlink_maxsz + \
560 encode_getattr_maxsz + \
562 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
563 decode_sequence_maxsz + \
564 decode_putfh_maxsz + \
565 decode_symlink_maxsz + \
566 decode_getattr_maxsz + \
568 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
569 encode_sequence_maxsz + \
570 encode_putfh_maxsz + \
571 encode_savefh_maxsz + \
572 encode_create_maxsz + \
573 encode_getfh_maxsz + \
574 encode_getattr_maxsz + \
575 encode_restorefh_maxsz + \
576 encode_getattr_maxsz)
577 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
578 decode_sequence_maxsz + \
579 decode_putfh_maxsz + \
580 decode_savefh_maxsz + \
581 decode_create_maxsz + \
582 decode_getfh_maxsz + \
583 decode_getattr_maxsz + \
584 decode_restorefh_maxsz + \
585 decode_getattr_maxsz)
586 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
587 encode_sequence_maxsz + \
588 encode_putfh_maxsz + \
589 encode_getattr_maxsz)
590 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
591 decode_sequence_maxsz + \
592 decode_putfh_maxsz + \
593 decode_getattr_maxsz)
594 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
595 encode_sequence_maxsz + \
596 encode_putfh_maxsz + \
598 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
599 decode_sequence_maxsz + \
600 decode_putfh_maxsz + \
602 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
603 encode_sequence_maxsz + \
604 encode_putfh_maxsz + \
605 encode_getattr_maxsz)
606 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
607 decode_sequence_maxsz + \
608 decode_putfh_maxsz + \
609 decode_getattr_maxsz)
610 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
611 encode_sequence_maxsz + \
612 encode_putfh_maxsz + \
613 encode_delegreturn_maxsz + \
614 encode_getattr_maxsz)
615 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
616 decode_sequence_maxsz + \
617 decode_delegreturn_maxsz + \
618 decode_getattr_maxsz)
619 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
620 encode_sequence_maxsz + \
621 encode_putfh_maxsz + \
623 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
624 decode_sequence_maxsz + \
625 decode_putfh_maxsz + \
627 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
628 encode_sequence_maxsz + \
629 encode_putfh_maxsz + \
631 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
632 decode_sequence_maxsz + \
633 decode_putfh_maxsz + \
635 #define NFS4_enc_fs_locations_sz \
636 (compound_encode_hdr_maxsz + \
637 encode_sequence_maxsz + \
638 encode_putfh_maxsz + \
639 encode_lookup_maxsz + \
640 encode_fs_locations_maxsz)
641 #define NFS4_dec_fs_locations_sz \
642 (compound_decode_hdr_maxsz + \
643 decode_sequence_maxsz + \
644 decode_putfh_maxsz + \
645 decode_lookup_maxsz + \
646 decode_fs_locations_maxsz)
647 #if defined(CONFIG_NFS_V4_1)
648 #define NFS4_enc_exchange_id_sz \
649 (compound_encode_hdr_maxsz + \
650 encode_exchange_id_maxsz)
651 #define NFS4_dec_exchange_id_sz \
652 (compound_decode_hdr_maxsz + \
653 decode_exchange_id_maxsz)
654 #define NFS4_enc_create_session_sz \
655 (compound_encode_hdr_maxsz + \
656 encode_create_session_maxsz)
657 #define NFS4_dec_create_session_sz \
658 (compound_decode_hdr_maxsz + \
659 decode_create_session_maxsz)
660 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
661 encode_destroy_session_maxsz)
662 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
663 decode_destroy_session_maxsz)
664 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
665 encode_sequence_maxsz + \
666 encode_putrootfh_maxsz + \
668 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
669 decode_sequence_maxsz + \
670 decode_putrootfh_maxsz + \
672 #endif /* CONFIG_NFS_V4_1 */
674 static const umode_t nfs_type2fmt[] = {
681 [NF4SOCK] = S_IFSOCK,
687 struct compound_hdr {
693 uint32_t replen; /* expected reply words */
698 * START OF "GENERIC" ENCODE ROUTINES.
699 * These may look a little ugly since they are imported from a "generic"
700 * set of XDR encode/decode routines which are intended to be shared by
701 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
703 * If the pain of reading these is too great, it should be a straightforward
704 * task to translate them into Linux-specific versions which are more
705 * consistent with the style used in NFSv2/v3...
707 #define WRITE32(n) *p++ = htonl(n)
708 #define WRITE64(n) do { \
709 *p++ = htonl((uint32_t)((n) >> 32)); \
710 *p++ = htonl((uint32_t)(n)); \
712 #define WRITEMEM(ptr,nbytes) do { \
713 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
716 #define RESERVE_SPACE(nbytes) do { \
717 p = xdr_reserve_space(xdr, nbytes); \
721 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
725 p = xdr_reserve_space(xdr, 4 + len);
727 xdr_encode_opaque(p, str, len);
730 static void encode_compound_hdr(struct xdr_stream *xdr,
731 struct rpc_rqst *req,
732 struct compound_hdr *hdr)
735 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
737 /* initialize running count of expected bytes in reply.
738 * NOTE: the replied tag SHOULD be the same is the one sent,
739 * but this is not required as a MUST for the server to do so. */
740 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
742 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
743 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
744 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
745 WRITE32(hdr->taglen);
746 WRITEMEM(hdr->tag, hdr->taglen);
747 WRITE32(hdr->minorversion);
752 static void encode_nops(struct compound_hdr *hdr)
754 BUG_ON(hdr->nops > NFS4_MAX_OPS);
755 *hdr->nops_p = htonl(hdr->nops);
758 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
762 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
764 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
767 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
769 char owner_name[IDMAP_NAMESZ];
770 char owner_group[IDMAP_NAMESZ];
771 int owner_namelen = 0;
772 int owner_grouplen = 0;
780 * We reserve enough space to write the entire attribute buffer at once.
781 * In the worst-case, this would be
782 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
783 * = 36 bytes, plus any contribution from variable-length fields
784 * such as owner/group.
789 if (iap->ia_valid & ATTR_SIZE)
791 if (iap->ia_valid & ATTR_MODE)
793 if (iap->ia_valid & ATTR_UID) {
794 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
795 if (owner_namelen < 0) {
796 dprintk("nfs: couldn't resolve uid %d to string\n",
799 strcpy(owner_name, "nobody");
800 owner_namelen = sizeof("nobody") - 1;
803 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
805 if (iap->ia_valid & ATTR_GID) {
806 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
807 if (owner_grouplen < 0) {
808 dprintk("nfs: couldn't resolve gid %d to string\n",
810 strcpy(owner_group, "nobody");
811 owner_grouplen = sizeof("nobody") - 1;
814 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
816 if (iap->ia_valid & ATTR_ATIME_SET)
818 else if (iap->ia_valid & ATTR_ATIME)
820 if (iap->ia_valid & ATTR_MTIME_SET)
822 else if (iap->ia_valid & ATTR_MTIME)
827 * We write the bitmap length now, but leave the bitmap and the attribute
828 * buffer length to be backfilled at the end of this routine.
834 if (iap->ia_valid & ATTR_SIZE) {
835 bmval0 |= FATTR4_WORD0_SIZE;
836 WRITE64(iap->ia_size);
838 if (iap->ia_valid & ATTR_MODE) {
839 bmval1 |= FATTR4_WORD1_MODE;
840 WRITE32(iap->ia_mode & S_IALLUGO);
842 if (iap->ia_valid & ATTR_UID) {
843 bmval1 |= FATTR4_WORD1_OWNER;
844 WRITE32(owner_namelen);
845 WRITEMEM(owner_name, owner_namelen);
847 if (iap->ia_valid & ATTR_GID) {
848 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
849 WRITE32(owner_grouplen);
850 WRITEMEM(owner_group, owner_grouplen);
852 if (iap->ia_valid & ATTR_ATIME_SET) {
853 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
854 WRITE32(NFS4_SET_TO_CLIENT_TIME);
856 WRITE32(iap->ia_mtime.tv_sec);
857 WRITE32(iap->ia_mtime.tv_nsec);
859 else if (iap->ia_valid & ATTR_ATIME) {
860 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
861 WRITE32(NFS4_SET_TO_SERVER_TIME);
863 if (iap->ia_valid & ATTR_MTIME_SET) {
864 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
865 WRITE32(NFS4_SET_TO_CLIENT_TIME);
867 WRITE32(iap->ia_mtime.tv_sec);
868 WRITE32(iap->ia_mtime.tv_nsec);
870 else if (iap->ia_valid & ATTR_MTIME) {
871 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
872 WRITE32(NFS4_SET_TO_SERVER_TIME);
876 * Now we backfill the bitmap and the attribute buffer length.
878 if (len != ((char *)p - (char *)q) + 4) {
879 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
880 len, ((char *)p - (char *)q) + 4);
883 len = (char *)p - (char *)q - 12;
884 *q++ = htonl(bmval0);
885 *q++ = htonl(bmval1);
891 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
899 hdr->replen += decode_access_maxsz;
902 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
906 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
908 WRITE32(arg->seqid->sequence->counter);
909 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
911 hdr->replen += decode_close_maxsz;
914 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
920 WRITE64(args->offset);
921 WRITE32(args->count);
923 hdr->replen += decode_commit_maxsz;
926 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
932 WRITE32(create->ftype);
934 switch (create->ftype) {
937 WRITE32(create->u.symlink.len);
938 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
941 case NF4BLK: case NF4CHR:
943 WRITE32(create->u.device.specdata1);
944 WRITE32(create->u.device.specdata2);
951 RESERVE_SPACE(4 + create->name->len);
952 WRITE32(create->name->len);
953 WRITEMEM(create->name->name, create->name->len);
955 hdr->replen += decode_create_maxsz;
957 encode_attrs(xdr, create->attrs, create->server);
960 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
969 hdr->replen += decode_getattr_maxsz;
972 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
982 hdr->replen += decode_getattr_maxsz;
985 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
987 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
988 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
991 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
993 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
994 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
997 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
999 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1000 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1003 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1010 hdr->replen += decode_getfh_maxsz;
1013 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1017 RESERVE_SPACE(8 + name->len);
1020 WRITEMEM(name->name, name->len);
1022 hdr->replen += decode_link_maxsz;
1025 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1027 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1028 return block ? NFS4_READW_LT : NFS4_READ_LT;
1029 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1032 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1034 if (fl->fl_end == OFFSET_MAX)
1035 return ~(uint64_t)0;
1036 return fl->fl_end - fl->fl_start + 1;
1040 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1041 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1043 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1049 WRITE32(nfs4_lock_type(args->fl, args->block));
1050 WRITE32(args->reclaim);
1051 WRITE64(args->fl->fl_start);
1052 WRITE64(nfs4_lock_length(args->fl));
1053 WRITE32(args->new_lock_owner);
1054 if (args->new_lock_owner){
1055 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
1056 WRITE32(args->open_seqid->sequence->counter);
1057 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
1058 WRITE32(args->lock_seqid->sequence->counter);
1059 WRITE64(args->lock_owner.clientid);
1061 WRITEMEM("lock id:", 8);
1062 WRITE64(args->lock_owner.id);
1065 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1066 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
1067 WRITE32(args->lock_seqid->sequence->counter);
1070 hdr->replen += decode_lock_maxsz;
1073 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1079 WRITE32(nfs4_lock_type(args->fl, 0));
1080 WRITE64(args->fl->fl_start);
1081 WRITE64(nfs4_lock_length(args->fl));
1082 WRITE64(args->lock_owner.clientid);
1084 WRITEMEM("lock id:", 8);
1085 WRITE64(args->lock_owner.id);
1087 hdr->replen += decode_lockt_maxsz;
1090 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1094 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
1096 WRITE32(nfs4_lock_type(args->fl, 0));
1097 WRITE32(args->seqid->sequence->counter);
1098 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
1099 WRITE64(args->fl->fl_start);
1100 WRITE64(nfs4_lock_length(args->fl));
1102 hdr->replen += decode_locku_maxsz;
1105 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1107 int len = name->len;
1110 RESERVE_SPACE(8 + len);
1113 WRITEMEM(name->name, len);
1115 hdr->replen += decode_lookup_maxsz;
1118 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1123 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1125 WRITE32(NFS4_SHARE_ACCESS_READ);
1128 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1130 case FMODE_READ|FMODE_WRITE:
1131 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1136 WRITE32(0); /* for linux, share_deny = 0 always */
1139 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1143 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1148 WRITE32(arg->seqid->sequence->counter);
1149 encode_share_access(xdr, arg->fmode);
1151 WRITE64(arg->clientid);
1153 WRITEMEM("open id:", 8);
1157 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1162 switch(arg->open_flags & O_EXCL) {
1164 WRITE32(NFS4_CREATE_UNCHECKED);
1165 encode_attrs(xdr, arg->u.attrs, arg->server);
1168 WRITE32(NFS4_CREATE_EXCLUSIVE);
1169 encode_nfs4_verifier(xdr, &arg->u.verifier);
1173 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1178 switch (arg->open_flags & O_CREAT) {
1180 WRITE32(NFS4_OPEN_NOCREATE);
1183 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1184 WRITE32(NFS4_OPEN_CREATE);
1185 encode_createmode(xdr, arg);
1189 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1194 switch (delegation_type) {
1196 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1199 WRITE32(NFS4_OPEN_DELEGATE_READ);
1201 case FMODE_WRITE|FMODE_READ:
1202 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1209 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1214 WRITE32(NFS4_OPEN_CLAIM_NULL);
1215 encode_string(xdr, name->len, name->name);
1218 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1223 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1224 encode_delegation_type(xdr, type);
1227 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1231 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1232 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1233 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1234 encode_string(xdr, name->len, name->name);
1237 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1239 encode_openhdr(xdr, arg);
1240 encode_opentype(xdr, arg);
1241 switch (arg->claim) {
1242 case NFS4_OPEN_CLAIM_NULL:
1243 encode_claim_null(xdr, arg->name);
1245 case NFS4_OPEN_CLAIM_PREVIOUS:
1246 encode_claim_previous(xdr, arg->u.delegation_type);
1248 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1249 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1255 hdr->replen += decode_open_maxsz;
1258 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1262 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1263 WRITE32(OP_OPEN_CONFIRM);
1264 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1265 WRITE32(arg->seqid->sequence->counter);
1267 hdr->replen += decode_open_confirm_maxsz;
1270 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1274 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1275 WRITE32(OP_OPEN_DOWNGRADE);
1276 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1277 WRITE32(arg->seqid->sequence->counter);
1278 encode_share_access(xdr, arg->fmode);
1280 hdr->replen += decode_open_downgrade_maxsz;
1284 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1289 RESERVE_SPACE(8 + len);
1292 WRITEMEM(fh->data, len);
1294 hdr->replen += decode_putfh_maxsz;
1297 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1302 WRITE32(OP_PUTROOTFH);
1304 hdr->replen += decode_putrootfh_maxsz;
1307 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1309 nfs4_stateid stateid;
1312 RESERVE_SPACE(NFS4_STATEID_SIZE);
1313 if (ctx->state != NULL) {
1314 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1315 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1317 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1320 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1327 encode_stateid(xdr, args->context);
1330 WRITE64(args->offset);
1331 WRITE32(args->count);
1333 hdr->replen += decode_read_maxsz;
1336 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1338 uint32_t attrs[2] = {
1339 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1340 FATTR4_WORD1_MOUNTED_ON_FILEID,
1344 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1345 WRITE32(OP_READDIR);
1346 WRITE64(readdir->cookie);
1347 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1348 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1349 WRITE32(readdir->count);
1351 /* Switch to mounted_on_fileid if the server supports it */
1352 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1353 attrs[0] &= ~FATTR4_WORD0_FILEID;
1355 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1356 WRITE32(attrs[0] & readdir->bitmask[0]);
1357 WRITE32(attrs[1] & readdir->bitmask[1]);
1359 hdr->replen += decode_readdir_maxsz;
1360 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1362 (unsigned long long)readdir->cookie,
1363 ((u32 *)readdir->verifier.data)[0],
1364 ((u32 *)readdir->verifier.data)[1],
1365 attrs[0] & readdir->bitmask[0],
1366 attrs[1] & readdir->bitmask[1]);
1369 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1374 WRITE32(OP_READLINK);
1376 hdr->replen += decode_readlink_maxsz;
1379 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1383 RESERVE_SPACE(8 + name->len);
1386 WRITEMEM(name->name, name->len);
1388 hdr->replen += decode_remove_maxsz;
1391 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1395 RESERVE_SPACE(8 + oldname->len);
1397 WRITE32(oldname->len);
1398 WRITEMEM(oldname->name, oldname->len);
1400 RESERVE_SPACE(4 + newname->len);
1401 WRITE32(newname->len);
1402 WRITEMEM(newname->name, newname->len);
1404 hdr->replen += decode_rename_maxsz;
1407 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1413 WRITE64(client_stateid->cl_clientid);
1415 hdr->replen += decode_renew_maxsz;
1419 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1424 WRITE32(OP_RESTOREFH);
1426 hdr->replen += decode_restorefh_maxsz;
1430 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1434 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1435 WRITE32(OP_SETATTR);
1436 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1439 WRITE32(FATTR4_WORD0_ACL);
1440 if (arg->acl_len % 4)
1443 WRITE32(arg->acl_len);
1444 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1446 hdr->replen += decode_setacl_maxsz;
1451 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1458 hdr->replen += decode_savefh_maxsz;
1461 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1465 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1466 WRITE32(OP_SETATTR);
1467 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1469 hdr->replen += decode_setattr_maxsz;
1470 encode_attrs(xdr, arg->iap, server);
1473 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1477 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1478 WRITE32(OP_SETCLIENTID);
1479 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1481 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1483 WRITE32(setclientid->sc_prog);
1484 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1485 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1487 WRITE32(setclientid->sc_cb_ident);
1489 hdr->replen += decode_setclientid_maxsz;
1492 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1496 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1497 WRITE32(OP_SETCLIENTID_CONFIRM);
1498 WRITE64(client_state->cl_clientid);
1499 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1501 hdr->replen += decode_setclientid_confirm_maxsz;
1504 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1511 encode_stateid(xdr, args->context);
1514 WRITE64(args->offset);
1515 WRITE32(args->stable);
1516 WRITE32(args->count);
1518 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1520 hdr->replen += decode_write_maxsz;
1523 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1527 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1529 WRITE32(OP_DELEGRETURN);
1530 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1532 hdr->replen += decode_delegreturn_maxsz;
1535 #if defined(CONFIG_NFS_V4_1)
1536 /* NFSv4.1 operations */
1537 static void encode_exchange_id(struct xdr_stream *xdr,
1538 struct nfs41_exchange_id_args *args,
1539 struct compound_hdr *hdr)
1543 RESERVE_SPACE(4 + sizeof(args->verifier->data));
1544 WRITE32(OP_EXCHANGE_ID);
1545 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1547 encode_string(xdr, args->id_len, args->id);
1550 WRITE32(args->flags);
1551 WRITE32(0); /* zero length state_protect4_a */
1552 WRITE32(0); /* zero length implementation id array */
1554 hdr->replen += decode_exchange_id_maxsz;
1557 static void encode_create_session(struct xdr_stream *xdr,
1558 struct nfs41_create_session_args *args,
1559 struct compound_hdr *hdr)
1562 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1564 struct nfs_client *clp = args->client;
1567 WRITE32(OP_CREATE_SESSION);
1570 WRITE64(clp->cl_ex_clid);
1573 WRITE32(clp->cl_seqid); /*Sequence id */
1574 WRITE32(args->flags); /*flags */
1576 RESERVE_SPACE(2*28); /* 2 channel_attrs */
1578 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1579 WRITE32(args->fc_attrs.max_rqst_sz); /* max req size */
1580 WRITE32(args->fc_attrs.max_resp_sz); /* max resp size */
1581 WRITE32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1582 WRITE32(args->fc_attrs.max_ops); /* max operations */
1583 WRITE32(args->fc_attrs.max_reqs); /* max requests */
1584 WRITE32(0); /* rdmachannel_attrs */
1587 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1588 WRITE32(args->bc_attrs.max_rqst_sz); /* max req size */
1589 WRITE32(args->bc_attrs.max_resp_sz); /* max resp size */
1590 WRITE32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1591 WRITE32(args->bc_attrs.max_ops); /* max operations */
1592 WRITE32(args->bc_attrs.max_reqs); /* max requests */
1593 WRITE32(0); /* rdmachannel_attrs */
1596 WRITE32(args->cb_program); /* cb_program */
1598 RESERVE_SPACE(4); /* # of security flavors */
1602 WRITE32(RPC_AUTH_UNIX); /* auth_sys */
1604 /* authsys_parms rfc1831 */
1606 WRITE32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1607 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1609 RESERVE_SPACE(16 + len);
1611 WRITEMEM(machine_name, len);
1612 WRITE32(0); /* UID */
1613 WRITE32(0); /* GID */
1614 WRITE32(0); /* No more gids */
1616 hdr->replen += decode_create_session_maxsz;
1619 static void encode_destroy_session(struct xdr_stream *xdr,
1620 struct nfs4_session *session,
1621 struct compound_hdr *hdr)
1624 RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
1625 WRITE32(OP_DESTROY_SESSION);
1626 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1628 hdr->replen += decode_destroy_session_maxsz;
1630 #endif /* CONFIG_NFS_V4_1 */
1632 static void encode_sequence(struct xdr_stream *xdr,
1633 const struct nfs4_sequence_args *args,
1634 struct compound_hdr *hdr)
1636 #if defined(CONFIG_NFS_V4_1)
1637 struct nfs4_session *session = args->sa_session;
1644 hdr->replen += decode_sequence_maxsz;
1645 #endif /* CONFIG_NFS_V4_1 */
1649 * END OF "GENERIC" ENCODE ROUTINES.
1652 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1654 #if defined(CONFIG_NFS_V4_1)
1655 if (args->sa_session)
1656 return args->sa_session->clp->cl_minorversion;
1657 #endif /* CONFIG_NFS_V4_1 */
1662 * Encode an ACCESS request
1664 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1666 struct xdr_stream xdr;
1667 struct compound_hdr hdr = {
1668 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1671 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1672 encode_compound_hdr(&xdr, req, &hdr);
1673 encode_sequence(&xdr, &args->seq_args, &hdr);
1674 encode_putfh(&xdr, args->fh, &hdr);
1675 encode_access(&xdr, args->access, &hdr);
1676 encode_getfattr(&xdr, args->bitmask, &hdr);
1682 * Encode LOOKUP request
1684 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1686 struct xdr_stream xdr;
1687 struct compound_hdr hdr = {
1688 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1691 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1692 encode_compound_hdr(&xdr, req, &hdr);
1693 encode_sequence(&xdr, &args->seq_args, &hdr);
1694 encode_putfh(&xdr, args->dir_fh, &hdr);
1695 encode_lookup(&xdr, args->name, &hdr);
1696 encode_getfh(&xdr, &hdr);
1697 encode_getfattr(&xdr, args->bitmask, &hdr);
1703 * Encode LOOKUP_ROOT request
1705 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1707 struct xdr_stream xdr;
1708 struct compound_hdr hdr = {
1709 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1712 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1713 encode_compound_hdr(&xdr, req, &hdr);
1714 encode_sequence(&xdr, &args->seq_args, &hdr);
1715 encode_putrootfh(&xdr, &hdr);
1716 encode_getfh(&xdr, &hdr);
1717 encode_getfattr(&xdr, args->bitmask, &hdr);
1723 * Encode REMOVE request
1725 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1727 struct xdr_stream xdr;
1728 struct compound_hdr hdr = {
1729 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1732 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1733 encode_compound_hdr(&xdr, req, &hdr);
1734 encode_sequence(&xdr, &args->seq_args, &hdr);
1735 encode_putfh(&xdr, args->fh, &hdr);
1736 encode_remove(&xdr, &args->name, &hdr);
1737 encode_getfattr(&xdr, args->bitmask, &hdr);
1743 * Encode RENAME request
1745 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1747 struct xdr_stream xdr;
1748 struct compound_hdr hdr = {
1749 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1752 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1753 encode_compound_hdr(&xdr, req, &hdr);
1754 encode_sequence(&xdr, &args->seq_args, &hdr);
1755 encode_putfh(&xdr, args->old_dir, &hdr);
1756 encode_savefh(&xdr, &hdr);
1757 encode_putfh(&xdr, args->new_dir, &hdr);
1758 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1759 encode_getfattr(&xdr, args->bitmask, &hdr);
1760 encode_restorefh(&xdr, &hdr);
1761 encode_getfattr(&xdr, args->bitmask, &hdr);
1767 * Encode LINK request
1769 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1771 struct xdr_stream xdr;
1772 struct compound_hdr hdr = {
1773 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1776 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1777 encode_compound_hdr(&xdr, req, &hdr);
1778 encode_sequence(&xdr, &args->seq_args, &hdr);
1779 encode_putfh(&xdr, args->fh, &hdr);
1780 encode_savefh(&xdr, &hdr);
1781 encode_putfh(&xdr, args->dir_fh, &hdr);
1782 encode_link(&xdr, args->name, &hdr);
1783 encode_getfattr(&xdr, args->bitmask, &hdr);
1784 encode_restorefh(&xdr, &hdr);
1785 encode_getfattr(&xdr, args->bitmask, &hdr);
1791 * Encode CREATE request
1793 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1795 struct xdr_stream xdr;
1796 struct compound_hdr hdr = {
1797 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1800 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1801 encode_compound_hdr(&xdr, req, &hdr);
1802 encode_sequence(&xdr, &args->seq_args, &hdr);
1803 encode_putfh(&xdr, args->dir_fh, &hdr);
1804 encode_savefh(&xdr, &hdr);
1805 encode_create(&xdr, args, &hdr);
1806 encode_getfh(&xdr, &hdr);
1807 encode_getfattr(&xdr, args->bitmask, &hdr);
1808 encode_restorefh(&xdr, &hdr);
1809 encode_getfattr(&xdr, args->bitmask, &hdr);
1815 * Encode SYMLINK request
1817 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1819 return nfs4_xdr_enc_create(req, p, args);
1823 * Encode GETATTR request
1825 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1827 struct xdr_stream xdr;
1828 struct compound_hdr hdr = {
1829 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1832 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1833 encode_compound_hdr(&xdr, req, &hdr);
1834 encode_sequence(&xdr, &args->seq_args, &hdr);
1835 encode_putfh(&xdr, args->fh, &hdr);
1836 encode_getfattr(&xdr, args->bitmask, &hdr);
1842 * Encode a CLOSE request
1844 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1846 struct xdr_stream xdr;
1847 struct compound_hdr hdr = {
1848 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1851 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1852 encode_compound_hdr(&xdr, req, &hdr);
1853 encode_sequence(&xdr, &args->seq_args, &hdr);
1854 encode_putfh(&xdr, args->fh, &hdr);
1855 encode_close(&xdr, args, &hdr);
1856 encode_getfattr(&xdr, args->bitmask, &hdr);
1862 * Encode an OPEN request
1864 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1866 struct xdr_stream xdr;
1867 struct compound_hdr hdr = {
1868 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1871 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1872 encode_compound_hdr(&xdr, req, &hdr);
1873 encode_sequence(&xdr, &args->seq_args, &hdr);
1874 encode_putfh(&xdr, args->fh, &hdr);
1875 encode_savefh(&xdr, &hdr);
1876 encode_open(&xdr, args, &hdr);
1877 encode_getfh(&xdr, &hdr);
1878 encode_getfattr(&xdr, args->bitmask, &hdr);
1879 encode_restorefh(&xdr, &hdr);
1880 encode_getfattr(&xdr, args->bitmask, &hdr);
1886 * Encode an OPEN_CONFIRM request
1888 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1890 struct xdr_stream xdr;
1891 struct compound_hdr hdr = {
1895 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1896 encode_compound_hdr(&xdr, req, &hdr);
1897 encode_putfh(&xdr, args->fh, &hdr);
1898 encode_open_confirm(&xdr, args, &hdr);
1904 * Encode an OPEN request with no attributes.
1906 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1908 struct xdr_stream xdr;
1909 struct compound_hdr hdr = {
1910 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1914 encode_compound_hdr(&xdr, req, &hdr);
1915 encode_sequence(&xdr, &args->seq_args, &hdr);
1916 encode_putfh(&xdr, args->fh, &hdr);
1917 encode_open(&xdr, args, &hdr);
1918 encode_getfattr(&xdr, args->bitmask, &hdr);
1924 * Encode an OPEN_DOWNGRADE request
1926 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1928 struct xdr_stream xdr;
1929 struct compound_hdr hdr = {
1930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1933 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1934 encode_compound_hdr(&xdr, req, &hdr);
1935 encode_sequence(&xdr, &args->seq_args, &hdr);
1936 encode_putfh(&xdr, args->fh, &hdr);
1937 encode_open_downgrade(&xdr, args, &hdr);
1938 encode_getfattr(&xdr, args->bitmask, &hdr);
1944 * Encode a LOCK request
1946 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
1950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1954 encode_compound_hdr(&xdr, req, &hdr);
1955 encode_sequence(&xdr, &args->seq_args, &hdr);
1956 encode_putfh(&xdr, args->fh, &hdr);
1957 encode_lock(&xdr, args, &hdr);
1963 * Encode a LOCKT request
1965 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1967 struct xdr_stream xdr;
1968 struct compound_hdr hdr = {
1969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1972 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1973 encode_compound_hdr(&xdr, req, &hdr);
1974 encode_sequence(&xdr, &args->seq_args, &hdr);
1975 encode_putfh(&xdr, args->fh, &hdr);
1976 encode_lockt(&xdr, args, &hdr);
1982 * Encode a LOCKU request
1984 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1986 struct xdr_stream xdr;
1987 struct compound_hdr hdr = {
1988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1991 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1992 encode_compound_hdr(&xdr, req, &hdr);
1993 encode_sequence(&xdr, &args->seq_args, &hdr);
1994 encode_putfh(&xdr, args->fh, &hdr);
1995 encode_locku(&xdr, args, &hdr);
2001 * Encode a READLINK request
2003 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
2005 struct xdr_stream xdr;
2006 struct compound_hdr hdr = {
2007 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2010 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2011 encode_compound_hdr(&xdr, req, &hdr);
2012 encode_sequence(&xdr, &args->seq_args, &hdr);
2013 encode_putfh(&xdr, args->fh, &hdr);
2014 encode_readlink(&xdr, args, req, &hdr);
2016 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2017 args->pgbase, args->pglen);
2023 * Encode a READDIR request
2025 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
2027 struct xdr_stream xdr;
2028 struct compound_hdr hdr = {
2029 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2032 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2033 encode_compound_hdr(&xdr, req, &hdr);
2034 encode_sequence(&xdr, &args->seq_args, &hdr);
2035 encode_putfh(&xdr, args->fh, &hdr);
2036 encode_readdir(&xdr, args, req, &hdr);
2038 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2039 args->pgbase, args->count);
2040 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2041 __func__, hdr.replen << 2, args->pages,
2042 args->pgbase, args->count);
2048 * Encode a READ request
2050 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
2052 struct xdr_stream xdr;
2053 struct compound_hdr hdr = {
2054 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2057 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2058 encode_compound_hdr(&xdr, req, &hdr);
2059 encode_sequence(&xdr, &args->seq_args, &hdr);
2060 encode_putfh(&xdr, args->fh, &hdr);
2061 encode_read(&xdr, args, &hdr);
2063 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2064 args->pages, args->pgbase, args->count);
2065 req->rq_rcv_buf.flags |= XDRBUF_READ;
2071 * Encode an SETATTR request
2073 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
2075 struct xdr_stream xdr;
2076 struct compound_hdr hdr = {
2077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2080 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2081 encode_compound_hdr(&xdr, req, &hdr);
2082 encode_sequence(&xdr, &args->seq_args, &hdr);
2083 encode_putfh(&xdr, args->fh, &hdr);
2084 encode_setattr(&xdr, args, args->server, &hdr);
2085 encode_getfattr(&xdr, args->bitmask, &hdr);
2091 * Encode a GETACL request
2094 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
2095 struct nfs_getaclargs *args)
2097 struct xdr_stream xdr;
2098 struct compound_hdr hdr = {
2099 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2103 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2104 encode_compound_hdr(&xdr, req, &hdr);
2105 encode_sequence(&xdr, &args->seq_args, &hdr);
2106 encode_putfh(&xdr, args->fh, &hdr);
2107 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
2108 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2110 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2111 args->acl_pages, args->acl_pgbase, args->acl_len);
2117 * Encode a WRITE request
2119 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
2121 struct xdr_stream xdr;
2122 struct compound_hdr hdr = {
2123 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2126 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2127 encode_compound_hdr(&xdr, req, &hdr);
2128 encode_sequence(&xdr, &args->seq_args, &hdr);
2129 encode_putfh(&xdr, args->fh, &hdr);
2130 encode_write(&xdr, args, &hdr);
2131 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2132 encode_getfattr(&xdr, args->bitmask, &hdr);
2140 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
2142 struct xdr_stream xdr;
2143 struct compound_hdr hdr = {
2144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2147 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2148 encode_compound_hdr(&xdr, req, &hdr);
2149 encode_sequence(&xdr, &args->seq_args, &hdr);
2150 encode_putfh(&xdr, args->fh, &hdr);
2151 encode_commit(&xdr, args, &hdr);
2152 encode_getfattr(&xdr, args->bitmask, &hdr);
2160 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
2162 struct xdr_stream xdr;
2163 struct compound_hdr hdr = {
2164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2167 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2168 encode_compound_hdr(&xdr, req, &hdr);
2169 encode_sequence(&xdr, &args->seq_args, &hdr);
2170 encode_putfh(&xdr, args->fh, &hdr);
2171 encode_fsinfo(&xdr, args->bitmask, &hdr);
2177 * a PATHCONF request
2179 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
2181 struct xdr_stream xdr;
2182 struct compound_hdr hdr = {
2183 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2186 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2187 encode_compound_hdr(&xdr, req, &hdr);
2188 encode_sequence(&xdr, &args->seq_args, &hdr);
2189 encode_putfh(&xdr, args->fh, &hdr);
2190 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2199 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2201 struct xdr_stream xdr;
2202 struct compound_hdr hdr = {
2203 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2206 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2207 encode_compound_hdr(&xdr, req, &hdr);
2208 encode_sequence(&xdr, &args->seq_args, &hdr);
2209 encode_putfh(&xdr, args->fh, &hdr);
2210 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2211 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2217 * GETATTR_BITMAP request
2219 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2220 struct nfs4_server_caps_arg *args)
2222 struct xdr_stream xdr;
2223 struct compound_hdr hdr = {
2224 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2227 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2228 encode_compound_hdr(&xdr, req, &hdr);
2229 encode_sequence(&xdr, &args->seq_args, &hdr);
2230 encode_putfh(&xdr, args->fhandle, &hdr);
2231 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2232 FATTR4_WORD0_LINK_SUPPORT|
2233 FATTR4_WORD0_SYMLINK_SUPPORT|
2234 FATTR4_WORD0_ACLSUPPORT, &hdr);
2242 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2244 struct xdr_stream xdr;
2245 struct compound_hdr hdr = {
2249 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2250 encode_compound_hdr(&xdr, req, &hdr);
2251 encode_renew(&xdr, clp, &hdr);
2257 * a SETCLIENTID request
2259 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2261 struct xdr_stream xdr;
2262 struct compound_hdr hdr = {
2266 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2267 encode_compound_hdr(&xdr, req, &hdr);
2268 encode_setclientid(&xdr, sc, &hdr);
2274 * a SETCLIENTID_CONFIRM request
2276 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2278 struct xdr_stream xdr;
2279 struct compound_hdr hdr = {
2282 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2284 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2285 encode_compound_hdr(&xdr, req, &hdr);
2286 encode_setclientid_confirm(&xdr, clp, &hdr);
2287 encode_putrootfh(&xdr, &hdr);
2288 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2294 * DELEGRETURN request
2296 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2298 struct xdr_stream xdr;
2299 struct compound_hdr hdr = {
2300 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2303 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2304 encode_compound_hdr(&xdr, req, &hdr);
2305 encode_sequence(&xdr, &args->seq_args, &hdr);
2306 encode_putfh(&xdr, args->fhandle, &hdr);
2307 encode_delegreturn(&xdr, args->stateid, &hdr);
2308 encode_getfattr(&xdr, args->bitmask, &hdr);
2314 * Encode FS_LOCATIONS request
2316 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2318 struct xdr_stream xdr;
2319 struct compound_hdr hdr = {
2320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2324 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2325 encode_compound_hdr(&xdr, req, &hdr);
2326 encode_sequence(&xdr, &args->seq_args, &hdr);
2327 encode_putfh(&xdr, args->dir_fh, &hdr);
2328 encode_lookup(&xdr, args->name, &hdr);
2329 replen = hdr.replen; /* get the attribute into args->page */
2330 encode_fs_locations(&xdr, args->bitmask, &hdr);
2332 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2338 #if defined(CONFIG_NFS_V4_1)
2340 * EXCHANGE_ID request
2342 static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2343 struct nfs41_exchange_id_args *args)
2345 struct xdr_stream xdr;
2346 struct compound_hdr hdr = {
2347 .minorversion = args->client->cl_minorversion,
2350 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2351 encode_compound_hdr(&xdr, req, &hdr);
2352 encode_exchange_id(&xdr, args, &hdr);
2358 * a CREATE_SESSION request
2360 static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2361 struct nfs41_create_session_args *args)
2363 struct xdr_stream xdr;
2364 struct compound_hdr hdr = {
2365 .minorversion = args->client->cl_minorversion,
2368 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2369 encode_compound_hdr(&xdr, req, &hdr);
2370 encode_create_session(&xdr, args, &hdr);
2376 * a DESTROY_SESSION request
2378 static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2379 struct nfs4_session *session)
2381 struct xdr_stream xdr;
2382 struct compound_hdr hdr = {
2383 .minorversion = session->clp->cl_minorversion,
2386 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2387 encode_compound_hdr(&xdr, req, &hdr);
2388 encode_destroy_session(&xdr, session, &hdr);
2394 * a GET_LEASE_TIME request
2396 static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2397 struct nfs4_get_lease_time_args *args)
2399 struct xdr_stream xdr;
2400 struct compound_hdr hdr = {
2401 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2403 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2405 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2406 encode_compound_hdr(&xdr, req, &hdr);
2407 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2408 encode_putrootfh(&xdr, &hdr);
2409 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2413 #endif /* CONFIG_NFS_V4_1 */
2416 * START OF "GENERIC" DECODE ROUTINES.
2417 * These may look a little ugly since they are imported from a "generic"
2418 * set of XDR encode/decode routines which are intended to be shared by
2419 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2421 * If the pain of reading these is too great, it should be a straightforward
2422 * task to translate them into Linux-specific versions which are more
2423 * consistent with the style used in NFSv2/v3...
2425 #define READ32(x) (x) = ntohl(*p++)
2426 #define READ64(x) do { \
2427 (x) = (u64)ntohl(*p++) << 32; \
2428 (x) |= ntohl(*p++); \
2430 #define READTIME(x) do { \
2432 (x.tv_sec) = ntohl(*p++); \
2433 (x.tv_nsec) = ntohl(*p++); \
2435 #define COPYMEM(x,nbytes) do { \
2436 memcpy((x), p, nbytes); \
2437 p += XDR_QUADLEN(nbytes); \
2440 #define READ_BUF(nbytes) do { \
2441 p = xdr_inline_decode(xdr, nbytes); \
2442 if (unlikely(!p)) { \
2443 dprintk("nfs: %s: prematurely hit end of receive" \
2444 " buffer\n", __func__); \
2445 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2446 __func__, xdr->p, nbytes, xdr->end); \
2451 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2458 *string = (char *)p;
2462 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2467 READ32(hdr->status);
2468 READ32(hdr->taglen);
2470 READ_BUF(hdr->taglen + 4);
2471 hdr->tag = (char *)p;
2472 p += XDR_QUADLEN(hdr->taglen);
2474 if (unlikely(hdr->nops < 1))
2475 return nfs4_stat_to_errno(hdr->status);
2479 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2487 if (opnum != expected) {
2488 dprintk("nfs: Server returned operation"
2489 " %d but we issued a request for %d\n",
2494 if (nfserr != NFS_OK)
2495 return nfs4_stat_to_errno(nfserr);
2500 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2503 unsigned int strlen;
2507 return decode_opaque_inline(xdr, &strlen, &str);
2510 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2518 bitmap[0] = bitmap[1] = 0;
2519 READ_BUF((bmlen << 2));
2528 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2538 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2540 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2541 decode_attr_bitmap(xdr, bitmask);
2542 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2544 bitmask[0] = bitmask[1] = 0;
2545 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2549 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2555 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2557 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2560 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2561 dprintk("%s: bad type %d\n", __func__, *type);
2564 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2565 ret = NFS_ATTR_FATTR_TYPE;
2567 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2571 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2577 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2579 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2582 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2583 ret = NFS_ATTR_FATTR_CHANGE;
2585 dprintk("%s: change attribute=%Lu\n", __func__,
2586 (unsigned long long)*change);
2590 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2596 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2598 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2601 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2602 ret = NFS_ATTR_FATTR_SIZE;
2604 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2608 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2613 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2615 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2618 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2620 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2624 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2629 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2631 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2634 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2636 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2640 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2647 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2649 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2651 READ64(fsid->major);
2652 READ64(fsid->minor);
2653 bitmap[0] &= ~FATTR4_WORD0_FSID;
2654 ret = NFS_ATTR_FATTR_FSID;
2656 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2657 (unsigned long long)fsid->major,
2658 (unsigned long long)fsid->minor);
2662 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2667 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2669 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2672 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2674 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2678 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2682 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2685 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2688 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2690 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2694 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2700 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2702 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2705 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2706 ret = NFS_ATTR_FATTR_FILEID;
2708 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2712 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2718 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2720 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2723 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2724 ret = NFS_ATTR_FATTR_FILEID;
2726 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2730 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2736 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2738 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2741 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2743 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2747 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2753 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2755 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2758 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2760 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2764 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2770 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2772 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2775 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2777 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2781 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2792 path->ncomponents = 0;
2793 while (path->ncomponents < n) {
2794 struct nfs4_string *component = &path->components[path->ncomponents];
2795 status = decode_opaque_inline(xdr, &component->len, &component->data);
2796 if (unlikely(status != 0))
2798 if (path->ncomponents != n)
2800 dprintk("%s", component->data);
2801 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2802 path->ncomponents++;
2804 dprintk("cannot parse %d components in path\n", n);
2812 /* a root pathname is sent as a zero component4 */
2813 path->ncomponents = 1;
2814 path->components[0].len=0;
2815 path->components[0].data=NULL;
2816 dprintk("path /\n");
2819 dprintk(" status %d", status);
2824 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2830 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2833 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2835 dprintk("%s: fsroot ", __func__);
2836 status = decode_pathname(xdr, &res->fs_path);
2837 if (unlikely(status != 0))
2843 res->nlocations = 0;
2844 while (res->nlocations < n) {
2846 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2852 dprintk("%s: servers ", __func__);
2853 while (loc->nservers < m) {
2854 struct nfs4_string *server = &loc->servers[loc->nservers];
2855 status = decode_opaque_inline(xdr, &server->len, &server->data);
2856 if (unlikely(status != 0))
2858 dprintk("%s ", server->data);
2859 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2863 dprintk("%s: using first %u of %u servers "
2864 "returned for location %u\n",
2866 NFS4_FS_LOCATION_MAXSERVERS,
2867 m, res->nlocations);
2868 for (i = loc->nservers; i < m; i++) {
2871 status = decode_opaque_inline(xdr, &len, &data);
2872 if (unlikely(status != 0))
2877 status = decode_pathname(xdr, &loc->rootpath);
2878 if (unlikely(status != 0))
2880 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2883 if (res->nlocations != 0)
2884 status = NFS_ATTR_FATTR_V4_REFERRAL;
2886 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2893 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2899 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2901 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2904 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2906 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2910 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2916 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2918 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2921 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2923 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2927 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2933 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2935 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2938 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2940 dprintk("%s: maxname=%u\n", __func__, *maxname);
2944 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2950 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2952 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2956 if (maxread > 0x7FFFFFFF)
2957 maxread = 0x7FFFFFFF;
2958 *res = (uint32_t)maxread;
2959 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2961 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
2965 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2971 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2973 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2977 if (maxwrite > 0x7FFFFFFF)
2978 maxwrite = 0x7FFFFFFF;
2979 *res = (uint32_t)maxwrite;
2980 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2982 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
2986 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
2993 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2995 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2998 *mode = tmp & ~S_IFMT;
2999 bitmap[1] &= ~FATTR4_WORD1_MODE;
3000 ret = NFS_ATTR_FATTR_MODE;
3002 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3006 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3012 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3014 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3017 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3018 ret = NFS_ATTR_FATTR_NLINK;
3020 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3024 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
3031 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3033 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3037 if (len < XDR_MAX_NETOBJ) {
3038 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3039 ret = NFS_ATTR_FATTR_OWNER;
3041 dprintk("%s: nfs_map_name_to_uid failed!\n",
3044 dprintk("%s: name too long (%u)!\n",
3046 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3048 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3052 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
3059 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3061 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3065 if (len < XDR_MAX_NETOBJ) {
3066 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3067 ret = NFS_ATTR_FATTR_GROUP;
3069 dprintk("%s: nfs_map_group_to_gid failed!\n",
3072 dprintk("%s: name too long (%u)!\n",
3074 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3076 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3080 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3082 uint32_t major = 0, minor = 0;
3087 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3089 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3095 tmp = MKDEV(major, minor);
3096 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3098 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3099 ret = NFS_ATTR_FATTR_RDEV;
3101 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3105 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3111 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3113 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3116 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3118 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3122 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3128 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3130 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3133 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3135 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3139 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3145 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3147 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3150 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3152 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3156 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3162 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3164 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3167 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3168 ret = NFS_ATTR_FATTR_SPACE_USED;
3170 dprintk("%s: space used=%Lu\n", __func__,
3171 (unsigned long long)*used);
3175 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3184 time->tv_sec = (time_t)sec;
3185 time->tv_nsec = (long)nsec;
3189 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3195 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3197 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3198 status = decode_attr_time(xdr, time);
3200 status = NFS_ATTR_FATTR_ATIME;
3201 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3203 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3207 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3213 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3215 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3216 status = decode_attr_time(xdr, time);
3218 status = NFS_ATTR_FATTR_CTIME;
3219 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3221 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3225 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3231 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3233 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3234 status = decode_attr_time(xdr, time);
3236 status = NFS_ATTR_FATTR_MTIME;
3237 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3239 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3243 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3245 unsigned int attrwords = XDR_QUADLEN(attrlen);
3246 unsigned int nwords = xdr->p - savep;
3248 if (unlikely(attrwords != nwords)) {
3249 dprintk("%s: server returned incorrect attribute length: "
3253 (attrwords < nwords) ? '<' : '>',
3260 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3265 READ32(cinfo->atomic);
3266 READ64(cinfo->before);
3267 READ64(cinfo->after);
3271 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3277 status = decode_op_hdr(xdr, OP_ACCESS);
3283 access->supported = supp;
3284 access->access = acc;
3288 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3293 status = decode_op_hdr(xdr, OP_CLOSE);
3295 nfs_increment_open_seqid(status, res->seqid);
3298 READ_BUF(NFS4_STATEID_SIZE);
3299 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3303 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3308 status = decode_op_hdr(xdr, OP_COMMIT);
3312 COPYMEM(res->verf->verifier, 8);
3316 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3322 status = decode_op_hdr(xdr, OP_CREATE);
3325 if ((status = decode_change_info(xdr, cinfo)))
3329 READ_BUF(bmlen << 2);
3333 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3336 uint32_t attrlen, bitmap[2] = {0};
3339 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3341 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3343 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3345 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3347 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3349 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3351 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3353 status = verify_attr_len(xdr, savep, attrlen);
3355 dprintk("%s: xdr returned %d!\n", __func__, -status);
3359 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3362 uint32_t attrlen, bitmap[2] = {0};
3365 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3367 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3369 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3372 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3374 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3376 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3378 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3380 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3382 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3385 status = verify_attr_len(xdr, savep, attrlen);
3387 dprintk("%s: xdr returned %d!\n", __func__, -status);
3391 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3394 uint32_t attrlen, bitmap[2] = {0};
3397 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3399 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3401 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3404 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3406 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3409 status = verify_attr_len(xdr, savep, attrlen);
3411 dprintk("%s: xdr returned %d!\n", __func__, -status);
3415 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3425 status = decode_op_hdr(xdr, OP_GETATTR);
3429 status = decode_attr_bitmap(xdr, bitmap);
3433 status = decode_attr_length(xdr, &attrlen, &savep);
3438 status = decode_attr_type(xdr, bitmap, &type);
3443 fattr->mode |= nfs_type2fmt[type];
3444 fattr->valid |= status;
3447 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3450 fattr->valid |= status;
3452 status = decode_attr_size(xdr, bitmap, &fattr->size);
3455 fattr->valid |= status;
3457 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3460 fattr->valid |= status;
3462 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3465 fattr->valid |= status;
3467 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3468 struct nfs4_fs_locations,
3472 fattr->valid |= status;
3474 status = decode_attr_mode(xdr, bitmap, &fmode);
3478 fattr->mode |= fmode;
3479 fattr->valid |= status;
3482 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3485 fattr->valid |= status;
3487 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3490 fattr->valid |= status;
3492 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3495 fattr->valid |= status;
3497 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3500 fattr->valid |= status;
3502 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3505 fattr->valid |= status;
3507 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3510 fattr->valid |= status;
3512 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3515 fattr->valid |= status;
3517 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3520 fattr->valid |= status;
3522 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3525 if (status != 0 && !(fattr->valid & status)) {
3526 fattr->fileid = fileid;
3527 fattr->valid |= status;
3530 status = verify_attr_len(xdr, savep, attrlen);
3532 dprintk("%s: xdr returned %d\n", __func__, -status);
3537 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3540 uint32_t attrlen, bitmap[2];
3543 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3545 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3547 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3550 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3552 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3554 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3556 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3558 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3559 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3561 fsinfo->wtpref = fsinfo->wtmax;
3563 status = verify_attr_len(xdr, savep, attrlen);
3565 dprintk("%s: xdr returned %d!\n", __func__, -status);
3569 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3575 /* Zero handle first to allow comparisons */
3576 memset(fh, 0, sizeof(*fh));
3578 status = decode_op_hdr(xdr, OP_GETFH);
3584 if (len > NFS4_FHSIZE)
3588 COPYMEM(fh->data, len);
3592 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3596 status = decode_op_hdr(xdr, OP_LINK);
3599 return decode_change_info(xdr, cinfo);
3603 * We create the owner, so we know a proper owner.id length is 4.
3605 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3607 uint64_t offset, length, clientid;
3609 uint32_t namelen, type;
3616 fl->fl_start = (loff_t)offset;
3617 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3618 if (length == ~(uint64_t)0)
3619 fl->fl_end = OFFSET_MAX;
3620 fl->fl_type = F_WRLCK;
3622 fl->fl_type = F_RDLCK;
3628 return -NFS4ERR_DENIED;
3631 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3636 status = decode_op_hdr(xdr, OP_LOCK);
3640 READ_BUF(NFS4_STATEID_SIZE);
3641 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3642 } else if (status == -NFS4ERR_DENIED)
3643 status = decode_lock_denied(xdr, NULL);
3644 if (res->open_seqid != NULL)
3645 nfs_increment_open_seqid(status, res->open_seqid);
3646 nfs_increment_lock_seqid(status, res->lock_seqid);
3651 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3654 status = decode_op_hdr(xdr, OP_LOCKT);
3655 if (status == -NFS4ERR_DENIED)
3656 return decode_lock_denied(xdr, res->denied);
3660 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3665 status = decode_op_hdr(xdr, OP_LOCKU);
3667 nfs_increment_lock_seqid(status, res->seqid);
3669 READ_BUF(NFS4_STATEID_SIZE);
3670 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3675 static int decode_lookup(struct xdr_stream *xdr)
3677 return decode_op_hdr(xdr, OP_LOOKUP);
3680 /* This is too sick! */
3681 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3684 uint32_t limit_type, nblocks, blocksize;
3688 switch (limit_type) {
3695 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3700 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3703 uint32_t delegation_type;
3706 READ32(delegation_type);
3707 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3708 res->delegation_type = 0;
3711 READ_BUF(NFS4_STATEID_SIZE+4);
3712 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3713 READ32(res->do_recall);
3715 switch (delegation_type) {
3716 case NFS4_OPEN_DELEGATE_READ:
3717 res->delegation_type = FMODE_READ;
3719 case NFS4_OPEN_DELEGATE_WRITE:
3720 res->delegation_type = FMODE_WRITE|FMODE_READ;
3721 if (decode_space_limit(xdr, &res->maxsize) < 0)
3724 return decode_ace(xdr, NULL, res->server->nfs_client);
3727 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3730 uint32_t savewords, bmlen, i;
3733 status = decode_op_hdr(xdr, OP_OPEN);
3735 nfs_increment_open_seqid(status, res->seqid);
3738 READ_BUF(NFS4_STATEID_SIZE);
3739 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3741 decode_change_info(xdr, &res->cinfo);
3744 READ32(res->rflags);
3749 READ_BUF(bmlen << 2);
3750 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3751 for (i = 0; i < savewords; ++i)
3752 READ32(res->attrset[i]);
3753 for (; i < NFS4_BITMAP_SIZE; i++)
3754 res->attrset[i] = 0;
3756 return decode_delegation(xdr, res);
3758 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3762 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3767 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3769 nfs_increment_open_seqid(status, res->seqid);
3772 READ_BUF(NFS4_STATEID_SIZE);
3773 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3777 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3782 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3784 nfs_increment_open_seqid(status, res->seqid);
3787 READ_BUF(NFS4_STATEID_SIZE);
3788 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3792 static int decode_putfh(struct xdr_stream *xdr)
3794 return decode_op_hdr(xdr, OP_PUTFH);
3797 static int decode_putrootfh(struct xdr_stream *xdr)
3799 return decode_op_hdr(xdr, OP_PUTROOTFH);
3802 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3804 struct kvec *iov = req->rq_rcv_buf.head;
3806 uint32_t count, eof, recvd, hdrlen;
3809 status = decode_op_hdr(xdr, OP_READ);
3815 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3816 recvd = req->rq_rcv_buf.len - hdrlen;
3817 if (count > recvd) {
3818 dprintk("NFS: server cheating in read reply: "
3819 "count %u > recvd %u\n", count, recvd);
3823 xdr_read_pages(xdr, count);
3829 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3831 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3832 struct page *page = *rcvbuf->pages;
3833 struct kvec *iov = rcvbuf->head;
3835 u32 recvd, pglen = rcvbuf->page_len;
3836 __be32 *end, *entry, *p, *kaddr;
3837 unsigned int nr = 0;
3840 status = decode_op_hdr(xdr, OP_READDIR);
3844 COPYMEM(readdir->verifier.data, 8);
3845 dprintk("%s: verifier = %08x:%08x\n",
3847 ((u32 *)readdir->verifier.data)[0],
3848 ((u32 *)readdir->verifier.data)[1]);
3851 hdrlen = (char *) p - (char *) iov->iov_base;
3852 recvd = rcvbuf->len - hdrlen;
3855 xdr_read_pages(xdr, pglen);
3857 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3858 kaddr = p = kmap_atomic(page, KM_USER0);
3859 end = p + ((pglen + readdir->pgbase) >> 2);
3862 /* Make sure the packet actually has a value_follows and EOF entry */
3863 if ((entry + 1) > end)
3866 for (; *p++; nr++) {
3867 u32 len, attrlen, xlen;
3870 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3871 p += 2; /* cookie */
3872 len = ntohl(*p++); /* filename length */
3873 if (len > NFS4_MAXNAMLEN) {
3874 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3878 xlen = XDR_QUADLEN(len);
3879 if (end - p < xlen + 1)
3881 dprintk("filename = %*s\n", len, (char *)p);
3883 len = ntohl(*p++); /* bitmap length */
3884 if (end - p < len + 1)
3887 attrlen = XDR_QUADLEN(ntohl(*p++));
3888 if (end - p < attrlen + 2)
3890 p += attrlen; /* attributes */
3894 * Apparently some server sends responses that are a valid size, but
3895 * contain no entries, and have value_follows==0 and EOF==0. For
3896 * those, just set the EOF marker.
3898 if (!nr && entry[1] == 0) {
3899 dprintk("NFS: readdir reply truncated!\n");
3903 kunmap_atomic(kaddr, KM_USER0);
3907 * When we get a short packet there are 2 possibilities. We can
3908 * return an error, or fix up the response to look like a valid
3909 * response and return what we have so far. If there are no
3910 * entries and the packet was short, then return -EIO. If there
3911 * are valid entries in the response, return them and pretend that
3912 * the call was successful, but incomplete. The caller can retry the
3913 * readdir starting at the last cookie.
3915 dprintk("%s: short packet at entry %d\n", __func__, nr);
3916 entry[0] = entry[1] = 0;
3920 kunmap_atomic(kaddr, KM_USER0);
3921 return -errno_NFSERR_IO;
3924 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3926 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3927 struct kvec *iov = rcvbuf->head;
3934 status = decode_op_hdr(xdr, OP_READLINK);
3938 /* Convert length of symlink */
3941 if (len >= rcvbuf->page_len || len <= 0) {
3942 dprintk("nfs: server returned giant symlink!\n");
3943 return -ENAMETOOLONG;
3945 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3946 recvd = req->rq_rcv_buf.len - hdrlen;
3948 dprintk("NFS: server cheating in readlink reply: "
3949 "count %u > recvd %u\n", len, recvd);
3952 xdr_read_pages(xdr, len);
3954 * The XDR encode routine has set things up so that
3955 * the link text will be copied directly into the
3956 * buffer. We just have to do overflow-checking,
3957 * and and null-terminate the text (the VFS expects
3958 * null-termination).
3960 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3961 kaddr[len+rcvbuf->page_base] = '\0';
3962 kunmap_atomic(kaddr, KM_USER0);
3966 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3970 status = decode_op_hdr(xdr, OP_REMOVE);
3973 status = decode_change_info(xdr, cinfo);
3978 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3979 struct nfs4_change_info *new_cinfo)
3983 status = decode_op_hdr(xdr, OP_RENAME);
3986 if ((status = decode_change_info(xdr, old_cinfo)))
3988 status = decode_change_info(xdr, new_cinfo);
3993 static int decode_renew(struct xdr_stream *xdr)
3995 return decode_op_hdr(xdr, OP_RENEW);
3999 decode_restorefh(struct xdr_stream *xdr)
4001 return decode_op_hdr(xdr, OP_RESTOREFH);
4004 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4010 struct kvec *iov = req->rq_rcv_buf.head;
4014 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4016 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4018 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4021 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4023 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4027 /* We ignore &savep and don't do consistency checks on
4028 * the attr length. Let userspace figure it out.... */
4029 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4030 recvd = req->rq_rcv_buf.len - hdrlen;
4031 if (attrlen > recvd) {
4032 dprintk("NFS: server cheating in getattr"
4033 " acl reply: attrlen %u > recvd %u\n",
4037 xdr_read_pages(xdr, attrlen);
4040 status = -EOPNOTSUPP;
4047 decode_savefh(struct xdr_stream *xdr)
4049 return decode_op_hdr(xdr, OP_SAVEFH);
4052 static int decode_setattr(struct xdr_stream *xdr)
4058 status = decode_op_hdr(xdr, OP_SETATTR);
4063 READ_BUF(bmlen << 2);
4067 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
4075 if (opnum != OP_SETCLIENTID) {
4076 dprintk("nfs: decode_setclientid: Server returned operation"
4081 if (nfserr == NFS_OK) {
4082 READ_BUF(8 + NFS4_VERIFIER_SIZE);
4083 READ64(clp->cl_clientid);
4084 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
4085 } else if (nfserr == NFSERR_CLID_INUSE) {
4088 /* skip netid string */
4093 /* skip uaddr string */
4097 return -NFSERR_CLID_INUSE;
4099 return nfs4_stat_to_errno(nfserr);
4104 static int decode_setclientid_confirm(struct xdr_stream *xdr)
4106 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4109 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4114 status = decode_op_hdr(xdr, OP_WRITE);
4120 READ32(res->verf->committed);
4121 COPYMEM(res->verf->verifier, 8);
4125 static int decode_delegreturn(struct xdr_stream *xdr)
4127 return decode_op_hdr(xdr, OP_DELEGRETURN);
4130 #if defined(CONFIG_NFS_V4_1)
4131 static int decode_exchange_id(struct xdr_stream *xdr,
4132 struct nfs41_exchange_id_res *res)
4137 struct nfs_client *clp = res->client;
4139 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4144 READ64(clp->cl_ex_clid);
4146 READ32(clp->cl_seqid);
4147 READ32(clp->cl_exchange_flags);
4149 /* We ask for SP4_NONE */
4151 if (dummy != SP4_NONE)
4154 /* Throw away minor_id */
4157 /* Throw away Major id */
4162 /* Throw away server_scope */
4167 /* Throw away Implementation id array */
4175 static int decode_chan_attrs(struct xdr_stream *xdr,
4176 struct nfs4_channel_attrs *attrs)
4182 READ32(attrs->headerpadsz);
4183 READ32(attrs->max_rqst_sz);
4184 READ32(attrs->max_resp_sz);
4185 READ32(attrs->max_resp_sz_cached);
4186 READ32(attrs->max_ops);
4187 READ32(attrs->max_reqs);
4189 if (unlikely(nr_attrs > 1)) {
4190 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4191 __func__, nr_attrs);
4195 READ_BUF(4); /* skip rdma_attrs */
4199 static int decode_create_session(struct xdr_stream *xdr,
4200 struct nfs41_create_session_res *res)
4204 struct nfs_client *clp = res->client;
4205 struct nfs4_session *session = clp->cl_session;
4207 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4213 READ_BUF(NFS4_MAX_SESSIONID_LEN);
4214 COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
4218 READ32(clp->cl_seqid);
4219 READ32(session->flags);
4221 /* Channel attributes */
4222 status = decode_chan_attrs(xdr, &session->fc_attrs);
4224 status = decode_chan_attrs(xdr, &session->bc_attrs);
4228 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4230 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4232 #endif /* CONFIG_NFS_V4_1 */
4234 static int decode_sequence(struct xdr_stream *xdr,
4235 struct nfs4_sequence_res *res,
4236 struct rpc_rqst *rqstp)
4238 #if defined(CONFIG_NFS_V4_1)
4239 if (!res->sr_session)
4243 #endif /* CONFIG_NFS_V4_1 */
4249 * END OF "GENERIC" DECODE ROUTINES.
4253 * Decode OPEN_DOWNGRADE response
4255 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4257 struct xdr_stream xdr;
4258 struct compound_hdr hdr;
4261 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4262 status = decode_compound_hdr(&xdr, &hdr);
4265 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4268 status = decode_putfh(&xdr);
4271 status = decode_open_downgrade(&xdr, res);
4274 decode_getfattr(&xdr, res->fattr, res->server);
4280 * Decode ACCESS response
4282 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
4284 struct xdr_stream xdr;
4285 struct compound_hdr hdr;
4288 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4289 status = decode_compound_hdr(&xdr, &hdr);
4292 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4295 status = decode_putfh(&xdr);
4298 status = decode_access(&xdr, res);
4301 decode_getfattr(&xdr, res->fattr, res->server);
4307 * Decode LOOKUP response
4309 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
4311 struct xdr_stream xdr;
4312 struct compound_hdr hdr;
4315 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4316 status = decode_compound_hdr(&xdr, &hdr);
4319 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4322 if ((status = decode_putfh(&xdr)) != 0)
4324 if ((status = decode_lookup(&xdr)) != 0)
4326 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4328 status = decode_getfattr(&xdr, res->fattr, res->server);
4334 * Decode LOOKUP_ROOT response
4336 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
4338 struct xdr_stream xdr;
4339 struct compound_hdr hdr;
4342 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4343 status = decode_compound_hdr(&xdr, &hdr);
4346 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4349 if ((status = decode_putrootfh(&xdr)) != 0)
4351 if ((status = decode_getfh(&xdr, res->fh)) == 0)
4352 status = decode_getfattr(&xdr, res->fattr, res->server);
4358 * Decode REMOVE response
4360 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
4362 struct xdr_stream xdr;
4363 struct compound_hdr hdr;
4366 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4367 status = decode_compound_hdr(&xdr, &hdr);
4370 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4373 if ((status = decode_putfh(&xdr)) != 0)
4375 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4377 decode_getfattr(&xdr, &res->dir_attr, res->server);
4383 * Decode RENAME response
4385 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
4387 struct xdr_stream xdr;
4388 struct compound_hdr hdr;
4391 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4392 status = decode_compound_hdr(&xdr, &hdr);
4395 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4398 if ((status = decode_putfh(&xdr)) != 0)
4400 if ((status = decode_savefh(&xdr)) != 0)
4402 if ((status = decode_putfh(&xdr)) != 0)
4404 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4406 /* Current FH is target directory */
4407 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4409 if ((status = decode_restorefh(&xdr)) != 0)
4411 decode_getfattr(&xdr, res->old_fattr, res->server);
4417 * Decode LINK response
4419 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
4421 struct xdr_stream xdr;
4422 struct compound_hdr hdr;
4425 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4426 status = decode_compound_hdr(&xdr, &hdr);
4429 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4432 if ((status = decode_putfh(&xdr)) != 0)
4434 if ((status = decode_savefh(&xdr)) != 0)
4436 if ((status = decode_putfh(&xdr)) != 0)
4438 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4441 * Note order: OP_LINK leaves the directory as the current
4444 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4446 if ((status = decode_restorefh(&xdr)) != 0)
4448 decode_getfattr(&xdr, res->fattr, res->server);
4454 * Decode CREATE response
4456 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
4458 struct xdr_stream xdr;
4459 struct compound_hdr hdr;
4462 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4463 status = decode_compound_hdr(&xdr, &hdr);
4466 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4469 if ((status = decode_putfh(&xdr)) != 0)
4471 if ((status = decode_savefh(&xdr)) != 0)
4473 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4475 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4477 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4479 if ((status = decode_restorefh(&xdr)) != 0)
4481 decode_getfattr(&xdr, res->dir_fattr, res->server);
4487 * Decode SYMLINK response
4489 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
4491 return nfs4_xdr_dec_create(rqstp, p, res);
4495 * Decode GETATTR response
4497 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
4499 struct xdr_stream xdr;
4500 struct compound_hdr hdr;
4503 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4504 status = decode_compound_hdr(&xdr, &hdr);
4507 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4510 status = decode_putfh(&xdr);
4513 status = decode_getfattr(&xdr, res->fattr, res->server);
4519 * Encode an SETACL request
4522 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
4524 struct xdr_stream xdr;
4525 struct compound_hdr hdr = {
4526 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
4530 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
4531 encode_compound_hdr(&xdr, req, &hdr);
4532 encode_sequence(&xdr, &args->seq_args, &hdr);
4533 encode_putfh(&xdr, args->fh, &hdr);
4534 status = encode_setacl(&xdr, args, &hdr);
4540 * Decode SETACL response
4543 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4544 struct nfs_setaclres *res)
4546 struct xdr_stream xdr;
4547 struct compound_hdr hdr;
4550 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4551 status = decode_compound_hdr(&xdr, &hdr);
4554 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4557 status = decode_putfh(&xdr);
4560 status = decode_setattr(&xdr);
4566 * Decode GETACL response
4569 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4570 struct nfs_getaclres *res)
4572 struct xdr_stream xdr;
4573 struct compound_hdr hdr;
4576 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4577 status = decode_compound_hdr(&xdr, &hdr);
4580 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4583 status = decode_putfh(&xdr);
4586 status = decode_getacl(&xdr, rqstp, &res->acl_len);
4593 * Decode CLOSE response
4595 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4597 struct xdr_stream xdr;
4598 struct compound_hdr hdr;
4601 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4602 status = decode_compound_hdr(&xdr, &hdr);
4605 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4608 status = decode_putfh(&xdr);
4611 status = decode_close(&xdr, res);
4615 * Note: Server may do delete on close for this file
4616 * in which case the getattr call will fail with
4617 * an ESTALE error. Shouldn't be a problem,
4618 * though, since fattr->valid will remain unset.
4620 decode_getfattr(&xdr, res->fattr, res->server);
4626 * Decode OPEN response
4628 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4630 struct xdr_stream xdr;
4631 struct compound_hdr hdr;
4634 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4635 status = decode_compound_hdr(&xdr, &hdr);
4638 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4641 status = decode_putfh(&xdr);
4644 status = decode_savefh(&xdr);
4647 status = decode_open(&xdr, res);
4650 if (decode_getfh(&xdr, &res->fh) != 0)
4652 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4654 if (decode_restorefh(&xdr) != 0)
4656 decode_getfattr(&xdr, res->dir_attr, res->server);
4662 * Decode OPEN_CONFIRM response
4664 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4666 struct xdr_stream xdr;
4667 struct compound_hdr hdr;
4670 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4671 status = decode_compound_hdr(&xdr, &hdr);
4674 status = decode_putfh(&xdr);
4677 status = decode_open_confirm(&xdr, res);
4683 * Decode OPEN response
4685 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4687 struct xdr_stream xdr;
4688 struct compound_hdr hdr;
4691 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4692 status = decode_compound_hdr(&xdr, &hdr);
4695 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4698 status = decode_putfh(&xdr);
4701 status = decode_open(&xdr, res);
4704 decode_getfattr(&xdr, res->f_attr, res->server);
4710 * Decode SETATTR response
4712 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4714 struct xdr_stream xdr;
4715 struct compound_hdr hdr;
4718 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4719 status = decode_compound_hdr(&xdr, &hdr);
4722 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4725 status = decode_putfh(&xdr);
4728 status = decode_setattr(&xdr);
4731 decode_getfattr(&xdr, res->fattr, res->server);
4737 * Decode LOCK response
4739 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4741 struct xdr_stream xdr;
4742 struct compound_hdr hdr;
4745 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4746 status = decode_compound_hdr(&xdr, &hdr);
4749 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4752 status = decode_putfh(&xdr);
4755 status = decode_lock(&xdr, res);
4761 * Decode LOCKT response
4763 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4765 struct xdr_stream xdr;
4766 struct compound_hdr hdr;
4769 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4770 status = decode_compound_hdr(&xdr, &hdr);
4773 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4776 status = decode_putfh(&xdr);
4779 status = decode_lockt(&xdr, res);
4785 * Decode LOCKU response
4787 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4789 struct xdr_stream xdr;
4790 struct compound_hdr hdr;
4793 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4794 status = decode_compound_hdr(&xdr, &hdr);
4797 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4800 status = decode_putfh(&xdr);
4803 status = decode_locku(&xdr, res);
4809 * Decode READLINK response
4811 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4812 struct nfs4_readlink_res *res)
4814 struct xdr_stream xdr;
4815 struct compound_hdr hdr;
4818 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4819 status = decode_compound_hdr(&xdr, &hdr);
4822 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4825 status = decode_putfh(&xdr);
4828 status = decode_readlink(&xdr, rqstp);
4834 * Decode READDIR response
4836 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4838 struct xdr_stream xdr;
4839 struct compound_hdr hdr;
4842 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4843 status = decode_compound_hdr(&xdr, &hdr);
4846 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4849 status = decode_putfh(&xdr);
4852 status = decode_readdir(&xdr, rqstp, res);
4858 * Decode Read response
4860 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4862 struct xdr_stream xdr;
4863 struct compound_hdr hdr;
4866 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4867 status = decode_compound_hdr(&xdr, &hdr);
4870 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4873 status = decode_putfh(&xdr);
4876 status = decode_read(&xdr, rqstp, res);
4878 status = res->count;
4884 * Decode WRITE response
4886 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4888 struct xdr_stream xdr;
4889 struct compound_hdr hdr;
4892 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4893 status = decode_compound_hdr(&xdr, &hdr);
4896 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4899 status = decode_putfh(&xdr);
4902 status = decode_write(&xdr, res);
4905 decode_getfattr(&xdr, res->fattr, res->server);
4907 status = res->count;
4913 * Decode COMMIT response
4915 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4917 struct xdr_stream xdr;
4918 struct compound_hdr hdr;
4921 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4922 status = decode_compound_hdr(&xdr, &hdr);
4925 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4928 status = decode_putfh(&xdr);
4931 status = decode_commit(&xdr, res);
4934 decode_getfattr(&xdr, res->fattr, res->server);
4942 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4943 struct nfs4_fsinfo_res *res)
4945 struct xdr_stream xdr;
4946 struct compound_hdr hdr;
4949 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4950 status = decode_compound_hdr(&xdr, &hdr);
4952 status = decode_sequence(&xdr, &res->seq_res, req);
4954 status = decode_putfh(&xdr);
4956 status = decode_fsinfo(&xdr, res->fsinfo);
4963 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4964 struct nfs4_pathconf_res *res)
4966 struct xdr_stream xdr;
4967 struct compound_hdr hdr;
4970 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4971 status = decode_compound_hdr(&xdr, &hdr);
4973 status = decode_sequence(&xdr, &res->seq_res, req);
4975 status = decode_putfh(&xdr);
4977 status = decode_pathconf(&xdr, res->pathconf);
4984 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4985 struct nfs4_statfs_res *res)
4987 struct xdr_stream xdr;
4988 struct compound_hdr hdr;
4991 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4992 status = decode_compound_hdr(&xdr, &hdr);
4994 status = decode_sequence(&xdr, &res->seq_res, req);
4996 status = decode_putfh(&xdr);
4998 status = decode_statfs(&xdr, res->fsstat);
5003 * GETATTR_BITMAP request
5005 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
5007 struct xdr_stream xdr;
5008 struct compound_hdr hdr;
5011 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5012 status = decode_compound_hdr(&xdr, &hdr);
5015 status = decode_sequence(&xdr, &res->seq_res, req);
5018 if ((status = decode_putfh(&xdr)) != 0)
5020 status = decode_server_caps(&xdr, res);
5026 * Decode RENEW response
5028 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
5030 struct xdr_stream xdr;
5031 struct compound_hdr hdr;
5034 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5035 status = decode_compound_hdr(&xdr, &hdr);
5037 status = decode_renew(&xdr);
5042 * a SETCLIENTID request
5044 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
5045 struct nfs_client *clp)
5047 struct xdr_stream xdr;
5048 struct compound_hdr hdr;
5051 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5052 status = decode_compound_hdr(&xdr, &hdr);
5054 status = decode_setclientid(&xdr, clp);
5059 * a SETCLIENTID_CONFIRM request
5061 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
5063 struct xdr_stream xdr;
5064 struct compound_hdr hdr;
5067 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5068 status = decode_compound_hdr(&xdr, &hdr);
5070 status = decode_setclientid_confirm(&xdr);
5072 status = decode_putrootfh(&xdr);
5074 status = decode_fsinfo(&xdr, fsinfo);
5079 * DELEGRETURN request
5081 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
5083 struct xdr_stream xdr;
5084 struct compound_hdr hdr;
5087 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5088 status = decode_compound_hdr(&xdr, &hdr);
5091 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5094 status = decode_putfh(&xdr);
5097 status = decode_delegreturn(&xdr);
5098 decode_getfattr(&xdr, res->fattr, res->server);
5104 * FS_LOCATIONS request
5106 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5107 struct nfs4_fs_locations_res *res)
5109 struct xdr_stream xdr;
5110 struct compound_hdr hdr;
5113 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5114 status = decode_compound_hdr(&xdr, &hdr);
5117 status = decode_sequence(&xdr, &res->seq_res, req);
5120 if ((status = decode_putfh(&xdr)) != 0)
5122 if ((status = decode_lookup(&xdr)) != 0)
5124 xdr_enter_page(&xdr, PAGE_SIZE);
5125 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
5126 res->fs_locations->server);
5131 #if defined(CONFIG_NFS_V4_1)
5133 * EXCHANGE_ID request
5135 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5138 struct xdr_stream xdr;
5139 struct compound_hdr hdr;
5142 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5143 status = decode_compound_hdr(&xdr, &hdr);
5145 status = decode_exchange_id(&xdr, res);
5150 * a CREATE_SESSION request
5152 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5153 struct nfs41_create_session_res *res)
5155 struct xdr_stream xdr;
5156 struct compound_hdr hdr;
5159 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5160 status = decode_compound_hdr(&xdr, &hdr);
5162 status = decode_create_session(&xdr, res);
5167 * a DESTROY_SESSION request
5169 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5172 struct xdr_stream xdr;
5173 struct compound_hdr hdr;
5176 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5177 status = decode_compound_hdr(&xdr, &hdr);
5179 status = decode_destroy_session(&xdr, dummy);
5184 * a GET_LEASE_TIME request
5186 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5187 struct nfs4_get_lease_time_res *res)
5189 struct xdr_stream xdr;
5190 struct compound_hdr hdr;
5193 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5194 status = decode_compound_hdr(&xdr, &hdr);
5196 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5198 status = decode_putrootfh(&xdr);
5200 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5203 #endif /* CONFIG_NFS_V4_1 */
5205 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
5207 uint32_t bitmap[2] = {0};
5212 return ERR_PTR(-EAGAIN);
5214 return ERR_PTR(-EBADCOOKIE);
5217 entry->prev_cookie = entry->cookie;
5218 p = xdr_decode_hyper(p, &entry->cookie);
5219 entry->len = ntohl(*p++);
5220 entry->name = (const char *) p;
5221 p += XDR_QUADLEN(entry->len);
5224 * In case the server doesn't return an inode number,
5225 * we fake one here. (We don't use inode number 0,
5226 * since glibc seems to choke on it...)
5230 len = ntohl(*p++); /* bitmap length */
5232 bitmap[0] = ntohl(*p++);
5234 bitmap[1] = ntohl(*p++);
5238 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5240 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5241 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5242 /* Ignore the return value of rdattr_error for now */
5246 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5247 xdr_decode_hyper(p, &entry->ino);
5248 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5249 xdr_decode_hyper(p, &entry->ino);
5253 entry->eof = !p[0] && p[1];
5258 * We need to translate between nfs status return values and
5259 * the local errno values which may not be the same.
5266 { NFS4ERR_PERM, -EPERM },
5267 { NFS4ERR_NOENT, -ENOENT },
5268 { NFS4ERR_IO, -errno_NFSERR_IO},
5269 { NFS4ERR_NXIO, -ENXIO },
5270 { NFS4ERR_ACCESS, -EACCES },
5271 { NFS4ERR_EXIST, -EEXIST },
5272 { NFS4ERR_XDEV, -EXDEV },
5273 { NFS4ERR_NOTDIR, -ENOTDIR },
5274 { NFS4ERR_ISDIR, -EISDIR },
5275 { NFS4ERR_INVAL, -EINVAL },
5276 { NFS4ERR_FBIG, -EFBIG },
5277 { NFS4ERR_NOSPC, -ENOSPC },
5278 { NFS4ERR_ROFS, -EROFS },
5279 { NFS4ERR_MLINK, -EMLINK },
5280 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5281 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5282 { NFS4ERR_DQUOT, -EDQUOT },
5283 { NFS4ERR_STALE, -ESTALE },
5284 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5285 { NFS4ERR_BADOWNER, -EINVAL },
5286 { NFS4ERR_BADNAME, -EINVAL },
5287 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5288 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5289 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5290 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5291 { NFS4ERR_BADTYPE, -EBADTYPE },
5292 { NFS4ERR_LOCKED, -EAGAIN },
5293 { NFS4ERR_RESOURCE, -EREMOTEIO },
5294 { NFS4ERR_SYMLINK, -ELOOP },
5295 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5296 { NFS4ERR_DEADLOCK, -EDEADLK },
5297 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
5298 * to be handled by a
5305 * Convert an NFS error code to a local one.
5306 * This one is used jointly by NFSv2 and NFSv3.
5309 nfs4_stat_to_errno(int stat)
5312 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5313 if (nfs_errtbl[i].stat == stat)
5314 return nfs_errtbl[i].errno;
5316 if (stat <= 10000 || stat > 10100) {
5317 /* The server is looney tunes. */
5318 return -ESERVERFAULT;
5320 /* If we cannot translate the error, the recovery routines should
5322 * Note: remaining NFSv4 error codes have values > 10000, so should
5323 * not conflict with native Linux error codes.
5328 #define PROC(proc, argtype, restype) \
5329 [NFSPROC4_CLNT_##proc] = { \
5330 .p_proc = NFSPROC4_COMPOUND, \
5331 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5332 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
5333 .p_arglen = NFS4_##argtype##_sz, \
5334 .p_replen = NFS4_##restype##_sz, \
5335 .p_statidx = NFSPROC4_CLNT_##proc, \
5339 struct rpc_procinfo nfs4_procedures[] = {
5340 PROC(READ, enc_read, dec_read),
5341 PROC(WRITE, enc_write, dec_write),
5342 PROC(COMMIT, enc_commit, dec_commit),
5343 PROC(OPEN, enc_open, dec_open),
5344 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5345 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5346 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5347 PROC(CLOSE, enc_close, dec_close),
5348 PROC(SETATTR, enc_setattr, dec_setattr),
5349 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5350 PROC(RENEW, enc_renew, dec_renew),
5351 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5352 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5353 PROC(LOCK, enc_lock, dec_lock),
5354 PROC(LOCKT, enc_lockt, dec_lockt),
5355 PROC(LOCKU, enc_locku, dec_locku),
5356 PROC(ACCESS, enc_access, dec_access),
5357 PROC(GETATTR, enc_getattr, dec_getattr),
5358 PROC(LOOKUP, enc_lookup, dec_lookup),
5359 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5360 PROC(REMOVE, enc_remove, dec_remove),
5361 PROC(RENAME, enc_rename, dec_rename),
5362 PROC(LINK, enc_link, dec_link),
5363 PROC(SYMLINK, enc_symlink, dec_symlink),
5364 PROC(CREATE, enc_create, dec_create),
5365 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5366 PROC(STATFS, enc_statfs, dec_statfs),
5367 PROC(READLINK, enc_readlink, dec_readlink),
5368 PROC(READDIR, enc_readdir, dec_readdir),
5369 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5370 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
5371 PROC(GETACL, enc_getacl, dec_getacl),
5372 PROC(SETACL, enc_setacl, dec_setacl),
5373 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
5374 #if defined(CONFIG_NFS_V4_1)
5375 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
5376 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
5377 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
5378 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
5379 #endif /* CONFIG_NFS_V4_1 */
5382 struct rpc_version nfs_version4 = {
5384 .nrprocs = ARRAY_SIZE(nfs4_procedures),
5385 .procs = nfs4_procedures