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/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/sunrpc/clnt.h>
48 #include <linux/sunrpc/msg_prot.h>
49 #include <linux/nfs.h>
50 #include <linux/nfs4.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/nfs_idmap.h>
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 + encode_verifier_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_lockowner_maxsz (7)
206 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
208 1 + encode_stateid_maxsz + 1 + \
209 encode_lockowner_maxsz)
210 #define decode_lock_denied_maxsz \
211 (8 + decode_lockowner_maxsz)
212 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
213 decode_lock_denied_maxsz)
214 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
215 encode_lockowner_maxsz)
216 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
217 decode_lock_denied_maxsz)
218 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
219 encode_stateid_maxsz + \
221 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
222 decode_stateid_maxsz)
223 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
224 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
225 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
226 1 + nfs4_name_maxsz + \
229 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
230 #define encode_create_maxsz (op_encode_hdr_maxsz + \
231 1 + 2 + nfs4_name_maxsz + \
233 #define decode_create_maxsz (op_decode_hdr_maxsz + \
234 decode_change_info_maxsz + \
235 nfs4_fattr_bitmap_maxsz)
236 #define encode_statfs_maxsz (encode_getattr_maxsz)
237 #define decode_statfs_maxsz (decode_getattr_maxsz)
238 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
239 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
240 #define encode_getacl_maxsz (encode_getattr_maxsz)
241 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
242 nfs4_fattr_bitmap_maxsz + 1)
243 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
244 encode_stateid_maxsz + 3)
245 #define decode_setacl_maxsz (decode_setattr_maxsz)
246 #define encode_fs_locations_maxsz \
247 (encode_getattr_maxsz)
248 #define decode_fs_locations_maxsz \
251 #if defined(CONFIG_NFS_V4_1)
252 #define NFS4_MAX_MACHINE_NAME_LEN (64)
254 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
255 encode_verifier_maxsz + \
256 1 /* co_ownerid.len */ + \
257 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
260 0 /* SP4_NONE (for now) */ + \
261 1 /* zero implemetation id array */)
262 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
263 2 /* eir_clientid */ + \
264 1 /* eir_sequenceid */ + \
265 1 /* eir_flags */ + \
267 0 /* SP4_NONE (for now) */ + \
268 2 /* eir_server_owner.so_minor_id */ + \
269 /* eir_server_owner.so_major_id<> */ \
270 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
271 /* eir_server_scope<> */ \
272 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
273 1 /* eir_server_impl_id array length */ + \
274 0 /* ignored eir_server_impl_id contents */)
275 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
276 #define decode_channel_attrs_maxsz (6 + \
277 1 /* ca_rdma_ird.len */ + \
279 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
280 2 /* csa_clientid */ + \
281 1 /* csa_sequence */ + \
282 1 /* csa_flags */ + \
283 encode_channel_attrs_maxsz + \
284 encode_channel_attrs_maxsz + \
285 1 /* csa_cb_program */ + \
286 1 /* csa_sec_parms.len (1) */ + \
287 1 /* cb_secflavor (AUTH_SYS) */ + \
289 1 /* machinename.len */ + \
290 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
293 1 /* gids.len (0) */)
294 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
295 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
296 1 /* csr_sequence */ + \
297 1 /* csr_flags */ + \
298 decode_channel_attrs_maxsz + \
299 decode_channel_attrs_maxsz)
300 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
301 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
302 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
303 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
304 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
305 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
306 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
307 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
308 #else /* CONFIG_NFS_V4_1 */
309 #define encode_sequence_maxsz 0
310 #define decode_sequence_maxsz 0
311 #endif /* CONFIG_NFS_V4_1 */
313 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
314 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
315 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
316 encode_sequence_maxsz + \
317 encode_putfh_maxsz + \
319 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
320 decode_sequence_maxsz + \
321 decode_putfh_maxsz + \
323 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
324 encode_sequence_maxsz + \
325 encode_putfh_maxsz + \
326 encode_readlink_maxsz)
327 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
328 decode_sequence_maxsz + \
329 decode_putfh_maxsz + \
330 decode_readlink_maxsz)
331 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
332 encode_sequence_maxsz + \
333 encode_putfh_maxsz + \
334 encode_readdir_maxsz)
335 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
336 decode_sequence_maxsz + \
337 decode_putfh_maxsz + \
338 decode_readdir_maxsz)
339 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
340 encode_sequence_maxsz + \
341 encode_putfh_maxsz + \
342 encode_write_maxsz + \
343 encode_getattr_maxsz)
344 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
345 decode_sequence_maxsz + \
346 decode_putfh_maxsz + \
347 decode_write_maxsz + \
348 decode_getattr_maxsz)
349 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
350 encode_sequence_maxsz + \
351 encode_putfh_maxsz + \
352 encode_commit_maxsz + \
353 encode_getattr_maxsz)
354 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
355 decode_sequence_maxsz + \
356 decode_putfh_maxsz + \
357 decode_commit_maxsz + \
358 decode_getattr_maxsz)
359 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
360 encode_sequence_maxsz + \
361 encode_putfh_maxsz + \
362 encode_savefh_maxsz + \
363 encode_open_maxsz + \
364 encode_getfh_maxsz + \
365 encode_getattr_maxsz + \
366 encode_restorefh_maxsz + \
367 encode_getattr_maxsz)
368 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
369 decode_sequence_maxsz + \
370 decode_putfh_maxsz + \
371 decode_savefh_maxsz + \
372 decode_open_maxsz + \
373 decode_getfh_maxsz + \
374 decode_getattr_maxsz + \
375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
377 #define NFS4_enc_open_confirm_sz \
378 (compound_encode_hdr_maxsz + \
379 encode_putfh_maxsz + \
380 encode_open_confirm_maxsz)
381 #define NFS4_dec_open_confirm_sz \
382 (compound_decode_hdr_maxsz + \
383 decode_putfh_maxsz + \
384 decode_open_confirm_maxsz)
385 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
386 encode_sequence_maxsz + \
387 encode_putfh_maxsz + \
388 encode_open_maxsz + \
389 encode_getattr_maxsz)
390 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
391 decode_sequence_maxsz + \
392 decode_putfh_maxsz + \
393 decode_open_maxsz + \
394 decode_getattr_maxsz)
395 #define NFS4_enc_open_downgrade_sz \
396 (compound_encode_hdr_maxsz + \
397 encode_sequence_maxsz + \
398 encode_putfh_maxsz + \
399 encode_open_downgrade_maxsz + \
400 encode_getattr_maxsz)
401 #define NFS4_dec_open_downgrade_sz \
402 (compound_decode_hdr_maxsz + \
403 decode_sequence_maxsz + \
404 decode_putfh_maxsz + \
405 decode_open_downgrade_maxsz + \
406 decode_getattr_maxsz)
407 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
408 encode_sequence_maxsz + \
409 encode_putfh_maxsz + \
410 encode_close_maxsz + \
411 encode_getattr_maxsz)
412 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
413 decode_sequence_maxsz + \
414 decode_putfh_maxsz + \
415 decode_close_maxsz + \
416 decode_getattr_maxsz)
417 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
418 encode_sequence_maxsz + \
419 encode_putfh_maxsz + \
420 encode_setattr_maxsz + \
421 encode_getattr_maxsz)
422 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
423 decode_sequence_maxsz + \
424 decode_putfh_maxsz + \
425 decode_setattr_maxsz + \
426 decode_getattr_maxsz)
427 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
428 encode_sequence_maxsz + \
429 encode_putfh_maxsz + \
431 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
432 decode_sequence_maxsz + \
433 decode_putfh_maxsz + \
435 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
437 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
439 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
440 encode_setclientid_maxsz)
441 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
442 decode_setclientid_maxsz)
443 #define NFS4_enc_setclientid_confirm_sz \
444 (compound_encode_hdr_maxsz + \
445 encode_setclientid_confirm_maxsz + \
446 encode_putrootfh_maxsz + \
448 #define NFS4_dec_setclientid_confirm_sz \
449 (compound_decode_hdr_maxsz + \
450 decode_setclientid_confirm_maxsz + \
451 decode_putrootfh_maxsz + \
453 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
454 encode_sequence_maxsz + \
455 encode_putfh_maxsz + \
457 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
458 decode_sequence_maxsz + \
459 decode_putfh_maxsz + \
461 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
462 encode_sequence_maxsz + \
463 encode_putfh_maxsz + \
465 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
466 decode_sequence_maxsz + \
467 decode_putfh_maxsz + \
469 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
470 encode_sequence_maxsz + \
471 encode_putfh_maxsz + \
473 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
474 decode_sequence_maxsz + \
475 decode_putfh_maxsz + \
477 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
478 encode_sequence_maxsz + \
479 encode_putfh_maxsz + \
480 encode_access_maxsz + \
481 encode_getattr_maxsz)
482 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
483 decode_sequence_maxsz + \
484 decode_putfh_maxsz + \
485 decode_access_maxsz + \
486 decode_getattr_maxsz)
487 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
488 encode_sequence_maxsz + \
489 encode_putfh_maxsz + \
490 encode_getattr_maxsz)
491 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
492 decode_sequence_maxsz + \
493 decode_putfh_maxsz + \
494 decode_getattr_maxsz)
495 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
496 encode_sequence_maxsz + \
497 encode_putfh_maxsz + \
498 encode_lookup_maxsz + \
499 encode_getattr_maxsz + \
501 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
502 decode_sequence_maxsz + \
503 decode_putfh_maxsz + \
504 decode_lookup_maxsz + \
505 decode_getattr_maxsz + \
507 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
508 encode_sequence_maxsz + \
509 encode_putrootfh_maxsz + \
510 encode_getattr_maxsz + \
512 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
513 decode_sequence_maxsz + \
514 decode_putrootfh_maxsz + \
515 decode_getattr_maxsz + \
517 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
518 encode_sequence_maxsz + \
519 encode_putfh_maxsz + \
520 encode_remove_maxsz + \
521 encode_getattr_maxsz)
522 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
523 decode_sequence_maxsz + \
524 decode_putfh_maxsz + \
525 decode_remove_maxsz + \
526 decode_getattr_maxsz)
527 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
528 encode_sequence_maxsz + \
529 encode_putfh_maxsz + \
530 encode_savefh_maxsz + \
531 encode_putfh_maxsz + \
532 encode_rename_maxsz + \
533 encode_getattr_maxsz + \
534 encode_restorefh_maxsz + \
535 encode_getattr_maxsz)
536 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
537 decode_sequence_maxsz + \
538 decode_putfh_maxsz + \
539 decode_savefh_maxsz + \
540 decode_putfh_maxsz + \
541 decode_rename_maxsz + \
542 decode_getattr_maxsz + \
543 decode_restorefh_maxsz + \
544 decode_getattr_maxsz)
545 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
546 encode_sequence_maxsz + \
547 encode_putfh_maxsz + \
548 encode_savefh_maxsz + \
549 encode_putfh_maxsz + \
550 encode_link_maxsz + \
551 decode_getattr_maxsz + \
552 encode_restorefh_maxsz + \
553 decode_getattr_maxsz)
554 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
555 decode_sequence_maxsz + \
556 decode_putfh_maxsz + \
557 decode_savefh_maxsz + \
558 decode_putfh_maxsz + \
559 decode_link_maxsz + \
560 decode_getattr_maxsz + \
561 decode_restorefh_maxsz + \
562 decode_getattr_maxsz)
563 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
564 encode_sequence_maxsz + \
565 encode_putfh_maxsz + \
566 encode_symlink_maxsz + \
567 encode_getattr_maxsz + \
569 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
570 decode_sequence_maxsz + \
571 decode_putfh_maxsz + \
572 decode_symlink_maxsz + \
573 decode_getattr_maxsz + \
575 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
576 encode_sequence_maxsz + \
577 encode_putfh_maxsz + \
578 encode_savefh_maxsz + \
579 encode_create_maxsz + \
580 encode_getfh_maxsz + \
581 encode_getattr_maxsz + \
582 encode_restorefh_maxsz + \
583 encode_getattr_maxsz)
584 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
585 decode_sequence_maxsz + \
586 decode_putfh_maxsz + \
587 decode_savefh_maxsz + \
588 decode_create_maxsz + \
589 decode_getfh_maxsz + \
590 decode_getattr_maxsz + \
591 decode_restorefh_maxsz + \
592 decode_getattr_maxsz)
593 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
594 encode_sequence_maxsz + \
595 encode_putfh_maxsz + \
596 encode_getattr_maxsz)
597 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
598 decode_sequence_maxsz + \
599 decode_putfh_maxsz + \
600 decode_getattr_maxsz)
601 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
602 encode_sequence_maxsz + \
603 encode_putfh_maxsz + \
605 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
606 decode_sequence_maxsz + \
607 decode_putfh_maxsz + \
609 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
610 encode_sequence_maxsz + \
611 encode_putfh_maxsz + \
612 encode_getattr_maxsz)
613 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
614 decode_sequence_maxsz + \
615 decode_putfh_maxsz + \
616 decode_getattr_maxsz)
617 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
618 encode_sequence_maxsz + \
619 encode_putfh_maxsz + \
620 encode_delegreturn_maxsz + \
621 encode_getattr_maxsz)
622 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
623 decode_sequence_maxsz + \
624 decode_delegreturn_maxsz + \
625 decode_getattr_maxsz)
626 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
627 encode_sequence_maxsz + \
628 encode_putfh_maxsz + \
630 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
631 decode_sequence_maxsz + \
632 decode_putfh_maxsz + \
634 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
635 encode_sequence_maxsz + \
636 encode_putfh_maxsz + \
638 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
639 decode_sequence_maxsz + \
640 decode_putfh_maxsz + \
642 #define NFS4_enc_fs_locations_sz \
643 (compound_encode_hdr_maxsz + \
644 encode_sequence_maxsz + \
645 encode_putfh_maxsz + \
646 encode_lookup_maxsz + \
647 encode_fs_locations_maxsz)
648 #define NFS4_dec_fs_locations_sz \
649 (compound_decode_hdr_maxsz + \
650 decode_sequence_maxsz + \
651 decode_putfh_maxsz + \
652 decode_lookup_maxsz + \
653 decode_fs_locations_maxsz)
654 #if defined(CONFIG_NFS_V4_1)
655 #define NFS4_enc_exchange_id_sz \
656 (compound_encode_hdr_maxsz + \
657 encode_exchange_id_maxsz)
658 #define NFS4_dec_exchange_id_sz \
659 (compound_decode_hdr_maxsz + \
660 decode_exchange_id_maxsz)
661 #define NFS4_enc_create_session_sz \
662 (compound_encode_hdr_maxsz + \
663 encode_create_session_maxsz)
664 #define NFS4_dec_create_session_sz \
665 (compound_decode_hdr_maxsz + \
666 decode_create_session_maxsz)
667 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
668 encode_destroy_session_maxsz)
669 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
670 decode_destroy_session_maxsz)
671 #define NFS4_enc_sequence_sz \
672 (compound_decode_hdr_maxsz + \
673 encode_sequence_maxsz)
674 #define NFS4_dec_sequence_sz \
675 (compound_decode_hdr_maxsz + \
676 decode_sequence_maxsz)
677 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
678 encode_sequence_maxsz + \
679 encode_putrootfh_maxsz + \
681 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
682 decode_sequence_maxsz + \
683 decode_putrootfh_maxsz + \
685 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
686 encode_sequence_maxsz + \
687 encode_reclaim_complete_maxsz)
688 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
689 decode_sequence_maxsz + \
690 decode_reclaim_complete_maxsz)
692 const u32 nfs41_maxwrite_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
693 compound_encode_hdr_maxsz
+
694 encode_sequence_maxsz
+
696 encode_getattr_maxsz
) *
699 const u32 nfs41_maxread_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
700 compound_decode_hdr_maxsz
+
701 decode_sequence_maxsz
+
702 decode_putfh_maxsz
) *
704 #endif /* CONFIG_NFS_V4_1 */
706 static const umode_t nfs_type2fmt
[] = {
713 [NF4SOCK
] = S_IFSOCK
,
719 struct compound_hdr
{
725 uint32_t replen
; /* expected reply words */
729 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
731 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
736 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
740 p
= xdr_reserve_space(xdr
, 4 + len
);
742 xdr_encode_opaque(p
, str
, len
);
745 static void encode_compound_hdr(struct xdr_stream
*xdr
,
746 struct rpc_rqst
*req
,
747 struct compound_hdr
*hdr
)
750 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
752 /* initialize running count of expected bytes in reply.
753 * NOTE: the replied tag SHOULD be the same is the one sent,
754 * but this is not required as a MUST for the server to do so. */
755 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
757 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
758 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
759 p
= reserve_space(xdr
, 4 + hdr
->taglen
+ 8);
760 p
= xdr_encode_opaque(p
, hdr
->tag
, hdr
->taglen
);
761 *p
++ = cpu_to_be32(hdr
->minorversion
);
763 *p
= cpu_to_be32(hdr
->nops
);
766 static void encode_nops(struct compound_hdr
*hdr
)
768 BUG_ON(hdr
->nops
> NFS4_MAX_OPS
);
769 *hdr
->nops_p
= htonl(hdr
->nops
);
772 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
776 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
778 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
781 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
783 char owner_name
[IDMAP_NAMESZ
];
784 char owner_group
[IDMAP_NAMESZ
];
785 int owner_namelen
= 0;
786 int owner_grouplen
= 0;
794 * We reserve enough space to write the entire attribute buffer at once.
795 * In the worst-case, this would be
796 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
797 * = 36 bytes, plus any contribution from variable-length fields
798 * such as owner/group.
803 if (iap
->ia_valid
& ATTR_SIZE
)
805 if (iap
->ia_valid
& ATTR_MODE
)
807 if (iap
->ia_valid
& ATTR_UID
) {
808 owner_namelen
= nfs_map_uid_to_name(server
->nfs_client
, iap
->ia_uid
, owner_name
);
809 if (owner_namelen
< 0) {
810 dprintk("nfs: couldn't resolve uid %d to string\n",
813 strcpy(owner_name
, "nobody");
814 owner_namelen
= sizeof("nobody") - 1;
817 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
819 if (iap
->ia_valid
& ATTR_GID
) {
820 owner_grouplen
= nfs_map_gid_to_group(server
->nfs_client
, iap
->ia_gid
, owner_group
);
821 if (owner_grouplen
< 0) {
822 dprintk("nfs: couldn't resolve gid %d to string\n",
824 strcpy(owner_group
, "nobody");
825 owner_grouplen
= sizeof("nobody") - 1;
828 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
830 if (iap
->ia_valid
& ATTR_ATIME_SET
)
832 else if (iap
->ia_valid
& ATTR_ATIME
)
834 if (iap
->ia_valid
& ATTR_MTIME_SET
)
836 else if (iap
->ia_valid
& ATTR_MTIME
)
838 p
= reserve_space(xdr
, len
);
841 * We write the bitmap length now, but leave the bitmap and the attribute
842 * buffer length to be backfilled at the end of this routine.
844 *p
++ = cpu_to_be32(2);
848 if (iap
->ia_valid
& ATTR_SIZE
) {
849 bmval0
|= FATTR4_WORD0_SIZE
;
850 p
= xdr_encode_hyper(p
, iap
->ia_size
);
852 if (iap
->ia_valid
& ATTR_MODE
) {
853 bmval1
|= FATTR4_WORD1_MODE
;
854 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
856 if (iap
->ia_valid
& ATTR_UID
) {
857 bmval1
|= FATTR4_WORD1_OWNER
;
858 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
860 if (iap
->ia_valid
& ATTR_GID
) {
861 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
862 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
864 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
865 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
866 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
867 *p
++ = cpu_to_be32(0);
868 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_sec
);
869 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_nsec
);
871 else if (iap
->ia_valid
& ATTR_ATIME
) {
872 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
873 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
875 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
876 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
877 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
878 *p
++ = cpu_to_be32(0);
879 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_sec
);
880 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
882 else if (iap
->ia_valid
& ATTR_MTIME
) {
883 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
884 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
888 * Now we backfill the bitmap and the attribute buffer length.
890 if (len
!= ((char *)p
- (char *)q
) + 4) {
891 printk(KERN_ERR
"nfs: Attr length error, %u != %Zu\n",
892 len
, ((char *)p
- (char *)q
) + 4);
895 len
= (char *)p
- (char *)q
- 12;
896 *q
++ = htonl(bmval0
);
897 *q
++ = htonl(bmval1
);
903 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
907 p
= reserve_space(xdr
, 8);
908 *p
++ = cpu_to_be32(OP_ACCESS
);
909 *p
= cpu_to_be32(access
);
911 hdr
->replen
+= decode_access_maxsz
;
914 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
918 p
= reserve_space(xdr
, 8+NFS4_STATEID_SIZE
);
919 *p
++ = cpu_to_be32(OP_CLOSE
);
920 *p
++ = cpu_to_be32(arg
->seqid
->sequence
->counter
);
921 xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
923 hdr
->replen
+= decode_close_maxsz
;
926 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
930 p
= reserve_space(xdr
, 16);
931 *p
++ = cpu_to_be32(OP_COMMIT
);
932 p
= xdr_encode_hyper(p
, args
->offset
);
933 *p
= cpu_to_be32(args
->count
);
935 hdr
->replen
+= decode_commit_maxsz
;
938 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
942 p
= reserve_space(xdr
, 8);
943 *p
++ = cpu_to_be32(OP_CREATE
);
944 *p
= cpu_to_be32(create
->ftype
);
946 switch (create
->ftype
) {
948 p
= reserve_space(xdr
, 4);
949 *p
= cpu_to_be32(create
->u
.symlink
.len
);
950 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
953 case NF4BLK
: case NF4CHR
:
954 p
= reserve_space(xdr
, 8);
955 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
956 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
963 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
965 hdr
->replen
+= decode_create_maxsz
;
967 encode_attrs(xdr
, create
->attrs
, create
->server
);
970 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
974 p
= reserve_space(xdr
, 12);
975 *p
++ = cpu_to_be32(OP_GETATTR
);
976 *p
++ = cpu_to_be32(1);
977 *p
= cpu_to_be32(bitmap
);
979 hdr
->replen
+= decode_getattr_maxsz
;
982 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
986 p
= reserve_space(xdr
, 16);
987 *p
++ = cpu_to_be32(OP_GETATTR
);
988 *p
++ = cpu_to_be32(2);
989 *p
++ = cpu_to_be32(bm0
);
990 *p
= cpu_to_be32(bm1
);
992 hdr
->replen
+= decode_getattr_maxsz
;
995 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
997 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
998 bitmask
[1] & nfs4_fattr_bitmap
[1], hdr
);
1001 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1003 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
1004 bitmask
[1] & nfs4_fsinfo_bitmap
[1], hdr
);
1007 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1009 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
1010 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
1013 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1017 p
= reserve_space(xdr
, 4);
1018 *p
= cpu_to_be32(OP_GETFH
);
1020 hdr
->replen
+= decode_getfh_maxsz
;
1023 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1027 p
= reserve_space(xdr
, 8 + name
->len
);
1028 *p
++ = cpu_to_be32(OP_LINK
);
1029 xdr_encode_opaque(p
, name
->name
, name
->len
);
1031 hdr
->replen
+= decode_link_maxsz
;
1034 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1036 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
1037 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1038 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1041 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1043 if (fl
->fl_end
== OFFSET_MAX
)
1044 return ~(uint64_t)0;
1045 return fl
->fl_end
- fl
->fl_start
+ 1;
1048 static void encode_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
)
1052 p
= reserve_space(xdr
, 28);
1053 p
= xdr_encode_hyper(p
, lowner
->clientid
);
1054 *p
++ = cpu_to_be32(16);
1055 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1056 xdr_encode_hyper(p
, lowner
->id
);
1060 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1061 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1063 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1067 p
= reserve_space(xdr
, 32);
1068 *p
++ = cpu_to_be32(OP_LOCK
);
1069 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1070 *p
++ = cpu_to_be32(args
->reclaim
);
1071 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1072 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1073 *p
= cpu_to_be32(args
->new_lock_owner
);
1074 if (args
->new_lock_owner
){
1075 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1076 *p
++ = cpu_to_be32(args
->open_seqid
->sequence
->counter
);
1077 p
= xdr_encode_opaque_fixed(p
, args
->open_stateid
->data
, NFS4_STATEID_SIZE
);
1078 *p
++ = cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1079 encode_lockowner(xdr
, &args
->lock_owner
);
1082 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
+4);
1083 p
= xdr_encode_opaque_fixed(p
, args
->lock_stateid
->data
, NFS4_STATEID_SIZE
);
1084 *p
= cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1087 hdr
->replen
+= decode_lock_maxsz
;
1090 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1094 p
= reserve_space(xdr
, 24);
1095 *p
++ = cpu_to_be32(OP_LOCKT
);
1096 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1097 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1098 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1099 encode_lockowner(xdr
, &args
->lock_owner
);
1101 hdr
->replen
+= decode_lockt_maxsz
;
1104 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1108 p
= reserve_space(xdr
, 12+NFS4_STATEID_SIZE
+16);
1109 *p
++ = cpu_to_be32(OP_LOCKU
);
1110 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1111 *p
++ = cpu_to_be32(args
->seqid
->sequence
->counter
);
1112 p
= xdr_encode_opaque_fixed(p
, args
->stateid
->data
, NFS4_STATEID_SIZE
);
1113 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1114 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1116 hdr
->replen
+= decode_locku_maxsz
;
1119 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1121 int len
= name
->len
;
1124 p
= reserve_space(xdr
, 8 + len
);
1125 *p
++ = cpu_to_be32(OP_LOOKUP
);
1126 xdr_encode_opaque(p
, name
->name
, len
);
1128 hdr
->replen
+= decode_lookup_maxsz
;
1131 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
1135 p
= reserve_space(xdr
, 8);
1136 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1138 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ
);
1141 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE
);
1143 case FMODE_READ
|FMODE_WRITE
:
1144 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH
);
1147 *p
++ = cpu_to_be32(0);
1149 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1152 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1156 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1159 p
= reserve_space(xdr
, 8);
1160 *p
++ = cpu_to_be32(OP_OPEN
);
1161 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1162 encode_share_access(xdr
, arg
->fmode
);
1163 p
= reserve_space(xdr
, 28);
1164 p
= xdr_encode_hyper(p
, arg
->clientid
);
1165 *p
++ = cpu_to_be32(16);
1166 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1167 xdr_encode_hyper(p
, arg
->id
);
1170 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1173 struct nfs_client
*clp
;
1175 p
= reserve_space(xdr
, 4);
1176 switch(arg
->open_flags
& O_EXCL
) {
1178 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1179 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1182 clp
= arg
->server
->nfs_client
;
1183 if (clp
->cl_mvops
->minor_version
> 0) {
1184 if (nfs4_has_persistent_session(clp
)) {
1185 *p
= cpu_to_be32(NFS4_CREATE_GUARDED
);
1186 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1190 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1191 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1193 encode_attrs(xdr
, &dummy
, arg
->server
);
1196 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1197 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1202 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1206 p
= reserve_space(xdr
, 4);
1207 switch (arg
->open_flags
& O_CREAT
) {
1209 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1212 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
1213 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1214 encode_createmode(xdr
, arg
);
1218 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1222 p
= reserve_space(xdr
, 4);
1223 switch (delegation_type
) {
1225 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1228 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1230 case FMODE_WRITE
|FMODE_READ
:
1231 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1238 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1242 p
= reserve_space(xdr
, 4);
1243 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1244 encode_string(xdr
, name
->len
, name
->name
);
1247 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1251 p
= reserve_space(xdr
, 4);
1252 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1253 encode_delegation_type(xdr
, type
);
1256 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1260 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1261 *p
++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1262 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1263 encode_string(xdr
, name
->len
, name
->name
);
1266 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1268 encode_openhdr(xdr
, arg
);
1269 encode_opentype(xdr
, arg
);
1270 switch (arg
->claim
) {
1271 case NFS4_OPEN_CLAIM_NULL
:
1272 encode_claim_null(xdr
, arg
->name
);
1274 case NFS4_OPEN_CLAIM_PREVIOUS
:
1275 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1277 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1278 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1284 hdr
->replen
+= decode_open_maxsz
;
1287 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1291 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1292 *p
++ = cpu_to_be32(OP_OPEN_CONFIRM
);
1293 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1294 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1296 hdr
->replen
+= decode_open_confirm_maxsz
;
1299 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1303 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1304 *p
++ = cpu_to_be32(OP_OPEN_DOWNGRADE
);
1305 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1306 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1307 encode_share_access(xdr
, arg
->fmode
);
1309 hdr
->replen
+= decode_open_downgrade_maxsz
;
1313 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1318 p
= reserve_space(xdr
, 8 + len
);
1319 *p
++ = cpu_to_be32(OP_PUTFH
);
1320 xdr_encode_opaque(p
, fh
->data
, len
);
1322 hdr
->replen
+= decode_putfh_maxsz
;
1325 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1329 p
= reserve_space(xdr
, 4);
1330 *p
= cpu_to_be32(OP_PUTROOTFH
);
1332 hdr
->replen
+= decode_putrootfh_maxsz
;
1335 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
, const struct nfs_lock_context
*l_ctx
)
1337 nfs4_stateid stateid
;
1340 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
);
1341 if (ctx
->state
!= NULL
) {
1342 nfs4_copy_stateid(&stateid
, ctx
->state
, l_ctx
->lockowner
);
1343 xdr_encode_opaque_fixed(p
, stateid
.data
, NFS4_STATEID_SIZE
);
1345 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1348 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
, struct compound_hdr
*hdr
)
1352 p
= reserve_space(xdr
, 4);
1353 *p
= cpu_to_be32(OP_READ
);
1355 encode_stateid(xdr
, args
->context
, args
->lock_context
);
1357 p
= reserve_space(xdr
, 12);
1358 p
= xdr_encode_hyper(p
, args
->offset
);
1359 *p
= cpu_to_be32(args
->count
);
1361 hdr
->replen
+= decode_read_maxsz
;
1364 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1366 uint32_t attrs
[2] = {
1367 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1368 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1372 p
= reserve_space(xdr
, 12+NFS4_VERIFIER_SIZE
+20);
1373 *p
++ = cpu_to_be32(OP_READDIR
);
1374 p
= xdr_encode_hyper(p
, readdir
->cookie
);
1375 p
= xdr_encode_opaque_fixed(p
, readdir
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1376 *p
++ = cpu_to_be32(readdir
->count
>> 1); /* We're not doing readdirplus */
1377 *p
++ = cpu_to_be32(readdir
->count
);
1378 *p
++ = cpu_to_be32(2);
1379 /* Switch to mounted_on_fileid if the server supports it */
1380 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1381 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1383 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1384 *p
++ = cpu_to_be32(attrs
[0] & readdir
->bitmask
[0]);
1385 *p
= cpu_to_be32(attrs
[1] & readdir
->bitmask
[1]);
1387 hdr
->replen
+= decode_readdir_maxsz
;
1388 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1390 (unsigned long long)readdir
->cookie
,
1391 ((u32
*)readdir
->verifier
.data
)[0],
1392 ((u32
*)readdir
->verifier
.data
)[1],
1393 attrs
[0] & readdir
->bitmask
[0],
1394 attrs
[1] & readdir
->bitmask
[1]);
1397 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1401 p
= reserve_space(xdr
, 4);
1402 *p
= cpu_to_be32(OP_READLINK
);
1404 hdr
->replen
+= decode_readlink_maxsz
;
1407 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1411 p
= reserve_space(xdr
, 8 + name
->len
);
1412 *p
++ = cpu_to_be32(OP_REMOVE
);
1413 xdr_encode_opaque(p
, name
->name
, name
->len
);
1415 hdr
->replen
+= decode_remove_maxsz
;
1418 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1422 p
= reserve_space(xdr
, 4);
1423 *p
= cpu_to_be32(OP_RENAME
);
1424 encode_string(xdr
, oldname
->len
, oldname
->name
);
1425 encode_string(xdr
, newname
->len
, newname
->name
);
1427 hdr
->replen
+= decode_rename_maxsz
;
1430 static void encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
, struct compound_hdr
*hdr
)
1434 p
= reserve_space(xdr
, 12);
1435 *p
++ = cpu_to_be32(OP_RENEW
);
1436 xdr_encode_hyper(p
, client_stateid
->cl_clientid
);
1438 hdr
->replen
+= decode_renew_maxsz
;
1442 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1446 p
= reserve_space(xdr
, 4);
1447 *p
= cpu_to_be32(OP_RESTOREFH
);
1449 hdr
->replen
+= decode_restorefh_maxsz
;
1453 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1457 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1458 *p
++ = cpu_to_be32(OP_SETATTR
);
1459 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1460 p
= reserve_space(xdr
, 2*4);
1461 *p
++ = cpu_to_be32(1);
1462 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1463 if (arg
->acl_len
% 4)
1465 p
= reserve_space(xdr
, 4);
1466 *p
= cpu_to_be32(arg
->acl_len
);
1467 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1469 hdr
->replen
+= decode_setacl_maxsz
;
1474 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1478 p
= reserve_space(xdr
, 4);
1479 *p
= cpu_to_be32(OP_SAVEFH
);
1481 hdr
->replen
+= decode_savefh_maxsz
;
1484 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1488 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1489 *p
++ = cpu_to_be32(OP_SETATTR
);
1490 xdr_encode_opaque_fixed(p
, arg
->stateid
.data
, NFS4_STATEID_SIZE
);
1492 hdr
->replen
+= decode_setattr_maxsz
;
1493 encode_attrs(xdr
, arg
->iap
, server
);
1496 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1500 p
= reserve_space(xdr
, 4 + NFS4_VERIFIER_SIZE
);
1501 *p
++ = cpu_to_be32(OP_SETCLIENTID
);
1502 xdr_encode_opaque_fixed(p
, setclientid
->sc_verifier
->data
, NFS4_VERIFIER_SIZE
);
1504 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1505 p
= reserve_space(xdr
, 4);
1506 *p
= cpu_to_be32(setclientid
->sc_prog
);
1507 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1508 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1509 p
= reserve_space(xdr
, 4);
1510 *p
= cpu_to_be32(setclientid
->sc_cb_ident
);
1512 hdr
->replen
+= decode_setclientid_maxsz
;
1515 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_setclientid_res
*arg
, struct compound_hdr
*hdr
)
1519 p
= reserve_space(xdr
, 12 + NFS4_VERIFIER_SIZE
);
1520 *p
++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM
);
1521 p
= xdr_encode_hyper(p
, arg
->clientid
);
1522 xdr_encode_opaque_fixed(p
, arg
->confirm
.data
, NFS4_VERIFIER_SIZE
);
1524 hdr
->replen
+= decode_setclientid_confirm_maxsz
;
1527 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1531 p
= reserve_space(xdr
, 4);
1532 *p
= cpu_to_be32(OP_WRITE
);
1534 encode_stateid(xdr
, args
->context
, args
->lock_context
);
1536 p
= reserve_space(xdr
, 16);
1537 p
= xdr_encode_hyper(p
, args
->offset
);
1538 *p
++ = cpu_to_be32(args
->stable
);
1539 *p
= cpu_to_be32(args
->count
);
1541 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1543 hdr
->replen
+= decode_write_maxsz
;
1546 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1550 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1552 *p
++ = cpu_to_be32(OP_DELEGRETURN
);
1553 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1555 hdr
->replen
+= decode_delegreturn_maxsz
;
1558 #if defined(CONFIG_NFS_V4_1)
1559 /* NFSv4.1 operations */
1560 static void encode_exchange_id(struct xdr_stream
*xdr
,
1561 struct nfs41_exchange_id_args
*args
,
1562 struct compound_hdr
*hdr
)
1566 p
= reserve_space(xdr
, 4 + sizeof(args
->verifier
->data
));
1567 *p
++ = cpu_to_be32(OP_EXCHANGE_ID
);
1568 xdr_encode_opaque_fixed(p
, args
->verifier
->data
, sizeof(args
->verifier
->data
));
1570 encode_string(xdr
, args
->id_len
, args
->id
);
1572 p
= reserve_space(xdr
, 12);
1573 *p
++ = cpu_to_be32(args
->flags
);
1574 *p
++ = cpu_to_be32(0); /* zero length state_protect4_a */
1575 *p
= cpu_to_be32(0); /* zero length implementation id array */
1577 hdr
->replen
+= decode_exchange_id_maxsz
;
1580 static void encode_create_session(struct xdr_stream
*xdr
,
1581 struct nfs41_create_session_args
*args
,
1582 struct compound_hdr
*hdr
)
1585 char machine_name
[NFS4_MAX_MACHINE_NAME_LEN
];
1587 struct nfs_client
*clp
= args
->client
;
1588 u32 max_resp_sz_cached
;
1591 * Assumes OPEN is the biggest non-idempotent compound.
1592 * 2 is the verifier.
1594 max_resp_sz_cached
= (NFS4_dec_open_sz
+ RPC_REPHDRSIZE
+
1595 RPC_MAX_AUTH_SIZE
+ 2) * XDR_UNIT
;
1597 len
= scnprintf(machine_name
, sizeof(machine_name
), "%s",
1600 p
= reserve_space(xdr
, 20 + 2*28 + 20 + len
+ 12);
1601 *p
++ = cpu_to_be32(OP_CREATE_SESSION
);
1602 p
= xdr_encode_hyper(p
, clp
->cl_ex_clid
);
1603 *p
++ = cpu_to_be32(clp
->cl_seqid
); /*Sequence id */
1604 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1607 *p
++ = cpu_to_be32(args
->fc_attrs
.headerpadsz
); /* header padding size */
1608 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1609 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1610 *p
++ = cpu_to_be32(max_resp_sz_cached
); /* Max resp sz cached */
1611 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1612 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1613 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1616 *p
++ = cpu_to_be32(args
->fc_attrs
.headerpadsz
); /* header padding size */
1617 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1618 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1619 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1620 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1621 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1622 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1624 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1625 *p
++ = cpu_to_be32(1);
1626 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1628 /* authsys_parms rfc1831 */
1629 *p
++ = cpu_to_be32((u32
)clp
->cl_boot_time
.tv_nsec
); /* stamp */
1630 p
= xdr_encode_opaque(p
, machine_name
, len
);
1631 *p
++ = cpu_to_be32(0); /* UID */
1632 *p
++ = cpu_to_be32(0); /* GID */
1633 *p
= cpu_to_be32(0); /* No more gids */
1635 hdr
->replen
+= decode_create_session_maxsz
;
1638 static void encode_destroy_session(struct xdr_stream
*xdr
,
1639 struct nfs4_session
*session
,
1640 struct compound_hdr
*hdr
)
1643 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
);
1644 *p
++ = cpu_to_be32(OP_DESTROY_SESSION
);
1645 xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1647 hdr
->replen
+= decode_destroy_session_maxsz
;
1650 static void encode_reclaim_complete(struct xdr_stream
*xdr
,
1651 struct nfs41_reclaim_complete_args
*args
,
1652 struct compound_hdr
*hdr
)
1656 p
= reserve_space(xdr
, 8);
1657 *p
++ = cpu_to_be32(OP_RECLAIM_COMPLETE
);
1658 *p
++ = cpu_to_be32(args
->one_fs
);
1660 hdr
->replen
+= decode_reclaim_complete_maxsz
;
1662 #endif /* CONFIG_NFS_V4_1 */
1664 static void encode_sequence(struct xdr_stream
*xdr
,
1665 const struct nfs4_sequence_args
*args
,
1666 struct compound_hdr
*hdr
)
1668 #if defined(CONFIG_NFS_V4_1)
1669 struct nfs4_session
*session
= args
->sa_session
;
1670 struct nfs4_slot_table
*tp
;
1671 struct nfs4_slot
*slot
;
1677 tp
= &session
->fc_slot_table
;
1679 WARN_ON(args
->sa_slotid
== NFS4_MAX_SLOT_TABLE
);
1680 slot
= tp
->slots
+ args
->sa_slotid
;
1682 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
+ 16);
1683 *p
++ = cpu_to_be32(OP_SEQUENCE
);
1686 * Sessionid + seqid + slotid + max slotid + cache_this
1688 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1689 "max_slotid=%d cache_this=%d\n",
1691 ((u32
*)session
->sess_id
.data
)[0],
1692 ((u32
*)session
->sess_id
.data
)[1],
1693 ((u32
*)session
->sess_id
.data
)[2],
1694 ((u32
*)session
->sess_id
.data
)[3],
1695 slot
->seq_nr
, args
->sa_slotid
,
1696 tp
->highest_used_slotid
, args
->sa_cache_this
);
1697 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1698 *p
++ = cpu_to_be32(slot
->seq_nr
);
1699 *p
++ = cpu_to_be32(args
->sa_slotid
);
1700 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1701 *p
= cpu_to_be32(args
->sa_cache_this
);
1703 hdr
->replen
+= decode_sequence_maxsz
;
1704 #endif /* CONFIG_NFS_V4_1 */
1708 * END OF "GENERIC" ENCODE ROUTINES.
1711 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
1713 #if defined(CONFIG_NFS_V4_1)
1714 if (args
->sa_session
)
1715 return args
->sa_session
->clp
->cl_mvops
->minor_version
;
1716 #endif /* CONFIG_NFS_V4_1 */
1721 * Encode an ACCESS request
1723 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_accessargs
*args
)
1725 struct xdr_stream xdr
;
1726 struct compound_hdr hdr
= {
1727 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1730 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1731 encode_compound_hdr(&xdr
, req
, &hdr
);
1732 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1733 encode_putfh(&xdr
, args
->fh
, &hdr
);
1734 encode_access(&xdr
, args
->access
, &hdr
);
1735 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1741 * Encode LOOKUP request
1743 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_arg
*args
)
1745 struct xdr_stream xdr
;
1746 struct compound_hdr hdr
= {
1747 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1750 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1751 encode_compound_hdr(&xdr
, req
, &hdr
);
1752 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1753 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1754 encode_lookup(&xdr
, args
->name
, &hdr
);
1755 encode_getfh(&xdr
, &hdr
);
1756 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1762 * Encode LOOKUP_ROOT request
1764 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_root_arg
*args
)
1766 struct xdr_stream xdr
;
1767 struct compound_hdr hdr
= {
1768 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1771 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1772 encode_compound_hdr(&xdr
, req
, &hdr
);
1773 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1774 encode_putrootfh(&xdr
, &hdr
);
1775 encode_getfh(&xdr
, &hdr
);
1776 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1782 * Encode REMOVE request
1784 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_removeargs
*args
)
1786 struct xdr_stream xdr
;
1787 struct compound_hdr hdr
= {
1788 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1791 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1792 encode_compound_hdr(&xdr
, req
, &hdr
);
1793 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1794 encode_putfh(&xdr
, args
->fh
, &hdr
);
1795 encode_remove(&xdr
, &args
->name
, &hdr
);
1796 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1802 * Encode RENAME request
1804 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_rename_arg
*args
)
1806 struct xdr_stream xdr
;
1807 struct compound_hdr hdr
= {
1808 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1811 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1812 encode_compound_hdr(&xdr
, req
, &hdr
);
1813 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1814 encode_putfh(&xdr
, args
->old_dir
, &hdr
);
1815 encode_savefh(&xdr
, &hdr
);
1816 encode_putfh(&xdr
, args
->new_dir
, &hdr
);
1817 encode_rename(&xdr
, args
->old_name
, args
->new_name
, &hdr
);
1818 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1819 encode_restorefh(&xdr
, &hdr
);
1820 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1826 * Encode LINK request
1828 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_link_arg
*args
)
1830 struct xdr_stream xdr
;
1831 struct compound_hdr hdr
= {
1832 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1835 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1836 encode_compound_hdr(&xdr
, req
, &hdr
);
1837 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1838 encode_putfh(&xdr
, args
->fh
, &hdr
);
1839 encode_savefh(&xdr
, &hdr
);
1840 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1841 encode_link(&xdr
, args
->name
, &hdr
);
1842 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1843 encode_restorefh(&xdr
, &hdr
);
1844 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1850 * Encode CREATE request
1852 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1854 struct xdr_stream xdr
;
1855 struct compound_hdr hdr
= {
1856 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1859 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1860 encode_compound_hdr(&xdr
, req
, &hdr
);
1861 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1862 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1863 encode_savefh(&xdr
, &hdr
);
1864 encode_create(&xdr
, args
, &hdr
);
1865 encode_getfh(&xdr
, &hdr
);
1866 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1867 encode_restorefh(&xdr
, &hdr
);
1868 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1874 * Encode SYMLINK request
1876 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1878 return nfs4_xdr_enc_create(req
, p
, args
);
1882 * Encode GETATTR request
1884 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_getattr_arg
*args
)
1886 struct xdr_stream xdr
;
1887 struct compound_hdr hdr
= {
1888 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1891 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1892 encode_compound_hdr(&xdr
, req
, &hdr
);
1893 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1894 encode_putfh(&xdr
, args
->fh
, &hdr
);
1895 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1901 * Encode a CLOSE request
1903 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1905 struct xdr_stream xdr
;
1906 struct compound_hdr hdr
= {
1907 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1910 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1911 encode_compound_hdr(&xdr
, req
, &hdr
);
1912 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1913 encode_putfh(&xdr
, args
->fh
, &hdr
);
1914 encode_close(&xdr
, args
, &hdr
);
1915 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1921 * Encode an OPEN request
1923 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1925 struct xdr_stream xdr
;
1926 struct compound_hdr hdr
= {
1927 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1930 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1931 encode_compound_hdr(&xdr
, req
, &hdr
);
1932 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1933 encode_putfh(&xdr
, args
->fh
, &hdr
);
1934 encode_savefh(&xdr
, &hdr
);
1935 encode_open(&xdr
, args
, &hdr
);
1936 encode_getfh(&xdr
, &hdr
);
1937 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1938 encode_restorefh(&xdr
, &hdr
);
1939 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1945 * Encode an OPEN_CONFIRM request
1947 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_open_confirmargs
*args
)
1949 struct xdr_stream xdr
;
1950 struct compound_hdr hdr
= {
1954 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1955 encode_compound_hdr(&xdr
, req
, &hdr
);
1956 encode_putfh(&xdr
, args
->fh
, &hdr
);
1957 encode_open_confirm(&xdr
, args
, &hdr
);
1963 * Encode an OPEN request with no attributes.
1965 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*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_open(&xdr
, args
, &hdr
);
1977 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1983 * Encode an OPEN_DOWNGRADE request
1985 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1987 struct xdr_stream xdr
;
1988 struct compound_hdr hdr
= {
1989 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1992 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1993 encode_compound_hdr(&xdr
, req
, &hdr
);
1994 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1995 encode_putfh(&xdr
, args
->fh
, &hdr
);
1996 encode_open_downgrade(&xdr
, args
, &hdr
);
1997 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2003 * Encode a LOCK request
2005 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lock_args
*args
)
2007 struct xdr_stream xdr
;
2008 struct compound_hdr hdr
= {
2009 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2012 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2013 encode_compound_hdr(&xdr
, req
, &hdr
);
2014 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2015 encode_putfh(&xdr
, args
->fh
, &hdr
);
2016 encode_lock(&xdr
, args
, &hdr
);
2022 * Encode a LOCKT request
2024 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lockt_args
*args
)
2026 struct xdr_stream xdr
;
2027 struct compound_hdr hdr
= {
2028 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2031 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2032 encode_compound_hdr(&xdr
, req
, &hdr
);
2033 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2034 encode_putfh(&xdr
, args
->fh
, &hdr
);
2035 encode_lockt(&xdr
, args
, &hdr
);
2041 * Encode a LOCKU request
2043 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, __be32
*p
, struct nfs_locku_args
*args
)
2045 struct xdr_stream xdr
;
2046 struct compound_hdr hdr
= {
2047 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2050 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2051 encode_compound_hdr(&xdr
, req
, &hdr
);
2052 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2053 encode_putfh(&xdr
, args
->fh
, &hdr
);
2054 encode_locku(&xdr
, args
, &hdr
);
2060 * Encode a READLINK request
2062 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readlink
*args
)
2064 struct xdr_stream xdr
;
2065 struct compound_hdr hdr
= {
2066 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2069 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2070 encode_compound_hdr(&xdr
, req
, &hdr
);
2071 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2072 encode_putfh(&xdr
, args
->fh
, &hdr
);
2073 encode_readlink(&xdr
, args
, req
, &hdr
);
2075 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2076 args
->pgbase
, args
->pglen
);
2082 * Encode a READDIR request
2084 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readdir_arg
*args
)
2086 struct xdr_stream xdr
;
2087 struct compound_hdr hdr
= {
2088 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2091 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2092 encode_compound_hdr(&xdr
, req
, &hdr
);
2093 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2094 encode_putfh(&xdr
, args
->fh
, &hdr
);
2095 encode_readdir(&xdr
, args
, req
, &hdr
);
2097 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2098 args
->pgbase
, args
->count
);
2099 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2100 __func__
, hdr
.replen
<< 2, args
->pages
,
2101 args
->pgbase
, args
->count
);
2107 * Encode a READ request
2109 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readargs
*args
)
2111 struct xdr_stream xdr
;
2112 struct compound_hdr hdr
= {
2113 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2116 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2117 encode_compound_hdr(&xdr
, req
, &hdr
);
2118 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2119 encode_putfh(&xdr
, args
->fh
, &hdr
);
2120 encode_read(&xdr
, args
, &hdr
);
2122 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2123 args
->pages
, args
->pgbase
, args
->count
);
2124 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2130 * Encode an SETATTR request
2132 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setattrargs
*args
)
2134 struct xdr_stream xdr
;
2135 struct compound_hdr hdr
= {
2136 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2139 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2140 encode_compound_hdr(&xdr
, req
, &hdr
);
2141 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2142 encode_putfh(&xdr
, args
->fh
, &hdr
);
2143 encode_setattr(&xdr
, args
, args
->server
, &hdr
);
2144 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2150 * Encode a GETACL request
2153 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, __be32
*p
,
2154 struct nfs_getaclargs
*args
)
2156 struct xdr_stream xdr
;
2157 struct compound_hdr hdr
= {
2158 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2162 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2163 encode_compound_hdr(&xdr
, req
, &hdr
);
2164 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2165 encode_putfh(&xdr
, args
->fh
, &hdr
);
2166 replen
= hdr
.replen
+ op_decode_hdr_maxsz
+ nfs4_fattr_bitmap_maxsz
+ 1;
2167 encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2169 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2170 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
2176 * Encode a WRITE request
2178 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
2180 struct xdr_stream xdr
;
2181 struct compound_hdr hdr
= {
2182 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2185 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2186 encode_compound_hdr(&xdr
, req
, &hdr
);
2187 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2188 encode_putfh(&xdr
, args
->fh
, &hdr
);
2189 encode_write(&xdr
, args
, &hdr
);
2190 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2191 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2199 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*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_commit(&xdr
, args
, &hdr
);
2211 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2219 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fsinfo_arg
*args
)
2221 struct xdr_stream xdr
;
2222 struct compound_hdr hdr
= {
2223 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2226 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2227 encode_compound_hdr(&xdr
, req
, &hdr
);
2228 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2229 encode_putfh(&xdr
, args
->fh
, &hdr
);
2230 encode_fsinfo(&xdr
, args
->bitmask
, &hdr
);
2236 * a PATHCONF request
2238 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_pathconf_arg
*args
)
2240 struct xdr_stream xdr
;
2241 struct compound_hdr hdr
= {
2242 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2245 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2246 encode_compound_hdr(&xdr
, req
, &hdr
);
2247 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2248 encode_putfh(&xdr
, args
->fh
, &hdr
);
2249 encode_getattr_one(&xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2258 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_statfs_arg
*args
)
2260 struct xdr_stream xdr
;
2261 struct compound_hdr hdr
= {
2262 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2265 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2266 encode_compound_hdr(&xdr
, req
, &hdr
);
2267 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2268 encode_putfh(&xdr
, args
->fh
, &hdr
);
2269 encode_getattr_two(&xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2270 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2276 * GETATTR_BITMAP request
2278 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, __be32
*p
,
2279 struct nfs4_server_caps_arg
*args
)
2281 struct xdr_stream xdr
;
2282 struct compound_hdr hdr
= {
2283 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2286 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2287 encode_compound_hdr(&xdr
, req
, &hdr
);
2288 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2289 encode_putfh(&xdr
, args
->fhandle
, &hdr
);
2290 encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2291 FATTR4_WORD0_LINK_SUPPORT
|
2292 FATTR4_WORD0_SYMLINK_SUPPORT
|
2293 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2301 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
2303 struct xdr_stream xdr
;
2304 struct compound_hdr hdr
= {
2308 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2309 encode_compound_hdr(&xdr
, req
, &hdr
);
2310 encode_renew(&xdr
, clp
, &hdr
);
2316 * a SETCLIENTID request
2318 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid
*sc
)
2320 struct xdr_stream xdr
;
2321 struct compound_hdr hdr
= {
2325 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2326 encode_compound_hdr(&xdr
, req
, &hdr
);
2327 encode_setclientid(&xdr
, sc
, &hdr
);
2333 * a SETCLIENTID_CONFIRM request
2335 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid_res
*arg
)
2337 struct xdr_stream xdr
;
2338 struct compound_hdr hdr
= {
2341 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2343 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2344 encode_compound_hdr(&xdr
, req
, &hdr
);
2345 encode_setclientid_confirm(&xdr
, arg
, &hdr
);
2346 encode_putrootfh(&xdr
, &hdr
);
2347 encode_fsinfo(&xdr
, lease_bitmap
, &hdr
);
2353 * DELEGRETURN request
2355 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_delegreturnargs
*args
)
2357 struct xdr_stream xdr
;
2358 struct compound_hdr hdr
= {
2359 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2362 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2363 encode_compound_hdr(&xdr
, req
, &hdr
);
2364 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2365 encode_putfh(&xdr
, args
->fhandle
, &hdr
);
2366 encode_delegreturn(&xdr
, args
->stateid
, &hdr
);
2367 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2373 * Encode FS_LOCATIONS request
2375 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations_arg
*args
)
2377 struct xdr_stream xdr
;
2378 struct compound_hdr hdr
= {
2379 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2383 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2384 encode_compound_hdr(&xdr
, req
, &hdr
);
2385 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2386 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
2387 encode_lookup(&xdr
, args
->name
, &hdr
);
2388 replen
= hdr
.replen
; /* get the attribute into args->page */
2389 encode_fs_locations(&xdr
, args
->bitmask
, &hdr
);
2391 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2397 #if defined(CONFIG_NFS_V4_1)
2399 * EXCHANGE_ID request
2401 static int nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
, uint32_t *p
,
2402 struct nfs41_exchange_id_args
*args
)
2404 struct xdr_stream xdr
;
2405 struct compound_hdr hdr
= {
2406 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2409 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2410 encode_compound_hdr(&xdr
, req
, &hdr
);
2411 encode_exchange_id(&xdr
, args
, &hdr
);
2417 * a CREATE_SESSION request
2419 static int nfs4_xdr_enc_create_session(struct rpc_rqst
*req
, uint32_t *p
,
2420 struct nfs41_create_session_args
*args
)
2422 struct xdr_stream xdr
;
2423 struct compound_hdr hdr
= {
2424 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2427 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2428 encode_compound_hdr(&xdr
, req
, &hdr
);
2429 encode_create_session(&xdr
, args
, &hdr
);
2435 * a DESTROY_SESSION request
2437 static int nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
, uint32_t *p
,
2438 struct nfs4_session
*session
)
2440 struct xdr_stream xdr
;
2441 struct compound_hdr hdr
= {
2442 .minorversion
= session
->clp
->cl_mvops
->minor_version
,
2445 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2446 encode_compound_hdr(&xdr
, req
, &hdr
);
2447 encode_destroy_session(&xdr
, session
, &hdr
);
2453 * a SEQUENCE request
2455 static int nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, uint32_t *p
,
2456 struct nfs4_sequence_args
*args
)
2458 struct xdr_stream xdr
;
2459 struct compound_hdr hdr
= {
2460 .minorversion
= nfs4_xdr_minorversion(args
),
2463 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2464 encode_compound_hdr(&xdr
, req
, &hdr
);
2465 encode_sequence(&xdr
, args
, &hdr
);
2471 * a GET_LEASE_TIME request
2473 static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
, uint32_t *p
,
2474 struct nfs4_get_lease_time_args
*args
)
2476 struct xdr_stream xdr
;
2477 struct compound_hdr hdr
= {
2478 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2480 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2482 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2483 encode_compound_hdr(&xdr
, req
, &hdr
);
2484 encode_sequence(&xdr
, &args
->la_seq_args
, &hdr
);
2485 encode_putrootfh(&xdr
, &hdr
);
2486 encode_fsinfo(&xdr
, lease_bitmap
, &hdr
);
2492 * a RECLAIM_COMPLETE request
2494 static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
, uint32_t *p
,
2495 struct nfs41_reclaim_complete_args
*args
)
2497 struct xdr_stream xdr
;
2498 struct compound_hdr hdr
= {
2499 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2502 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2503 encode_compound_hdr(&xdr
, req
, &hdr
);
2504 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2505 encode_reclaim_complete(&xdr
, args
, &hdr
);
2510 #endif /* CONFIG_NFS_V4_1 */
2512 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
2514 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2515 "Remaining buffer length is %tu words.\n",
2516 func
, xdr
->end
- xdr
->p
);
2519 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2523 p
= xdr_inline_decode(xdr
, 4);
2526 *len
= be32_to_cpup(p
);
2527 p
= xdr_inline_decode(xdr
, *len
);
2530 *string
= (char *)p
;
2533 print_overflow_msg(__func__
, xdr
);
2537 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2541 p
= xdr_inline_decode(xdr
, 8);
2544 hdr
->status
= be32_to_cpup(p
++);
2545 hdr
->taglen
= be32_to_cpup(p
);
2547 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
2550 hdr
->tag
= (char *)p
;
2551 p
+= XDR_QUADLEN(hdr
->taglen
);
2552 hdr
->nops
= be32_to_cpup(p
);
2553 if (unlikely(hdr
->nops
< 1))
2554 return nfs4_stat_to_errno(hdr
->status
);
2557 print_overflow_msg(__func__
, xdr
);
2561 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2567 p
= xdr_inline_decode(xdr
, 8);
2570 opnum
= be32_to_cpup(p
++);
2571 if (opnum
!= expected
) {
2572 dprintk("nfs: Server returned operation"
2573 " %d but we issued a request for %d\n",
2577 nfserr
= be32_to_cpup(p
);
2578 if (nfserr
!= NFS_OK
)
2579 return nfs4_stat_to_errno(nfserr
);
2582 print_overflow_msg(__func__
, xdr
);
2587 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2590 unsigned int strlen
;
2593 p
= xdr_inline_decode(xdr
, 12);
2595 return decode_opaque_inline(xdr
, &strlen
, &str
);
2596 print_overflow_msg(__func__
, xdr
);
2600 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2605 p
= xdr_inline_decode(xdr
, 4);
2608 bmlen
= be32_to_cpup(p
);
2610 bitmap
[0] = bitmap
[1] = 0;
2611 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
2615 bitmap
[0] = be32_to_cpup(p
++);
2617 bitmap
[1] = be32_to_cpup(p
);
2621 print_overflow_msg(__func__
, xdr
);
2625 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
2629 p
= xdr_inline_decode(xdr
, 4);
2632 *attrlen
= be32_to_cpup(p
);
2636 print_overflow_msg(__func__
, xdr
);
2640 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2642 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2643 decode_attr_bitmap(xdr
, bitmask
);
2644 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2646 bitmask
[0] = bitmask
[1] = 0;
2647 dprintk("%s: bitmask=%08x:%08x\n", __func__
, bitmask
[0], bitmask
[1]);
2651 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2657 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2659 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2660 p
= xdr_inline_decode(xdr
, 4);
2663 *type
= be32_to_cpup(p
);
2664 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2665 dprintk("%s: bad type %d\n", __func__
, *type
);
2668 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2669 ret
= NFS_ATTR_FATTR_TYPE
;
2671 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
2674 print_overflow_msg(__func__
, xdr
);
2678 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2684 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2686 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2687 p
= xdr_inline_decode(xdr
, 8);
2690 xdr_decode_hyper(p
, change
);
2691 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2692 ret
= NFS_ATTR_FATTR_CHANGE
;
2694 dprintk("%s: change attribute=%Lu\n", __func__
,
2695 (unsigned long long)*change
);
2698 print_overflow_msg(__func__
, xdr
);
2702 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2708 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2710 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2711 p
= xdr_inline_decode(xdr
, 8);
2714 xdr_decode_hyper(p
, size
);
2715 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2716 ret
= NFS_ATTR_FATTR_SIZE
;
2718 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
2721 print_overflow_msg(__func__
, xdr
);
2725 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2730 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2732 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2733 p
= xdr_inline_decode(xdr
, 4);
2736 *res
= be32_to_cpup(p
);
2737 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2739 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2742 print_overflow_msg(__func__
, xdr
);
2746 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2751 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2753 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2754 p
= xdr_inline_decode(xdr
, 4);
2757 *res
= be32_to_cpup(p
);
2758 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2760 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2763 print_overflow_msg(__func__
, xdr
);
2767 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
2774 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2776 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2777 p
= xdr_inline_decode(xdr
, 16);
2780 p
= xdr_decode_hyper(p
, &fsid
->major
);
2781 xdr_decode_hyper(p
, &fsid
->minor
);
2782 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2783 ret
= NFS_ATTR_FATTR_FSID
;
2785 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
2786 (unsigned long long)fsid
->major
,
2787 (unsigned long long)fsid
->minor
);
2790 print_overflow_msg(__func__
, xdr
);
2794 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2799 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2801 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2802 p
= xdr_inline_decode(xdr
, 4);
2805 *res
= be32_to_cpup(p
);
2806 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2808 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
2811 print_overflow_msg(__func__
, xdr
);
2815 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2819 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2820 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2822 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2823 p
= xdr_inline_decode(xdr
, 4);
2826 *res
= be32_to_cpup(p
);
2827 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2829 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
2832 print_overflow_msg(__func__
, xdr
);
2836 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2842 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2844 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2845 p
= xdr_inline_decode(xdr
, 8);
2848 xdr_decode_hyper(p
, fileid
);
2849 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2850 ret
= NFS_ATTR_FATTR_FILEID
;
2852 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2855 print_overflow_msg(__func__
, xdr
);
2859 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2865 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
2867 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
2868 p
= xdr_inline_decode(xdr
, 8);
2871 xdr_decode_hyper(p
, fileid
);
2872 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
2873 ret
= NFS_ATTR_FATTR_FILEID
;
2875 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2878 print_overflow_msg(__func__
, xdr
);
2882 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2888 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2890 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2891 p
= xdr_inline_decode(xdr
, 8);
2894 xdr_decode_hyper(p
, res
);
2895 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2897 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
2900 print_overflow_msg(__func__
, xdr
);
2904 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2910 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2912 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2913 p
= xdr_inline_decode(xdr
, 8);
2916 xdr_decode_hyper(p
, res
);
2917 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2919 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
2922 print_overflow_msg(__func__
, xdr
);
2926 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2932 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2934 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2935 p
= xdr_inline_decode(xdr
, 8);
2938 xdr_decode_hyper(p
, res
);
2939 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2941 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
2944 print_overflow_msg(__func__
, xdr
);
2948 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
2954 p
= xdr_inline_decode(xdr
, 4);
2957 n
= be32_to_cpup(p
);
2961 path
->ncomponents
= 0;
2962 while (path
->ncomponents
< n
) {
2963 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
2964 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
2965 if (unlikely(status
!= 0))
2967 if (path
->ncomponents
!= n
)
2969 dprintk("%s", component
->data
);
2970 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
2971 path
->ncomponents
++;
2973 dprintk("cannot parse %d components in path\n", n
);
2981 /* a root pathname is sent as a zero component4 */
2982 path
->ncomponents
= 1;
2983 path
->components
[0].len
=0;
2984 path
->components
[0].data
=NULL
;
2985 dprintk("path /\n");
2988 dprintk(" status %d", status
);
2992 print_overflow_msg(__func__
, xdr
);
2996 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
3002 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
3005 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
3007 dprintk("%s: fsroot ", __func__
);
3008 status
= decode_pathname(xdr
, &res
->fs_path
);
3009 if (unlikely(status
!= 0))
3011 p
= xdr_inline_decode(xdr
, 4);
3014 n
= be32_to_cpup(p
);
3017 res
->nlocations
= 0;
3018 while (res
->nlocations
< n
) {
3020 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
3022 p
= xdr_inline_decode(xdr
, 4);
3025 m
= be32_to_cpup(p
);
3028 dprintk("%s: servers ", __func__
);
3029 while (loc
->nservers
< m
) {
3030 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
3031 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3032 if (unlikely(status
!= 0))
3034 dprintk("%s ", server
->data
);
3035 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
3039 dprintk("%s: using first %u of %u servers "
3040 "returned for location %u\n",
3042 NFS4_FS_LOCATION_MAXSERVERS
,
3043 m
, res
->nlocations
);
3044 for (i
= loc
->nservers
; i
< m
; i
++) {
3047 status
= decode_opaque_inline(xdr
, &len
, &data
);
3048 if (unlikely(status
!= 0))
3053 status
= decode_pathname(xdr
, &loc
->rootpath
);
3054 if (unlikely(status
!= 0))
3056 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
3059 if (res
->nlocations
!= 0)
3060 status
= NFS_ATTR_FATTR_V4_REFERRAL
;
3062 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3065 print_overflow_msg(__func__
, xdr
);
3071 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3077 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3079 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3080 p
= xdr_inline_decode(xdr
, 8);
3083 xdr_decode_hyper(p
, res
);
3084 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3086 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3089 print_overflow_msg(__func__
, xdr
);
3093 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3099 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3101 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3102 p
= xdr_inline_decode(xdr
, 4);
3105 *maxlink
= be32_to_cpup(p
);
3106 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3108 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3111 print_overflow_msg(__func__
, xdr
);
3115 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3121 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3123 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3124 p
= xdr_inline_decode(xdr
, 4);
3127 *maxname
= be32_to_cpup(p
);
3128 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3130 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3133 print_overflow_msg(__func__
, xdr
);
3137 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3143 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3145 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3147 p
= xdr_inline_decode(xdr
, 8);
3150 xdr_decode_hyper(p
, &maxread
);
3151 if (maxread
> 0x7FFFFFFF)
3152 maxread
= 0x7FFFFFFF;
3153 *res
= (uint32_t)maxread
;
3154 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3156 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3159 print_overflow_msg(__func__
, xdr
);
3163 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3169 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3171 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3173 p
= xdr_inline_decode(xdr
, 8);
3176 xdr_decode_hyper(p
, &maxwrite
);
3177 if (maxwrite
> 0x7FFFFFFF)
3178 maxwrite
= 0x7FFFFFFF;
3179 *res
= (uint32_t)maxwrite
;
3180 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3182 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3185 print_overflow_msg(__func__
, xdr
);
3189 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3196 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3198 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3199 p
= xdr_inline_decode(xdr
, 4);
3202 tmp
= be32_to_cpup(p
);
3203 *mode
= tmp
& ~S_IFMT
;
3204 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3205 ret
= NFS_ATTR_FATTR_MODE
;
3207 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3210 print_overflow_msg(__func__
, xdr
);
3214 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3220 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3222 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3223 p
= xdr_inline_decode(xdr
, 4);
3226 *nlink
= be32_to_cpup(p
);
3227 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3228 ret
= NFS_ATTR_FATTR_NLINK
;
3230 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3233 print_overflow_msg(__func__
, xdr
);
3237 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3238 struct nfs_client
*clp
, uint32_t *uid
, int may_sleep
)
3245 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3247 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3248 p
= xdr_inline_decode(xdr
, 4);
3251 len
= be32_to_cpup(p
);
3252 p
= xdr_inline_decode(xdr
, len
);
3257 } else if (len
< XDR_MAX_NETOBJ
) {
3258 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) == 0)
3259 ret
= NFS_ATTR_FATTR_OWNER
;
3261 dprintk("%s: nfs_map_name_to_uid failed!\n",
3264 dprintk("%s: name too long (%u)!\n",
3266 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3268 dprintk("%s: uid=%d\n", __func__
, (int)*uid
);
3271 print_overflow_msg(__func__
, xdr
);
3275 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3276 struct nfs_client
*clp
, uint32_t *gid
, int may_sleep
)
3283 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3285 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3286 p
= xdr_inline_decode(xdr
, 4);
3289 len
= be32_to_cpup(p
);
3290 p
= xdr_inline_decode(xdr
, len
);
3295 } else if (len
< XDR_MAX_NETOBJ
) {
3296 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) == 0)
3297 ret
= NFS_ATTR_FATTR_GROUP
;
3299 dprintk("%s: nfs_map_group_to_gid failed!\n",
3302 dprintk("%s: name too long (%u)!\n",
3304 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3306 dprintk("%s: gid=%d\n", __func__
, (int)*gid
);
3309 print_overflow_msg(__func__
, xdr
);
3313 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3315 uint32_t major
= 0, minor
= 0;
3320 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3322 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3325 p
= xdr_inline_decode(xdr
, 8);
3328 major
= be32_to_cpup(p
++);
3329 minor
= be32_to_cpup(p
);
3330 tmp
= MKDEV(major
, minor
);
3331 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3333 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3334 ret
= NFS_ATTR_FATTR_RDEV
;
3336 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3339 print_overflow_msg(__func__
, xdr
);
3343 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3349 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3351 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3352 p
= xdr_inline_decode(xdr
, 8);
3355 xdr_decode_hyper(p
, res
);
3356 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3358 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3361 print_overflow_msg(__func__
, xdr
);
3365 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3371 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3373 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3374 p
= xdr_inline_decode(xdr
, 8);
3377 xdr_decode_hyper(p
, res
);
3378 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3380 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3383 print_overflow_msg(__func__
, xdr
);
3387 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3393 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
3395 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
3396 p
= xdr_inline_decode(xdr
, 8);
3399 xdr_decode_hyper(p
, res
);
3400 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
3402 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
3405 print_overflow_msg(__func__
, xdr
);
3409 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
3415 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
3417 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
3418 p
= xdr_inline_decode(xdr
, 8);
3421 xdr_decode_hyper(p
, used
);
3422 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
3423 ret
= NFS_ATTR_FATTR_SPACE_USED
;
3425 dprintk("%s: space used=%Lu\n", __func__
,
3426 (unsigned long long)*used
);
3429 print_overflow_msg(__func__
, xdr
);
3433 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
3439 p
= xdr_inline_decode(xdr
, 12);
3442 p
= xdr_decode_hyper(p
, &sec
);
3443 nsec
= be32_to_cpup(p
);
3444 time
->tv_sec
= (time_t)sec
;
3445 time
->tv_nsec
= (long)nsec
;
3448 print_overflow_msg(__func__
, xdr
);
3452 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3458 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
3460 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
3461 status
= decode_attr_time(xdr
, time
);
3463 status
= NFS_ATTR_FATTR_ATIME
;
3464 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
3466 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
3470 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3476 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
3478 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
3479 status
= decode_attr_time(xdr
, time
);
3481 status
= NFS_ATTR_FATTR_CTIME
;
3482 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
3484 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
3488 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3494 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
3496 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
3497 status
= decode_attr_time(xdr
, time
);
3499 status
= NFS_ATTR_FATTR_MTIME
;
3500 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
3502 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
3506 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
3508 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
3509 unsigned int nwords
= xdr
->p
- savep
;
3511 if (unlikely(attrwords
!= nwords
)) {
3512 dprintk("%s: server returned incorrect attribute length: "
3516 (attrwords
< nwords
) ? '<' : '>',
3523 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3527 p
= xdr_inline_decode(xdr
, 20);
3530 cinfo
->atomic
= be32_to_cpup(p
++);
3531 p
= xdr_decode_hyper(p
, &cinfo
->before
);
3532 xdr_decode_hyper(p
, &cinfo
->after
);
3535 print_overflow_msg(__func__
, xdr
);
3539 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
3545 status
= decode_op_hdr(xdr
, OP_ACCESS
);
3548 p
= xdr_inline_decode(xdr
, 8);
3551 supp
= be32_to_cpup(p
++);
3552 acc
= be32_to_cpup(p
);
3553 access
->supported
= supp
;
3554 access
->access
= acc
;
3557 print_overflow_msg(__func__
, xdr
);
3561 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
3565 p
= xdr_inline_decode(xdr
, len
);
3567 memcpy(buf
, p
, len
);
3570 print_overflow_msg(__func__
, xdr
);
3574 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
3576 return decode_opaque_fixed(xdr
, stateid
->data
, NFS4_STATEID_SIZE
);
3579 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3583 status
= decode_op_hdr(xdr
, OP_CLOSE
);
3585 nfs_increment_open_seqid(status
, res
->seqid
);
3587 status
= decode_stateid(xdr
, &res
->stateid
);
3591 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
3593 return decode_opaque_fixed(xdr
, verifier
, 8);
3596 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3600 status
= decode_op_hdr(xdr
, OP_COMMIT
);
3602 status
= decode_verifier(xdr
, res
->verf
->verifier
);
3606 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3612 status
= decode_op_hdr(xdr
, OP_CREATE
);
3615 if ((status
= decode_change_info(xdr
, cinfo
)))
3617 p
= xdr_inline_decode(xdr
, 4);
3620 bmlen
= be32_to_cpup(p
);
3621 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
3625 print_overflow_msg(__func__
, xdr
);
3629 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
3632 uint32_t attrlen
, bitmap
[2] = {0};
3635 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3637 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3639 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3641 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
3643 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
3645 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
3647 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
3649 status
= verify_attr_len(xdr
, savep
, attrlen
);
3651 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3655 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
3658 uint32_t attrlen
, bitmap
[2] = {0};
3661 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3663 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3665 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3668 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
3670 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
3672 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
3674 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
3676 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
3678 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
3681 status
= verify_attr_len(xdr
, savep
, attrlen
);
3683 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3687 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
3690 uint32_t attrlen
, bitmap
[2] = {0};
3693 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3695 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3697 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3700 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
3702 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
3705 status
= verify_attr_len(xdr
, savep
, attrlen
);
3707 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3711 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
3712 const struct nfs_server
*server
, int may_sleep
)
3722 status
= decode_op_hdr(xdr
, OP_GETATTR
);
3726 status
= decode_attr_bitmap(xdr
, bitmap
);
3730 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
3735 status
= decode_attr_type(xdr
, bitmap
, &type
);
3740 fattr
->mode
|= nfs_type2fmt
[type
];
3741 fattr
->valid
|= status
;
3744 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
3747 fattr
->valid
|= status
;
3749 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
3752 fattr
->valid
|= status
;
3754 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
3757 fattr
->valid
|= status
;
3759 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
3762 fattr
->valid
|= status
;
3764 status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
3765 struct nfs4_fs_locations
,
3769 fattr
->valid
|= status
;
3771 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
3775 fattr
->mode
|= fmode
;
3776 fattr
->valid
|= status
;
3779 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
3782 fattr
->valid
|= status
;
3784 status
= decode_attr_owner(xdr
, bitmap
, server
->nfs_client
,
3785 &fattr
->uid
, may_sleep
);
3788 fattr
->valid
|= status
;
3790 status
= decode_attr_group(xdr
, bitmap
, server
->nfs_client
,
3791 &fattr
->gid
, may_sleep
);
3794 fattr
->valid
|= status
;
3796 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
3799 fattr
->valid
|= status
;
3801 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
3804 fattr
->valid
|= status
;
3806 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
3809 fattr
->valid
|= status
;
3811 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
3814 fattr
->valid
|= status
;
3816 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
3819 fattr
->valid
|= status
;
3821 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fileid
);
3824 if (status
!= 0 && !(fattr
->valid
& status
)) {
3825 fattr
->fileid
= fileid
;
3826 fattr
->valid
|= status
;
3829 status
= verify_attr_len(xdr
, savep
, attrlen
);
3831 dprintk("%s: xdr returned %d\n", __func__
, -status
);
3836 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
3839 uint32_t attrlen
, bitmap
[2];
3842 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3844 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3846 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3849 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
3851 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
3853 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
3855 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
3857 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
3858 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
3860 fsinfo
->wtpref
= fsinfo
->wtmax
;
3862 status
= verify_attr_len(xdr
, savep
, attrlen
);
3864 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3868 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
3874 /* Zero handle first to allow comparisons */
3875 memset(fh
, 0, sizeof(*fh
));
3877 status
= decode_op_hdr(xdr
, OP_GETFH
);
3881 p
= xdr_inline_decode(xdr
, 4);
3884 len
= be32_to_cpup(p
);
3885 if (len
> NFS4_FHSIZE
)
3888 p
= xdr_inline_decode(xdr
, len
);
3891 memcpy(fh
->data
, p
, len
);
3894 print_overflow_msg(__func__
, xdr
);
3898 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3902 status
= decode_op_hdr(xdr
, OP_LINK
);
3905 return decode_change_info(xdr
, cinfo
);
3909 * We create the owner, so we know a proper owner.id length is 4.
3911 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
3913 uint64_t offset
, length
, clientid
;
3915 uint32_t namelen
, type
;
3917 p
= xdr_inline_decode(xdr
, 32);
3920 p
= xdr_decode_hyper(p
, &offset
);
3921 p
= xdr_decode_hyper(p
, &length
);
3922 type
= be32_to_cpup(p
++);
3924 fl
->fl_start
= (loff_t
)offset
;
3925 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
3926 if (length
== ~(uint64_t)0)
3927 fl
->fl_end
= OFFSET_MAX
;
3928 fl
->fl_type
= F_WRLCK
;
3930 fl
->fl_type
= F_RDLCK
;
3933 p
= xdr_decode_hyper(p
, &clientid
);
3934 namelen
= be32_to_cpup(p
);
3935 p
= xdr_inline_decode(xdr
, namelen
);
3937 return -NFS4ERR_DENIED
;
3939 print_overflow_msg(__func__
, xdr
);
3943 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
3947 status
= decode_op_hdr(xdr
, OP_LOCK
);
3951 status
= decode_stateid(xdr
, &res
->stateid
);
3952 if (unlikely(status
))
3954 } else if (status
== -NFS4ERR_DENIED
)
3955 status
= decode_lock_denied(xdr
, NULL
);
3956 if (res
->open_seqid
!= NULL
)
3957 nfs_increment_open_seqid(status
, res
->open_seqid
);
3958 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
3963 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
3966 status
= decode_op_hdr(xdr
, OP_LOCKT
);
3967 if (status
== -NFS4ERR_DENIED
)
3968 return decode_lock_denied(xdr
, res
->denied
);
3972 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
3976 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3978 nfs_increment_lock_seqid(status
, res
->seqid
);
3980 status
= decode_stateid(xdr
, &res
->stateid
);
3984 static int decode_lookup(struct xdr_stream
*xdr
)
3986 return decode_op_hdr(xdr
, OP_LOOKUP
);
3989 /* This is too sick! */
3990 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3993 uint32_t limit_type
, nblocks
, blocksize
;
3995 p
= xdr_inline_decode(xdr
, 12);
3998 limit_type
= be32_to_cpup(p
++);
3999 switch (limit_type
) {
4001 xdr_decode_hyper(p
, maxsize
);
4004 nblocks
= be32_to_cpup(p
++);
4005 blocksize
= be32_to_cpup(p
);
4006 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
4010 print_overflow_msg(__func__
, xdr
);
4014 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4017 uint32_t delegation_type
;
4020 p
= xdr_inline_decode(xdr
, 4);
4023 delegation_type
= be32_to_cpup(p
);
4024 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
4025 res
->delegation_type
= 0;
4028 status
= decode_stateid(xdr
, &res
->delegation
);
4029 if (unlikely(status
))
4031 p
= xdr_inline_decode(xdr
, 4);
4034 res
->do_recall
= be32_to_cpup(p
);
4036 switch (delegation_type
) {
4037 case NFS4_OPEN_DELEGATE_READ
:
4038 res
->delegation_type
= FMODE_READ
;
4040 case NFS4_OPEN_DELEGATE_WRITE
:
4041 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
4042 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
4045 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
4047 print_overflow_msg(__func__
, xdr
);
4051 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4054 uint32_t savewords
, bmlen
, i
;
4057 status
= decode_op_hdr(xdr
, OP_OPEN
);
4059 nfs_increment_open_seqid(status
, res
->seqid
);
4061 status
= decode_stateid(xdr
, &res
->stateid
);
4062 if (unlikely(status
))
4065 decode_change_info(xdr
, &res
->cinfo
);
4067 p
= xdr_inline_decode(xdr
, 8);
4070 res
->rflags
= be32_to_cpup(p
++);
4071 bmlen
= be32_to_cpup(p
);
4075 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4078 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
4079 for (i
= 0; i
< savewords
; ++i
)
4080 res
->attrset
[i
] = be32_to_cpup(p
++);
4081 for (; i
< NFS4_BITMAP_SIZE
; i
++)
4082 res
->attrset
[i
] = 0;
4084 return decode_delegation(xdr
, res
);
4086 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
4089 print_overflow_msg(__func__
, xdr
);
4093 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
4097 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
4099 nfs_increment_open_seqid(status
, res
->seqid
);
4101 status
= decode_stateid(xdr
, &res
->stateid
);
4105 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4109 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
4111 nfs_increment_open_seqid(status
, res
->seqid
);
4113 status
= decode_stateid(xdr
, &res
->stateid
);
4117 static int decode_putfh(struct xdr_stream
*xdr
)
4119 return decode_op_hdr(xdr
, OP_PUTFH
);
4122 static int decode_putrootfh(struct xdr_stream
*xdr
)
4124 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
4127 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
4129 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4131 uint32_t count
, eof
, recvd
, hdrlen
;
4134 status
= decode_op_hdr(xdr
, OP_READ
);
4137 p
= xdr_inline_decode(xdr
, 8);
4140 eof
= be32_to_cpup(p
++);
4141 count
= be32_to_cpup(p
);
4142 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
4143 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4144 if (count
> recvd
) {
4145 dprintk("NFS: server cheating in read reply: "
4146 "count %u > recvd %u\n", count
, recvd
);
4150 xdr_read_pages(xdr
, count
);
4155 print_overflow_msg(__func__
, xdr
);
4159 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
4161 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4162 struct page
*page
= *rcvbuf
->pages
;
4163 struct kvec
*iov
= rcvbuf
->head
;
4165 u32 recvd
, pglen
= rcvbuf
->page_len
;
4166 __be32
*end
, *entry
, *p
, *kaddr
;
4167 unsigned int nr
= 0;
4170 status
= decode_op_hdr(xdr
, OP_READDIR
);
4172 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
4173 if (unlikely(status
))
4175 dprintk("%s: verifier = %08x:%08x\n",
4177 ((u32
*)readdir
->verifier
.data
)[0],
4178 ((u32
*)readdir
->verifier
.data
)[1]);
4181 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4182 recvd
= rcvbuf
->len
- hdrlen
;
4185 xdr_read_pages(xdr
, pglen
);
4187 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
4188 kaddr
= p
= kmap_atomic(page
, KM_USER0
);
4189 end
= p
+ ((pglen
+ readdir
->pgbase
) >> 2);
4192 /* Make sure the packet actually has a value_follows and EOF entry */
4193 if ((entry
+ 1) > end
)
4196 for (; *p
++; nr
++) {
4197 u32 len
, attrlen
, xlen
;
4200 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
4201 p
+= 2; /* cookie */
4202 len
= ntohl(*p
++); /* filename length */
4203 if (len
> NFS4_MAXNAMLEN
) {
4204 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4208 xlen
= XDR_QUADLEN(len
);
4209 if (end
- p
< xlen
+ 1)
4211 dprintk("filename = %*s\n", len
, (char *)p
);
4213 len
= ntohl(*p
++); /* bitmap length */
4214 if (end
- p
< len
+ 1)
4217 attrlen
= XDR_QUADLEN(ntohl(*p
++));
4218 if (end
- p
< attrlen
+ 2)
4220 p
+= attrlen
; /* attributes */
4224 * Apparently some server sends responses that are a valid size, but
4225 * contain no entries, and have value_follows==0 and EOF==0. For
4226 * those, just set the EOF marker.
4228 if (!nr
&& entry
[1] == 0) {
4229 dprintk("NFS: readdir reply truncated!\n");
4233 kunmap_atomic(kaddr
, KM_USER0
);
4237 * When we get a short packet there are 2 possibilities. We can
4238 * return an error, or fix up the response to look like a valid
4239 * response and return what we have so far. If there are no
4240 * entries and the packet was short, then return -EIO. If there
4241 * are valid entries in the response, return them and pretend that
4242 * the call was successful, but incomplete. The caller can retry the
4243 * readdir starting at the last cookie.
4245 dprintk("%s: short packet at entry %d\n", __func__
, nr
);
4246 entry
[0] = entry
[1] = 0;
4250 kunmap_atomic(kaddr
, KM_USER0
);
4251 return -errno_NFSERR_IO
;
4254 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
4256 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4257 struct kvec
*iov
= rcvbuf
->head
;
4264 status
= decode_op_hdr(xdr
, OP_READLINK
);
4268 /* Convert length of symlink */
4269 p
= xdr_inline_decode(xdr
, 4);
4272 len
= be32_to_cpup(p
);
4273 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
4274 dprintk("nfs: server returned giant symlink!\n");
4275 return -ENAMETOOLONG
;
4277 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4278 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4280 dprintk("NFS: server cheating in readlink reply: "
4281 "count %u > recvd %u\n", len
, recvd
);
4284 xdr_read_pages(xdr
, len
);
4286 * The XDR encode routine has set things up so that
4287 * the link text will be copied directly into the
4288 * buffer. We just have to do overflow-checking,
4289 * and and null-terminate the text (the VFS expects
4290 * null-termination).
4292 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
4293 kaddr
[len
+rcvbuf
->page_base
] = '\0';
4294 kunmap_atomic(kaddr
, KM_USER0
);
4297 print_overflow_msg(__func__
, xdr
);
4301 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4305 status
= decode_op_hdr(xdr
, OP_REMOVE
);
4308 status
= decode_change_info(xdr
, cinfo
);
4313 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
4314 struct nfs4_change_info
*new_cinfo
)
4318 status
= decode_op_hdr(xdr
, OP_RENAME
);
4321 if ((status
= decode_change_info(xdr
, old_cinfo
)))
4323 status
= decode_change_info(xdr
, new_cinfo
);
4328 static int decode_renew(struct xdr_stream
*xdr
)
4330 return decode_op_hdr(xdr
, OP_RENEW
);
4334 decode_restorefh(struct xdr_stream
*xdr
)
4336 return decode_op_hdr(xdr
, OP_RESTOREFH
);
4339 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
4345 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4349 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4351 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4353 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4356 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
4358 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
4362 /* We ignore &savep and don't do consistency checks on
4363 * the attr length. Let userspace figure it out.... */
4364 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
4365 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4366 if (attrlen
> recvd
) {
4367 dprintk("NFS: server cheating in getattr"
4368 " acl reply: attrlen %u > recvd %u\n",
4372 xdr_read_pages(xdr
, attrlen
);
4375 status
= -EOPNOTSUPP
;
4382 decode_savefh(struct xdr_stream
*xdr
)
4384 return decode_op_hdr(xdr
, OP_SAVEFH
);
4387 static int decode_setattr(struct xdr_stream
*xdr
)
4393 status
= decode_op_hdr(xdr
, OP_SETATTR
);
4396 p
= xdr_inline_decode(xdr
, 4);
4399 bmlen
= be32_to_cpup(p
);
4400 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4404 print_overflow_msg(__func__
, xdr
);
4408 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
4414 p
= xdr_inline_decode(xdr
, 8);
4417 opnum
= be32_to_cpup(p
++);
4418 if (opnum
!= OP_SETCLIENTID
) {
4419 dprintk("nfs: decode_setclientid: Server returned operation"
4423 nfserr
= be32_to_cpup(p
);
4424 if (nfserr
== NFS_OK
) {
4425 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
4428 p
= xdr_decode_hyper(p
, &res
->clientid
);
4429 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
4430 } else if (nfserr
== NFSERR_CLID_INUSE
) {
4433 /* skip netid string */
4434 p
= xdr_inline_decode(xdr
, 4);
4437 len
= be32_to_cpup(p
);
4438 p
= xdr_inline_decode(xdr
, len
);
4442 /* skip uaddr string */
4443 p
= xdr_inline_decode(xdr
, 4);
4446 len
= be32_to_cpup(p
);
4447 p
= xdr_inline_decode(xdr
, len
);
4450 return -NFSERR_CLID_INUSE
;
4452 return nfs4_stat_to_errno(nfserr
);
4456 print_overflow_msg(__func__
, xdr
);
4460 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
4462 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
4465 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
4470 status
= decode_op_hdr(xdr
, OP_WRITE
);
4474 p
= xdr_inline_decode(xdr
, 16);
4477 res
->count
= be32_to_cpup(p
++);
4478 res
->verf
->committed
= be32_to_cpup(p
++);
4479 memcpy(res
->verf
->verifier
, p
, 8);
4482 print_overflow_msg(__func__
, xdr
);
4486 static int decode_delegreturn(struct xdr_stream
*xdr
)
4488 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
4491 #if defined(CONFIG_NFS_V4_1)
4492 static int decode_exchange_id(struct xdr_stream
*xdr
,
4493 struct nfs41_exchange_id_res
*res
)
4499 struct nfs_client
*clp
= res
->client
;
4501 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
4505 p
= xdr_inline_decode(xdr
, 8);
4508 xdr_decode_hyper(p
, &clp
->cl_ex_clid
);
4509 p
= xdr_inline_decode(xdr
, 12);
4512 clp
->cl_seqid
= be32_to_cpup(p
++);
4513 clp
->cl_exchange_flags
= be32_to_cpup(p
++);
4515 /* We ask for SP4_NONE */
4516 dummy
= be32_to_cpup(p
);
4517 if (dummy
!= SP4_NONE
)
4520 /* Throw away minor_id */
4521 p
= xdr_inline_decode(xdr
, 8);
4525 /* Throw away Major id */
4526 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4527 if (unlikely(status
))
4530 /* Throw away server_scope */
4531 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4532 if (unlikely(status
))
4535 /* Throw away Implementation id array */
4536 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4537 if (unlikely(status
))
4542 print_overflow_msg(__func__
, xdr
);
4546 static int decode_chan_attrs(struct xdr_stream
*xdr
,
4547 struct nfs4_channel_attrs
*attrs
)
4552 p
= xdr_inline_decode(xdr
, 28);
4555 attrs
->headerpadsz
= be32_to_cpup(p
++);
4556 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
4557 attrs
->max_resp_sz
= be32_to_cpup(p
++);
4558 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
4559 attrs
->max_ops
= be32_to_cpup(p
++);
4560 attrs
->max_reqs
= be32_to_cpup(p
++);
4561 nr_attrs
= be32_to_cpup(p
);
4562 if (unlikely(nr_attrs
> 1)) {
4563 printk(KERN_WARNING
"%s: Invalid rdma channel attrs count %u\n",
4564 __func__
, nr_attrs
);
4567 if (nr_attrs
== 1) {
4568 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
4574 print_overflow_msg(__func__
, xdr
);
4578 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
4580 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
4583 static int decode_create_session(struct xdr_stream
*xdr
,
4584 struct nfs41_create_session_res
*res
)
4588 struct nfs_client
*clp
= res
->client
;
4589 struct nfs4_session
*session
= clp
->cl_session
;
4591 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
4593 status
= decode_sessionid(xdr
, &session
->sess_id
);
4594 if (unlikely(status
))
4598 p
= xdr_inline_decode(xdr
, 8);
4601 clp
->cl_seqid
= be32_to_cpup(p
++);
4602 session
->flags
= be32_to_cpup(p
);
4604 /* Channel attributes */
4605 status
= decode_chan_attrs(xdr
, &session
->fc_attrs
);
4607 status
= decode_chan_attrs(xdr
, &session
->bc_attrs
);
4610 print_overflow_msg(__func__
, xdr
);
4614 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
4616 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
4619 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
4621 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
4623 #endif /* CONFIG_NFS_V4_1 */
4625 static int decode_sequence(struct xdr_stream
*xdr
,
4626 struct nfs4_sequence_res
*res
,
4627 struct rpc_rqst
*rqstp
)
4629 #if defined(CONFIG_NFS_V4_1)
4630 struct nfs4_slot
*slot
;
4631 struct nfs4_sessionid id
;
4636 if (!res
->sr_session
)
4639 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
4641 status
= decode_sessionid(xdr
, &id
);
4642 if (unlikely(status
))
4646 * If the server returns different values for sessionID, slotID or
4647 * sequence number, the server is looney tunes.
4649 status
= -EREMOTEIO
;
4651 if (memcmp(id
.data
, res
->sr_session
->sess_id
.data
,
4652 NFS4_MAX_SESSIONID_LEN
)) {
4653 dprintk("%s Invalid session id\n", __func__
);
4657 p
= xdr_inline_decode(xdr
, 20);
4662 slot
= &res
->sr_session
->fc_slot_table
.slots
[res
->sr_slotid
];
4663 dummy
= be32_to_cpup(p
++);
4664 if (dummy
!= slot
->seq_nr
) {
4665 dprintk("%s Invalid sequence number\n", __func__
);
4669 dummy
= be32_to_cpup(p
++);
4670 if (dummy
!= res
->sr_slotid
) {
4671 dprintk("%s Invalid slot id\n", __func__
);
4674 /* highest slot id - currently not processed */
4675 dummy
= be32_to_cpup(p
++);
4676 /* target highest slot id - currently not processed */
4677 dummy
= be32_to_cpup(p
++);
4679 res
->sr_status_flags
= be32_to_cpup(p
);
4682 res
->sr_status
= status
;
4685 print_overflow_msg(__func__
, xdr
);
4688 #else /* CONFIG_NFS_V4_1 */
4690 #endif /* CONFIG_NFS_V4_1 */
4694 * END OF "GENERIC" DECODE ROUTINES.
4698 * Decode OPEN_DOWNGRADE response
4700 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
4702 struct xdr_stream xdr
;
4703 struct compound_hdr hdr
;
4706 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4707 status
= decode_compound_hdr(&xdr
, &hdr
);
4710 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4713 status
= decode_putfh(&xdr
);
4716 status
= decode_open_downgrade(&xdr
, res
);
4719 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4720 !RPC_IS_ASYNC(rqstp
->rq_task
));
4726 * Decode ACCESS response
4728 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_accessres
*res
)
4730 struct xdr_stream xdr
;
4731 struct compound_hdr hdr
;
4734 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4735 status
= decode_compound_hdr(&xdr
, &hdr
);
4738 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4741 status
= decode_putfh(&xdr
);
4744 status
= decode_access(&xdr
, res
);
4747 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4748 !RPC_IS_ASYNC(rqstp
->rq_task
));
4754 * Decode LOOKUP response
4756 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
4758 struct xdr_stream xdr
;
4759 struct compound_hdr hdr
;
4762 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4763 status
= decode_compound_hdr(&xdr
, &hdr
);
4766 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4769 if ((status
= decode_putfh(&xdr
)) != 0)
4771 if ((status
= decode_lookup(&xdr
)) != 0)
4773 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
4775 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
4776 ,!RPC_IS_ASYNC(rqstp
->rq_task
));
4782 * Decode LOOKUP_ROOT response
4784 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
4786 struct xdr_stream xdr
;
4787 struct compound_hdr hdr
;
4790 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4791 status
= decode_compound_hdr(&xdr
, &hdr
);
4794 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4797 if ((status
= decode_putrootfh(&xdr
)) != 0)
4799 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
4800 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4801 !RPC_IS_ASYNC(rqstp
->rq_task
));
4807 * Decode REMOVE response
4809 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_removeres
*res
)
4811 struct xdr_stream xdr
;
4812 struct compound_hdr hdr
;
4815 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4816 status
= decode_compound_hdr(&xdr
, &hdr
);
4819 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4822 if ((status
= decode_putfh(&xdr
)) != 0)
4824 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
4826 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
4827 !RPC_IS_ASYNC(rqstp
->rq_task
));
4833 * Decode RENAME response
4835 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_rename_res
*res
)
4837 struct xdr_stream xdr
;
4838 struct compound_hdr hdr
;
4841 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4842 status
= decode_compound_hdr(&xdr
, &hdr
);
4845 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4848 if ((status
= decode_putfh(&xdr
)) != 0)
4850 if ((status
= decode_savefh(&xdr
)) != 0)
4852 if ((status
= decode_putfh(&xdr
)) != 0)
4854 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
4856 /* Current FH is target directory */
4857 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
,
4858 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4860 if ((status
= decode_restorefh(&xdr
)) != 0)
4862 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
,
4863 !RPC_IS_ASYNC(rqstp
->rq_task
));
4869 * Decode LINK response
4871 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_link_res
*res
)
4873 struct xdr_stream xdr
;
4874 struct compound_hdr hdr
;
4877 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4878 status
= decode_compound_hdr(&xdr
, &hdr
);
4881 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4884 if ((status
= decode_putfh(&xdr
)) != 0)
4886 if ((status
= decode_savefh(&xdr
)) != 0)
4888 if ((status
= decode_putfh(&xdr
)) != 0)
4890 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
4893 * Note order: OP_LINK leaves the directory as the current
4896 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
4897 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4899 if ((status
= decode_restorefh(&xdr
)) != 0)
4901 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4902 !RPC_IS_ASYNC(rqstp
->rq_task
));
4908 * Decode CREATE response
4910 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
4912 struct xdr_stream xdr
;
4913 struct compound_hdr hdr
;
4916 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4917 status
= decode_compound_hdr(&xdr
, &hdr
);
4920 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4923 if ((status
= decode_putfh(&xdr
)) != 0)
4925 if ((status
= decode_savefh(&xdr
)) != 0)
4927 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
4929 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
4931 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4932 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4934 if ((status
= decode_restorefh(&xdr
)) != 0)
4936 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
,
4937 !RPC_IS_ASYNC(rqstp
->rq_task
));
4943 * Decode SYMLINK response
4945 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
4947 return nfs4_xdr_dec_create(rqstp
, p
, res
);
4951 * Decode GETATTR response
4953 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_getattr_res
*res
)
4955 struct xdr_stream xdr
;
4956 struct compound_hdr hdr
;
4959 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4960 status
= decode_compound_hdr(&xdr
, &hdr
);
4963 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4966 status
= decode_putfh(&xdr
);
4969 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4970 !RPC_IS_ASYNC(rqstp
->rq_task
));
4976 * Encode an SETACL request
4979 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setaclargs
*args
)
4981 struct xdr_stream xdr
;
4982 struct compound_hdr hdr
= {
4983 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
4987 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
4988 encode_compound_hdr(&xdr
, req
, &hdr
);
4989 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
4990 encode_putfh(&xdr
, args
->fh
, &hdr
);
4991 status
= encode_setacl(&xdr
, args
, &hdr
);
4997 * Decode SETACL response
5000 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, __be32
*p
,
5001 struct nfs_setaclres
*res
)
5003 struct xdr_stream xdr
;
5004 struct compound_hdr hdr
;
5007 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5008 status
= decode_compound_hdr(&xdr
, &hdr
);
5011 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5014 status
= decode_putfh(&xdr
);
5017 status
= decode_setattr(&xdr
);
5023 * Decode GETACL response
5026 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, __be32
*p
,
5027 struct nfs_getaclres
*res
)
5029 struct xdr_stream xdr
;
5030 struct compound_hdr hdr
;
5033 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5034 status
= decode_compound_hdr(&xdr
, &hdr
);
5037 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5040 status
= decode_putfh(&xdr
);
5043 status
= decode_getacl(&xdr
, rqstp
, &res
->acl_len
);
5050 * Decode CLOSE response
5052 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
5054 struct xdr_stream xdr
;
5055 struct compound_hdr hdr
;
5058 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5059 status
= decode_compound_hdr(&xdr
, &hdr
);
5062 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5065 status
= decode_putfh(&xdr
);
5068 status
= decode_close(&xdr
, res
);
5072 * Note: Server may do delete on close for this file
5073 * in which case the getattr call will fail with
5074 * an ESTALE error. Shouldn't be a problem,
5075 * though, since fattr->valid will remain unset.
5077 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5078 !RPC_IS_ASYNC(rqstp
->rq_task
));
5084 * Decode OPEN response
5086 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
5088 struct xdr_stream xdr
;
5089 struct compound_hdr hdr
;
5092 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5093 status
= decode_compound_hdr(&xdr
, &hdr
);
5096 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5099 status
= decode_putfh(&xdr
);
5102 status
= decode_savefh(&xdr
);
5105 status
= decode_open(&xdr
, res
);
5108 if (decode_getfh(&xdr
, &res
->fh
) != 0)
5110 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
,
5111 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5113 if (decode_restorefh(&xdr
) != 0)
5115 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
5116 !RPC_IS_ASYNC(rqstp
->rq_task
));
5122 * Decode OPEN_CONFIRM response
5124 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_open_confirmres
*res
)
5126 struct xdr_stream xdr
;
5127 struct compound_hdr hdr
;
5130 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5131 status
= decode_compound_hdr(&xdr
, &hdr
);
5134 status
= decode_putfh(&xdr
);
5137 status
= decode_open_confirm(&xdr
, res
);
5143 * Decode OPEN response
5145 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
5147 struct xdr_stream xdr
;
5148 struct compound_hdr hdr
;
5151 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5152 status
= decode_compound_hdr(&xdr
, &hdr
);
5155 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5158 status
= decode_putfh(&xdr
);
5161 status
= decode_open(&xdr
, res
);
5164 decode_getfattr(&xdr
, res
->f_attr
, res
->server
,
5165 !RPC_IS_ASYNC(rqstp
->rq_task
));
5171 * Decode SETATTR response
5173 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_setattrres
*res
)
5175 struct xdr_stream xdr
;
5176 struct compound_hdr hdr
;
5179 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5180 status
= decode_compound_hdr(&xdr
, &hdr
);
5183 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5186 status
= decode_putfh(&xdr
);
5189 status
= decode_setattr(&xdr
);
5192 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5193 !RPC_IS_ASYNC(rqstp
->rq_task
));
5199 * Decode LOCK response
5201 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lock_res
*res
)
5203 struct xdr_stream xdr
;
5204 struct compound_hdr hdr
;
5207 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5208 status
= decode_compound_hdr(&xdr
, &hdr
);
5211 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5214 status
= decode_putfh(&xdr
);
5217 status
= decode_lock(&xdr
, res
);
5223 * Decode LOCKT response
5225 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lockt_res
*res
)
5227 struct xdr_stream xdr
;
5228 struct compound_hdr hdr
;
5231 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5232 status
= decode_compound_hdr(&xdr
, &hdr
);
5235 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5238 status
= decode_putfh(&xdr
);
5241 status
= decode_lockt(&xdr
, res
);
5247 * Decode LOCKU response
5249 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_locku_res
*res
)
5251 struct xdr_stream xdr
;
5252 struct compound_hdr hdr
;
5255 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5256 status
= decode_compound_hdr(&xdr
, &hdr
);
5259 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5262 status
= decode_putfh(&xdr
);
5265 status
= decode_locku(&xdr
, res
);
5271 * Decode READLINK response
5273 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, __be32
*p
,
5274 struct nfs4_readlink_res
*res
)
5276 struct xdr_stream xdr
;
5277 struct compound_hdr hdr
;
5280 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5281 status
= decode_compound_hdr(&xdr
, &hdr
);
5284 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5287 status
= decode_putfh(&xdr
);
5290 status
= decode_readlink(&xdr
, rqstp
);
5296 * Decode READDIR response
5298 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_readdir_res
*res
)
5300 struct xdr_stream xdr
;
5301 struct compound_hdr hdr
;
5304 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5305 status
= decode_compound_hdr(&xdr
, &hdr
);
5308 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5311 status
= decode_putfh(&xdr
);
5314 status
= decode_readdir(&xdr
, rqstp
, res
);
5320 * Decode Read response
5322 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_readres
*res
)
5324 struct xdr_stream xdr
;
5325 struct compound_hdr hdr
;
5328 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5329 status
= decode_compound_hdr(&xdr
, &hdr
);
5332 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5335 status
= decode_putfh(&xdr
);
5338 status
= decode_read(&xdr
, rqstp
, res
);
5340 status
= res
->count
;
5346 * Decode WRITE response
5348 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
5350 struct xdr_stream xdr
;
5351 struct compound_hdr hdr
;
5354 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5355 status
= decode_compound_hdr(&xdr
, &hdr
);
5358 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5361 status
= decode_putfh(&xdr
);
5364 status
= decode_write(&xdr
, res
);
5367 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5368 !RPC_IS_ASYNC(rqstp
->rq_task
));
5370 status
= res
->count
;
5376 * Decode COMMIT response
5378 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
5380 struct xdr_stream xdr
;
5381 struct compound_hdr hdr
;
5384 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5385 status
= decode_compound_hdr(&xdr
, &hdr
);
5388 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5391 status
= decode_putfh(&xdr
);
5394 status
= decode_commit(&xdr
, res
);
5397 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5398 !RPC_IS_ASYNC(rqstp
->rq_task
));
5404 * Decode FSINFO response
5406 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, __be32
*p
,
5407 struct nfs4_fsinfo_res
*res
)
5409 struct xdr_stream xdr
;
5410 struct compound_hdr hdr
;
5413 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5414 status
= decode_compound_hdr(&xdr
, &hdr
);
5416 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5418 status
= decode_putfh(&xdr
);
5420 status
= decode_fsinfo(&xdr
, res
->fsinfo
);
5425 * Decode PATHCONF response
5427 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, __be32
*p
,
5428 struct nfs4_pathconf_res
*res
)
5430 struct xdr_stream xdr
;
5431 struct compound_hdr hdr
;
5434 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5435 status
= decode_compound_hdr(&xdr
, &hdr
);
5437 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5439 status
= decode_putfh(&xdr
);
5441 status
= decode_pathconf(&xdr
, res
->pathconf
);
5446 * Decode STATFS response
5448 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, __be32
*p
,
5449 struct nfs4_statfs_res
*res
)
5451 struct xdr_stream xdr
;
5452 struct compound_hdr hdr
;
5455 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5456 status
= decode_compound_hdr(&xdr
, &hdr
);
5458 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5460 status
= decode_putfh(&xdr
);
5462 status
= decode_statfs(&xdr
, res
->fsstat
);
5467 * Decode GETATTR_BITMAP response
5469 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_server_caps_res
*res
)
5471 struct xdr_stream xdr
;
5472 struct compound_hdr hdr
;
5475 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5476 status
= decode_compound_hdr(&xdr
, &hdr
);
5479 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5482 if ((status
= decode_putfh(&xdr
)) != 0)
5484 status
= decode_server_caps(&xdr
, res
);
5490 * Decode RENEW response
5492 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, __be32
*p
, void *dummy
)
5494 struct xdr_stream xdr
;
5495 struct compound_hdr hdr
;
5498 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5499 status
= decode_compound_hdr(&xdr
, &hdr
);
5501 status
= decode_renew(&xdr
);
5506 * Decode SETCLIENTID response
5508 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, __be32
*p
,
5509 struct nfs4_setclientid_res
*res
)
5511 struct xdr_stream xdr
;
5512 struct compound_hdr hdr
;
5515 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5516 status
= decode_compound_hdr(&xdr
, &hdr
);
5518 status
= decode_setclientid(&xdr
, res
);
5523 * Decode SETCLIENTID_CONFIRM response
5525 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
5527 struct xdr_stream xdr
;
5528 struct compound_hdr hdr
;
5531 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5532 status
= decode_compound_hdr(&xdr
, &hdr
);
5534 status
= decode_setclientid_confirm(&xdr
);
5536 status
= decode_putrootfh(&xdr
);
5538 status
= decode_fsinfo(&xdr
, fsinfo
);
5543 * Decode DELEGRETURN response
5545 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_delegreturnres
*res
)
5547 struct xdr_stream xdr
;
5548 struct compound_hdr hdr
;
5551 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5552 status
= decode_compound_hdr(&xdr
, &hdr
);
5555 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5558 status
= decode_putfh(&xdr
);
5561 status
= decode_delegreturn(&xdr
);
5564 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5565 !RPC_IS_ASYNC(rqstp
->rq_task
));
5571 * Decode FS_LOCATIONS response
5573 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
, __be32
*p
,
5574 struct nfs4_fs_locations_res
*res
)
5576 struct xdr_stream xdr
;
5577 struct compound_hdr hdr
;
5580 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5581 status
= decode_compound_hdr(&xdr
, &hdr
);
5584 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5587 if ((status
= decode_putfh(&xdr
)) != 0)
5589 if ((status
= decode_lookup(&xdr
)) != 0)
5591 xdr_enter_page(&xdr
, PAGE_SIZE
);
5592 status
= decode_getfattr(&xdr
, &res
->fs_locations
->fattr
,
5593 res
->fs_locations
->server
,
5594 !RPC_IS_ASYNC(req
->rq_task
));
5599 #if defined(CONFIG_NFS_V4_1)
5601 * Decode EXCHANGE_ID response
5603 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
, uint32_t *p
,
5606 struct xdr_stream xdr
;
5607 struct compound_hdr hdr
;
5610 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5611 status
= decode_compound_hdr(&xdr
, &hdr
);
5613 status
= decode_exchange_id(&xdr
, res
);
5618 * Decode CREATE_SESSION response
5620 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
, uint32_t *p
,
5621 struct nfs41_create_session_res
*res
)
5623 struct xdr_stream xdr
;
5624 struct compound_hdr hdr
;
5627 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5628 status
= decode_compound_hdr(&xdr
, &hdr
);
5630 status
= decode_create_session(&xdr
, res
);
5635 * Decode DESTROY_SESSION response
5637 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
, uint32_t *p
,
5640 struct xdr_stream xdr
;
5641 struct compound_hdr hdr
;
5644 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5645 status
= decode_compound_hdr(&xdr
, &hdr
);
5647 status
= decode_destroy_session(&xdr
, dummy
);
5652 * Decode SEQUENCE response
5654 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
, uint32_t *p
,
5655 struct nfs4_sequence_res
*res
)
5657 struct xdr_stream xdr
;
5658 struct compound_hdr hdr
;
5661 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5662 status
= decode_compound_hdr(&xdr
, &hdr
);
5664 status
= decode_sequence(&xdr
, res
, rqstp
);
5669 * Decode GET_LEASE_TIME response
5671 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
, uint32_t *p
,
5672 struct nfs4_get_lease_time_res
*res
)
5674 struct xdr_stream xdr
;
5675 struct compound_hdr hdr
;
5678 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5679 status
= decode_compound_hdr(&xdr
, &hdr
);
5681 status
= decode_sequence(&xdr
, &res
->lr_seq_res
, rqstp
);
5683 status
= decode_putrootfh(&xdr
);
5685 status
= decode_fsinfo(&xdr
, res
->lr_fsinfo
);
5690 * Decode RECLAIM_COMPLETE response
5692 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
, uint32_t *p
,
5693 struct nfs41_reclaim_complete_res
*res
)
5695 struct xdr_stream xdr
;
5696 struct compound_hdr hdr
;
5699 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5700 status
= decode_compound_hdr(&xdr
, &hdr
);
5702 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5704 status
= decode_reclaim_complete(&xdr
, (void *)NULL
);
5707 #endif /* CONFIG_NFS_V4_1 */
5709 __be32
*nfs4_decode_dirent(__be32
*p
, struct nfs_entry
*entry
, int plus
)
5711 uint32_t bitmap
[2] = {0};
5716 return ERR_PTR(-EAGAIN
);
5718 return ERR_PTR(-EBADCOOKIE
);
5721 entry
->prev_cookie
= entry
->cookie
;
5722 p
= xdr_decode_hyper(p
, &entry
->cookie
);
5723 entry
->len
= ntohl(*p
++);
5724 entry
->name
= (const char *) p
;
5725 p
+= XDR_QUADLEN(entry
->len
);
5728 * In case the server doesn't return an inode number,
5729 * we fake one here. (We don't use inode number 0,
5730 * since glibc seems to choke on it...)
5734 len
= ntohl(*p
++); /* bitmap length */
5736 bitmap
[0] = ntohl(*p
++);
5738 bitmap
[1] = ntohl(*p
++);
5742 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
5744 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
5745 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
5746 /* Ignore the return value of rdattr_error for now */
5750 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
5751 xdr_decode_hyper(p
, &entry
->ino
);
5752 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
5753 xdr_decode_hyper(p
, &entry
->ino
);
5757 entry
->eof
= !p
[0] && p
[1];
5762 * We need to translate between nfs status return values and
5763 * the local errno values which may not be the same.
5770 { NFS4ERR_PERM
, -EPERM
},
5771 { NFS4ERR_NOENT
, -ENOENT
},
5772 { NFS4ERR_IO
, -errno_NFSERR_IO
},
5773 { NFS4ERR_NXIO
, -ENXIO
},
5774 { NFS4ERR_ACCESS
, -EACCES
},
5775 { NFS4ERR_EXIST
, -EEXIST
},
5776 { NFS4ERR_XDEV
, -EXDEV
},
5777 { NFS4ERR_NOTDIR
, -ENOTDIR
},
5778 { NFS4ERR_ISDIR
, -EISDIR
},
5779 { NFS4ERR_INVAL
, -EINVAL
},
5780 { NFS4ERR_FBIG
, -EFBIG
},
5781 { NFS4ERR_NOSPC
, -ENOSPC
},
5782 { NFS4ERR_ROFS
, -EROFS
},
5783 { NFS4ERR_MLINK
, -EMLINK
},
5784 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
5785 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
5786 { NFS4ERR_DQUOT
, -EDQUOT
},
5787 { NFS4ERR_STALE
, -ESTALE
},
5788 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
5789 { NFS4ERR_BADOWNER
, -EINVAL
},
5790 { NFS4ERR_BADNAME
, -EINVAL
},
5791 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
5792 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
5793 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
5794 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
5795 { NFS4ERR_BADTYPE
, -EBADTYPE
},
5796 { NFS4ERR_LOCKED
, -EAGAIN
},
5797 { NFS4ERR_SYMLINK
, -ELOOP
},
5798 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
5799 { NFS4ERR_DEADLOCK
, -EDEADLK
},
5800 { NFS4ERR_WRONGSEC
, -EPERM
}, /* FIXME: this needs
5801 * to be handled by a
5808 * Convert an NFS error code to a local one.
5809 * This one is used jointly by NFSv2 and NFSv3.
5812 nfs4_stat_to_errno(int stat
)
5815 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
5816 if (nfs_errtbl
[i
].stat
== stat
)
5817 return nfs_errtbl
[i
].errno
;
5819 if (stat
<= 10000 || stat
> 10100) {
5820 /* The server is looney tunes. */
5823 /* If we cannot translate the error, the recovery routines should
5825 * Note: remaining NFSv4 error codes have values > 10000, so should
5826 * not conflict with native Linux error codes.
5831 #define PROC(proc, argtype, restype) \
5832 [NFSPROC4_CLNT_##proc] = { \
5833 .p_proc = NFSPROC4_COMPOUND, \
5834 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5835 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
5836 .p_arglen = NFS4_##argtype##_sz, \
5837 .p_replen = NFS4_##restype##_sz, \
5838 .p_statidx = NFSPROC4_CLNT_##proc, \
5842 struct rpc_procinfo nfs4_procedures
[] = {
5843 PROC(READ
, enc_read
, dec_read
),
5844 PROC(WRITE
, enc_write
, dec_write
),
5845 PROC(COMMIT
, enc_commit
, dec_commit
),
5846 PROC(OPEN
, enc_open
, dec_open
),
5847 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
5848 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
5849 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
5850 PROC(CLOSE
, enc_close
, dec_close
),
5851 PROC(SETATTR
, enc_setattr
, dec_setattr
),
5852 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
5853 PROC(RENEW
, enc_renew
, dec_renew
),
5854 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
5855 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
5856 PROC(LOCK
, enc_lock
, dec_lock
),
5857 PROC(LOCKT
, enc_lockt
, dec_lockt
),
5858 PROC(LOCKU
, enc_locku
, dec_locku
),
5859 PROC(ACCESS
, enc_access
, dec_access
),
5860 PROC(GETATTR
, enc_getattr
, dec_getattr
),
5861 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
5862 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
5863 PROC(REMOVE
, enc_remove
, dec_remove
),
5864 PROC(RENAME
, enc_rename
, dec_rename
),
5865 PROC(LINK
, enc_link
, dec_link
),
5866 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
5867 PROC(CREATE
, enc_create
, dec_create
),
5868 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
5869 PROC(STATFS
, enc_statfs
, dec_statfs
),
5870 PROC(READLINK
, enc_readlink
, dec_readlink
),
5871 PROC(READDIR
, enc_readdir
, dec_readdir
),
5872 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
5873 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
5874 PROC(GETACL
, enc_getacl
, dec_getacl
),
5875 PROC(SETACL
, enc_setacl
, dec_setacl
),
5876 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
5877 #if defined(CONFIG_NFS_V4_1)
5878 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
5879 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
5880 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
5881 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
5882 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
5883 PROC(RECLAIM_COMPLETE
, enc_reclaim_complete
, dec_reclaim_complete
),
5884 #endif /* CONFIG_NFS_V4_1 */
5887 struct rpc_version nfs_version4
= {
5889 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
5890 .procs
= nfs4_procedures