4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/errno.h>
43 #include <linux/string.h>
45 #include <linux/pagemap.h>
46 #include <linux/proc_fs.h>
47 #include <linux/kdev_t.h>
48 #include <linux/sunrpc/clnt.h>
49 #include <linux/nfs.h>
50 #include <linux/nfs4.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/nfs_idmap.h>
55 #define NFSDBG_FACILITY NFSDBG_XDR
57 /* Mapping from NFS error code to "errno" error code. */
58 #define errno_NFSERR_IO EIO
60 static int nfs4_stat_to_errno(int);
62 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64 #define NFS4_MAXTAGLEN 20
66 #define NFS4_MAXTAGLEN 0
69 /* lock,open owner id:
70 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
72 #define open_owner_id_maxsz (1 + 4)
73 #define lock_owner_id_maxsz (1 + 4)
74 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
75 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define op_encode_hdr_maxsz (1)
78 #define op_decode_hdr_maxsz (2)
79 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
80 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
82 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
86 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
87 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
88 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
89 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
90 ((3+NFS4_FHSIZE) >> 2))
91 #define nfs4_fattr_bitmap_maxsz 3
92 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
93 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
94 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
95 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
96 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 /* This is based on getfattr, which uses the most attributes: */
98 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
99 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
100 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
101 nfs4_fattr_value_maxsz)
102 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
103 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
108 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
109 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
110 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
111 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
112 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
113 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
114 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
115 #define decode_renew_maxsz (op_decode_hdr_maxsz)
116 #define encode_setclientid_maxsz \
117 (op_encode_hdr_maxsz + \
118 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
119 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
122 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 #define decode_setclientid_maxsz \
125 (op_decode_hdr_maxsz + \
127 1024) /* large value for CLID_INUSE */
128 #define encode_setclientid_confirm_maxsz \
129 (op_encode_hdr_maxsz + \
130 3 + (NFS4_VERIFIER_SIZE >> 2))
131 #define decode_setclientid_confirm_maxsz \
132 (op_decode_hdr_maxsz)
133 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
134 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
135 #define encode_share_access_maxsz \
137 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
138 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
139 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
140 #define encode_open_maxsz (op_encode_hdr_maxsz + \
141 2 + encode_share_access_maxsz + 2 + \
142 open_owner_id_maxsz + \
143 encode_opentype_maxsz + \
144 encode_claim_null_maxsz)
145 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
146 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
148 #define decode_change_info_maxsz (5)
149 #define decode_open_maxsz (op_decode_hdr_maxsz + \
150 decode_stateid_maxsz + \
151 decode_change_info_maxsz + 1 + \
152 nfs4_fattr_bitmap_maxsz + \
153 decode_delegation_maxsz)
154 #define encode_open_confirm_maxsz \
155 (op_encode_hdr_maxsz + \
156 encode_stateid_maxsz + 1)
157 #define decode_open_confirm_maxsz \
158 (op_decode_hdr_maxsz + \
159 decode_stateid_maxsz)
160 #define encode_open_downgrade_maxsz \
161 (op_encode_hdr_maxsz + \
162 encode_stateid_maxsz + 1 + \
163 encode_share_access_maxsz)
164 #define decode_open_downgrade_maxsz \
165 (op_decode_hdr_maxsz + \
166 decode_stateid_maxsz)
167 #define encode_close_maxsz (op_encode_hdr_maxsz + \
168 1 + encode_stateid_maxsz)
169 #define decode_close_maxsz (op_decode_hdr_maxsz + \
170 decode_stateid_maxsz)
171 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
172 encode_stateid_maxsz + \
174 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
175 nfs4_fattr_bitmap_maxsz)
176 #define encode_read_maxsz (op_encode_hdr_maxsz + \
177 encode_stateid_maxsz + 3)
178 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
179 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
180 2 + encode_verifier_maxsz + 5)
181 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
182 decode_verifier_maxsz)
183 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
184 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
185 #define encode_write_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 4)
187 #define decode_write_maxsz (op_decode_hdr_maxsz + \
188 2 + decode_verifier_maxsz)
189 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
190 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
195 decode_change_info_maxsz)
196 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
199 decode_change_info_maxsz + \
200 decode_change_info_maxsz)
201 #define encode_link_maxsz (op_encode_hdr_maxsz + \
203 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
204 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
206 1 + encode_stateid_maxsz + 8)
207 #define decode_lock_denied_maxsz \
208 (8 + decode_lockowner_maxsz)
209 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
210 decode_lock_denied_maxsz)
211 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
212 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
213 decode_lock_denied_maxsz)
214 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
215 encode_stateid_maxsz + \
217 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
218 decode_stateid_maxsz)
219 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
220 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
221 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
222 1 + nfs4_name_maxsz + \
225 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
226 #define encode_create_maxsz (op_encode_hdr_maxsz + \
227 1 + 2 + nfs4_name_maxsz + \
229 #define decode_create_maxsz (op_decode_hdr_maxsz + \
230 decode_change_info_maxsz + \
231 nfs4_fattr_bitmap_maxsz)
232 #define encode_statfs_maxsz (encode_getattr_maxsz)
233 #define decode_statfs_maxsz (decode_getattr_maxsz)
234 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
235 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
236 #define encode_getacl_maxsz (encode_getattr_maxsz)
237 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
238 nfs4_fattr_bitmap_maxsz + 1)
239 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
240 encode_stateid_maxsz + 3)
241 #define decode_setacl_maxsz (decode_setattr_maxsz)
242 #define encode_fs_locations_maxsz \
243 (encode_getattr_maxsz)
244 #define decode_fs_locations_maxsz \
247 #if defined(CONFIG_NFS_V4_1)
248 #define NFS4_MAX_MACHINE_NAME_LEN (64)
250 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
251 encode_verifier_maxsz + \
252 1 /* co_ownerid.len */ + \
253 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
256 0 /* SP4_NONE (for now) */ + \
257 1 /* zero implemetation id array */)
258 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
259 2 /* eir_clientid */ + \
260 1 /* eir_sequenceid */ + \
261 1 /* eir_flags */ + \
263 0 /* SP4_NONE (for now) */ + \
264 2 /* eir_server_owner.so_minor_id */ + \
265 /* eir_server_owner.so_major_id<> */ \
266 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
267 /* eir_server_scope<> */ \
268 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
269 1 /* eir_server_impl_id array length */ + \
270 0 /* ignored eir_server_impl_id contents */)
271 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
272 #define decode_channel_attrs_maxsz (6 + \
273 1 /* ca_rdma_ird.len */ + \
275 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
276 2 /* csa_clientid */ + \
277 1 /* csa_sequence */ + \
278 1 /* csa_flags */ + \
279 encode_channel_attrs_maxsz + \
280 encode_channel_attrs_maxsz + \
281 1 /* csa_cb_program */ + \
282 1 /* csa_sec_parms.len (1) */ + \
283 1 /* cb_secflavor (AUTH_SYS) */ + \
285 1 /* machinename.len */ + \
286 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
289 1 /* gids.len (0) */)
290 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
291 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
292 1 /* csr_sequence */ + \
293 1 /* csr_flags */ + \
294 decode_channel_attrs_maxsz + \
295 decode_channel_attrs_maxsz)
296 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
297 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
298 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
299 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
300 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
302 #else /* CONFIG_NFS_V4_1 */
303 #define encode_sequence_maxsz 0
304 #define decode_sequence_maxsz 0
305 #endif /* CONFIG_NFS_V4_1 */
307 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
308 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
309 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
310 encode_sequence_maxsz + \
311 encode_putfh_maxsz + \
313 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
314 decode_sequence_maxsz + \
315 decode_putfh_maxsz + \
317 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
318 encode_sequence_maxsz + \
319 encode_putfh_maxsz + \
320 encode_readlink_maxsz)
321 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
322 decode_sequence_maxsz + \
323 decode_putfh_maxsz + \
324 decode_readlink_maxsz)
325 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
326 encode_sequence_maxsz + \
327 encode_putfh_maxsz + \
328 encode_readdir_maxsz)
329 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
330 decode_sequence_maxsz + \
331 decode_putfh_maxsz + \
332 decode_readdir_maxsz)
333 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
334 encode_sequence_maxsz + \
335 encode_putfh_maxsz + \
336 encode_write_maxsz + \
337 encode_getattr_maxsz)
338 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
339 decode_sequence_maxsz + \
340 decode_putfh_maxsz + \
341 decode_write_maxsz + \
342 decode_getattr_maxsz)
343 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
344 encode_sequence_maxsz + \
345 encode_putfh_maxsz + \
346 encode_commit_maxsz + \
347 encode_getattr_maxsz)
348 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
349 decode_sequence_maxsz + \
350 decode_putfh_maxsz + \
351 decode_commit_maxsz + \
352 decode_getattr_maxsz)
353 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
354 encode_sequence_maxsz + \
355 encode_putfh_maxsz + \
356 encode_savefh_maxsz + \
357 encode_open_maxsz + \
358 encode_getfh_maxsz + \
359 encode_getattr_maxsz + \
360 encode_restorefh_maxsz + \
361 encode_getattr_maxsz)
362 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
363 decode_sequence_maxsz + \
364 decode_putfh_maxsz + \
365 decode_savefh_maxsz + \
366 decode_open_maxsz + \
367 decode_getfh_maxsz + \
368 decode_getattr_maxsz + \
369 decode_restorefh_maxsz + \
370 decode_getattr_maxsz)
371 #define NFS4_enc_open_confirm_sz \
372 (compound_encode_hdr_maxsz + \
373 encode_putfh_maxsz + \
374 encode_open_confirm_maxsz)
375 #define NFS4_dec_open_confirm_sz \
376 (compound_decode_hdr_maxsz + \
377 decode_putfh_maxsz + \
378 decode_open_confirm_maxsz)
379 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
380 encode_sequence_maxsz + \
381 encode_putfh_maxsz + \
382 encode_open_maxsz + \
383 encode_getattr_maxsz)
384 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
385 decode_sequence_maxsz + \
386 decode_putfh_maxsz + \
387 decode_open_maxsz + \
388 decode_getattr_maxsz)
389 #define NFS4_enc_open_downgrade_sz \
390 (compound_encode_hdr_maxsz + \
391 encode_sequence_maxsz + \
392 encode_putfh_maxsz + \
393 encode_open_downgrade_maxsz + \
394 encode_getattr_maxsz)
395 #define NFS4_dec_open_downgrade_sz \
396 (compound_decode_hdr_maxsz + \
397 decode_sequence_maxsz + \
398 decode_putfh_maxsz + \
399 decode_open_downgrade_maxsz + \
400 decode_getattr_maxsz)
401 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
402 encode_sequence_maxsz + \
403 encode_putfh_maxsz + \
404 encode_close_maxsz + \
405 encode_getattr_maxsz)
406 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
407 decode_sequence_maxsz + \
408 decode_putfh_maxsz + \
409 decode_close_maxsz + \
410 decode_getattr_maxsz)
411 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
412 encode_sequence_maxsz + \
413 encode_putfh_maxsz + \
414 encode_setattr_maxsz + \
415 encode_getattr_maxsz)
416 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
417 decode_sequence_maxsz + \
418 decode_putfh_maxsz + \
419 decode_setattr_maxsz + \
420 decode_getattr_maxsz)
421 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
422 encode_sequence_maxsz + \
423 encode_putfh_maxsz + \
425 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
426 decode_sequence_maxsz + \
427 decode_putfh_maxsz + \
429 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
431 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
433 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
434 encode_setclientid_maxsz)
435 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
436 decode_setclientid_maxsz)
437 #define NFS4_enc_setclientid_confirm_sz \
438 (compound_encode_hdr_maxsz + \
439 encode_setclientid_confirm_maxsz + \
440 encode_putrootfh_maxsz + \
442 #define NFS4_dec_setclientid_confirm_sz \
443 (compound_decode_hdr_maxsz + \
444 decode_setclientid_confirm_maxsz + \
445 decode_putrootfh_maxsz + \
447 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
448 encode_sequence_maxsz + \
449 encode_putfh_maxsz + \
451 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
452 decode_sequence_maxsz + \
453 decode_putfh_maxsz + \
455 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
456 encode_sequence_maxsz + \
457 encode_putfh_maxsz + \
459 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
460 decode_sequence_maxsz + \
461 decode_putfh_maxsz + \
463 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
464 encode_sequence_maxsz + \
465 encode_putfh_maxsz + \
467 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
468 decode_sequence_maxsz + \
469 decode_putfh_maxsz + \
471 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
472 encode_sequence_maxsz + \
473 encode_putfh_maxsz + \
474 encode_access_maxsz + \
475 encode_getattr_maxsz)
476 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
477 decode_sequence_maxsz + \
478 decode_putfh_maxsz + \
479 decode_access_maxsz + \
480 decode_getattr_maxsz)
481 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
482 encode_sequence_maxsz + \
483 encode_putfh_maxsz + \
484 encode_getattr_maxsz)
485 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
486 decode_sequence_maxsz + \
487 decode_putfh_maxsz + \
488 decode_getattr_maxsz)
489 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
490 encode_sequence_maxsz + \
491 encode_putfh_maxsz + \
492 encode_lookup_maxsz + \
493 encode_getattr_maxsz + \
495 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
496 decode_sequence_maxsz + \
497 decode_putfh_maxsz + \
498 decode_lookup_maxsz + \
499 decode_getattr_maxsz + \
501 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
502 encode_sequence_maxsz + \
503 encode_putrootfh_maxsz + \
504 encode_getattr_maxsz + \
506 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
507 decode_sequence_maxsz + \
508 decode_putrootfh_maxsz + \
509 decode_getattr_maxsz + \
511 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
512 encode_sequence_maxsz + \
513 encode_putfh_maxsz + \
514 encode_remove_maxsz + \
515 encode_getattr_maxsz)
516 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
517 decode_sequence_maxsz + \
518 decode_putfh_maxsz + \
519 decode_remove_maxsz + \
520 decode_getattr_maxsz)
521 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
522 encode_sequence_maxsz + \
523 encode_putfh_maxsz + \
524 encode_savefh_maxsz + \
525 encode_putfh_maxsz + \
526 encode_rename_maxsz + \
527 encode_getattr_maxsz + \
528 encode_restorefh_maxsz + \
529 encode_getattr_maxsz)
530 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
531 decode_sequence_maxsz + \
532 decode_putfh_maxsz + \
533 decode_savefh_maxsz + \
534 decode_putfh_maxsz + \
535 decode_rename_maxsz + \
536 decode_getattr_maxsz + \
537 decode_restorefh_maxsz + \
538 decode_getattr_maxsz)
539 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
540 encode_sequence_maxsz + \
541 encode_putfh_maxsz + \
542 encode_savefh_maxsz + \
543 encode_putfh_maxsz + \
544 encode_link_maxsz + \
545 decode_getattr_maxsz + \
546 encode_restorefh_maxsz + \
547 decode_getattr_maxsz)
548 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
549 decode_sequence_maxsz + \
550 decode_putfh_maxsz + \
551 decode_savefh_maxsz + \
552 decode_putfh_maxsz + \
553 decode_link_maxsz + \
554 decode_getattr_maxsz + \
555 decode_restorefh_maxsz + \
556 decode_getattr_maxsz)
557 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
558 encode_sequence_maxsz + \
559 encode_putfh_maxsz + \
560 encode_symlink_maxsz + \
561 encode_getattr_maxsz + \
563 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
564 decode_sequence_maxsz + \
565 decode_putfh_maxsz + \
566 decode_symlink_maxsz + \
567 decode_getattr_maxsz + \
569 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
570 encode_sequence_maxsz + \
571 encode_putfh_maxsz + \
572 encode_savefh_maxsz + \
573 encode_create_maxsz + \
574 encode_getfh_maxsz + \
575 encode_getattr_maxsz + \
576 encode_restorefh_maxsz + \
577 encode_getattr_maxsz)
578 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
579 decode_sequence_maxsz + \
580 decode_putfh_maxsz + \
581 decode_savefh_maxsz + \
582 decode_create_maxsz + \
583 decode_getfh_maxsz + \
584 decode_getattr_maxsz + \
585 decode_restorefh_maxsz + \
586 decode_getattr_maxsz)
587 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
588 encode_sequence_maxsz + \
589 encode_putfh_maxsz + \
590 encode_getattr_maxsz)
591 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
592 decode_sequence_maxsz + \
593 decode_putfh_maxsz + \
594 decode_getattr_maxsz)
595 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
596 encode_sequence_maxsz + \
597 encode_putfh_maxsz + \
599 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
600 decode_sequence_maxsz + \
601 decode_putfh_maxsz + \
603 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
604 encode_sequence_maxsz + \
605 encode_putfh_maxsz + \
606 encode_getattr_maxsz)
607 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
608 decode_sequence_maxsz + \
609 decode_putfh_maxsz + \
610 decode_getattr_maxsz)
611 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
612 encode_sequence_maxsz + \
613 encode_putfh_maxsz + \
614 encode_delegreturn_maxsz + \
615 encode_getattr_maxsz)
616 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
617 decode_sequence_maxsz + \
618 decode_delegreturn_maxsz + \
619 decode_getattr_maxsz)
620 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
621 encode_sequence_maxsz + \
622 encode_putfh_maxsz + \
624 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
625 decode_sequence_maxsz + \
626 decode_putfh_maxsz + \
628 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
629 encode_sequence_maxsz + \
630 encode_putfh_maxsz + \
632 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
633 decode_sequence_maxsz + \
634 decode_putfh_maxsz + \
636 #define NFS4_enc_fs_locations_sz \
637 (compound_encode_hdr_maxsz + \
638 encode_sequence_maxsz + \
639 encode_putfh_maxsz + \
640 encode_lookup_maxsz + \
641 encode_fs_locations_maxsz)
642 #define NFS4_dec_fs_locations_sz \
643 (compound_decode_hdr_maxsz + \
644 decode_sequence_maxsz + \
645 decode_putfh_maxsz + \
646 decode_lookup_maxsz + \
647 decode_fs_locations_maxsz)
648 #if defined(CONFIG_NFS_V4_1)
649 #define NFS4_enc_exchange_id_sz \
650 (compound_encode_hdr_maxsz + \
651 encode_exchange_id_maxsz)
652 #define NFS4_dec_exchange_id_sz \
653 (compound_decode_hdr_maxsz + \
654 decode_exchange_id_maxsz)
655 #define NFS4_enc_create_session_sz \
656 (compound_encode_hdr_maxsz + \
657 encode_create_session_maxsz)
658 #define NFS4_dec_create_session_sz \
659 (compound_decode_hdr_maxsz + \
660 decode_create_session_maxsz)
661 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
662 encode_destroy_session_maxsz)
663 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
664 decode_destroy_session_maxsz)
665 #define NFS4_enc_sequence_sz \
666 (compound_decode_hdr_maxsz + \
667 encode_sequence_maxsz)
668 #define NFS4_dec_sequence_sz \
669 (compound_decode_hdr_maxsz + \
670 decode_sequence_maxsz)
671 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
672 encode_sequence_maxsz + \
673 encode_putrootfh_maxsz + \
675 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
676 decode_sequence_maxsz + \
677 decode_putrootfh_maxsz + \
679 #endif /* CONFIG_NFS_V4_1 */
681 static const umode_t nfs_type2fmt
[] = {
688 [NF4SOCK
] = S_IFSOCK
,
694 struct compound_hdr
{
700 uint32_t replen
; /* expected reply words */
704 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
706 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
711 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
715 p
= xdr_reserve_space(xdr
, 4 + len
);
717 xdr_encode_opaque(p
, str
, len
);
720 static void encode_compound_hdr(struct xdr_stream
*xdr
,
721 struct rpc_rqst
*req
,
722 struct compound_hdr
*hdr
)
725 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
727 /* initialize running count of expected bytes in reply.
728 * NOTE: the replied tag SHOULD be the same is the one sent,
729 * but this is not required as a MUST for the server to do so. */
730 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
732 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
733 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
734 p
= reserve_space(xdr
, 4 + hdr
->taglen
+ 8);
735 p
= xdr_encode_opaque(p
, hdr
->tag
, hdr
->taglen
);
736 *p
++ = cpu_to_be32(hdr
->minorversion
);
738 *p
= cpu_to_be32(hdr
->nops
);
741 static void encode_nops(struct compound_hdr
*hdr
)
743 BUG_ON(hdr
->nops
> NFS4_MAX_OPS
);
744 *hdr
->nops_p
= htonl(hdr
->nops
);
747 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
751 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
753 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
756 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
758 char owner_name
[IDMAP_NAMESZ
];
759 char owner_group
[IDMAP_NAMESZ
];
760 int owner_namelen
= 0;
761 int owner_grouplen
= 0;
769 * We reserve enough space to write the entire attribute buffer at once.
770 * In the worst-case, this would be
771 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
772 * = 36 bytes, plus any contribution from variable-length fields
773 * such as owner/group.
778 if (iap
->ia_valid
& ATTR_SIZE
)
780 if (iap
->ia_valid
& ATTR_MODE
)
782 if (iap
->ia_valid
& ATTR_UID
) {
783 owner_namelen
= nfs_map_uid_to_name(server
->nfs_client
, iap
->ia_uid
, owner_name
);
784 if (owner_namelen
< 0) {
785 dprintk("nfs: couldn't resolve uid %d to string\n",
788 strcpy(owner_name
, "nobody");
789 owner_namelen
= sizeof("nobody") - 1;
792 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
794 if (iap
->ia_valid
& ATTR_GID
) {
795 owner_grouplen
= nfs_map_gid_to_group(server
->nfs_client
, iap
->ia_gid
, owner_group
);
796 if (owner_grouplen
< 0) {
797 dprintk("nfs: couldn't resolve gid %d to string\n",
799 strcpy(owner_group
, "nobody");
800 owner_grouplen
= sizeof("nobody") - 1;
803 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
805 if (iap
->ia_valid
& ATTR_ATIME_SET
)
807 else if (iap
->ia_valid
& ATTR_ATIME
)
809 if (iap
->ia_valid
& ATTR_MTIME_SET
)
811 else if (iap
->ia_valid
& ATTR_MTIME
)
813 p
= reserve_space(xdr
, len
);
816 * We write the bitmap length now, but leave the bitmap and the attribute
817 * buffer length to be backfilled at the end of this routine.
819 *p
++ = cpu_to_be32(2);
823 if (iap
->ia_valid
& ATTR_SIZE
) {
824 bmval0
|= FATTR4_WORD0_SIZE
;
825 p
= xdr_encode_hyper(p
, iap
->ia_size
);
827 if (iap
->ia_valid
& ATTR_MODE
) {
828 bmval1
|= FATTR4_WORD1_MODE
;
829 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
831 if (iap
->ia_valid
& ATTR_UID
) {
832 bmval1
|= FATTR4_WORD1_OWNER
;
833 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
835 if (iap
->ia_valid
& ATTR_GID
) {
836 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
837 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
839 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
840 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
841 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
842 *p
++ = cpu_to_be32(0);
843 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_sec
);
844 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
846 else if (iap
->ia_valid
& ATTR_ATIME
) {
847 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
848 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
850 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
851 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
852 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
853 *p
++ = cpu_to_be32(0);
854 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_sec
);
855 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
857 else if (iap
->ia_valid
& ATTR_MTIME
) {
858 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
859 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
863 * Now we backfill the bitmap and the attribute buffer length.
865 if (len
!= ((char *)p
- (char *)q
) + 4) {
866 printk(KERN_ERR
"nfs: Attr length error, %u != %Zu\n",
867 len
, ((char *)p
- (char *)q
) + 4);
870 len
= (char *)p
- (char *)q
- 12;
871 *q
++ = htonl(bmval0
);
872 *q
++ = htonl(bmval1
);
878 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
882 p
= reserve_space(xdr
, 8);
883 *p
++ = cpu_to_be32(OP_ACCESS
);
884 *p
= cpu_to_be32(access
);
886 hdr
->replen
+= decode_access_maxsz
;
889 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
893 p
= reserve_space(xdr
, 8+NFS4_STATEID_SIZE
);
894 *p
++ = cpu_to_be32(OP_CLOSE
);
895 *p
++ = cpu_to_be32(arg
->seqid
->sequence
->counter
);
896 xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
898 hdr
->replen
+= decode_close_maxsz
;
901 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
905 p
= reserve_space(xdr
, 16);
906 *p
++ = cpu_to_be32(OP_COMMIT
);
907 p
= xdr_encode_hyper(p
, args
->offset
);
908 *p
= cpu_to_be32(args
->count
);
910 hdr
->replen
+= decode_commit_maxsz
;
913 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
917 p
= reserve_space(xdr
, 8);
918 *p
++ = cpu_to_be32(OP_CREATE
);
919 *p
= cpu_to_be32(create
->ftype
);
921 switch (create
->ftype
) {
923 p
= reserve_space(xdr
, 4);
924 *p
= cpu_to_be32(create
->u
.symlink
.len
);
925 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
928 case NF4BLK
: case NF4CHR
:
929 p
= reserve_space(xdr
, 8);
930 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
931 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
938 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
940 hdr
->replen
+= decode_create_maxsz
;
942 encode_attrs(xdr
, create
->attrs
, create
->server
);
945 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
949 p
= reserve_space(xdr
, 12);
950 *p
++ = cpu_to_be32(OP_GETATTR
);
951 *p
++ = cpu_to_be32(1);
952 *p
= cpu_to_be32(bitmap
);
954 hdr
->replen
+= decode_getattr_maxsz
;
957 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
961 p
= reserve_space(xdr
, 16);
962 *p
++ = cpu_to_be32(OP_GETATTR
);
963 *p
++ = cpu_to_be32(2);
964 *p
++ = cpu_to_be32(bm0
);
965 *p
= cpu_to_be32(bm1
);
967 hdr
->replen
+= decode_getattr_maxsz
;
970 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
972 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
973 bitmask
[1] & nfs4_fattr_bitmap
[1], hdr
);
976 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
978 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
979 bitmask
[1] & nfs4_fsinfo_bitmap
[1], hdr
);
982 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
984 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
985 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
988 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
992 p
= reserve_space(xdr
, 4);
993 *p
= cpu_to_be32(OP_GETFH
);
995 hdr
->replen
+= decode_getfh_maxsz
;
998 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1002 p
= reserve_space(xdr
, 8 + name
->len
);
1003 *p
++ = cpu_to_be32(OP_LINK
);
1004 xdr_encode_opaque(p
, name
->name
, name
->len
);
1006 hdr
->replen
+= decode_link_maxsz
;
1009 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1011 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
1012 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1013 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1016 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1018 if (fl
->fl_end
== OFFSET_MAX
)
1019 return ~(uint64_t)0;
1020 return fl
->fl_end
- fl
->fl_start
+ 1;
1024 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1025 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1027 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1031 p
= reserve_space(xdr
, 32);
1032 *p
++ = cpu_to_be32(OP_LOCK
);
1033 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1034 *p
++ = cpu_to_be32(args
->reclaim
);
1035 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1036 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1037 *p
= cpu_to_be32(args
->new_lock_owner
);
1038 if (args
->new_lock_owner
){
1039 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+32);
1040 *p
++ = cpu_to_be32(args
->open_seqid
->sequence
->counter
);
1041 p
= xdr_encode_opaque_fixed(p
, args
->open_stateid
->data
, NFS4_STATEID_SIZE
);
1042 *p
++ = cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1043 p
= xdr_encode_hyper(p
, args
->lock_owner
.clientid
);
1044 *p
++ = cpu_to_be32(16);
1045 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1046 xdr_encode_hyper(p
, args
->lock_owner
.id
);
1049 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
+4);
1050 p
= xdr_encode_opaque_fixed(p
, args
->lock_stateid
->data
, NFS4_STATEID_SIZE
);
1051 *p
= cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1054 hdr
->replen
+= decode_lock_maxsz
;
1057 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1061 p
= reserve_space(xdr
, 52);
1062 *p
++ = cpu_to_be32(OP_LOCKT
);
1063 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1064 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1065 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1066 p
= xdr_encode_hyper(p
, args
->lock_owner
.clientid
);
1067 *p
++ = cpu_to_be32(16);
1068 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1069 xdr_encode_hyper(p
, args
->lock_owner
.id
);
1071 hdr
->replen
+= decode_lockt_maxsz
;
1074 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1078 p
= reserve_space(xdr
, 12+NFS4_STATEID_SIZE
+16);
1079 *p
++ = cpu_to_be32(OP_LOCKU
);
1080 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1081 *p
++ = cpu_to_be32(args
->seqid
->sequence
->counter
);
1082 p
= xdr_encode_opaque_fixed(p
, args
->stateid
->data
, NFS4_STATEID_SIZE
);
1083 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1084 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1086 hdr
->replen
+= decode_locku_maxsz
;
1089 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1091 int len
= name
->len
;
1094 p
= reserve_space(xdr
, 8 + len
);
1095 *p
++ = cpu_to_be32(OP_LOOKUP
);
1096 xdr_encode_opaque(p
, name
->name
, len
);
1098 hdr
->replen
+= decode_lookup_maxsz
;
1101 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
1105 p
= reserve_space(xdr
, 8);
1106 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1108 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ
);
1111 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE
);
1113 case FMODE_READ
|FMODE_WRITE
:
1114 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH
);
1117 *p
++ = cpu_to_be32(0);
1119 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1122 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1126 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1129 p
= reserve_space(xdr
, 8);
1130 *p
++ = cpu_to_be32(OP_OPEN
);
1131 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1132 encode_share_access(xdr
, arg
->fmode
);
1133 p
= reserve_space(xdr
, 28);
1134 p
= xdr_encode_hyper(p
, arg
->clientid
);
1135 *p
++ = cpu_to_be32(16);
1136 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1137 xdr_encode_hyper(p
, arg
->id
);
1140 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1144 p
= reserve_space(xdr
, 4);
1145 switch(arg
->open_flags
& O_EXCL
) {
1147 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1148 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1151 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1152 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1156 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1160 p
= reserve_space(xdr
, 4);
1161 switch (arg
->open_flags
& O_CREAT
) {
1163 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1166 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
1167 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1168 encode_createmode(xdr
, arg
);
1172 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1176 p
= reserve_space(xdr
, 4);
1177 switch (delegation_type
) {
1179 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1182 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1184 case FMODE_WRITE
|FMODE_READ
:
1185 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1192 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1196 p
= reserve_space(xdr
, 4);
1197 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1198 encode_string(xdr
, name
->len
, name
->name
);
1201 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1205 p
= reserve_space(xdr
, 4);
1206 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1207 encode_delegation_type(xdr
, type
);
1210 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1214 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1215 *p
++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1216 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1217 encode_string(xdr
, name
->len
, name
->name
);
1220 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1222 encode_openhdr(xdr
, arg
);
1223 encode_opentype(xdr
, arg
);
1224 switch (arg
->claim
) {
1225 case NFS4_OPEN_CLAIM_NULL
:
1226 encode_claim_null(xdr
, arg
->name
);
1228 case NFS4_OPEN_CLAIM_PREVIOUS
:
1229 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1231 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1232 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1238 hdr
->replen
+= decode_open_maxsz
;
1241 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1245 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1246 *p
++ = cpu_to_be32(OP_OPEN_CONFIRM
);
1247 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1248 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1250 hdr
->replen
+= decode_open_confirm_maxsz
;
1253 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1257 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1258 *p
++ = cpu_to_be32(OP_OPEN_DOWNGRADE
);
1259 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1260 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1261 encode_share_access(xdr
, arg
->fmode
);
1263 hdr
->replen
+= decode_open_downgrade_maxsz
;
1267 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1272 p
= reserve_space(xdr
, 8 + len
);
1273 *p
++ = cpu_to_be32(OP_PUTFH
);
1274 xdr_encode_opaque(p
, fh
->data
, len
);
1276 hdr
->replen
+= decode_putfh_maxsz
;
1279 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1283 p
= reserve_space(xdr
, 4);
1284 *p
= cpu_to_be32(OP_PUTROOTFH
);
1286 hdr
->replen
+= decode_putrootfh_maxsz
;
1289 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
)
1291 nfs4_stateid stateid
;
1294 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
);
1295 if (ctx
->state
!= NULL
) {
1296 nfs4_copy_stateid(&stateid
, ctx
->state
, ctx
->lockowner
);
1297 xdr_encode_opaque_fixed(p
, stateid
.data
, NFS4_STATEID_SIZE
);
1299 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1302 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
, struct compound_hdr
*hdr
)
1306 p
= reserve_space(xdr
, 4);
1307 *p
= cpu_to_be32(OP_READ
);
1309 encode_stateid(xdr
, args
->context
);
1311 p
= reserve_space(xdr
, 12);
1312 p
= xdr_encode_hyper(p
, args
->offset
);
1313 *p
= cpu_to_be32(args
->count
);
1315 hdr
->replen
+= decode_read_maxsz
;
1318 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1320 uint32_t attrs
[2] = {
1321 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1322 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1326 p
= reserve_space(xdr
, 12+NFS4_VERIFIER_SIZE
+20);
1327 *p
++ = cpu_to_be32(OP_READDIR
);
1328 p
= xdr_encode_hyper(p
, readdir
->cookie
);
1329 p
= xdr_encode_opaque_fixed(p
, readdir
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1330 *p
++ = cpu_to_be32(readdir
->count
>> 1); /* We're not doing readdirplus */
1331 *p
++ = cpu_to_be32(readdir
->count
);
1332 *p
++ = cpu_to_be32(2);
1333 /* Switch to mounted_on_fileid if the server supports it */
1334 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1335 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1337 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1338 *p
++ = cpu_to_be32(attrs
[0] & readdir
->bitmask
[0]);
1339 *p
= cpu_to_be32(attrs
[1] & readdir
->bitmask
[1]);
1341 hdr
->replen
+= decode_readdir_maxsz
;
1342 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1344 (unsigned long long)readdir
->cookie
,
1345 ((u32
*)readdir
->verifier
.data
)[0],
1346 ((u32
*)readdir
->verifier
.data
)[1],
1347 attrs
[0] & readdir
->bitmask
[0],
1348 attrs
[1] & readdir
->bitmask
[1]);
1351 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1355 p
= reserve_space(xdr
, 4);
1356 *p
= cpu_to_be32(OP_READLINK
);
1358 hdr
->replen
+= decode_readlink_maxsz
;
1361 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1365 p
= reserve_space(xdr
, 8 + name
->len
);
1366 *p
++ = cpu_to_be32(OP_REMOVE
);
1367 xdr_encode_opaque(p
, name
->name
, name
->len
);
1369 hdr
->replen
+= decode_remove_maxsz
;
1372 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1376 p
= reserve_space(xdr
, 4);
1377 *p
= cpu_to_be32(OP_RENAME
);
1378 encode_string(xdr
, oldname
->len
, oldname
->name
);
1379 encode_string(xdr
, newname
->len
, newname
->name
);
1381 hdr
->replen
+= decode_rename_maxsz
;
1384 static void encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
, struct compound_hdr
*hdr
)
1388 p
= reserve_space(xdr
, 12);
1389 *p
++ = cpu_to_be32(OP_RENEW
);
1390 xdr_encode_hyper(p
, client_stateid
->cl_clientid
);
1392 hdr
->replen
+= decode_renew_maxsz
;
1396 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1400 p
= reserve_space(xdr
, 4);
1401 *p
= cpu_to_be32(OP_RESTOREFH
);
1403 hdr
->replen
+= decode_restorefh_maxsz
;
1407 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1411 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1412 *p
++ = cpu_to_be32(OP_SETATTR
);
1413 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1414 p
= reserve_space(xdr
, 2*4);
1415 *p
++ = cpu_to_be32(1);
1416 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1417 if (arg
->acl_len
% 4)
1419 p
= reserve_space(xdr
, 4);
1420 *p
= cpu_to_be32(arg
->acl_len
);
1421 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1423 hdr
->replen
+= decode_setacl_maxsz
;
1428 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1432 p
= reserve_space(xdr
, 4);
1433 *p
= cpu_to_be32(OP_SAVEFH
);
1435 hdr
->replen
+= decode_savefh_maxsz
;
1438 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1442 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1443 *p
++ = cpu_to_be32(OP_SETATTR
);
1444 xdr_encode_opaque_fixed(p
, arg
->stateid
.data
, NFS4_STATEID_SIZE
);
1446 hdr
->replen
+= decode_setattr_maxsz
;
1447 encode_attrs(xdr
, arg
->iap
, server
);
1450 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1454 p
= reserve_space(xdr
, 4 + NFS4_VERIFIER_SIZE
);
1455 *p
++ = cpu_to_be32(OP_SETCLIENTID
);
1456 xdr_encode_opaque_fixed(p
, setclientid
->sc_verifier
->data
, NFS4_VERIFIER_SIZE
);
1458 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1459 p
= reserve_space(xdr
, 4);
1460 *p
= cpu_to_be32(setclientid
->sc_prog
);
1461 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1462 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1463 p
= reserve_space(xdr
, 4);
1464 *p
= cpu_to_be32(setclientid
->sc_cb_ident
);
1466 hdr
->replen
+= decode_setclientid_maxsz
;
1469 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs_client
*client_state
, struct compound_hdr
*hdr
)
1473 p
= reserve_space(xdr
, 12 + NFS4_VERIFIER_SIZE
);
1474 *p
++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM
);
1475 p
= xdr_encode_hyper(p
, client_state
->cl_clientid
);
1476 xdr_encode_opaque_fixed(p
, client_state
->cl_confirm
.data
, NFS4_VERIFIER_SIZE
);
1478 hdr
->replen
+= decode_setclientid_confirm_maxsz
;
1481 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1485 p
= reserve_space(xdr
, 4);
1486 *p
= cpu_to_be32(OP_WRITE
);
1488 encode_stateid(xdr
, args
->context
);
1490 p
= reserve_space(xdr
, 16);
1491 p
= xdr_encode_hyper(p
, args
->offset
);
1492 *p
++ = cpu_to_be32(args
->stable
);
1493 *p
= cpu_to_be32(args
->count
);
1495 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1497 hdr
->replen
+= decode_write_maxsz
;
1500 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1504 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1506 *p
++ = cpu_to_be32(OP_DELEGRETURN
);
1507 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1509 hdr
->replen
+= decode_delegreturn_maxsz
;
1512 #if defined(CONFIG_NFS_V4_1)
1513 /* NFSv4.1 operations */
1514 static void encode_exchange_id(struct xdr_stream
*xdr
,
1515 struct nfs41_exchange_id_args
*args
,
1516 struct compound_hdr
*hdr
)
1520 p
= reserve_space(xdr
, 4 + sizeof(args
->verifier
->data
));
1521 *p
++ = cpu_to_be32(OP_EXCHANGE_ID
);
1522 xdr_encode_opaque_fixed(p
, args
->verifier
->data
, sizeof(args
->verifier
->data
));
1524 encode_string(xdr
, args
->id_len
, args
->id
);
1526 p
= reserve_space(xdr
, 12);
1527 *p
++ = cpu_to_be32(args
->flags
);
1528 *p
++ = cpu_to_be32(0); /* zero length state_protect4_a */
1529 *p
= cpu_to_be32(0); /* zero length implementation id array */
1531 hdr
->replen
+= decode_exchange_id_maxsz
;
1534 static void encode_create_session(struct xdr_stream
*xdr
,
1535 struct nfs41_create_session_args
*args
,
1536 struct compound_hdr
*hdr
)
1539 char machine_name
[NFS4_MAX_MACHINE_NAME_LEN
];
1541 struct nfs_client
*clp
= args
->client
;
1543 len
= scnprintf(machine_name
, sizeof(machine_name
), "%s",
1546 p
= reserve_space(xdr
, 20 + 2*28 + 20 + len
+ 12);
1547 *p
++ = cpu_to_be32(OP_CREATE_SESSION
);
1548 p
= xdr_encode_hyper(p
, clp
->cl_ex_clid
);
1549 *p
++ = cpu_to_be32(clp
->cl_seqid
); /*Sequence id */
1550 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1553 *p
++ = cpu_to_be32(args
->fc_attrs
.headerpadsz
); /* header padding size */
1554 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1555 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1556 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1557 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1558 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1559 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1562 *p
++ = cpu_to_be32(args
->fc_attrs
.headerpadsz
); /* header padding size */
1563 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1564 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1565 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1566 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1567 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1568 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1570 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1571 *p
++ = cpu_to_be32(1);
1572 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1574 /* authsys_parms rfc1831 */
1575 *p
++ = cpu_to_be32((u32
)clp
->cl_boot_time
.tv_nsec
); /* stamp */
1576 p
= xdr_encode_opaque(p
, machine_name
, len
);
1577 *p
++ = cpu_to_be32(0); /* UID */
1578 *p
++ = cpu_to_be32(0); /* GID */
1579 *p
= cpu_to_be32(0); /* No more gids */
1581 hdr
->replen
+= decode_create_session_maxsz
;
1584 static void encode_destroy_session(struct xdr_stream
*xdr
,
1585 struct nfs4_session
*session
,
1586 struct compound_hdr
*hdr
)
1589 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
);
1590 *p
++ = cpu_to_be32(OP_DESTROY_SESSION
);
1591 xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1593 hdr
->replen
+= decode_destroy_session_maxsz
;
1595 #endif /* CONFIG_NFS_V4_1 */
1597 static void encode_sequence(struct xdr_stream
*xdr
,
1598 const struct nfs4_sequence_args
*args
,
1599 struct compound_hdr
*hdr
)
1601 #if defined(CONFIG_NFS_V4_1)
1602 struct nfs4_session
*session
= args
->sa_session
;
1603 struct nfs4_slot_table
*tp
;
1604 struct nfs4_slot
*slot
;
1610 tp
= &session
->fc_slot_table
;
1612 WARN_ON(args
->sa_slotid
== NFS4_MAX_SLOT_TABLE
);
1613 slot
= tp
->slots
+ args
->sa_slotid
;
1615 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
+ 16);
1616 *p
++ = cpu_to_be32(OP_SEQUENCE
);
1619 * Sessionid + seqid + slotid + max slotid + cache_this
1621 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1622 "max_slotid=%d cache_this=%d\n",
1624 ((u32
*)session
->sess_id
.data
)[0],
1625 ((u32
*)session
->sess_id
.data
)[1],
1626 ((u32
*)session
->sess_id
.data
)[2],
1627 ((u32
*)session
->sess_id
.data
)[3],
1628 slot
->seq_nr
, args
->sa_slotid
,
1629 tp
->highest_used_slotid
, args
->sa_cache_this
);
1630 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1631 *p
++ = cpu_to_be32(slot
->seq_nr
);
1632 *p
++ = cpu_to_be32(args
->sa_slotid
);
1633 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1634 *p
= cpu_to_be32(args
->sa_cache_this
);
1636 hdr
->replen
+= decode_sequence_maxsz
;
1637 #endif /* CONFIG_NFS_V4_1 */
1641 * END OF "GENERIC" ENCODE ROUTINES.
1644 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
1646 #if defined(CONFIG_NFS_V4_1)
1647 if (args
->sa_session
)
1648 return args
->sa_session
->clp
->cl_minorversion
;
1649 #endif /* CONFIG_NFS_V4_1 */
1654 * Encode an ACCESS request
1656 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_accessargs
*args
)
1658 struct xdr_stream xdr
;
1659 struct compound_hdr hdr
= {
1660 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1663 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1664 encode_compound_hdr(&xdr
, req
, &hdr
);
1665 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1666 encode_putfh(&xdr
, args
->fh
, &hdr
);
1667 encode_access(&xdr
, args
->access
, &hdr
);
1668 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1674 * Encode LOOKUP request
1676 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_arg
*args
)
1678 struct xdr_stream xdr
;
1679 struct compound_hdr hdr
= {
1680 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1683 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1684 encode_compound_hdr(&xdr
, req
, &hdr
);
1685 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1686 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1687 encode_lookup(&xdr
, args
->name
, &hdr
);
1688 encode_getfh(&xdr
, &hdr
);
1689 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1695 * Encode LOOKUP_ROOT request
1697 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_root_arg
*args
)
1699 struct xdr_stream xdr
;
1700 struct compound_hdr hdr
= {
1701 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1704 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1705 encode_compound_hdr(&xdr
, req
, &hdr
);
1706 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1707 encode_putrootfh(&xdr
, &hdr
);
1708 encode_getfh(&xdr
, &hdr
);
1709 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1715 * Encode REMOVE request
1717 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_removeargs
*args
)
1719 struct xdr_stream xdr
;
1720 struct compound_hdr hdr
= {
1721 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1724 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1725 encode_compound_hdr(&xdr
, req
, &hdr
);
1726 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1727 encode_putfh(&xdr
, args
->fh
, &hdr
);
1728 encode_remove(&xdr
, &args
->name
, &hdr
);
1729 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1735 * Encode RENAME request
1737 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_rename_arg
*args
)
1739 struct xdr_stream xdr
;
1740 struct compound_hdr hdr
= {
1741 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1744 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1745 encode_compound_hdr(&xdr
, req
, &hdr
);
1746 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1747 encode_putfh(&xdr
, args
->old_dir
, &hdr
);
1748 encode_savefh(&xdr
, &hdr
);
1749 encode_putfh(&xdr
, args
->new_dir
, &hdr
);
1750 encode_rename(&xdr
, args
->old_name
, args
->new_name
, &hdr
);
1751 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1752 encode_restorefh(&xdr
, &hdr
);
1753 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1759 * Encode LINK request
1761 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_link_arg
*args
)
1763 struct xdr_stream xdr
;
1764 struct compound_hdr hdr
= {
1765 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1768 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1769 encode_compound_hdr(&xdr
, req
, &hdr
);
1770 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1771 encode_putfh(&xdr
, args
->fh
, &hdr
);
1772 encode_savefh(&xdr
, &hdr
);
1773 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1774 encode_link(&xdr
, args
->name
, &hdr
);
1775 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1776 encode_restorefh(&xdr
, &hdr
);
1777 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1783 * Encode CREATE request
1785 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1787 struct xdr_stream xdr
;
1788 struct compound_hdr hdr
= {
1789 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1792 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1793 encode_compound_hdr(&xdr
, req
, &hdr
);
1794 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1795 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1796 encode_savefh(&xdr
, &hdr
);
1797 encode_create(&xdr
, args
, &hdr
);
1798 encode_getfh(&xdr
, &hdr
);
1799 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1800 encode_restorefh(&xdr
, &hdr
);
1801 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1807 * Encode SYMLINK request
1809 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1811 return nfs4_xdr_enc_create(req
, p
, args
);
1815 * Encode GETATTR request
1817 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_getattr_arg
*args
)
1819 struct xdr_stream xdr
;
1820 struct compound_hdr hdr
= {
1821 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1824 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1825 encode_compound_hdr(&xdr
, req
, &hdr
);
1826 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1827 encode_putfh(&xdr
, args
->fh
, &hdr
);
1828 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1834 * Encode a CLOSE request
1836 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1838 struct xdr_stream xdr
;
1839 struct compound_hdr hdr
= {
1840 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1843 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1844 encode_compound_hdr(&xdr
, req
, &hdr
);
1845 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1846 encode_putfh(&xdr
, args
->fh
, &hdr
);
1847 encode_close(&xdr
, args
, &hdr
);
1848 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1854 * Encode an OPEN request
1856 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1858 struct xdr_stream xdr
;
1859 struct compound_hdr hdr
= {
1860 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1863 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1864 encode_compound_hdr(&xdr
, req
, &hdr
);
1865 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1866 encode_putfh(&xdr
, args
->fh
, &hdr
);
1867 encode_savefh(&xdr
, &hdr
);
1868 encode_open(&xdr
, args
, &hdr
);
1869 encode_getfh(&xdr
, &hdr
);
1870 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1871 encode_restorefh(&xdr
, &hdr
);
1872 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1878 * Encode an OPEN_CONFIRM request
1880 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_open_confirmargs
*args
)
1882 struct xdr_stream xdr
;
1883 struct compound_hdr hdr
= {
1887 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1888 encode_compound_hdr(&xdr
, req
, &hdr
);
1889 encode_putfh(&xdr
, args
->fh
, &hdr
);
1890 encode_open_confirm(&xdr
, args
, &hdr
);
1896 * Encode an OPEN request with no attributes.
1898 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1900 struct xdr_stream xdr
;
1901 struct compound_hdr hdr
= {
1902 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1905 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1906 encode_compound_hdr(&xdr
, req
, &hdr
);
1907 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1908 encode_putfh(&xdr
, args
->fh
, &hdr
);
1909 encode_open(&xdr
, args
, &hdr
);
1910 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1916 * Encode an OPEN_DOWNGRADE request
1918 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1920 struct xdr_stream xdr
;
1921 struct compound_hdr hdr
= {
1922 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1925 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1926 encode_compound_hdr(&xdr
, req
, &hdr
);
1927 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1928 encode_putfh(&xdr
, args
->fh
, &hdr
);
1929 encode_open_downgrade(&xdr
, args
, &hdr
);
1930 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1936 * Encode a LOCK request
1938 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lock_args
*args
)
1940 struct xdr_stream xdr
;
1941 struct compound_hdr hdr
= {
1942 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1945 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1946 encode_compound_hdr(&xdr
, req
, &hdr
);
1947 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1948 encode_putfh(&xdr
, args
->fh
, &hdr
);
1949 encode_lock(&xdr
, args
, &hdr
);
1955 * Encode a LOCKT request
1957 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lockt_args
*args
)
1959 struct xdr_stream xdr
;
1960 struct compound_hdr hdr
= {
1961 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1964 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1965 encode_compound_hdr(&xdr
, req
, &hdr
);
1966 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1967 encode_putfh(&xdr
, args
->fh
, &hdr
);
1968 encode_lockt(&xdr
, args
, &hdr
);
1974 * Encode a LOCKU request
1976 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, __be32
*p
, struct nfs_locku_args
*args
)
1978 struct xdr_stream xdr
;
1979 struct compound_hdr hdr
= {
1980 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1983 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1984 encode_compound_hdr(&xdr
, req
, &hdr
);
1985 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1986 encode_putfh(&xdr
, args
->fh
, &hdr
);
1987 encode_locku(&xdr
, args
, &hdr
);
1993 * Encode a READLINK request
1995 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readlink
*args
)
1997 struct xdr_stream xdr
;
1998 struct compound_hdr hdr
= {
1999 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2002 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2003 encode_compound_hdr(&xdr
, req
, &hdr
);
2004 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2005 encode_putfh(&xdr
, args
->fh
, &hdr
);
2006 encode_readlink(&xdr
, args
, req
, &hdr
);
2008 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2009 args
->pgbase
, args
->pglen
);
2015 * Encode a READDIR request
2017 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readdir_arg
*args
)
2019 struct xdr_stream xdr
;
2020 struct compound_hdr hdr
= {
2021 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2024 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2025 encode_compound_hdr(&xdr
, req
, &hdr
);
2026 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2027 encode_putfh(&xdr
, args
->fh
, &hdr
);
2028 encode_readdir(&xdr
, args
, req
, &hdr
);
2030 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2031 args
->pgbase
, args
->count
);
2032 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2033 __func__
, hdr
.replen
<< 2, args
->pages
,
2034 args
->pgbase
, args
->count
);
2040 * Encode a READ request
2042 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readargs
*args
)
2044 struct xdr_stream xdr
;
2045 struct compound_hdr hdr
= {
2046 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2049 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2050 encode_compound_hdr(&xdr
, req
, &hdr
);
2051 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2052 encode_putfh(&xdr
, args
->fh
, &hdr
);
2053 encode_read(&xdr
, args
, &hdr
);
2055 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2056 args
->pages
, args
->pgbase
, args
->count
);
2057 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2063 * Encode an SETATTR request
2065 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setattrargs
*args
)
2067 struct xdr_stream xdr
;
2068 struct compound_hdr hdr
= {
2069 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2072 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2073 encode_compound_hdr(&xdr
, req
, &hdr
);
2074 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2075 encode_putfh(&xdr
, args
->fh
, &hdr
);
2076 encode_setattr(&xdr
, args
, args
->server
, &hdr
);
2077 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2083 * Encode a GETACL request
2086 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, __be32
*p
,
2087 struct nfs_getaclargs
*args
)
2089 struct xdr_stream xdr
;
2090 struct compound_hdr hdr
= {
2091 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2095 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2096 encode_compound_hdr(&xdr
, req
, &hdr
);
2097 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2098 encode_putfh(&xdr
, args
->fh
, &hdr
);
2099 replen
= hdr
.replen
+ nfs4_fattr_bitmap_maxsz
+ 1;
2100 encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2102 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2103 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
2109 * Encode a WRITE request
2111 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
2113 struct xdr_stream xdr
;
2114 struct compound_hdr hdr
= {
2115 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2118 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2119 encode_compound_hdr(&xdr
, req
, &hdr
);
2120 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2121 encode_putfh(&xdr
, args
->fh
, &hdr
);
2122 encode_write(&xdr
, args
, &hdr
);
2123 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2124 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2132 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*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_commit(&xdr
, args
, &hdr
);
2144 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2152 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fsinfo_arg
*args
)
2154 struct xdr_stream xdr
;
2155 struct compound_hdr hdr
= {
2156 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2159 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2160 encode_compound_hdr(&xdr
, req
, &hdr
);
2161 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2162 encode_putfh(&xdr
, args
->fh
, &hdr
);
2163 encode_fsinfo(&xdr
, args
->bitmask
, &hdr
);
2169 * a PATHCONF request
2171 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_pathconf_arg
*args
)
2173 struct xdr_stream xdr
;
2174 struct compound_hdr hdr
= {
2175 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2178 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2179 encode_compound_hdr(&xdr
, req
, &hdr
);
2180 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2181 encode_putfh(&xdr
, args
->fh
, &hdr
);
2182 encode_getattr_one(&xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2191 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_statfs_arg
*args
)
2193 struct xdr_stream xdr
;
2194 struct compound_hdr hdr
= {
2195 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2198 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2199 encode_compound_hdr(&xdr
, req
, &hdr
);
2200 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2201 encode_putfh(&xdr
, args
->fh
, &hdr
);
2202 encode_getattr_two(&xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2203 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2209 * GETATTR_BITMAP request
2211 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, __be32
*p
,
2212 struct nfs4_server_caps_arg
*args
)
2214 struct xdr_stream xdr
;
2215 struct compound_hdr hdr
= {
2216 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2219 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2220 encode_compound_hdr(&xdr
, req
, &hdr
);
2221 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2222 encode_putfh(&xdr
, args
->fhandle
, &hdr
);
2223 encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2224 FATTR4_WORD0_LINK_SUPPORT
|
2225 FATTR4_WORD0_SYMLINK_SUPPORT
|
2226 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2234 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
2236 struct xdr_stream xdr
;
2237 struct compound_hdr hdr
= {
2241 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2242 encode_compound_hdr(&xdr
, req
, &hdr
);
2243 encode_renew(&xdr
, clp
, &hdr
);
2249 * a SETCLIENTID request
2251 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid
*sc
)
2253 struct xdr_stream xdr
;
2254 struct compound_hdr hdr
= {
2258 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2259 encode_compound_hdr(&xdr
, req
, &hdr
);
2260 encode_setclientid(&xdr
, sc
, &hdr
);
2266 * a SETCLIENTID_CONFIRM request
2268 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
2270 struct xdr_stream xdr
;
2271 struct compound_hdr hdr
= {
2274 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2276 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2277 encode_compound_hdr(&xdr
, req
, &hdr
);
2278 encode_setclientid_confirm(&xdr
, clp
, &hdr
);
2279 encode_putrootfh(&xdr
, &hdr
);
2280 encode_fsinfo(&xdr
, lease_bitmap
, &hdr
);
2286 * DELEGRETURN request
2288 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_delegreturnargs
*args
)
2290 struct xdr_stream xdr
;
2291 struct compound_hdr hdr
= {
2292 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2295 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2296 encode_compound_hdr(&xdr
, req
, &hdr
);
2297 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2298 encode_putfh(&xdr
, args
->fhandle
, &hdr
);
2299 encode_delegreturn(&xdr
, args
->stateid
, &hdr
);
2300 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2306 * Encode FS_LOCATIONS request
2308 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations_arg
*args
)
2310 struct xdr_stream xdr
;
2311 struct compound_hdr hdr
= {
2312 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2316 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2317 encode_compound_hdr(&xdr
, req
, &hdr
);
2318 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2319 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
2320 encode_lookup(&xdr
, args
->name
, &hdr
);
2321 replen
= hdr
.replen
; /* get the attribute into args->page */
2322 encode_fs_locations(&xdr
, args
->bitmask
, &hdr
);
2324 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2330 #if defined(CONFIG_NFS_V4_1)
2332 * EXCHANGE_ID request
2334 static int nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
, uint32_t *p
,
2335 struct nfs41_exchange_id_args
*args
)
2337 struct xdr_stream xdr
;
2338 struct compound_hdr hdr
= {
2339 .minorversion
= args
->client
->cl_minorversion
,
2342 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2343 encode_compound_hdr(&xdr
, req
, &hdr
);
2344 encode_exchange_id(&xdr
, args
, &hdr
);
2350 * a CREATE_SESSION request
2352 static int nfs4_xdr_enc_create_session(struct rpc_rqst
*req
, uint32_t *p
,
2353 struct nfs41_create_session_args
*args
)
2355 struct xdr_stream xdr
;
2356 struct compound_hdr hdr
= {
2357 .minorversion
= args
->client
->cl_minorversion
,
2360 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2361 encode_compound_hdr(&xdr
, req
, &hdr
);
2362 encode_create_session(&xdr
, args
, &hdr
);
2368 * a DESTROY_SESSION request
2370 static int nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
, uint32_t *p
,
2371 struct nfs4_session
*session
)
2373 struct xdr_stream xdr
;
2374 struct compound_hdr hdr
= {
2375 .minorversion
= session
->clp
->cl_minorversion
,
2378 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2379 encode_compound_hdr(&xdr
, req
, &hdr
);
2380 encode_destroy_session(&xdr
, session
, &hdr
);
2386 * a SEQUENCE request
2388 static int nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, uint32_t *p
,
2389 struct nfs4_sequence_args
*args
)
2391 struct xdr_stream xdr
;
2392 struct compound_hdr hdr
= {
2393 .minorversion
= nfs4_xdr_minorversion(args
),
2396 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2397 encode_compound_hdr(&xdr
, req
, &hdr
);
2398 encode_sequence(&xdr
, args
, &hdr
);
2404 * a GET_LEASE_TIME request
2406 static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
, uint32_t *p
,
2407 struct nfs4_get_lease_time_args
*args
)
2409 struct xdr_stream xdr
;
2410 struct compound_hdr hdr
= {
2411 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2413 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2415 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2416 encode_compound_hdr(&xdr
, req
, &hdr
);
2417 encode_sequence(&xdr
, &args
->la_seq_args
, &hdr
);
2418 encode_putrootfh(&xdr
, &hdr
);
2419 encode_fsinfo(&xdr
, lease_bitmap
, &hdr
);
2423 #endif /* CONFIG_NFS_V4_1 */
2425 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
2427 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2428 "Remaining buffer length is %tu words.\n",
2429 func
, xdr
->end
- xdr
->p
);
2432 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2436 p
= xdr_inline_decode(xdr
, 4);
2439 *len
= be32_to_cpup(p
);
2440 p
= xdr_inline_decode(xdr
, *len
);
2443 *string
= (char *)p
;
2446 print_overflow_msg(__func__
, xdr
);
2450 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2454 p
= xdr_inline_decode(xdr
, 8);
2457 hdr
->status
= be32_to_cpup(p
++);
2458 hdr
->taglen
= be32_to_cpup(p
);
2460 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
2463 hdr
->tag
= (char *)p
;
2464 p
+= XDR_QUADLEN(hdr
->taglen
);
2465 hdr
->nops
= be32_to_cpup(p
);
2466 if (unlikely(hdr
->nops
< 1))
2467 return nfs4_stat_to_errno(hdr
->status
);
2470 print_overflow_msg(__func__
, xdr
);
2474 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2480 p
= xdr_inline_decode(xdr
, 8);
2483 opnum
= be32_to_cpup(p
++);
2484 if (opnum
!= expected
) {
2485 dprintk("nfs: Server returned operation"
2486 " %d but we issued a request for %d\n",
2490 nfserr
= be32_to_cpup(p
);
2491 if (nfserr
!= NFS_OK
)
2492 return nfs4_stat_to_errno(nfserr
);
2495 print_overflow_msg(__func__
, xdr
);
2500 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2503 unsigned int strlen
;
2506 p
= xdr_inline_decode(xdr
, 12);
2508 return decode_opaque_inline(xdr
, &strlen
, &str
);
2509 print_overflow_msg(__func__
, xdr
);
2513 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2518 p
= xdr_inline_decode(xdr
, 4);
2521 bmlen
= be32_to_cpup(p
);
2523 bitmap
[0] = bitmap
[1] = 0;
2524 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
2528 bitmap
[0] = be32_to_cpup(p
++);
2530 bitmap
[1] = be32_to_cpup(p
);
2534 print_overflow_msg(__func__
, xdr
);
2538 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
2542 p
= xdr_inline_decode(xdr
, 4);
2545 *attrlen
= be32_to_cpup(p
);
2549 print_overflow_msg(__func__
, xdr
);
2553 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2555 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2556 decode_attr_bitmap(xdr
, bitmask
);
2557 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2559 bitmask
[0] = bitmask
[1] = 0;
2560 dprintk("%s: bitmask=%08x:%08x\n", __func__
, bitmask
[0], bitmask
[1]);
2564 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2570 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2572 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2573 p
= xdr_inline_decode(xdr
, 4);
2576 *type
= be32_to_cpup(p
);
2577 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2578 dprintk("%s: bad type %d\n", __func__
, *type
);
2581 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2582 ret
= NFS_ATTR_FATTR_TYPE
;
2584 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
2587 print_overflow_msg(__func__
, xdr
);
2591 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2597 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2599 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2600 p
= xdr_inline_decode(xdr
, 8);
2603 xdr_decode_hyper(p
, change
);
2604 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2605 ret
= NFS_ATTR_FATTR_CHANGE
;
2607 dprintk("%s: change attribute=%Lu\n", __func__
,
2608 (unsigned long long)*change
);
2611 print_overflow_msg(__func__
, xdr
);
2615 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2621 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2623 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2624 p
= xdr_inline_decode(xdr
, 8);
2627 xdr_decode_hyper(p
, size
);
2628 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2629 ret
= NFS_ATTR_FATTR_SIZE
;
2631 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
2634 print_overflow_msg(__func__
, xdr
);
2638 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2643 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2645 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2646 p
= xdr_inline_decode(xdr
, 4);
2649 *res
= be32_to_cpup(p
);
2650 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2652 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2655 print_overflow_msg(__func__
, xdr
);
2659 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2664 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2666 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2667 p
= xdr_inline_decode(xdr
, 4);
2670 *res
= be32_to_cpup(p
);
2671 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2673 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2676 print_overflow_msg(__func__
, xdr
);
2680 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
2687 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2689 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2690 p
= xdr_inline_decode(xdr
, 16);
2693 p
= xdr_decode_hyper(p
, &fsid
->major
);
2694 xdr_decode_hyper(p
, &fsid
->minor
);
2695 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2696 ret
= NFS_ATTR_FATTR_FSID
;
2698 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
2699 (unsigned long long)fsid
->major
,
2700 (unsigned long long)fsid
->minor
);
2703 print_overflow_msg(__func__
, xdr
);
2707 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2712 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2714 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2715 p
= xdr_inline_decode(xdr
, 4);
2718 *res
= be32_to_cpup(p
);
2719 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2721 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
2724 print_overflow_msg(__func__
, xdr
);
2728 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2732 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2733 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2735 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2736 p
= xdr_inline_decode(xdr
, 4);
2739 *res
= be32_to_cpup(p
);
2740 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2742 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
2745 print_overflow_msg(__func__
, xdr
);
2749 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2755 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2757 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2758 p
= xdr_inline_decode(xdr
, 8);
2761 xdr_decode_hyper(p
, fileid
);
2762 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2763 ret
= NFS_ATTR_FATTR_FILEID
;
2765 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2768 print_overflow_msg(__func__
, xdr
);
2772 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2778 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
2780 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
2781 p
= xdr_inline_decode(xdr
, 8);
2784 xdr_decode_hyper(p
, fileid
);
2785 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
2786 ret
= NFS_ATTR_FATTR_FILEID
;
2788 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2791 print_overflow_msg(__func__
, xdr
);
2795 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2801 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2803 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2804 p
= xdr_inline_decode(xdr
, 8);
2807 xdr_decode_hyper(p
, res
);
2808 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2810 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
2813 print_overflow_msg(__func__
, xdr
);
2817 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2823 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2825 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2826 p
= xdr_inline_decode(xdr
, 8);
2829 xdr_decode_hyper(p
, res
);
2830 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2832 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
2835 print_overflow_msg(__func__
, xdr
);
2839 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2845 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2847 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2848 p
= xdr_inline_decode(xdr
, 8);
2851 xdr_decode_hyper(p
, res
);
2852 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2854 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
2857 print_overflow_msg(__func__
, xdr
);
2861 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
2867 p
= xdr_inline_decode(xdr
, 4);
2870 n
= be32_to_cpup(p
);
2874 path
->ncomponents
= 0;
2875 while (path
->ncomponents
< n
) {
2876 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
2877 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
2878 if (unlikely(status
!= 0))
2880 if (path
->ncomponents
!= n
)
2882 dprintk("%s", component
->data
);
2883 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
2884 path
->ncomponents
++;
2886 dprintk("cannot parse %d components in path\n", n
);
2894 /* a root pathname is sent as a zero component4 */
2895 path
->ncomponents
= 1;
2896 path
->components
[0].len
=0;
2897 path
->components
[0].data
=NULL
;
2898 dprintk("path /\n");
2901 dprintk(" status %d", status
);
2905 print_overflow_msg(__func__
, xdr
);
2909 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
2915 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
2918 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
2920 dprintk("%s: fsroot ", __func__
);
2921 status
= decode_pathname(xdr
, &res
->fs_path
);
2922 if (unlikely(status
!= 0))
2924 p
= xdr_inline_decode(xdr
, 4);
2927 n
= be32_to_cpup(p
);
2930 res
->nlocations
= 0;
2931 while (res
->nlocations
< n
) {
2933 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
2935 p
= xdr_inline_decode(xdr
, 4);
2938 m
= be32_to_cpup(p
);
2941 dprintk("%s: servers ", __func__
);
2942 while (loc
->nservers
< m
) {
2943 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
2944 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
2945 if (unlikely(status
!= 0))
2947 dprintk("%s ", server
->data
);
2948 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
2952 dprintk("%s: using first %u of %u servers "
2953 "returned for location %u\n",
2955 NFS4_FS_LOCATION_MAXSERVERS
,
2956 m
, res
->nlocations
);
2957 for (i
= loc
->nservers
; i
< m
; i
++) {
2960 status
= decode_opaque_inline(xdr
, &len
, &data
);
2961 if (unlikely(status
!= 0))
2966 status
= decode_pathname(xdr
, &loc
->rootpath
);
2967 if (unlikely(status
!= 0))
2969 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
2972 if (res
->nlocations
!= 0)
2973 status
= NFS_ATTR_FATTR_V4_REFERRAL
;
2975 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
2978 print_overflow_msg(__func__
, xdr
);
2984 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2990 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
2992 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
2993 p
= xdr_inline_decode(xdr
, 8);
2996 xdr_decode_hyper(p
, res
);
2997 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
2999 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3002 print_overflow_msg(__func__
, xdr
);
3006 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3012 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3014 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3015 p
= xdr_inline_decode(xdr
, 4);
3018 *maxlink
= be32_to_cpup(p
);
3019 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3021 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3024 print_overflow_msg(__func__
, xdr
);
3028 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3034 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3036 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3037 p
= xdr_inline_decode(xdr
, 4);
3040 *maxname
= be32_to_cpup(p
);
3041 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3043 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3046 print_overflow_msg(__func__
, xdr
);
3050 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3056 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3058 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3060 p
= xdr_inline_decode(xdr
, 8);
3063 xdr_decode_hyper(p
, &maxread
);
3064 if (maxread
> 0x7FFFFFFF)
3065 maxread
= 0x7FFFFFFF;
3066 *res
= (uint32_t)maxread
;
3067 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3069 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3072 print_overflow_msg(__func__
, xdr
);
3076 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3082 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3084 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3086 p
= xdr_inline_decode(xdr
, 8);
3089 xdr_decode_hyper(p
, &maxwrite
);
3090 if (maxwrite
> 0x7FFFFFFF)
3091 maxwrite
= 0x7FFFFFFF;
3092 *res
= (uint32_t)maxwrite
;
3093 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3095 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3098 print_overflow_msg(__func__
, xdr
);
3102 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3109 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3111 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3112 p
= xdr_inline_decode(xdr
, 4);
3115 tmp
= be32_to_cpup(p
);
3116 *mode
= tmp
& ~S_IFMT
;
3117 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3118 ret
= NFS_ATTR_FATTR_MODE
;
3120 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3123 print_overflow_msg(__func__
, xdr
);
3127 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3133 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3135 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3136 p
= xdr_inline_decode(xdr
, 4);
3139 *nlink
= be32_to_cpup(p
);
3140 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3141 ret
= NFS_ATTR_FATTR_NLINK
;
3143 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3146 print_overflow_msg(__func__
, xdr
);
3150 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3151 struct nfs_client
*clp
, uint32_t *uid
, int may_sleep
)
3158 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3160 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3161 p
= xdr_inline_decode(xdr
, 4);
3164 len
= be32_to_cpup(p
);
3165 p
= xdr_inline_decode(xdr
, len
);
3170 } else if (len
< XDR_MAX_NETOBJ
) {
3171 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) == 0)
3172 ret
= NFS_ATTR_FATTR_OWNER
;
3174 dprintk("%s: nfs_map_name_to_uid failed!\n",
3177 dprintk("%s: name too long (%u)!\n",
3179 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3181 dprintk("%s: uid=%d\n", __func__
, (int)*uid
);
3184 print_overflow_msg(__func__
, xdr
);
3188 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3189 struct nfs_client
*clp
, uint32_t *gid
, int may_sleep
)
3196 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3198 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3199 p
= xdr_inline_decode(xdr
, 4);
3202 len
= be32_to_cpup(p
);
3203 p
= xdr_inline_decode(xdr
, len
);
3208 } else if (len
< XDR_MAX_NETOBJ
) {
3209 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) == 0)
3210 ret
= NFS_ATTR_FATTR_GROUP
;
3212 dprintk("%s: nfs_map_group_to_gid failed!\n",
3215 dprintk("%s: name too long (%u)!\n",
3217 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3219 dprintk("%s: gid=%d\n", __func__
, (int)*gid
);
3222 print_overflow_msg(__func__
, xdr
);
3226 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3228 uint32_t major
= 0, minor
= 0;
3233 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3235 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3238 p
= xdr_inline_decode(xdr
, 8);
3241 major
= be32_to_cpup(p
++);
3242 minor
= be32_to_cpup(p
);
3243 tmp
= MKDEV(major
, minor
);
3244 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3246 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3247 ret
= NFS_ATTR_FATTR_RDEV
;
3249 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3252 print_overflow_msg(__func__
, xdr
);
3256 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3262 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3264 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3265 p
= xdr_inline_decode(xdr
, 8);
3268 xdr_decode_hyper(p
, res
);
3269 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3271 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3274 print_overflow_msg(__func__
, xdr
);
3278 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3284 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3286 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3287 p
= xdr_inline_decode(xdr
, 8);
3290 xdr_decode_hyper(p
, res
);
3291 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3293 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3296 print_overflow_msg(__func__
, xdr
);
3300 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3306 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
3308 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
3309 p
= xdr_inline_decode(xdr
, 8);
3312 xdr_decode_hyper(p
, res
);
3313 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
3315 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
3318 print_overflow_msg(__func__
, xdr
);
3322 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
3328 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
3330 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
3331 p
= xdr_inline_decode(xdr
, 8);
3334 xdr_decode_hyper(p
, used
);
3335 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
3336 ret
= NFS_ATTR_FATTR_SPACE_USED
;
3338 dprintk("%s: space used=%Lu\n", __func__
,
3339 (unsigned long long)*used
);
3342 print_overflow_msg(__func__
, xdr
);
3346 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
3352 p
= xdr_inline_decode(xdr
, 12);
3355 p
= xdr_decode_hyper(p
, &sec
);
3356 nsec
= be32_to_cpup(p
);
3357 time
->tv_sec
= (time_t)sec
;
3358 time
->tv_nsec
= (long)nsec
;
3361 print_overflow_msg(__func__
, xdr
);
3365 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3371 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
3373 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
3374 status
= decode_attr_time(xdr
, time
);
3376 status
= NFS_ATTR_FATTR_ATIME
;
3377 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
3379 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
3383 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3389 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
3391 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
3392 status
= decode_attr_time(xdr
, time
);
3394 status
= NFS_ATTR_FATTR_CTIME
;
3395 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
3397 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
3401 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3407 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
3409 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
3410 status
= decode_attr_time(xdr
, time
);
3412 status
= NFS_ATTR_FATTR_MTIME
;
3413 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
3415 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
3419 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
3421 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
3422 unsigned int nwords
= xdr
->p
- savep
;
3424 if (unlikely(attrwords
!= nwords
)) {
3425 dprintk("%s: server returned incorrect attribute length: "
3429 (attrwords
< nwords
) ? '<' : '>',
3436 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3440 p
= xdr_inline_decode(xdr
, 20);
3443 cinfo
->atomic
= be32_to_cpup(p
++);
3444 p
= xdr_decode_hyper(p
, &cinfo
->before
);
3445 xdr_decode_hyper(p
, &cinfo
->after
);
3448 print_overflow_msg(__func__
, xdr
);
3452 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
3458 status
= decode_op_hdr(xdr
, OP_ACCESS
);
3461 p
= xdr_inline_decode(xdr
, 8);
3464 supp
= be32_to_cpup(p
++);
3465 acc
= be32_to_cpup(p
);
3466 access
->supported
= supp
;
3467 access
->access
= acc
;
3470 print_overflow_msg(__func__
, xdr
);
3474 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
3478 p
= xdr_inline_decode(xdr
, len
);
3480 memcpy(buf
, p
, len
);
3483 print_overflow_msg(__func__
, xdr
);
3487 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
3489 return decode_opaque_fixed(xdr
, stateid
->data
, NFS4_STATEID_SIZE
);
3492 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3496 status
= decode_op_hdr(xdr
, OP_CLOSE
);
3498 nfs_increment_open_seqid(status
, res
->seqid
);
3500 status
= decode_stateid(xdr
, &res
->stateid
);
3504 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
3506 return decode_opaque_fixed(xdr
, verifier
, 8);
3509 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3513 status
= decode_op_hdr(xdr
, OP_COMMIT
);
3515 status
= decode_verifier(xdr
, res
->verf
->verifier
);
3519 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3525 status
= decode_op_hdr(xdr
, OP_CREATE
);
3528 if ((status
= decode_change_info(xdr
, cinfo
)))
3530 p
= xdr_inline_decode(xdr
, 4);
3533 bmlen
= be32_to_cpup(p
);
3534 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
3538 print_overflow_msg(__func__
, xdr
);
3542 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
3545 uint32_t attrlen
, bitmap
[2] = {0};
3548 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3550 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3552 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3554 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
3556 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
3558 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
3560 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
3562 status
= verify_attr_len(xdr
, savep
, attrlen
);
3564 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3568 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
3571 uint32_t attrlen
, bitmap
[2] = {0};
3574 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3576 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3578 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3581 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
3583 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
3585 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
3587 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
3589 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
3591 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
3594 status
= verify_attr_len(xdr
, savep
, attrlen
);
3596 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3600 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
3603 uint32_t attrlen
, bitmap
[2] = {0};
3606 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3608 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3610 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3613 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
3615 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
3618 status
= verify_attr_len(xdr
, savep
, attrlen
);
3620 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3624 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
3625 const struct nfs_server
*server
, int may_sleep
)
3635 status
= decode_op_hdr(xdr
, OP_GETATTR
);
3639 status
= decode_attr_bitmap(xdr
, bitmap
);
3643 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
3648 status
= decode_attr_type(xdr
, bitmap
, &type
);
3653 fattr
->mode
|= nfs_type2fmt
[type
];
3654 fattr
->valid
|= status
;
3657 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
3660 fattr
->valid
|= status
;
3662 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
3665 fattr
->valid
|= status
;
3667 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
3670 fattr
->valid
|= status
;
3672 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
3675 fattr
->valid
|= status
;
3677 status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
3678 struct nfs4_fs_locations
,
3682 fattr
->valid
|= status
;
3684 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
3688 fattr
->mode
|= fmode
;
3689 fattr
->valid
|= status
;
3692 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
3695 fattr
->valid
|= status
;
3697 status
= decode_attr_owner(xdr
, bitmap
, server
->nfs_client
,
3698 &fattr
->uid
, may_sleep
);
3701 fattr
->valid
|= status
;
3703 status
= decode_attr_group(xdr
, bitmap
, server
->nfs_client
,
3704 &fattr
->gid
, may_sleep
);
3707 fattr
->valid
|= status
;
3709 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
3712 fattr
->valid
|= status
;
3714 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
3717 fattr
->valid
|= status
;
3719 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
3722 fattr
->valid
|= status
;
3724 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
3727 fattr
->valid
|= status
;
3729 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
3732 fattr
->valid
|= status
;
3734 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fileid
);
3737 if (status
!= 0 && !(fattr
->valid
& status
)) {
3738 fattr
->fileid
= fileid
;
3739 fattr
->valid
|= status
;
3742 status
= verify_attr_len(xdr
, savep
, attrlen
);
3744 dprintk("%s: xdr returned %d\n", __func__
, -status
);
3749 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
3752 uint32_t attrlen
, bitmap
[2];
3755 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3757 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3759 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3762 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
3764 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
3766 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
3768 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
3770 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
3771 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
3773 fsinfo
->wtpref
= fsinfo
->wtmax
;
3775 status
= verify_attr_len(xdr
, savep
, attrlen
);
3777 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3781 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
3787 /* Zero handle first to allow comparisons */
3788 memset(fh
, 0, sizeof(*fh
));
3790 status
= decode_op_hdr(xdr
, OP_GETFH
);
3794 p
= xdr_inline_decode(xdr
, 4);
3797 len
= be32_to_cpup(p
);
3798 if (len
> NFS4_FHSIZE
)
3801 p
= xdr_inline_decode(xdr
, len
);
3804 memcpy(fh
->data
, p
, len
);
3807 print_overflow_msg(__func__
, xdr
);
3811 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3815 status
= decode_op_hdr(xdr
, OP_LINK
);
3818 return decode_change_info(xdr
, cinfo
);
3822 * We create the owner, so we know a proper owner.id length is 4.
3824 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
3826 uint64_t offset
, length
, clientid
;
3828 uint32_t namelen
, type
;
3830 p
= xdr_inline_decode(xdr
, 32);
3833 p
= xdr_decode_hyper(p
, &offset
);
3834 p
= xdr_decode_hyper(p
, &length
);
3835 type
= be32_to_cpup(p
++);
3837 fl
->fl_start
= (loff_t
)offset
;
3838 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
3839 if (length
== ~(uint64_t)0)
3840 fl
->fl_end
= OFFSET_MAX
;
3841 fl
->fl_type
= F_WRLCK
;
3843 fl
->fl_type
= F_RDLCK
;
3846 p
= xdr_decode_hyper(p
, &clientid
);
3847 namelen
= be32_to_cpup(p
);
3848 p
= xdr_inline_decode(xdr
, namelen
);
3850 return -NFS4ERR_DENIED
;
3852 print_overflow_msg(__func__
, xdr
);
3856 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
3860 status
= decode_op_hdr(xdr
, OP_LOCK
);
3864 status
= decode_stateid(xdr
, &res
->stateid
);
3865 if (unlikely(status
))
3867 } else if (status
== -NFS4ERR_DENIED
)
3868 status
= decode_lock_denied(xdr
, NULL
);
3869 if (res
->open_seqid
!= NULL
)
3870 nfs_increment_open_seqid(status
, res
->open_seqid
);
3871 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
3876 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
3879 status
= decode_op_hdr(xdr
, OP_LOCKT
);
3880 if (status
== -NFS4ERR_DENIED
)
3881 return decode_lock_denied(xdr
, res
->denied
);
3885 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
3889 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3891 nfs_increment_lock_seqid(status
, res
->seqid
);
3893 status
= decode_stateid(xdr
, &res
->stateid
);
3897 static int decode_lookup(struct xdr_stream
*xdr
)
3899 return decode_op_hdr(xdr
, OP_LOOKUP
);
3902 /* This is too sick! */
3903 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3906 uint32_t limit_type
, nblocks
, blocksize
;
3908 p
= xdr_inline_decode(xdr
, 12);
3911 limit_type
= be32_to_cpup(p
++);
3912 switch (limit_type
) {
3914 xdr_decode_hyper(p
, maxsize
);
3917 nblocks
= be32_to_cpup(p
++);
3918 blocksize
= be32_to_cpup(p
);
3919 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
3923 print_overflow_msg(__func__
, xdr
);
3927 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3930 uint32_t delegation_type
;
3933 p
= xdr_inline_decode(xdr
, 4);
3936 delegation_type
= be32_to_cpup(p
);
3937 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
3938 res
->delegation_type
= 0;
3941 status
= decode_stateid(xdr
, &res
->delegation
);
3942 if (unlikely(status
))
3944 p
= xdr_inline_decode(xdr
, 4);
3947 res
->do_recall
= be32_to_cpup(p
);
3949 switch (delegation_type
) {
3950 case NFS4_OPEN_DELEGATE_READ
:
3951 res
->delegation_type
= FMODE_READ
;
3953 case NFS4_OPEN_DELEGATE_WRITE
:
3954 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
3955 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
3958 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
3960 print_overflow_msg(__func__
, xdr
);
3964 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3967 uint32_t savewords
, bmlen
, i
;
3970 status
= decode_op_hdr(xdr
, OP_OPEN
);
3972 nfs_increment_open_seqid(status
, res
->seqid
);
3974 status
= decode_stateid(xdr
, &res
->stateid
);
3975 if (unlikely(status
))
3978 decode_change_info(xdr
, &res
->cinfo
);
3980 p
= xdr_inline_decode(xdr
, 8);
3983 res
->rflags
= be32_to_cpup(p
++);
3984 bmlen
= be32_to_cpup(p
);
3988 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
3991 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
3992 for (i
= 0; i
< savewords
; ++i
)
3993 res
->attrset
[i
] = be32_to_cpup(p
++);
3994 for (; i
< NFS4_BITMAP_SIZE
; i
++)
3995 res
->attrset
[i
] = 0;
3997 return decode_delegation(xdr
, res
);
3999 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
4002 print_overflow_msg(__func__
, xdr
);
4006 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
4010 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
4012 nfs_increment_open_seqid(status
, res
->seqid
);
4014 status
= decode_stateid(xdr
, &res
->stateid
);
4018 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4022 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
4024 nfs_increment_open_seqid(status
, res
->seqid
);
4026 status
= decode_stateid(xdr
, &res
->stateid
);
4030 static int decode_putfh(struct xdr_stream
*xdr
)
4032 return decode_op_hdr(xdr
, OP_PUTFH
);
4035 static int decode_putrootfh(struct xdr_stream
*xdr
)
4037 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
4040 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
4042 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4044 uint32_t count
, eof
, recvd
, hdrlen
;
4047 status
= decode_op_hdr(xdr
, OP_READ
);
4050 p
= xdr_inline_decode(xdr
, 8);
4053 eof
= be32_to_cpup(p
++);
4054 count
= be32_to_cpup(p
);
4055 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
4056 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4057 if (count
> recvd
) {
4058 dprintk("NFS: server cheating in read reply: "
4059 "count %u > recvd %u\n", count
, recvd
);
4063 xdr_read_pages(xdr
, count
);
4068 print_overflow_msg(__func__
, xdr
);
4072 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
4074 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4075 struct page
*page
= *rcvbuf
->pages
;
4076 struct kvec
*iov
= rcvbuf
->head
;
4078 u32 recvd
, pglen
= rcvbuf
->page_len
;
4079 __be32
*end
, *entry
, *p
, *kaddr
;
4080 unsigned int nr
= 0;
4083 status
= decode_op_hdr(xdr
, OP_READDIR
);
4085 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
4086 if (unlikely(status
))
4088 dprintk("%s: verifier = %08x:%08x\n",
4090 ((u32
*)readdir
->verifier
.data
)[0],
4091 ((u32
*)readdir
->verifier
.data
)[1]);
4094 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4095 recvd
= rcvbuf
->len
- hdrlen
;
4098 xdr_read_pages(xdr
, pglen
);
4100 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
4101 kaddr
= p
= kmap_atomic(page
, KM_USER0
);
4102 end
= p
+ ((pglen
+ readdir
->pgbase
) >> 2);
4105 /* Make sure the packet actually has a value_follows and EOF entry */
4106 if ((entry
+ 1) > end
)
4109 for (; *p
++; nr
++) {
4110 u32 len
, attrlen
, xlen
;
4113 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
4114 p
+= 2; /* cookie */
4115 len
= ntohl(*p
++); /* filename length */
4116 if (len
> NFS4_MAXNAMLEN
) {
4117 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4121 xlen
= XDR_QUADLEN(len
);
4122 if (end
- p
< xlen
+ 1)
4124 dprintk("filename = %*s\n", len
, (char *)p
);
4126 len
= ntohl(*p
++); /* bitmap length */
4127 if (end
- p
< len
+ 1)
4130 attrlen
= XDR_QUADLEN(ntohl(*p
++));
4131 if (end
- p
< attrlen
+ 2)
4133 p
+= attrlen
; /* attributes */
4137 * Apparently some server sends responses that are a valid size, but
4138 * contain no entries, and have value_follows==0 and EOF==0. For
4139 * those, just set the EOF marker.
4141 if (!nr
&& entry
[1] == 0) {
4142 dprintk("NFS: readdir reply truncated!\n");
4146 kunmap_atomic(kaddr
, KM_USER0
);
4150 * When we get a short packet there are 2 possibilities. We can
4151 * return an error, or fix up the response to look like a valid
4152 * response and return what we have so far. If there are no
4153 * entries and the packet was short, then return -EIO. If there
4154 * are valid entries in the response, return them and pretend that
4155 * the call was successful, but incomplete. The caller can retry the
4156 * readdir starting at the last cookie.
4158 dprintk("%s: short packet at entry %d\n", __func__
, nr
);
4159 entry
[0] = entry
[1] = 0;
4163 kunmap_atomic(kaddr
, KM_USER0
);
4164 return -errno_NFSERR_IO
;
4167 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
4169 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4170 struct kvec
*iov
= rcvbuf
->head
;
4177 status
= decode_op_hdr(xdr
, OP_READLINK
);
4181 /* Convert length of symlink */
4182 p
= xdr_inline_decode(xdr
, 4);
4185 len
= be32_to_cpup(p
);
4186 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
4187 dprintk("nfs: server returned giant symlink!\n");
4188 return -ENAMETOOLONG
;
4190 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4191 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4193 dprintk("NFS: server cheating in readlink reply: "
4194 "count %u > recvd %u\n", len
, recvd
);
4197 xdr_read_pages(xdr
, len
);
4199 * The XDR encode routine has set things up so that
4200 * the link text will be copied directly into the
4201 * buffer. We just have to do overflow-checking,
4202 * and and null-terminate the text (the VFS expects
4203 * null-termination).
4205 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
4206 kaddr
[len
+rcvbuf
->page_base
] = '\0';
4207 kunmap_atomic(kaddr
, KM_USER0
);
4210 print_overflow_msg(__func__
, xdr
);
4214 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4218 status
= decode_op_hdr(xdr
, OP_REMOVE
);
4221 status
= decode_change_info(xdr
, cinfo
);
4226 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
4227 struct nfs4_change_info
*new_cinfo
)
4231 status
= decode_op_hdr(xdr
, OP_RENAME
);
4234 if ((status
= decode_change_info(xdr
, old_cinfo
)))
4236 status
= decode_change_info(xdr
, new_cinfo
);
4241 static int decode_renew(struct xdr_stream
*xdr
)
4243 return decode_op_hdr(xdr
, OP_RENEW
);
4247 decode_restorefh(struct xdr_stream
*xdr
)
4249 return decode_op_hdr(xdr
, OP_RESTOREFH
);
4252 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
4258 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4262 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4264 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4266 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4269 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
4271 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
4275 /* We ignore &savep and don't do consistency checks on
4276 * the attr length. Let userspace figure it out.... */
4277 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
4278 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4279 if (attrlen
> recvd
) {
4280 dprintk("NFS: server cheating in getattr"
4281 " acl reply: attrlen %u > recvd %u\n",
4285 xdr_read_pages(xdr
, attrlen
);
4288 status
= -EOPNOTSUPP
;
4295 decode_savefh(struct xdr_stream
*xdr
)
4297 return decode_op_hdr(xdr
, OP_SAVEFH
);
4300 static int decode_setattr(struct xdr_stream
*xdr
)
4306 status
= decode_op_hdr(xdr
, OP_SETATTR
);
4309 p
= xdr_inline_decode(xdr
, 4);
4312 bmlen
= be32_to_cpup(p
);
4313 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4317 print_overflow_msg(__func__
, xdr
);
4321 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs_client
*clp
)
4327 p
= xdr_inline_decode(xdr
, 8);
4330 opnum
= be32_to_cpup(p
++);
4331 if (opnum
!= OP_SETCLIENTID
) {
4332 dprintk("nfs: decode_setclientid: Server returned operation"
4336 nfserr
= be32_to_cpup(p
);
4337 if (nfserr
== NFS_OK
) {
4338 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
4341 p
= xdr_decode_hyper(p
, &clp
->cl_clientid
);
4342 memcpy(clp
->cl_confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
4343 } else if (nfserr
== NFSERR_CLID_INUSE
) {
4346 /* skip netid string */
4347 p
= xdr_inline_decode(xdr
, 4);
4350 len
= be32_to_cpup(p
);
4351 p
= xdr_inline_decode(xdr
, len
);
4355 /* skip uaddr string */
4356 p
= xdr_inline_decode(xdr
, 4);
4359 len
= be32_to_cpup(p
);
4360 p
= xdr_inline_decode(xdr
, len
);
4363 return -NFSERR_CLID_INUSE
;
4365 return nfs4_stat_to_errno(nfserr
);
4369 print_overflow_msg(__func__
, xdr
);
4373 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
4375 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
4378 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
4383 status
= decode_op_hdr(xdr
, OP_WRITE
);
4387 p
= xdr_inline_decode(xdr
, 16);
4390 res
->count
= be32_to_cpup(p
++);
4391 res
->verf
->committed
= be32_to_cpup(p
++);
4392 memcpy(res
->verf
->verifier
, p
, 8);
4395 print_overflow_msg(__func__
, xdr
);
4399 static int decode_delegreturn(struct xdr_stream
*xdr
)
4401 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
4404 #if defined(CONFIG_NFS_V4_1)
4405 static int decode_exchange_id(struct xdr_stream
*xdr
,
4406 struct nfs41_exchange_id_res
*res
)
4412 struct nfs_client
*clp
= res
->client
;
4414 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
4418 p
= xdr_inline_decode(xdr
, 8);
4421 xdr_decode_hyper(p
, &clp
->cl_ex_clid
);
4422 p
= xdr_inline_decode(xdr
, 12);
4425 clp
->cl_seqid
= be32_to_cpup(p
++);
4426 clp
->cl_exchange_flags
= be32_to_cpup(p
++);
4428 /* We ask for SP4_NONE */
4429 dummy
= be32_to_cpup(p
);
4430 if (dummy
!= SP4_NONE
)
4433 /* Throw away minor_id */
4434 p
= xdr_inline_decode(xdr
, 8);
4438 /* Throw away Major id */
4439 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4440 if (unlikely(status
))
4443 /* Throw away server_scope */
4444 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4445 if (unlikely(status
))
4448 /* Throw away Implementation id array */
4449 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4450 if (unlikely(status
))
4455 print_overflow_msg(__func__
, xdr
);
4459 static int decode_chan_attrs(struct xdr_stream
*xdr
,
4460 struct nfs4_channel_attrs
*attrs
)
4465 p
= xdr_inline_decode(xdr
, 28);
4468 attrs
->headerpadsz
= be32_to_cpup(p
++);
4469 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
4470 attrs
->max_resp_sz
= be32_to_cpup(p
++);
4471 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
4472 attrs
->max_ops
= be32_to_cpup(p
++);
4473 attrs
->max_reqs
= be32_to_cpup(p
++);
4474 nr_attrs
= be32_to_cpup(p
);
4475 if (unlikely(nr_attrs
> 1)) {
4476 printk(KERN_WARNING
"%s: Invalid rdma channel attrs count %u\n",
4477 __func__
, nr_attrs
);
4480 if (nr_attrs
== 1) {
4481 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
4487 print_overflow_msg(__func__
, xdr
);
4491 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
4493 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
4496 static int decode_create_session(struct xdr_stream
*xdr
,
4497 struct nfs41_create_session_res
*res
)
4501 struct nfs_client
*clp
= res
->client
;
4502 struct nfs4_session
*session
= clp
->cl_session
;
4504 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
4506 status
= decode_sessionid(xdr
, &session
->sess_id
);
4507 if (unlikely(status
))
4511 p
= xdr_inline_decode(xdr
, 8);
4514 clp
->cl_seqid
= be32_to_cpup(p
++);
4515 session
->flags
= be32_to_cpup(p
);
4517 /* Channel attributes */
4518 status
= decode_chan_attrs(xdr
, &session
->fc_attrs
);
4520 status
= decode_chan_attrs(xdr
, &session
->bc_attrs
);
4523 print_overflow_msg(__func__
, xdr
);
4527 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
4529 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
4531 #endif /* CONFIG_NFS_V4_1 */
4533 static int decode_sequence(struct xdr_stream
*xdr
,
4534 struct nfs4_sequence_res
*res
,
4535 struct rpc_rqst
*rqstp
)
4537 #if defined(CONFIG_NFS_V4_1)
4538 struct nfs4_slot
*slot
;
4539 struct nfs4_sessionid id
;
4544 if (!res
->sr_session
)
4547 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
4549 status
= decode_sessionid(xdr
, &id
);
4550 if (unlikely(status
))
4554 * If the server returns different values for sessionID, slotID or
4555 * sequence number, the server is looney tunes.
4557 status
= -ESERVERFAULT
;
4559 if (memcmp(id
.data
, res
->sr_session
->sess_id
.data
,
4560 NFS4_MAX_SESSIONID_LEN
)) {
4561 dprintk("%s Invalid session id\n", __func__
);
4565 p
= xdr_inline_decode(xdr
, 20);
4570 slot
= &res
->sr_session
->fc_slot_table
.slots
[res
->sr_slotid
];
4571 dummy
= be32_to_cpup(p
++);
4572 if (dummy
!= slot
->seq_nr
) {
4573 dprintk("%s Invalid sequence number\n", __func__
);
4577 dummy
= be32_to_cpup(p
++);
4578 if (dummy
!= res
->sr_slotid
) {
4579 dprintk("%s Invalid slot id\n", __func__
);
4582 /* highest slot id - currently not processed */
4583 dummy
= be32_to_cpup(p
++);
4584 /* target highest slot id - currently not processed */
4585 dummy
= be32_to_cpup(p
++);
4586 /* result flags - currently not processed */
4587 dummy
= be32_to_cpup(p
);
4590 res
->sr_status
= status
;
4593 print_overflow_msg(__func__
, xdr
);
4596 #else /* CONFIG_NFS_V4_1 */
4598 #endif /* CONFIG_NFS_V4_1 */
4602 * END OF "GENERIC" DECODE ROUTINES.
4606 * Decode OPEN_DOWNGRADE response
4608 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
4610 struct xdr_stream xdr
;
4611 struct compound_hdr hdr
;
4614 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4615 status
= decode_compound_hdr(&xdr
, &hdr
);
4618 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4621 status
= decode_putfh(&xdr
);
4624 status
= decode_open_downgrade(&xdr
, res
);
4627 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4628 !RPC_IS_ASYNC(rqstp
->rq_task
));
4634 * Decode ACCESS response
4636 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_accessres
*res
)
4638 struct xdr_stream xdr
;
4639 struct compound_hdr hdr
;
4642 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4643 status
= decode_compound_hdr(&xdr
, &hdr
);
4646 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4649 status
= decode_putfh(&xdr
);
4652 status
= decode_access(&xdr
, res
);
4655 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4656 !RPC_IS_ASYNC(rqstp
->rq_task
));
4662 * Decode LOOKUP response
4664 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
4666 struct xdr_stream xdr
;
4667 struct compound_hdr hdr
;
4670 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4671 status
= decode_compound_hdr(&xdr
, &hdr
);
4674 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4677 if ((status
= decode_putfh(&xdr
)) != 0)
4679 if ((status
= decode_lookup(&xdr
)) != 0)
4681 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
4683 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
4684 ,!RPC_IS_ASYNC(rqstp
->rq_task
));
4690 * Decode LOOKUP_ROOT response
4692 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
4694 struct xdr_stream xdr
;
4695 struct compound_hdr hdr
;
4698 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4699 status
= decode_compound_hdr(&xdr
, &hdr
);
4702 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4705 if ((status
= decode_putrootfh(&xdr
)) != 0)
4707 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
4708 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4709 !RPC_IS_ASYNC(rqstp
->rq_task
));
4715 * Decode REMOVE response
4717 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_removeres
*res
)
4719 struct xdr_stream xdr
;
4720 struct compound_hdr hdr
;
4723 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4724 status
= decode_compound_hdr(&xdr
, &hdr
);
4727 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4730 if ((status
= decode_putfh(&xdr
)) != 0)
4732 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
4734 decode_getfattr(&xdr
, &res
->dir_attr
, res
->server
,
4735 !RPC_IS_ASYNC(rqstp
->rq_task
));
4741 * Decode RENAME response
4743 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_rename_res
*res
)
4745 struct xdr_stream xdr
;
4746 struct compound_hdr hdr
;
4749 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4750 status
= decode_compound_hdr(&xdr
, &hdr
);
4753 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4756 if ((status
= decode_putfh(&xdr
)) != 0)
4758 if ((status
= decode_savefh(&xdr
)) != 0)
4760 if ((status
= decode_putfh(&xdr
)) != 0)
4762 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
4764 /* Current FH is target directory */
4765 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
,
4766 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4768 if ((status
= decode_restorefh(&xdr
)) != 0)
4770 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
,
4771 !RPC_IS_ASYNC(rqstp
->rq_task
));
4777 * Decode LINK response
4779 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_link_res
*res
)
4781 struct xdr_stream xdr
;
4782 struct compound_hdr hdr
;
4785 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4786 status
= decode_compound_hdr(&xdr
, &hdr
);
4789 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4792 if ((status
= decode_putfh(&xdr
)) != 0)
4794 if ((status
= decode_savefh(&xdr
)) != 0)
4796 if ((status
= decode_putfh(&xdr
)) != 0)
4798 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
4801 * Note order: OP_LINK leaves the directory as the current
4804 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
4805 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4807 if ((status
= decode_restorefh(&xdr
)) != 0)
4809 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4810 !RPC_IS_ASYNC(rqstp
->rq_task
));
4816 * Decode CREATE response
4818 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
4820 struct xdr_stream xdr
;
4821 struct compound_hdr hdr
;
4824 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4825 status
= decode_compound_hdr(&xdr
, &hdr
);
4828 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4831 if ((status
= decode_putfh(&xdr
)) != 0)
4833 if ((status
= decode_savefh(&xdr
)) != 0)
4835 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
4837 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
4839 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4840 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4842 if ((status
= decode_restorefh(&xdr
)) != 0)
4844 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
,
4845 !RPC_IS_ASYNC(rqstp
->rq_task
));
4851 * Decode SYMLINK response
4853 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
4855 return nfs4_xdr_dec_create(rqstp
, p
, res
);
4859 * Decode GETATTR response
4861 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_getattr_res
*res
)
4863 struct xdr_stream xdr
;
4864 struct compound_hdr hdr
;
4867 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4868 status
= decode_compound_hdr(&xdr
, &hdr
);
4871 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4874 status
= decode_putfh(&xdr
);
4877 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4878 !RPC_IS_ASYNC(rqstp
->rq_task
));
4884 * Encode an SETACL request
4887 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setaclargs
*args
)
4889 struct xdr_stream xdr
;
4890 struct compound_hdr hdr
= {
4891 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
4895 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
4896 encode_compound_hdr(&xdr
, req
, &hdr
);
4897 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
4898 encode_putfh(&xdr
, args
->fh
, &hdr
);
4899 status
= encode_setacl(&xdr
, args
, &hdr
);
4905 * Decode SETACL response
4908 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, __be32
*p
,
4909 struct nfs_setaclres
*res
)
4911 struct xdr_stream xdr
;
4912 struct compound_hdr hdr
;
4915 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4916 status
= decode_compound_hdr(&xdr
, &hdr
);
4919 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4922 status
= decode_putfh(&xdr
);
4925 status
= decode_setattr(&xdr
);
4931 * Decode GETACL response
4934 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, __be32
*p
,
4935 struct nfs_getaclres
*res
)
4937 struct xdr_stream xdr
;
4938 struct compound_hdr hdr
;
4941 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4942 status
= decode_compound_hdr(&xdr
, &hdr
);
4945 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4948 status
= decode_putfh(&xdr
);
4951 status
= decode_getacl(&xdr
, rqstp
, &res
->acl_len
);
4958 * Decode CLOSE response
4960 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
4962 struct xdr_stream xdr
;
4963 struct compound_hdr hdr
;
4966 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4967 status
= decode_compound_hdr(&xdr
, &hdr
);
4970 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4973 status
= decode_putfh(&xdr
);
4976 status
= decode_close(&xdr
, res
);
4980 * Note: Server may do delete on close for this file
4981 * in which case the getattr call will fail with
4982 * an ESTALE error. Shouldn't be a problem,
4983 * though, since fattr->valid will remain unset.
4985 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4986 !RPC_IS_ASYNC(rqstp
->rq_task
));
4992 * Decode OPEN response
4994 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
4996 struct xdr_stream xdr
;
4997 struct compound_hdr hdr
;
5000 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5001 status
= decode_compound_hdr(&xdr
, &hdr
);
5004 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5007 status
= decode_putfh(&xdr
);
5010 status
= decode_savefh(&xdr
);
5013 status
= decode_open(&xdr
, res
);
5016 if (decode_getfh(&xdr
, &res
->fh
) != 0)
5018 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
,
5019 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5021 if (decode_restorefh(&xdr
) != 0)
5023 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
5024 !RPC_IS_ASYNC(rqstp
->rq_task
));
5030 * Decode OPEN_CONFIRM response
5032 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_open_confirmres
*res
)
5034 struct xdr_stream xdr
;
5035 struct compound_hdr hdr
;
5038 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5039 status
= decode_compound_hdr(&xdr
, &hdr
);
5042 status
= decode_putfh(&xdr
);
5045 status
= decode_open_confirm(&xdr
, res
);
5051 * Decode OPEN response
5053 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
5055 struct xdr_stream xdr
;
5056 struct compound_hdr hdr
;
5059 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5060 status
= decode_compound_hdr(&xdr
, &hdr
);
5063 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5066 status
= decode_putfh(&xdr
);
5069 status
= decode_open(&xdr
, res
);
5072 decode_getfattr(&xdr
, res
->f_attr
, res
->server
,
5073 !RPC_IS_ASYNC(rqstp
->rq_task
));
5079 * Decode SETATTR response
5081 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_setattrres
*res
)
5083 struct xdr_stream xdr
;
5084 struct compound_hdr hdr
;
5087 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5088 status
= decode_compound_hdr(&xdr
, &hdr
);
5091 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5094 status
= decode_putfh(&xdr
);
5097 status
= decode_setattr(&xdr
);
5100 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5101 !RPC_IS_ASYNC(rqstp
->rq_task
));
5107 * Decode LOCK response
5109 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lock_res
*res
)
5111 struct xdr_stream xdr
;
5112 struct compound_hdr hdr
;
5115 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5116 status
= decode_compound_hdr(&xdr
, &hdr
);
5119 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5122 status
= decode_putfh(&xdr
);
5125 status
= decode_lock(&xdr
, res
);
5131 * Decode LOCKT response
5133 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lockt_res
*res
)
5135 struct xdr_stream xdr
;
5136 struct compound_hdr hdr
;
5139 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5140 status
= decode_compound_hdr(&xdr
, &hdr
);
5143 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5146 status
= decode_putfh(&xdr
);
5149 status
= decode_lockt(&xdr
, res
);
5155 * Decode LOCKU response
5157 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_locku_res
*res
)
5159 struct xdr_stream xdr
;
5160 struct compound_hdr hdr
;
5163 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5164 status
= decode_compound_hdr(&xdr
, &hdr
);
5167 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5170 status
= decode_putfh(&xdr
);
5173 status
= decode_locku(&xdr
, res
);
5179 * Decode READLINK response
5181 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, __be32
*p
,
5182 struct nfs4_readlink_res
*res
)
5184 struct xdr_stream xdr
;
5185 struct compound_hdr hdr
;
5188 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5189 status
= decode_compound_hdr(&xdr
, &hdr
);
5192 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5195 status
= decode_putfh(&xdr
);
5198 status
= decode_readlink(&xdr
, rqstp
);
5204 * Decode READDIR response
5206 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_readdir_res
*res
)
5208 struct xdr_stream xdr
;
5209 struct compound_hdr hdr
;
5212 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5213 status
= decode_compound_hdr(&xdr
, &hdr
);
5216 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5219 status
= decode_putfh(&xdr
);
5222 status
= decode_readdir(&xdr
, rqstp
, res
);
5228 * Decode Read response
5230 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_readres
*res
)
5232 struct xdr_stream xdr
;
5233 struct compound_hdr hdr
;
5236 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5237 status
= decode_compound_hdr(&xdr
, &hdr
);
5240 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5243 status
= decode_putfh(&xdr
);
5246 status
= decode_read(&xdr
, rqstp
, res
);
5248 status
= res
->count
;
5254 * Decode WRITE response
5256 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
5258 struct xdr_stream xdr
;
5259 struct compound_hdr hdr
;
5262 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5263 status
= decode_compound_hdr(&xdr
, &hdr
);
5266 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5269 status
= decode_putfh(&xdr
);
5272 status
= decode_write(&xdr
, res
);
5275 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5276 !RPC_IS_ASYNC(rqstp
->rq_task
));
5278 status
= res
->count
;
5284 * Decode COMMIT response
5286 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
5288 struct xdr_stream xdr
;
5289 struct compound_hdr hdr
;
5292 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5293 status
= decode_compound_hdr(&xdr
, &hdr
);
5296 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5299 status
= decode_putfh(&xdr
);
5302 status
= decode_commit(&xdr
, res
);
5305 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5306 !RPC_IS_ASYNC(rqstp
->rq_task
));
5314 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, __be32
*p
,
5315 struct nfs4_fsinfo_res
*res
)
5317 struct xdr_stream xdr
;
5318 struct compound_hdr hdr
;
5321 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5322 status
= decode_compound_hdr(&xdr
, &hdr
);
5324 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5326 status
= decode_putfh(&xdr
);
5328 status
= decode_fsinfo(&xdr
, res
->fsinfo
);
5335 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, __be32
*p
,
5336 struct nfs4_pathconf_res
*res
)
5338 struct xdr_stream xdr
;
5339 struct compound_hdr hdr
;
5342 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5343 status
= decode_compound_hdr(&xdr
, &hdr
);
5345 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5347 status
= decode_putfh(&xdr
);
5349 status
= decode_pathconf(&xdr
, res
->pathconf
);
5356 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, __be32
*p
,
5357 struct nfs4_statfs_res
*res
)
5359 struct xdr_stream xdr
;
5360 struct compound_hdr hdr
;
5363 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5364 status
= decode_compound_hdr(&xdr
, &hdr
);
5366 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5368 status
= decode_putfh(&xdr
);
5370 status
= decode_statfs(&xdr
, res
->fsstat
);
5375 * GETATTR_BITMAP request
5377 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_server_caps_res
*res
)
5379 struct xdr_stream xdr
;
5380 struct compound_hdr hdr
;
5383 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5384 status
= decode_compound_hdr(&xdr
, &hdr
);
5387 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5390 if ((status
= decode_putfh(&xdr
)) != 0)
5392 status
= decode_server_caps(&xdr
, res
);
5398 * Decode RENEW response
5400 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, __be32
*p
, void *dummy
)
5402 struct xdr_stream xdr
;
5403 struct compound_hdr hdr
;
5406 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5407 status
= decode_compound_hdr(&xdr
, &hdr
);
5409 status
= decode_renew(&xdr
);
5414 * a SETCLIENTID request
5416 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, __be32
*p
,
5417 struct nfs_client
*clp
)
5419 struct xdr_stream xdr
;
5420 struct compound_hdr hdr
;
5423 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5424 status
= decode_compound_hdr(&xdr
, &hdr
);
5426 status
= decode_setclientid(&xdr
, clp
);
5431 * a SETCLIENTID_CONFIRM request
5433 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
5435 struct xdr_stream xdr
;
5436 struct compound_hdr hdr
;
5439 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5440 status
= decode_compound_hdr(&xdr
, &hdr
);
5442 status
= decode_setclientid_confirm(&xdr
);
5444 status
= decode_putrootfh(&xdr
);
5446 status
= decode_fsinfo(&xdr
, fsinfo
);
5451 * DELEGRETURN request
5453 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_delegreturnres
*res
)
5455 struct xdr_stream xdr
;
5456 struct compound_hdr hdr
;
5459 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5460 status
= decode_compound_hdr(&xdr
, &hdr
);
5463 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5466 status
= decode_putfh(&xdr
);
5469 status
= decode_delegreturn(&xdr
);
5470 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5471 !RPC_IS_ASYNC(rqstp
->rq_task
));
5477 * FS_LOCATIONS request
5479 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
, __be32
*p
,
5480 struct nfs4_fs_locations_res
*res
)
5482 struct xdr_stream xdr
;
5483 struct compound_hdr hdr
;
5486 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5487 status
= decode_compound_hdr(&xdr
, &hdr
);
5490 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5493 if ((status
= decode_putfh(&xdr
)) != 0)
5495 if ((status
= decode_lookup(&xdr
)) != 0)
5497 xdr_enter_page(&xdr
, PAGE_SIZE
);
5498 status
= decode_getfattr(&xdr
, &res
->fs_locations
->fattr
,
5499 res
->fs_locations
->server
,
5500 !RPC_IS_ASYNC(req
->rq_task
));
5505 #if defined(CONFIG_NFS_V4_1)
5507 * EXCHANGE_ID request
5509 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
, uint32_t *p
,
5512 struct xdr_stream xdr
;
5513 struct compound_hdr hdr
;
5516 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5517 status
= decode_compound_hdr(&xdr
, &hdr
);
5519 status
= decode_exchange_id(&xdr
, res
);
5524 * a CREATE_SESSION request
5526 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
, uint32_t *p
,
5527 struct nfs41_create_session_res
*res
)
5529 struct xdr_stream xdr
;
5530 struct compound_hdr hdr
;
5533 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5534 status
= decode_compound_hdr(&xdr
, &hdr
);
5536 status
= decode_create_session(&xdr
, res
);
5541 * a DESTROY_SESSION request
5543 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
, uint32_t *p
,
5546 struct xdr_stream xdr
;
5547 struct compound_hdr hdr
;
5550 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5551 status
= decode_compound_hdr(&xdr
, &hdr
);
5553 status
= decode_destroy_session(&xdr
, dummy
);
5558 * a SEQUENCE request
5560 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
, uint32_t *p
,
5561 struct nfs4_sequence_res
*res
)
5563 struct xdr_stream xdr
;
5564 struct compound_hdr hdr
;
5567 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5568 status
= decode_compound_hdr(&xdr
, &hdr
);
5570 status
= decode_sequence(&xdr
, res
, rqstp
);
5575 * a GET_LEASE_TIME request
5577 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
, uint32_t *p
,
5578 struct nfs4_get_lease_time_res
*res
)
5580 struct xdr_stream xdr
;
5581 struct compound_hdr hdr
;
5584 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5585 status
= decode_compound_hdr(&xdr
, &hdr
);
5587 status
= decode_sequence(&xdr
, &res
->lr_seq_res
, rqstp
);
5589 status
= decode_putrootfh(&xdr
);
5591 status
= decode_fsinfo(&xdr
, res
->lr_fsinfo
);
5594 #endif /* CONFIG_NFS_V4_1 */
5596 __be32
*nfs4_decode_dirent(__be32
*p
, struct nfs_entry
*entry
, int plus
)
5598 uint32_t bitmap
[2] = {0};
5603 return ERR_PTR(-EAGAIN
);
5605 return ERR_PTR(-EBADCOOKIE
);
5608 entry
->prev_cookie
= entry
->cookie
;
5609 p
= xdr_decode_hyper(p
, &entry
->cookie
);
5610 entry
->len
= ntohl(*p
++);
5611 entry
->name
= (const char *) p
;
5612 p
+= XDR_QUADLEN(entry
->len
);
5615 * In case the server doesn't return an inode number,
5616 * we fake one here. (We don't use inode number 0,
5617 * since glibc seems to choke on it...)
5621 len
= ntohl(*p
++); /* bitmap length */
5623 bitmap
[0] = ntohl(*p
++);
5625 bitmap
[1] = ntohl(*p
++);
5629 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
5631 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
5632 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
5633 /* Ignore the return value of rdattr_error for now */
5637 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
5638 xdr_decode_hyper(p
, &entry
->ino
);
5639 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
5640 xdr_decode_hyper(p
, &entry
->ino
);
5644 entry
->eof
= !p
[0] && p
[1];
5649 * We need to translate between nfs status return values and
5650 * the local errno values which may not be the same.
5657 { NFS4ERR_PERM
, -EPERM
},
5658 { NFS4ERR_NOENT
, -ENOENT
},
5659 { NFS4ERR_IO
, -errno_NFSERR_IO
},
5660 { NFS4ERR_NXIO
, -ENXIO
},
5661 { NFS4ERR_ACCESS
, -EACCES
},
5662 { NFS4ERR_EXIST
, -EEXIST
},
5663 { NFS4ERR_XDEV
, -EXDEV
},
5664 { NFS4ERR_NOTDIR
, -ENOTDIR
},
5665 { NFS4ERR_ISDIR
, -EISDIR
},
5666 { NFS4ERR_INVAL
, -EINVAL
},
5667 { NFS4ERR_FBIG
, -EFBIG
},
5668 { NFS4ERR_NOSPC
, -ENOSPC
},
5669 { NFS4ERR_ROFS
, -EROFS
},
5670 { NFS4ERR_MLINK
, -EMLINK
},
5671 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
5672 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
5673 { NFS4ERR_DQUOT
, -EDQUOT
},
5674 { NFS4ERR_STALE
, -ESTALE
},
5675 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
5676 { NFS4ERR_BADOWNER
, -EINVAL
},
5677 { NFS4ERR_BADNAME
, -EINVAL
},
5678 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
5679 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
5680 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
5681 { NFS4ERR_SERVERFAULT
, -ESERVERFAULT
},
5682 { NFS4ERR_BADTYPE
, -EBADTYPE
},
5683 { NFS4ERR_LOCKED
, -EAGAIN
},
5684 { NFS4ERR_SYMLINK
, -ELOOP
},
5685 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
5686 { NFS4ERR_DEADLOCK
, -EDEADLK
},
5687 { NFS4ERR_WRONGSEC
, -EPERM
}, /* FIXME: this needs
5688 * to be handled by a
5695 * Convert an NFS error code to a local one.
5696 * This one is used jointly by NFSv2 and NFSv3.
5699 nfs4_stat_to_errno(int stat
)
5702 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
5703 if (nfs_errtbl
[i
].stat
== stat
)
5704 return nfs_errtbl
[i
].errno
;
5706 if (stat
<= 10000 || stat
> 10100) {
5707 /* The server is looney tunes. */
5708 return -ESERVERFAULT
;
5710 /* If we cannot translate the error, the recovery routines should
5712 * Note: remaining NFSv4 error codes have values > 10000, so should
5713 * not conflict with native Linux error codes.
5718 #define PROC(proc, argtype, restype) \
5719 [NFSPROC4_CLNT_##proc] = { \
5720 .p_proc = NFSPROC4_COMPOUND, \
5721 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5722 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
5723 .p_arglen = NFS4_##argtype##_sz, \
5724 .p_replen = NFS4_##restype##_sz, \
5725 .p_statidx = NFSPROC4_CLNT_##proc, \
5729 struct rpc_procinfo nfs4_procedures
[] = {
5730 PROC(READ
, enc_read
, dec_read
),
5731 PROC(WRITE
, enc_write
, dec_write
),
5732 PROC(COMMIT
, enc_commit
, dec_commit
),
5733 PROC(OPEN
, enc_open
, dec_open
),
5734 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
5735 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
5736 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
5737 PROC(CLOSE
, enc_close
, dec_close
),
5738 PROC(SETATTR
, enc_setattr
, dec_setattr
),
5739 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
5740 PROC(RENEW
, enc_renew
, dec_renew
),
5741 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
5742 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
5743 PROC(LOCK
, enc_lock
, dec_lock
),
5744 PROC(LOCKT
, enc_lockt
, dec_lockt
),
5745 PROC(LOCKU
, enc_locku
, dec_locku
),
5746 PROC(ACCESS
, enc_access
, dec_access
),
5747 PROC(GETATTR
, enc_getattr
, dec_getattr
),
5748 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
5749 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
5750 PROC(REMOVE
, enc_remove
, dec_remove
),
5751 PROC(RENAME
, enc_rename
, dec_rename
),
5752 PROC(LINK
, enc_link
, dec_link
),
5753 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
5754 PROC(CREATE
, enc_create
, dec_create
),
5755 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
5756 PROC(STATFS
, enc_statfs
, dec_statfs
),
5757 PROC(READLINK
, enc_readlink
, dec_readlink
),
5758 PROC(READDIR
, enc_readdir
, dec_readdir
),
5759 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
5760 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
5761 PROC(GETACL
, enc_getacl
, dec_getacl
),
5762 PROC(SETACL
, enc_setacl
, dec_setacl
),
5763 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
5764 #if defined(CONFIG_NFS_V4_1)
5765 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
5766 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
5767 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
5768 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
5769 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
5770 #endif /* CONFIG_NFS_V4_1 */
5773 struct rpc_version nfs_version4
= {
5775 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
5776 .procs
= nfs4_procedures