4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/sunrpc/clnt.h>
48 #include <linux/sunrpc/msg_prot.h>
49 #include <linux/nfs.h>
50 #include <linux/nfs4.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
197 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
202 #define encode_link_maxsz (op_encode_hdr_maxsz + \
204 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
205 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 1 + encode_stateid_maxsz + 8)
208 #define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
218 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
222 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
226 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227 #define encode_create_maxsz (op_encode_hdr_maxsz + \
228 1 + 2 + nfs4_name_maxsz + \
230 #define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
233 #define encode_statfs_maxsz (encode_getattr_maxsz)
234 #define decode_statfs_maxsz (decode_getattr_maxsz)
235 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
237 #define encode_getacl_maxsz (encode_getattr_maxsz)
238 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242 #define decode_setacl_maxsz (decode_setattr_maxsz)
243 #define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245 #define decode_fs_locations_maxsz \
248 #if defined(CONFIG_NFS_V4_1)
249 #define NFS4_MAX_MACHINE_NAME_LEN (64)
251 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
252 encode_verifier_maxsz + \
253 1 /* co_ownerid.len */ + \
254 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
257 0 /* SP4_NONE (for now) */ + \
258 1 /* zero implemetation id array */)
259 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
260 2 /* eir_clientid */ + \
261 1 /* eir_sequenceid */ + \
262 1 /* eir_flags */ + \
264 0 /* SP4_NONE (for now) */ + \
265 2 /* eir_server_owner.so_minor_id */ + \
266 /* eir_server_owner.so_major_id<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 /* eir_server_scope<> */ \
269 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
270 1 /* eir_server_impl_id array length */ + \
271 0 /* ignored eir_server_impl_id contents */)
272 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
273 #define decode_channel_attrs_maxsz (6 + \
274 1 /* ca_rdma_ird.len */ + \
276 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
277 2 /* csa_clientid */ + \
278 1 /* csa_sequence */ + \
279 1 /* csa_flags */ + \
280 encode_channel_attrs_maxsz + \
281 encode_channel_attrs_maxsz + \
282 1 /* csa_cb_program */ + \
283 1 /* csa_sec_parms.len (1) */ + \
284 1 /* cb_secflavor (AUTH_SYS) */ + \
286 1 /* machinename.len */ + \
287 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
290 1 /* gids.len (0) */)
291 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
292 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
293 1 /* csr_sequence */ + \
294 1 /* csr_flags */ + \
295 decode_channel_attrs_maxsz + \
296 decode_channel_attrs_maxsz)
297 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
298 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
299 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
301 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
302 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
303 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
304 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
305 #else /* CONFIG_NFS_V4_1 */
306 #define encode_sequence_maxsz 0
307 #define decode_sequence_maxsz 0
308 #endif /* CONFIG_NFS_V4_1 */
310 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
311 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
312 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
313 encode_sequence_maxsz + \
314 encode_putfh_maxsz + \
316 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
317 decode_sequence_maxsz + \
318 decode_putfh_maxsz + \
320 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
321 encode_sequence_maxsz + \
322 encode_putfh_maxsz + \
323 encode_readlink_maxsz)
324 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
325 decode_sequence_maxsz + \
326 decode_putfh_maxsz + \
327 decode_readlink_maxsz)
328 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
329 encode_sequence_maxsz + \
330 encode_putfh_maxsz + \
331 encode_readdir_maxsz)
332 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
333 decode_sequence_maxsz + \
334 decode_putfh_maxsz + \
335 decode_readdir_maxsz)
336 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
337 encode_sequence_maxsz + \
338 encode_putfh_maxsz + \
339 encode_write_maxsz + \
340 encode_getattr_maxsz)
341 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
342 decode_sequence_maxsz + \
343 decode_putfh_maxsz + \
344 decode_write_maxsz + \
345 decode_getattr_maxsz)
346 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
347 encode_sequence_maxsz + \
348 encode_putfh_maxsz + \
349 encode_commit_maxsz + \
350 encode_getattr_maxsz)
351 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
352 decode_sequence_maxsz + \
353 decode_putfh_maxsz + \
354 decode_commit_maxsz + \
355 decode_getattr_maxsz)
356 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
357 encode_sequence_maxsz + \
358 encode_putfh_maxsz + \
359 encode_savefh_maxsz + \
360 encode_open_maxsz + \
361 encode_getfh_maxsz + \
362 encode_getattr_maxsz + \
363 encode_restorefh_maxsz + \
364 encode_getattr_maxsz)
365 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
366 decode_sequence_maxsz + \
367 decode_putfh_maxsz + \
368 decode_savefh_maxsz + \
369 decode_open_maxsz + \
370 decode_getfh_maxsz + \
371 decode_getattr_maxsz + \
372 decode_restorefh_maxsz + \
373 decode_getattr_maxsz)
374 #define NFS4_enc_open_confirm_sz \
375 (compound_encode_hdr_maxsz + \
376 encode_putfh_maxsz + \
377 encode_open_confirm_maxsz)
378 #define NFS4_dec_open_confirm_sz \
379 (compound_decode_hdr_maxsz + \
380 decode_putfh_maxsz + \
381 decode_open_confirm_maxsz)
382 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
383 encode_sequence_maxsz + \
384 encode_putfh_maxsz + \
385 encode_open_maxsz + \
386 encode_getattr_maxsz)
387 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
388 decode_sequence_maxsz + \
389 decode_putfh_maxsz + \
390 decode_open_maxsz + \
391 decode_getattr_maxsz)
392 #define NFS4_enc_open_downgrade_sz \
393 (compound_encode_hdr_maxsz + \
394 encode_sequence_maxsz + \
395 encode_putfh_maxsz + \
396 encode_open_downgrade_maxsz + \
397 encode_getattr_maxsz)
398 #define NFS4_dec_open_downgrade_sz \
399 (compound_decode_hdr_maxsz + \
400 decode_sequence_maxsz + \
401 decode_putfh_maxsz + \
402 decode_open_downgrade_maxsz + \
403 decode_getattr_maxsz)
404 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
405 encode_sequence_maxsz + \
406 encode_putfh_maxsz + \
407 encode_close_maxsz + \
408 encode_getattr_maxsz)
409 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
410 decode_sequence_maxsz + \
411 decode_putfh_maxsz + \
412 decode_close_maxsz + \
413 decode_getattr_maxsz)
414 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
415 encode_sequence_maxsz + \
416 encode_putfh_maxsz + \
417 encode_setattr_maxsz + \
418 encode_getattr_maxsz)
419 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
420 decode_sequence_maxsz + \
421 decode_putfh_maxsz + \
422 decode_setattr_maxsz + \
423 decode_getattr_maxsz)
424 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
425 encode_sequence_maxsz + \
426 encode_putfh_maxsz + \
428 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
429 decode_sequence_maxsz + \
430 decode_putfh_maxsz + \
432 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
434 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
436 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
437 encode_setclientid_maxsz)
438 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
439 decode_setclientid_maxsz)
440 #define NFS4_enc_setclientid_confirm_sz \
441 (compound_encode_hdr_maxsz + \
442 encode_setclientid_confirm_maxsz + \
443 encode_putrootfh_maxsz + \
445 #define NFS4_dec_setclientid_confirm_sz \
446 (compound_decode_hdr_maxsz + \
447 decode_setclientid_confirm_maxsz + \
448 decode_putrootfh_maxsz + \
450 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
451 encode_sequence_maxsz + \
452 encode_putfh_maxsz + \
454 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
455 decode_sequence_maxsz + \
456 decode_putfh_maxsz + \
458 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
459 encode_sequence_maxsz + \
460 encode_putfh_maxsz + \
462 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
463 decode_sequence_maxsz + \
464 decode_putfh_maxsz + \
466 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
467 encode_sequence_maxsz + \
468 encode_putfh_maxsz + \
470 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
471 decode_sequence_maxsz + \
472 decode_putfh_maxsz + \
474 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
475 encode_sequence_maxsz + \
476 encode_putfh_maxsz + \
477 encode_access_maxsz + \
478 encode_getattr_maxsz)
479 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
480 decode_sequence_maxsz + \
481 decode_putfh_maxsz + \
482 decode_access_maxsz + \
483 decode_getattr_maxsz)
484 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
485 encode_sequence_maxsz + \
486 encode_putfh_maxsz + \
487 encode_getattr_maxsz)
488 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
489 decode_sequence_maxsz + \
490 decode_putfh_maxsz + \
491 decode_getattr_maxsz)
492 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
493 encode_sequence_maxsz + \
494 encode_putfh_maxsz + \
495 encode_lookup_maxsz + \
496 encode_getattr_maxsz + \
498 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
499 decode_sequence_maxsz + \
500 decode_putfh_maxsz + \
501 decode_lookup_maxsz + \
502 decode_getattr_maxsz + \
504 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
505 encode_sequence_maxsz + \
506 encode_putrootfh_maxsz + \
507 encode_getattr_maxsz + \
509 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
510 decode_sequence_maxsz + \
511 decode_putrootfh_maxsz + \
512 decode_getattr_maxsz + \
514 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
515 encode_sequence_maxsz + \
516 encode_putfh_maxsz + \
517 encode_remove_maxsz + \
518 encode_getattr_maxsz)
519 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
520 decode_sequence_maxsz + \
521 decode_putfh_maxsz + \
522 decode_remove_maxsz + \
523 decode_getattr_maxsz)
524 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
525 encode_sequence_maxsz + \
526 encode_putfh_maxsz + \
527 encode_savefh_maxsz + \
528 encode_putfh_maxsz + \
529 encode_rename_maxsz + \
530 encode_getattr_maxsz + \
531 encode_restorefh_maxsz + \
532 encode_getattr_maxsz)
533 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
534 decode_sequence_maxsz + \
535 decode_putfh_maxsz + \
536 decode_savefh_maxsz + \
537 decode_putfh_maxsz + \
538 decode_rename_maxsz + \
539 decode_getattr_maxsz + \
540 decode_restorefh_maxsz + \
541 decode_getattr_maxsz)
542 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
543 encode_sequence_maxsz + \
544 encode_putfh_maxsz + \
545 encode_savefh_maxsz + \
546 encode_putfh_maxsz + \
547 encode_link_maxsz + \
548 decode_getattr_maxsz + \
549 encode_restorefh_maxsz + \
550 decode_getattr_maxsz)
551 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
552 decode_sequence_maxsz + \
553 decode_putfh_maxsz + \
554 decode_savefh_maxsz + \
555 decode_putfh_maxsz + \
556 decode_link_maxsz + \
557 decode_getattr_maxsz + \
558 decode_restorefh_maxsz + \
559 decode_getattr_maxsz)
560 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
561 encode_sequence_maxsz + \
562 encode_putfh_maxsz + \
563 encode_symlink_maxsz + \
564 encode_getattr_maxsz + \
566 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
567 decode_sequence_maxsz + \
568 decode_putfh_maxsz + \
569 decode_symlink_maxsz + \
570 decode_getattr_maxsz + \
572 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
573 encode_sequence_maxsz + \
574 encode_putfh_maxsz + \
575 encode_savefh_maxsz + \
576 encode_create_maxsz + \
577 encode_getfh_maxsz + \
578 encode_getattr_maxsz + \
579 encode_restorefh_maxsz + \
580 encode_getattr_maxsz)
581 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
582 decode_sequence_maxsz + \
583 decode_putfh_maxsz + \
584 decode_savefh_maxsz + \
585 decode_create_maxsz + \
586 decode_getfh_maxsz + \
587 decode_getattr_maxsz + \
588 decode_restorefh_maxsz + \
589 decode_getattr_maxsz)
590 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
591 encode_sequence_maxsz + \
592 encode_putfh_maxsz + \
593 encode_getattr_maxsz)
594 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
595 decode_sequence_maxsz + \
596 decode_putfh_maxsz + \
597 decode_getattr_maxsz)
598 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
599 encode_sequence_maxsz + \
600 encode_putfh_maxsz + \
602 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
603 decode_sequence_maxsz + \
604 decode_putfh_maxsz + \
606 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
607 encode_sequence_maxsz + \
608 encode_putfh_maxsz + \
609 encode_getattr_maxsz)
610 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
611 decode_sequence_maxsz + \
612 decode_putfh_maxsz + \
613 decode_getattr_maxsz)
614 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
615 encode_sequence_maxsz + \
616 encode_putfh_maxsz + \
617 encode_delegreturn_maxsz + \
618 encode_getattr_maxsz)
619 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
620 decode_sequence_maxsz + \
621 decode_delegreturn_maxsz + \
622 decode_getattr_maxsz)
623 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
624 encode_sequence_maxsz + \
625 encode_putfh_maxsz + \
627 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
628 decode_sequence_maxsz + \
629 decode_putfh_maxsz + \
631 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
632 encode_sequence_maxsz + \
633 encode_putfh_maxsz + \
635 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
636 decode_sequence_maxsz + \
637 decode_putfh_maxsz + \
639 #define NFS4_enc_fs_locations_sz \
640 (compound_encode_hdr_maxsz + \
641 encode_sequence_maxsz + \
642 encode_putfh_maxsz + \
643 encode_lookup_maxsz + \
644 encode_fs_locations_maxsz)
645 #define NFS4_dec_fs_locations_sz \
646 (compound_decode_hdr_maxsz + \
647 decode_sequence_maxsz + \
648 decode_putfh_maxsz + \
649 decode_lookup_maxsz + \
650 decode_fs_locations_maxsz)
651 #if defined(CONFIG_NFS_V4_1)
652 #define NFS4_enc_exchange_id_sz \
653 (compound_encode_hdr_maxsz + \
654 encode_exchange_id_maxsz)
655 #define NFS4_dec_exchange_id_sz \
656 (compound_decode_hdr_maxsz + \
657 decode_exchange_id_maxsz)
658 #define NFS4_enc_create_session_sz \
659 (compound_encode_hdr_maxsz + \
660 encode_create_session_maxsz)
661 #define NFS4_dec_create_session_sz \
662 (compound_decode_hdr_maxsz + \
663 decode_create_session_maxsz)
664 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
665 encode_destroy_session_maxsz)
666 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
667 decode_destroy_session_maxsz)
668 #define NFS4_enc_sequence_sz \
669 (compound_decode_hdr_maxsz + \
670 encode_sequence_maxsz)
671 #define NFS4_dec_sequence_sz \
672 (compound_decode_hdr_maxsz + \
673 decode_sequence_maxsz)
674 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
675 encode_sequence_maxsz + \
676 encode_putrootfh_maxsz + \
678 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
679 decode_sequence_maxsz + \
680 decode_putrootfh_maxsz + \
682 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
683 encode_sequence_maxsz + \
684 encode_reclaim_complete_maxsz)
685 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
686 decode_sequence_maxsz + \
687 decode_reclaim_complete_maxsz)
689 const u32 nfs41_maxwrite_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
690 compound_encode_hdr_maxsz
+
691 encode_sequence_maxsz
+
693 encode_getattr_maxsz
) *
696 const u32 nfs41_maxread_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
697 compound_decode_hdr_maxsz
+
698 decode_sequence_maxsz
+
699 decode_putfh_maxsz
) *
701 #endif /* CONFIG_NFS_V4_1 */
703 static const umode_t nfs_type2fmt
[] = {
710 [NF4SOCK
] = S_IFSOCK
,
716 struct compound_hdr
{
722 uint32_t replen
; /* expected reply words */
726 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
728 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
733 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
737 p
= xdr_reserve_space(xdr
, 4 + len
);
739 xdr_encode_opaque(p
, str
, len
);
742 static void encode_compound_hdr(struct xdr_stream
*xdr
,
743 struct rpc_rqst
*req
,
744 struct compound_hdr
*hdr
)
747 struct rpc_auth
*auth
= req
->rq_task
->tk_msg
.rpc_cred
->cr_auth
;
749 /* initialize running count of expected bytes in reply.
750 * NOTE: the replied tag SHOULD be the same is the one sent,
751 * but this is not required as a MUST for the server to do so. */
752 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
754 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
755 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
756 p
= reserve_space(xdr
, 4 + hdr
->taglen
+ 8);
757 p
= xdr_encode_opaque(p
, hdr
->tag
, hdr
->taglen
);
758 *p
++ = cpu_to_be32(hdr
->minorversion
);
760 *p
= cpu_to_be32(hdr
->nops
);
763 static void encode_nops(struct compound_hdr
*hdr
)
765 BUG_ON(hdr
->nops
> NFS4_MAX_OPS
);
766 *hdr
->nops_p
= htonl(hdr
->nops
);
769 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
773 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
775 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
778 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
780 char owner_name
[IDMAP_NAMESZ
];
781 char owner_group
[IDMAP_NAMESZ
];
782 int owner_namelen
= 0;
783 int owner_grouplen
= 0;
791 * We reserve enough space to write the entire attribute buffer at once.
792 * In the worst-case, this would be
793 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
794 * = 36 bytes, plus any contribution from variable-length fields
795 * such as owner/group.
800 if (iap
->ia_valid
& ATTR_SIZE
)
802 if (iap
->ia_valid
& ATTR_MODE
)
804 if (iap
->ia_valid
& ATTR_UID
) {
805 owner_namelen
= nfs_map_uid_to_name(server
->nfs_client
, iap
->ia_uid
, owner_name
);
806 if (owner_namelen
< 0) {
807 dprintk("nfs: couldn't resolve uid %d to string\n",
810 strcpy(owner_name
, "nobody");
811 owner_namelen
= sizeof("nobody") - 1;
814 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
816 if (iap
->ia_valid
& ATTR_GID
) {
817 owner_grouplen
= nfs_map_gid_to_group(server
->nfs_client
, iap
->ia_gid
, owner_group
);
818 if (owner_grouplen
< 0) {
819 dprintk("nfs: couldn't resolve gid %d to string\n",
821 strcpy(owner_group
, "nobody");
822 owner_grouplen
= sizeof("nobody") - 1;
825 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
827 if (iap
->ia_valid
& ATTR_ATIME_SET
)
829 else if (iap
->ia_valid
& ATTR_ATIME
)
831 if (iap
->ia_valid
& ATTR_MTIME_SET
)
833 else if (iap
->ia_valid
& ATTR_MTIME
)
835 p
= reserve_space(xdr
, len
);
838 * We write the bitmap length now, but leave the bitmap and the attribute
839 * buffer length to be backfilled at the end of this routine.
841 *p
++ = cpu_to_be32(2);
845 if (iap
->ia_valid
& ATTR_SIZE
) {
846 bmval0
|= FATTR4_WORD0_SIZE
;
847 p
= xdr_encode_hyper(p
, iap
->ia_size
);
849 if (iap
->ia_valid
& ATTR_MODE
) {
850 bmval1
|= FATTR4_WORD1_MODE
;
851 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
853 if (iap
->ia_valid
& ATTR_UID
) {
854 bmval1
|= FATTR4_WORD1_OWNER
;
855 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
857 if (iap
->ia_valid
& ATTR_GID
) {
858 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
859 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
861 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
862 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
863 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
864 *p
++ = cpu_to_be32(0);
865 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_sec
);
866 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
868 else if (iap
->ia_valid
& ATTR_ATIME
) {
869 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
870 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
872 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
873 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
874 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
875 *p
++ = cpu_to_be32(0);
876 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_sec
);
877 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
879 else if (iap
->ia_valid
& ATTR_MTIME
) {
880 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
881 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
885 * Now we backfill the bitmap and the attribute buffer length.
887 if (len
!= ((char *)p
- (char *)q
) + 4) {
888 printk(KERN_ERR
"nfs: Attr length error, %u != %Zu\n",
889 len
, ((char *)p
- (char *)q
) + 4);
892 len
= (char *)p
- (char *)q
- 12;
893 *q
++ = htonl(bmval0
);
894 *q
++ = htonl(bmval1
);
900 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
904 p
= reserve_space(xdr
, 8);
905 *p
++ = cpu_to_be32(OP_ACCESS
);
906 *p
= cpu_to_be32(access
);
908 hdr
->replen
+= decode_access_maxsz
;
911 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
915 p
= reserve_space(xdr
, 8+NFS4_STATEID_SIZE
);
916 *p
++ = cpu_to_be32(OP_CLOSE
);
917 *p
++ = cpu_to_be32(arg
->seqid
->sequence
->counter
);
918 xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
920 hdr
->replen
+= decode_close_maxsz
;
923 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
927 p
= reserve_space(xdr
, 16);
928 *p
++ = cpu_to_be32(OP_COMMIT
);
929 p
= xdr_encode_hyper(p
, args
->offset
);
930 *p
= cpu_to_be32(args
->count
);
932 hdr
->replen
+= decode_commit_maxsz
;
935 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
939 p
= reserve_space(xdr
, 8);
940 *p
++ = cpu_to_be32(OP_CREATE
);
941 *p
= cpu_to_be32(create
->ftype
);
943 switch (create
->ftype
) {
945 p
= reserve_space(xdr
, 4);
946 *p
= cpu_to_be32(create
->u
.symlink
.len
);
947 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
950 case NF4BLK
: case NF4CHR
:
951 p
= reserve_space(xdr
, 8);
952 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
953 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
960 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
962 hdr
->replen
+= decode_create_maxsz
;
964 encode_attrs(xdr
, create
->attrs
, create
->server
);
967 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
971 p
= reserve_space(xdr
, 12);
972 *p
++ = cpu_to_be32(OP_GETATTR
);
973 *p
++ = cpu_to_be32(1);
974 *p
= cpu_to_be32(bitmap
);
976 hdr
->replen
+= decode_getattr_maxsz
;
979 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
983 p
= reserve_space(xdr
, 16);
984 *p
++ = cpu_to_be32(OP_GETATTR
);
985 *p
++ = cpu_to_be32(2);
986 *p
++ = cpu_to_be32(bm0
);
987 *p
= cpu_to_be32(bm1
);
989 hdr
->replen
+= decode_getattr_maxsz
;
992 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
994 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
995 bitmask
[1] & nfs4_fattr_bitmap
[1], hdr
);
998 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1000 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
1001 bitmask
[1] & nfs4_fsinfo_bitmap
[1], hdr
);
1004 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1006 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
1007 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
1010 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1014 p
= reserve_space(xdr
, 4);
1015 *p
= cpu_to_be32(OP_GETFH
);
1017 hdr
->replen
+= decode_getfh_maxsz
;
1020 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1024 p
= reserve_space(xdr
, 8 + name
->len
);
1025 *p
++ = cpu_to_be32(OP_LINK
);
1026 xdr_encode_opaque(p
, name
->name
, name
->len
);
1028 hdr
->replen
+= decode_link_maxsz
;
1031 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1033 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
1034 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1035 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1038 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1040 if (fl
->fl_end
== OFFSET_MAX
)
1041 return ~(uint64_t)0;
1042 return fl
->fl_end
- fl
->fl_start
+ 1;
1046 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1047 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1049 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1053 p
= reserve_space(xdr
, 32);
1054 *p
++ = cpu_to_be32(OP_LOCK
);
1055 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1056 *p
++ = cpu_to_be32(args
->reclaim
);
1057 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1058 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1059 *p
= cpu_to_be32(args
->new_lock_owner
);
1060 if (args
->new_lock_owner
){
1061 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+32);
1062 *p
++ = cpu_to_be32(args
->open_seqid
->sequence
->counter
);
1063 p
= xdr_encode_opaque_fixed(p
, args
->open_stateid
->data
, NFS4_STATEID_SIZE
);
1064 *p
++ = cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1065 p
= xdr_encode_hyper(p
, args
->lock_owner
.clientid
);
1066 *p
++ = cpu_to_be32(16);
1067 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1068 xdr_encode_hyper(p
, args
->lock_owner
.id
);
1071 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
+4);
1072 p
= xdr_encode_opaque_fixed(p
, args
->lock_stateid
->data
, NFS4_STATEID_SIZE
);
1073 *p
= cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1076 hdr
->replen
+= decode_lock_maxsz
;
1079 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1083 p
= reserve_space(xdr
, 52);
1084 *p
++ = cpu_to_be32(OP_LOCKT
);
1085 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1086 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1087 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1088 p
= xdr_encode_hyper(p
, args
->lock_owner
.clientid
);
1089 *p
++ = cpu_to_be32(16);
1090 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1091 xdr_encode_hyper(p
, args
->lock_owner
.id
);
1093 hdr
->replen
+= decode_lockt_maxsz
;
1096 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1100 p
= reserve_space(xdr
, 12+NFS4_STATEID_SIZE
+16);
1101 *p
++ = cpu_to_be32(OP_LOCKU
);
1102 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1103 *p
++ = cpu_to_be32(args
->seqid
->sequence
->counter
);
1104 p
= xdr_encode_opaque_fixed(p
, args
->stateid
->data
, NFS4_STATEID_SIZE
);
1105 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1106 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1108 hdr
->replen
+= decode_locku_maxsz
;
1111 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1113 int len
= name
->len
;
1116 p
= reserve_space(xdr
, 8 + len
);
1117 *p
++ = cpu_to_be32(OP_LOOKUP
);
1118 xdr_encode_opaque(p
, name
->name
, len
);
1120 hdr
->replen
+= decode_lookup_maxsz
;
1123 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
1127 p
= reserve_space(xdr
, 8);
1128 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1130 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ
);
1133 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE
);
1135 case FMODE_READ
|FMODE_WRITE
:
1136 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH
);
1139 *p
++ = cpu_to_be32(0);
1141 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1144 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1148 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1151 p
= reserve_space(xdr
, 8);
1152 *p
++ = cpu_to_be32(OP_OPEN
);
1153 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1154 encode_share_access(xdr
, arg
->fmode
);
1155 p
= reserve_space(xdr
, 28);
1156 p
= xdr_encode_hyper(p
, arg
->clientid
);
1157 *p
++ = cpu_to_be32(16);
1158 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1159 xdr_encode_hyper(p
, arg
->id
);
1162 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1165 struct nfs_client
*clp
;
1167 p
= reserve_space(xdr
, 4);
1168 switch(arg
->open_flags
& O_EXCL
) {
1170 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1171 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1174 clp
= arg
->server
->nfs_client
;
1175 if (clp
->cl_minorversion
> 0) {
1176 if (nfs4_has_persistent_session(clp
)) {
1177 *p
= cpu_to_be32(NFS4_CREATE_GUARDED
);
1178 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1182 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1183 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1185 encode_attrs(xdr
, &dummy
, arg
->server
);
1188 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1189 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1194 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1198 p
= reserve_space(xdr
, 4);
1199 switch (arg
->open_flags
& O_CREAT
) {
1201 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1204 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
1205 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1206 encode_createmode(xdr
, arg
);
1210 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1214 p
= reserve_space(xdr
, 4);
1215 switch (delegation_type
) {
1217 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1220 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1222 case FMODE_WRITE
|FMODE_READ
:
1223 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1230 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1234 p
= reserve_space(xdr
, 4);
1235 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1236 encode_string(xdr
, name
->len
, name
->name
);
1239 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1243 p
= reserve_space(xdr
, 4);
1244 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1245 encode_delegation_type(xdr
, type
);
1248 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1252 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1253 *p
++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1254 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1255 encode_string(xdr
, name
->len
, name
->name
);
1258 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1260 encode_openhdr(xdr
, arg
);
1261 encode_opentype(xdr
, arg
);
1262 switch (arg
->claim
) {
1263 case NFS4_OPEN_CLAIM_NULL
:
1264 encode_claim_null(xdr
, arg
->name
);
1266 case NFS4_OPEN_CLAIM_PREVIOUS
:
1267 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1269 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1270 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1276 hdr
->replen
+= decode_open_maxsz
;
1279 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1283 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1284 *p
++ = cpu_to_be32(OP_OPEN_CONFIRM
);
1285 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1286 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1288 hdr
->replen
+= decode_open_confirm_maxsz
;
1291 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1295 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1296 *p
++ = cpu_to_be32(OP_OPEN_DOWNGRADE
);
1297 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1298 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1299 encode_share_access(xdr
, arg
->fmode
);
1301 hdr
->replen
+= decode_open_downgrade_maxsz
;
1305 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1310 p
= reserve_space(xdr
, 8 + len
);
1311 *p
++ = cpu_to_be32(OP_PUTFH
);
1312 xdr_encode_opaque(p
, fh
->data
, len
);
1314 hdr
->replen
+= decode_putfh_maxsz
;
1317 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1321 p
= reserve_space(xdr
, 4);
1322 *p
= cpu_to_be32(OP_PUTROOTFH
);
1324 hdr
->replen
+= decode_putrootfh_maxsz
;
1327 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
)
1329 nfs4_stateid stateid
;
1332 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
);
1333 if (ctx
->state
!= NULL
) {
1334 nfs4_copy_stateid(&stateid
, ctx
->state
, ctx
->lockowner
);
1335 xdr_encode_opaque_fixed(p
, stateid
.data
, NFS4_STATEID_SIZE
);
1337 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1340 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
, struct compound_hdr
*hdr
)
1344 p
= reserve_space(xdr
, 4);
1345 *p
= cpu_to_be32(OP_READ
);
1347 encode_stateid(xdr
, args
->context
);
1349 p
= reserve_space(xdr
, 12);
1350 p
= xdr_encode_hyper(p
, args
->offset
);
1351 *p
= cpu_to_be32(args
->count
);
1353 hdr
->replen
+= decode_read_maxsz
;
1356 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1358 uint32_t attrs
[2] = {
1359 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1360 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1364 p
= reserve_space(xdr
, 12+NFS4_VERIFIER_SIZE
+20);
1365 *p
++ = cpu_to_be32(OP_READDIR
);
1366 p
= xdr_encode_hyper(p
, readdir
->cookie
);
1367 p
= xdr_encode_opaque_fixed(p
, readdir
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1368 *p
++ = cpu_to_be32(readdir
->count
>> 1); /* We're not doing readdirplus */
1369 *p
++ = cpu_to_be32(readdir
->count
);
1370 *p
++ = cpu_to_be32(2);
1371 /* Switch to mounted_on_fileid if the server supports it */
1372 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1373 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1375 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1376 *p
++ = cpu_to_be32(attrs
[0] & readdir
->bitmask
[0]);
1377 *p
= cpu_to_be32(attrs
[1] & readdir
->bitmask
[1]);
1379 hdr
->replen
+= decode_readdir_maxsz
;
1380 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1382 (unsigned long long)readdir
->cookie
,
1383 ((u32
*)readdir
->verifier
.data
)[0],
1384 ((u32
*)readdir
->verifier
.data
)[1],
1385 attrs
[0] & readdir
->bitmask
[0],
1386 attrs
[1] & readdir
->bitmask
[1]);
1389 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1393 p
= reserve_space(xdr
, 4);
1394 *p
= cpu_to_be32(OP_READLINK
);
1396 hdr
->replen
+= decode_readlink_maxsz
;
1399 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1403 p
= reserve_space(xdr
, 8 + name
->len
);
1404 *p
++ = cpu_to_be32(OP_REMOVE
);
1405 xdr_encode_opaque(p
, name
->name
, name
->len
);
1407 hdr
->replen
+= decode_remove_maxsz
;
1410 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1414 p
= reserve_space(xdr
, 4);
1415 *p
= cpu_to_be32(OP_RENAME
);
1416 encode_string(xdr
, oldname
->len
, oldname
->name
);
1417 encode_string(xdr
, newname
->len
, newname
->name
);
1419 hdr
->replen
+= decode_rename_maxsz
;
1422 static void encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
, struct compound_hdr
*hdr
)
1426 p
= reserve_space(xdr
, 12);
1427 *p
++ = cpu_to_be32(OP_RENEW
);
1428 xdr_encode_hyper(p
, client_stateid
->cl_clientid
);
1430 hdr
->replen
+= decode_renew_maxsz
;
1434 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1438 p
= reserve_space(xdr
, 4);
1439 *p
= cpu_to_be32(OP_RESTOREFH
);
1441 hdr
->replen
+= decode_restorefh_maxsz
;
1445 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1449 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1450 *p
++ = cpu_to_be32(OP_SETATTR
);
1451 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1452 p
= reserve_space(xdr
, 2*4);
1453 *p
++ = cpu_to_be32(1);
1454 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1455 if (arg
->acl_len
% 4)
1457 p
= reserve_space(xdr
, 4);
1458 *p
= cpu_to_be32(arg
->acl_len
);
1459 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1461 hdr
->replen
+= decode_setacl_maxsz
;
1466 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1470 p
= reserve_space(xdr
, 4);
1471 *p
= cpu_to_be32(OP_SAVEFH
);
1473 hdr
->replen
+= decode_savefh_maxsz
;
1476 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1480 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1481 *p
++ = cpu_to_be32(OP_SETATTR
);
1482 xdr_encode_opaque_fixed(p
, arg
->stateid
.data
, NFS4_STATEID_SIZE
);
1484 hdr
->replen
+= decode_setattr_maxsz
;
1485 encode_attrs(xdr
, arg
->iap
, server
);
1488 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1492 p
= reserve_space(xdr
, 4 + NFS4_VERIFIER_SIZE
);
1493 *p
++ = cpu_to_be32(OP_SETCLIENTID
);
1494 xdr_encode_opaque_fixed(p
, setclientid
->sc_verifier
->data
, NFS4_VERIFIER_SIZE
);
1496 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1497 p
= reserve_space(xdr
, 4);
1498 *p
= cpu_to_be32(setclientid
->sc_prog
);
1499 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1500 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1501 p
= reserve_space(xdr
, 4);
1502 *p
= cpu_to_be32(setclientid
->sc_cb_ident
);
1504 hdr
->replen
+= decode_setclientid_maxsz
;
1507 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_setclientid_res
*arg
, struct compound_hdr
*hdr
)
1511 p
= reserve_space(xdr
, 12 + NFS4_VERIFIER_SIZE
);
1512 *p
++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM
);
1513 p
= xdr_encode_hyper(p
, arg
->clientid
);
1514 xdr_encode_opaque_fixed(p
, arg
->confirm
.data
, NFS4_VERIFIER_SIZE
);
1516 hdr
->replen
+= decode_setclientid_confirm_maxsz
;
1519 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1523 p
= reserve_space(xdr
, 4);
1524 *p
= cpu_to_be32(OP_WRITE
);
1526 encode_stateid(xdr
, args
->context
);
1528 p
= reserve_space(xdr
, 16);
1529 p
= xdr_encode_hyper(p
, args
->offset
);
1530 *p
++ = cpu_to_be32(args
->stable
);
1531 *p
= cpu_to_be32(args
->count
);
1533 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1535 hdr
->replen
+= decode_write_maxsz
;
1538 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1542 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1544 *p
++ = cpu_to_be32(OP_DELEGRETURN
);
1545 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1547 hdr
->replen
+= decode_delegreturn_maxsz
;
1550 #if defined(CONFIG_NFS_V4_1)
1551 /* NFSv4.1 operations */
1552 static void encode_exchange_id(struct xdr_stream
*xdr
,
1553 struct nfs41_exchange_id_args
*args
,
1554 struct compound_hdr
*hdr
)
1558 p
= reserve_space(xdr
, 4 + sizeof(args
->verifier
->data
));
1559 *p
++ = cpu_to_be32(OP_EXCHANGE_ID
);
1560 xdr_encode_opaque_fixed(p
, args
->verifier
->data
, sizeof(args
->verifier
->data
));
1562 encode_string(xdr
, args
->id_len
, args
->id
);
1564 p
= reserve_space(xdr
, 12);
1565 *p
++ = cpu_to_be32(args
->flags
);
1566 *p
++ = cpu_to_be32(0); /* zero length state_protect4_a */
1567 *p
= cpu_to_be32(0); /* zero length implementation id array */
1569 hdr
->replen
+= decode_exchange_id_maxsz
;
1572 static void encode_create_session(struct xdr_stream
*xdr
,
1573 struct nfs41_create_session_args
*args
,
1574 struct compound_hdr
*hdr
)
1577 char machine_name
[NFS4_MAX_MACHINE_NAME_LEN
];
1579 struct nfs_client
*clp
= args
->client
;
1580 u32 max_resp_sz_cached
;
1583 * Assumes OPEN is the biggest non-idempotent compound.
1584 * 2 is the verifier.
1586 max_resp_sz_cached
= (NFS4_dec_open_sz
+ RPC_REPHDRSIZE
+
1587 RPC_MAX_AUTH_SIZE
+ 2) * XDR_UNIT
;
1589 len
= scnprintf(machine_name
, sizeof(machine_name
), "%s",
1592 p
= reserve_space(xdr
, 20 + 2*28 + 20 + len
+ 12);
1593 *p
++ = cpu_to_be32(OP_CREATE_SESSION
);
1594 p
= xdr_encode_hyper(p
, clp
->cl_ex_clid
);
1595 *p
++ = cpu_to_be32(clp
->cl_seqid
); /*Sequence id */
1596 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1599 *p
++ = cpu_to_be32(args
->fc_attrs
.headerpadsz
); /* header padding size */
1600 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1601 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1602 *p
++ = cpu_to_be32(max_resp_sz_cached
); /* Max resp sz cached */
1603 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1604 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1605 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1608 *p
++ = cpu_to_be32(args
->fc_attrs
.headerpadsz
); /* header padding size */
1609 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1610 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1611 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1612 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1613 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1614 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1616 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1617 *p
++ = cpu_to_be32(1);
1618 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1620 /* authsys_parms rfc1831 */
1621 *p
++ = cpu_to_be32((u32
)clp
->cl_boot_time
.tv_nsec
); /* stamp */
1622 p
= xdr_encode_opaque(p
, machine_name
, len
);
1623 *p
++ = cpu_to_be32(0); /* UID */
1624 *p
++ = cpu_to_be32(0); /* GID */
1625 *p
= cpu_to_be32(0); /* No more gids */
1627 hdr
->replen
+= decode_create_session_maxsz
;
1630 static void encode_destroy_session(struct xdr_stream
*xdr
,
1631 struct nfs4_session
*session
,
1632 struct compound_hdr
*hdr
)
1635 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
);
1636 *p
++ = cpu_to_be32(OP_DESTROY_SESSION
);
1637 xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1639 hdr
->replen
+= decode_destroy_session_maxsz
;
1642 static void encode_reclaim_complete(struct xdr_stream
*xdr
,
1643 struct nfs41_reclaim_complete_args
*args
,
1644 struct compound_hdr
*hdr
)
1648 p
= reserve_space(xdr
, 8);
1649 *p
++ = cpu_to_be32(OP_RECLAIM_COMPLETE
);
1650 *p
++ = cpu_to_be32(args
->one_fs
);
1652 hdr
->replen
+= decode_reclaim_complete_maxsz
;
1654 #endif /* CONFIG_NFS_V4_1 */
1656 static void encode_sequence(struct xdr_stream
*xdr
,
1657 const struct nfs4_sequence_args
*args
,
1658 struct compound_hdr
*hdr
)
1660 #if defined(CONFIG_NFS_V4_1)
1661 struct nfs4_session
*session
= args
->sa_session
;
1662 struct nfs4_slot_table
*tp
;
1663 struct nfs4_slot
*slot
;
1669 tp
= &session
->fc_slot_table
;
1671 WARN_ON(args
->sa_slotid
== NFS4_MAX_SLOT_TABLE
);
1672 slot
= tp
->slots
+ args
->sa_slotid
;
1674 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
+ 16);
1675 *p
++ = cpu_to_be32(OP_SEQUENCE
);
1678 * Sessionid + seqid + slotid + max slotid + cache_this
1680 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1681 "max_slotid=%d cache_this=%d\n",
1683 ((u32
*)session
->sess_id
.data
)[0],
1684 ((u32
*)session
->sess_id
.data
)[1],
1685 ((u32
*)session
->sess_id
.data
)[2],
1686 ((u32
*)session
->sess_id
.data
)[3],
1687 slot
->seq_nr
, args
->sa_slotid
,
1688 tp
->highest_used_slotid
, args
->sa_cache_this
);
1689 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1690 *p
++ = cpu_to_be32(slot
->seq_nr
);
1691 *p
++ = cpu_to_be32(args
->sa_slotid
);
1692 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1693 *p
= cpu_to_be32(args
->sa_cache_this
);
1695 hdr
->replen
+= decode_sequence_maxsz
;
1696 #endif /* CONFIG_NFS_V4_1 */
1700 * END OF "GENERIC" ENCODE ROUTINES.
1703 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
1705 #if defined(CONFIG_NFS_V4_1)
1706 if (args
->sa_session
)
1707 return args
->sa_session
->clp
->cl_minorversion
;
1708 #endif /* CONFIG_NFS_V4_1 */
1713 * Encode an ACCESS request
1715 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_accessargs
*args
)
1717 struct xdr_stream xdr
;
1718 struct compound_hdr hdr
= {
1719 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1722 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1723 encode_compound_hdr(&xdr
, req
, &hdr
);
1724 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1725 encode_putfh(&xdr
, args
->fh
, &hdr
);
1726 encode_access(&xdr
, args
->access
, &hdr
);
1727 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1733 * Encode LOOKUP request
1735 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_arg
*args
)
1737 struct xdr_stream xdr
;
1738 struct compound_hdr hdr
= {
1739 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1742 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1743 encode_compound_hdr(&xdr
, req
, &hdr
);
1744 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1745 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1746 encode_lookup(&xdr
, args
->name
, &hdr
);
1747 encode_getfh(&xdr
, &hdr
);
1748 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1754 * Encode LOOKUP_ROOT request
1756 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_root_arg
*args
)
1758 struct xdr_stream xdr
;
1759 struct compound_hdr hdr
= {
1760 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1763 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1764 encode_compound_hdr(&xdr
, req
, &hdr
);
1765 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1766 encode_putrootfh(&xdr
, &hdr
);
1767 encode_getfh(&xdr
, &hdr
);
1768 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1774 * Encode REMOVE request
1776 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_removeargs
*args
)
1778 struct xdr_stream xdr
;
1779 struct compound_hdr hdr
= {
1780 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1783 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1784 encode_compound_hdr(&xdr
, req
, &hdr
);
1785 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1786 encode_putfh(&xdr
, args
->fh
, &hdr
);
1787 encode_remove(&xdr
, &args
->name
, &hdr
);
1788 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1794 * Encode RENAME request
1796 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_rename_arg
*args
)
1798 struct xdr_stream xdr
;
1799 struct compound_hdr hdr
= {
1800 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1803 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1804 encode_compound_hdr(&xdr
, req
, &hdr
);
1805 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1806 encode_putfh(&xdr
, args
->old_dir
, &hdr
);
1807 encode_savefh(&xdr
, &hdr
);
1808 encode_putfh(&xdr
, args
->new_dir
, &hdr
);
1809 encode_rename(&xdr
, args
->old_name
, args
->new_name
, &hdr
);
1810 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1811 encode_restorefh(&xdr
, &hdr
);
1812 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1818 * Encode LINK request
1820 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_link_arg
*args
)
1822 struct xdr_stream xdr
;
1823 struct compound_hdr hdr
= {
1824 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1827 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1828 encode_compound_hdr(&xdr
, req
, &hdr
);
1829 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1830 encode_putfh(&xdr
, args
->fh
, &hdr
);
1831 encode_savefh(&xdr
, &hdr
);
1832 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1833 encode_link(&xdr
, args
->name
, &hdr
);
1834 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1835 encode_restorefh(&xdr
, &hdr
);
1836 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1842 * Encode CREATE request
1844 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1846 struct xdr_stream xdr
;
1847 struct compound_hdr hdr
= {
1848 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1851 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1852 encode_compound_hdr(&xdr
, req
, &hdr
);
1853 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1854 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
1855 encode_savefh(&xdr
, &hdr
);
1856 encode_create(&xdr
, args
, &hdr
);
1857 encode_getfh(&xdr
, &hdr
);
1858 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1859 encode_restorefh(&xdr
, &hdr
);
1860 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1866 * Encode SYMLINK request
1868 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1870 return nfs4_xdr_enc_create(req
, p
, args
);
1874 * Encode GETATTR request
1876 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_getattr_arg
*args
)
1878 struct xdr_stream xdr
;
1879 struct compound_hdr hdr
= {
1880 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1883 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1884 encode_compound_hdr(&xdr
, req
, &hdr
);
1885 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1886 encode_putfh(&xdr
, args
->fh
, &hdr
);
1887 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1893 * Encode a CLOSE request
1895 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1897 struct xdr_stream xdr
;
1898 struct compound_hdr hdr
= {
1899 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1902 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1903 encode_compound_hdr(&xdr
, req
, &hdr
);
1904 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1905 encode_putfh(&xdr
, args
->fh
, &hdr
);
1906 encode_close(&xdr
, args
, &hdr
);
1907 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1913 * Encode an OPEN request
1915 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1917 struct xdr_stream xdr
;
1918 struct compound_hdr hdr
= {
1919 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1922 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1923 encode_compound_hdr(&xdr
, req
, &hdr
);
1924 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1925 encode_putfh(&xdr
, args
->fh
, &hdr
);
1926 encode_savefh(&xdr
, &hdr
);
1927 encode_open(&xdr
, args
, &hdr
);
1928 encode_getfh(&xdr
, &hdr
);
1929 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1930 encode_restorefh(&xdr
, &hdr
);
1931 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1937 * Encode an OPEN_CONFIRM request
1939 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_open_confirmargs
*args
)
1941 struct xdr_stream xdr
;
1942 struct compound_hdr hdr
= {
1946 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1947 encode_compound_hdr(&xdr
, req
, &hdr
);
1948 encode_putfh(&xdr
, args
->fh
, &hdr
);
1949 encode_open_confirm(&xdr
, args
, &hdr
);
1955 * Encode an OPEN request with no attributes.
1957 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*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_open(&xdr
, args
, &hdr
);
1969 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1975 * Encode an OPEN_DOWNGRADE request
1977 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1979 struct xdr_stream xdr
;
1980 struct compound_hdr hdr
= {
1981 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1984 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1985 encode_compound_hdr(&xdr
, req
, &hdr
);
1986 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
1987 encode_putfh(&xdr
, args
->fh
, &hdr
);
1988 encode_open_downgrade(&xdr
, args
, &hdr
);
1989 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
1995 * Encode a LOCK request
1997 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lock_args
*args
)
1999 struct xdr_stream xdr
;
2000 struct compound_hdr hdr
= {
2001 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2004 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2005 encode_compound_hdr(&xdr
, req
, &hdr
);
2006 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2007 encode_putfh(&xdr
, args
->fh
, &hdr
);
2008 encode_lock(&xdr
, args
, &hdr
);
2014 * Encode a LOCKT request
2016 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lockt_args
*args
)
2018 struct xdr_stream xdr
;
2019 struct compound_hdr hdr
= {
2020 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2023 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2024 encode_compound_hdr(&xdr
, req
, &hdr
);
2025 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2026 encode_putfh(&xdr
, args
->fh
, &hdr
);
2027 encode_lockt(&xdr
, args
, &hdr
);
2033 * Encode a LOCKU request
2035 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, __be32
*p
, struct nfs_locku_args
*args
)
2037 struct xdr_stream xdr
;
2038 struct compound_hdr hdr
= {
2039 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2042 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2043 encode_compound_hdr(&xdr
, req
, &hdr
);
2044 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2045 encode_putfh(&xdr
, args
->fh
, &hdr
);
2046 encode_locku(&xdr
, args
, &hdr
);
2052 * Encode a READLINK request
2054 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readlink
*args
)
2056 struct xdr_stream xdr
;
2057 struct compound_hdr hdr
= {
2058 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2061 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2062 encode_compound_hdr(&xdr
, req
, &hdr
);
2063 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2064 encode_putfh(&xdr
, args
->fh
, &hdr
);
2065 encode_readlink(&xdr
, args
, req
, &hdr
);
2067 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2068 args
->pgbase
, args
->pglen
);
2074 * Encode a READDIR request
2076 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readdir_arg
*args
)
2078 struct xdr_stream xdr
;
2079 struct compound_hdr hdr
= {
2080 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2083 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2084 encode_compound_hdr(&xdr
, req
, &hdr
);
2085 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2086 encode_putfh(&xdr
, args
->fh
, &hdr
);
2087 encode_readdir(&xdr
, args
, req
, &hdr
);
2089 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2090 args
->pgbase
, args
->count
);
2091 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2092 __func__
, hdr
.replen
<< 2, args
->pages
,
2093 args
->pgbase
, args
->count
);
2099 * Encode a READ request
2101 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readargs
*args
)
2103 struct xdr_stream xdr
;
2104 struct compound_hdr hdr
= {
2105 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2108 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2109 encode_compound_hdr(&xdr
, req
, &hdr
);
2110 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2111 encode_putfh(&xdr
, args
->fh
, &hdr
);
2112 encode_read(&xdr
, args
, &hdr
);
2114 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2115 args
->pages
, args
->pgbase
, args
->count
);
2116 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2122 * Encode an SETATTR request
2124 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setattrargs
*args
)
2126 struct xdr_stream xdr
;
2127 struct compound_hdr hdr
= {
2128 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2131 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2132 encode_compound_hdr(&xdr
, req
, &hdr
);
2133 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2134 encode_putfh(&xdr
, args
->fh
, &hdr
);
2135 encode_setattr(&xdr
, args
, args
->server
, &hdr
);
2136 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2142 * Encode a GETACL request
2145 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, __be32
*p
,
2146 struct nfs_getaclargs
*args
)
2148 struct xdr_stream xdr
;
2149 struct compound_hdr hdr
= {
2150 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2154 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2155 encode_compound_hdr(&xdr
, req
, &hdr
);
2156 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2157 encode_putfh(&xdr
, args
->fh
, &hdr
);
2158 replen
= hdr
.replen
+ op_decode_hdr_maxsz
+ nfs4_fattr_bitmap_maxsz
+ 1;
2159 encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2161 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2162 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
2168 * Encode a WRITE request
2170 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
2172 struct xdr_stream xdr
;
2173 struct compound_hdr hdr
= {
2174 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2177 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2178 encode_compound_hdr(&xdr
, req
, &hdr
);
2179 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2180 encode_putfh(&xdr
, args
->fh
, &hdr
);
2181 encode_write(&xdr
, args
, &hdr
);
2182 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2183 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2191 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*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_commit(&xdr
, args
, &hdr
);
2203 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2211 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fsinfo_arg
*args
)
2213 struct xdr_stream xdr
;
2214 struct compound_hdr hdr
= {
2215 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2218 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2219 encode_compound_hdr(&xdr
, req
, &hdr
);
2220 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2221 encode_putfh(&xdr
, args
->fh
, &hdr
);
2222 encode_fsinfo(&xdr
, args
->bitmask
, &hdr
);
2228 * a PATHCONF request
2230 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_pathconf_arg
*args
)
2232 struct xdr_stream xdr
;
2233 struct compound_hdr hdr
= {
2234 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2237 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2238 encode_compound_hdr(&xdr
, req
, &hdr
);
2239 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2240 encode_putfh(&xdr
, args
->fh
, &hdr
);
2241 encode_getattr_one(&xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2250 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_statfs_arg
*args
)
2252 struct xdr_stream xdr
;
2253 struct compound_hdr hdr
= {
2254 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2257 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2258 encode_compound_hdr(&xdr
, req
, &hdr
);
2259 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2260 encode_putfh(&xdr
, args
->fh
, &hdr
);
2261 encode_getattr_two(&xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2262 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2268 * GETATTR_BITMAP request
2270 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, __be32
*p
,
2271 struct nfs4_server_caps_arg
*args
)
2273 struct xdr_stream xdr
;
2274 struct compound_hdr hdr
= {
2275 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2278 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2279 encode_compound_hdr(&xdr
, req
, &hdr
);
2280 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2281 encode_putfh(&xdr
, args
->fhandle
, &hdr
);
2282 encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2283 FATTR4_WORD0_LINK_SUPPORT
|
2284 FATTR4_WORD0_SYMLINK_SUPPORT
|
2285 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2293 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
2295 struct xdr_stream xdr
;
2296 struct compound_hdr hdr
= {
2300 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2301 encode_compound_hdr(&xdr
, req
, &hdr
);
2302 encode_renew(&xdr
, clp
, &hdr
);
2308 * a SETCLIENTID request
2310 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid
*sc
)
2312 struct xdr_stream xdr
;
2313 struct compound_hdr hdr
= {
2317 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2318 encode_compound_hdr(&xdr
, req
, &hdr
);
2319 encode_setclientid(&xdr
, sc
, &hdr
);
2325 * a SETCLIENTID_CONFIRM request
2327 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid_res
*arg
)
2329 struct xdr_stream xdr
;
2330 struct compound_hdr hdr
= {
2333 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2335 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2336 encode_compound_hdr(&xdr
, req
, &hdr
);
2337 encode_setclientid_confirm(&xdr
, arg
, &hdr
);
2338 encode_putrootfh(&xdr
, &hdr
);
2339 encode_fsinfo(&xdr
, lease_bitmap
, &hdr
);
2345 * DELEGRETURN request
2347 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_delegreturnargs
*args
)
2349 struct xdr_stream xdr
;
2350 struct compound_hdr hdr
= {
2351 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2354 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2355 encode_compound_hdr(&xdr
, req
, &hdr
);
2356 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2357 encode_putfh(&xdr
, args
->fhandle
, &hdr
);
2358 encode_delegreturn(&xdr
, args
->stateid
, &hdr
);
2359 encode_getfattr(&xdr
, args
->bitmask
, &hdr
);
2365 * Encode FS_LOCATIONS request
2367 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations_arg
*args
)
2369 struct xdr_stream xdr
;
2370 struct compound_hdr hdr
= {
2371 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2375 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2376 encode_compound_hdr(&xdr
, req
, &hdr
);
2377 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2378 encode_putfh(&xdr
, args
->dir_fh
, &hdr
);
2379 encode_lookup(&xdr
, args
->name
, &hdr
);
2380 replen
= hdr
.replen
; /* get the attribute into args->page */
2381 encode_fs_locations(&xdr
, args
->bitmask
, &hdr
);
2383 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2389 #if defined(CONFIG_NFS_V4_1)
2391 * EXCHANGE_ID request
2393 static int nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
, uint32_t *p
,
2394 struct nfs41_exchange_id_args
*args
)
2396 struct xdr_stream xdr
;
2397 struct compound_hdr hdr
= {
2398 .minorversion
= args
->client
->cl_minorversion
,
2401 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2402 encode_compound_hdr(&xdr
, req
, &hdr
);
2403 encode_exchange_id(&xdr
, args
, &hdr
);
2409 * a CREATE_SESSION request
2411 static int nfs4_xdr_enc_create_session(struct rpc_rqst
*req
, uint32_t *p
,
2412 struct nfs41_create_session_args
*args
)
2414 struct xdr_stream xdr
;
2415 struct compound_hdr hdr
= {
2416 .minorversion
= args
->client
->cl_minorversion
,
2419 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2420 encode_compound_hdr(&xdr
, req
, &hdr
);
2421 encode_create_session(&xdr
, args
, &hdr
);
2427 * a DESTROY_SESSION request
2429 static int nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
, uint32_t *p
,
2430 struct nfs4_session
*session
)
2432 struct xdr_stream xdr
;
2433 struct compound_hdr hdr
= {
2434 .minorversion
= session
->clp
->cl_minorversion
,
2437 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2438 encode_compound_hdr(&xdr
, req
, &hdr
);
2439 encode_destroy_session(&xdr
, session
, &hdr
);
2445 * a SEQUENCE request
2447 static int nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, uint32_t *p
,
2448 struct nfs4_sequence_args
*args
)
2450 struct xdr_stream xdr
;
2451 struct compound_hdr hdr
= {
2452 .minorversion
= nfs4_xdr_minorversion(args
),
2455 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2456 encode_compound_hdr(&xdr
, req
, &hdr
);
2457 encode_sequence(&xdr
, args
, &hdr
);
2463 * a GET_LEASE_TIME request
2465 static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
, uint32_t *p
,
2466 struct nfs4_get_lease_time_args
*args
)
2468 struct xdr_stream xdr
;
2469 struct compound_hdr hdr
= {
2470 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2472 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2474 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2475 encode_compound_hdr(&xdr
, req
, &hdr
);
2476 encode_sequence(&xdr
, &args
->la_seq_args
, &hdr
);
2477 encode_putrootfh(&xdr
, &hdr
);
2478 encode_fsinfo(&xdr
, lease_bitmap
, &hdr
);
2484 * a RECLAIM_COMPLETE request
2486 static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
, uint32_t *p
,
2487 struct nfs41_reclaim_complete_args
*args
)
2489 struct xdr_stream xdr
;
2490 struct compound_hdr hdr
= {
2491 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2494 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2495 encode_compound_hdr(&xdr
, req
, &hdr
);
2496 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
2497 encode_reclaim_complete(&xdr
, args
, &hdr
);
2502 #endif /* CONFIG_NFS_V4_1 */
2504 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
2506 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2507 "Remaining buffer length is %tu words.\n",
2508 func
, xdr
->end
- xdr
->p
);
2511 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2515 p
= xdr_inline_decode(xdr
, 4);
2518 *len
= be32_to_cpup(p
);
2519 p
= xdr_inline_decode(xdr
, *len
);
2522 *string
= (char *)p
;
2525 print_overflow_msg(__func__
, xdr
);
2529 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2533 p
= xdr_inline_decode(xdr
, 8);
2536 hdr
->status
= be32_to_cpup(p
++);
2537 hdr
->taglen
= be32_to_cpup(p
);
2539 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
2542 hdr
->tag
= (char *)p
;
2543 p
+= XDR_QUADLEN(hdr
->taglen
);
2544 hdr
->nops
= be32_to_cpup(p
);
2545 if (unlikely(hdr
->nops
< 1))
2546 return nfs4_stat_to_errno(hdr
->status
);
2549 print_overflow_msg(__func__
, xdr
);
2553 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2559 p
= xdr_inline_decode(xdr
, 8);
2562 opnum
= be32_to_cpup(p
++);
2563 if (opnum
!= expected
) {
2564 dprintk("nfs: Server returned operation"
2565 " %d but we issued a request for %d\n",
2569 nfserr
= be32_to_cpup(p
);
2570 if (nfserr
!= NFS_OK
)
2571 return nfs4_stat_to_errno(nfserr
);
2574 print_overflow_msg(__func__
, xdr
);
2579 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2582 unsigned int strlen
;
2585 p
= xdr_inline_decode(xdr
, 12);
2587 return decode_opaque_inline(xdr
, &strlen
, &str
);
2588 print_overflow_msg(__func__
, xdr
);
2592 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2597 p
= xdr_inline_decode(xdr
, 4);
2600 bmlen
= be32_to_cpup(p
);
2602 bitmap
[0] = bitmap
[1] = 0;
2603 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
2607 bitmap
[0] = be32_to_cpup(p
++);
2609 bitmap
[1] = be32_to_cpup(p
);
2613 print_overflow_msg(__func__
, xdr
);
2617 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
2621 p
= xdr_inline_decode(xdr
, 4);
2624 *attrlen
= be32_to_cpup(p
);
2628 print_overflow_msg(__func__
, xdr
);
2632 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2634 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2635 decode_attr_bitmap(xdr
, bitmask
);
2636 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2638 bitmask
[0] = bitmask
[1] = 0;
2639 dprintk("%s: bitmask=%08x:%08x\n", __func__
, bitmask
[0], bitmask
[1]);
2643 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2649 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2651 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2652 p
= xdr_inline_decode(xdr
, 4);
2655 *type
= be32_to_cpup(p
);
2656 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2657 dprintk("%s: bad type %d\n", __func__
, *type
);
2660 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2661 ret
= NFS_ATTR_FATTR_TYPE
;
2663 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
2666 print_overflow_msg(__func__
, xdr
);
2670 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2676 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2678 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2679 p
= xdr_inline_decode(xdr
, 8);
2682 xdr_decode_hyper(p
, change
);
2683 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2684 ret
= NFS_ATTR_FATTR_CHANGE
;
2686 dprintk("%s: change attribute=%Lu\n", __func__
,
2687 (unsigned long long)*change
);
2690 print_overflow_msg(__func__
, xdr
);
2694 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2700 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2702 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2703 p
= xdr_inline_decode(xdr
, 8);
2706 xdr_decode_hyper(p
, size
);
2707 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2708 ret
= NFS_ATTR_FATTR_SIZE
;
2710 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
2713 print_overflow_msg(__func__
, xdr
);
2717 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2722 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2724 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2725 p
= xdr_inline_decode(xdr
, 4);
2728 *res
= be32_to_cpup(p
);
2729 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2731 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2734 print_overflow_msg(__func__
, xdr
);
2738 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2743 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2745 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2746 p
= xdr_inline_decode(xdr
, 4);
2749 *res
= be32_to_cpup(p
);
2750 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2752 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
2755 print_overflow_msg(__func__
, xdr
);
2759 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
2766 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2768 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2769 p
= xdr_inline_decode(xdr
, 16);
2772 p
= xdr_decode_hyper(p
, &fsid
->major
);
2773 xdr_decode_hyper(p
, &fsid
->minor
);
2774 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2775 ret
= NFS_ATTR_FATTR_FSID
;
2777 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
2778 (unsigned long long)fsid
->major
,
2779 (unsigned long long)fsid
->minor
);
2782 print_overflow_msg(__func__
, xdr
);
2786 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2791 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2793 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2794 p
= xdr_inline_decode(xdr
, 4);
2797 *res
= be32_to_cpup(p
);
2798 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2800 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
2803 print_overflow_msg(__func__
, xdr
);
2807 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2811 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2812 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2814 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2815 p
= xdr_inline_decode(xdr
, 4);
2818 *res
= be32_to_cpup(p
);
2819 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2821 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
2824 print_overflow_msg(__func__
, xdr
);
2828 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2834 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2836 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2837 p
= xdr_inline_decode(xdr
, 8);
2840 xdr_decode_hyper(p
, fileid
);
2841 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2842 ret
= NFS_ATTR_FATTR_FILEID
;
2844 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2847 print_overflow_msg(__func__
, xdr
);
2851 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2857 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
2859 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
2860 p
= xdr_inline_decode(xdr
, 8);
2863 xdr_decode_hyper(p
, fileid
);
2864 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
2865 ret
= NFS_ATTR_FATTR_FILEID
;
2867 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
2870 print_overflow_msg(__func__
, xdr
);
2874 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2880 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2882 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2883 p
= xdr_inline_decode(xdr
, 8);
2886 xdr_decode_hyper(p
, res
);
2887 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2889 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
2892 print_overflow_msg(__func__
, xdr
);
2896 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2902 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2904 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2905 p
= xdr_inline_decode(xdr
, 8);
2908 xdr_decode_hyper(p
, res
);
2909 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2911 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
2914 print_overflow_msg(__func__
, xdr
);
2918 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2924 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2926 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2927 p
= xdr_inline_decode(xdr
, 8);
2930 xdr_decode_hyper(p
, res
);
2931 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2933 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
2936 print_overflow_msg(__func__
, xdr
);
2940 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
2946 p
= xdr_inline_decode(xdr
, 4);
2949 n
= be32_to_cpup(p
);
2953 path
->ncomponents
= 0;
2954 while (path
->ncomponents
< n
) {
2955 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
2956 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
2957 if (unlikely(status
!= 0))
2959 if (path
->ncomponents
!= n
)
2961 dprintk("%s", component
->data
);
2962 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
2963 path
->ncomponents
++;
2965 dprintk("cannot parse %d components in path\n", n
);
2973 /* a root pathname is sent as a zero component4 */
2974 path
->ncomponents
= 1;
2975 path
->components
[0].len
=0;
2976 path
->components
[0].data
=NULL
;
2977 dprintk("path /\n");
2980 dprintk(" status %d", status
);
2984 print_overflow_msg(__func__
, xdr
);
2988 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
2994 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
2997 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
2999 dprintk("%s: fsroot ", __func__
);
3000 status
= decode_pathname(xdr
, &res
->fs_path
);
3001 if (unlikely(status
!= 0))
3003 p
= xdr_inline_decode(xdr
, 4);
3006 n
= be32_to_cpup(p
);
3009 res
->nlocations
= 0;
3010 while (res
->nlocations
< n
) {
3012 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
3014 p
= xdr_inline_decode(xdr
, 4);
3017 m
= be32_to_cpup(p
);
3020 dprintk("%s: servers ", __func__
);
3021 while (loc
->nservers
< m
) {
3022 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
3023 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3024 if (unlikely(status
!= 0))
3026 dprintk("%s ", server
->data
);
3027 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
3031 dprintk("%s: using first %u of %u servers "
3032 "returned for location %u\n",
3034 NFS4_FS_LOCATION_MAXSERVERS
,
3035 m
, res
->nlocations
);
3036 for (i
= loc
->nservers
; i
< m
; i
++) {
3039 status
= decode_opaque_inline(xdr
, &len
, &data
);
3040 if (unlikely(status
!= 0))
3045 status
= decode_pathname(xdr
, &loc
->rootpath
);
3046 if (unlikely(status
!= 0))
3048 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
3051 if (res
->nlocations
!= 0)
3052 status
= NFS_ATTR_FATTR_V4_REFERRAL
;
3054 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3057 print_overflow_msg(__func__
, xdr
);
3063 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3069 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3071 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3072 p
= xdr_inline_decode(xdr
, 8);
3075 xdr_decode_hyper(p
, res
);
3076 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3078 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3081 print_overflow_msg(__func__
, xdr
);
3085 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3091 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3093 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3094 p
= xdr_inline_decode(xdr
, 4);
3097 *maxlink
= be32_to_cpup(p
);
3098 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3100 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3103 print_overflow_msg(__func__
, xdr
);
3107 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3113 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3115 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3116 p
= xdr_inline_decode(xdr
, 4);
3119 *maxname
= be32_to_cpup(p
);
3120 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3122 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3125 print_overflow_msg(__func__
, xdr
);
3129 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3135 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3137 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3139 p
= xdr_inline_decode(xdr
, 8);
3142 xdr_decode_hyper(p
, &maxread
);
3143 if (maxread
> 0x7FFFFFFF)
3144 maxread
= 0x7FFFFFFF;
3145 *res
= (uint32_t)maxread
;
3146 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3148 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3151 print_overflow_msg(__func__
, xdr
);
3155 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3161 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3163 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3165 p
= xdr_inline_decode(xdr
, 8);
3168 xdr_decode_hyper(p
, &maxwrite
);
3169 if (maxwrite
> 0x7FFFFFFF)
3170 maxwrite
= 0x7FFFFFFF;
3171 *res
= (uint32_t)maxwrite
;
3172 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3174 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3177 print_overflow_msg(__func__
, xdr
);
3181 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3188 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3190 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3191 p
= xdr_inline_decode(xdr
, 4);
3194 tmp
= be32_to_cpup(p
);
3195 *mode
= tmp
& ~S_IFMT
;
3196 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3197 ret
= NFS_ATTR_FATTR_MODE
;
3199 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3202 print_overflow_msg(__func__
, xdr
);
3206 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3212 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3214 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3215 p
= xdr_inline_decode(xdr
, 4);
3218 *nlink
= be32_to_cpup(p
);
3219 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3220 ret
= NFS_ATTR_FATTR_NLINK
;
3222 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3225 print_overflow_msg(__func__
, xdr
);
3229 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3230 struct nfs_client
*clp
, uint32_t *uid
, int may_sleep
)
3237 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3239 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3240 p
= xdr_inline_decode(xdr
, 4);
3243 len
= be32_to_cpup(p
);
3244 p
= xdr_inline_decode(xdr
, len
);
3249 } else if (len
< XDR_MAX_NETOBJ
) {
3250 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) == 0)
3251 ret
= NFS_ATTR_FATTR_OWNER
;
3253 dprintk("%s: nfs_map_name_to_uid failed!\n",
3256 dprintk("%s: name too long (%u)!\n",
3258 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3260 dprintk("%s: uid=%d\n", __func__
, (int)*uid
);
3263 print_overflow_msg(__func__
, xdr
);
3267 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3268 struct nfs_client
*clp
, uint32_t *gid
, int may_sleep
)
3275 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3277 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3278 p
= xdr_inline_decode(xdr
, 4);
3281 len
= be32_to_cpup(p
);
3282 p
= xdr_inline_decode(xdr
, len
);
3287 } else if (len
< XDR_MAX_NETOBJ
) {
3288 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) == 0)
3289 ret
= NFS_ATTR_FATTR_GROUP
;
3291 dprintk("%s: nfs_map_group_to_gid failed!\n",
3294 dprintk("%s: name too long (%u)!\n",
3296 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3298 dprintk("%s: gid=%d\n", __func__
, (int)*gid
);
3301 print_overflow_msg(__func__
, xdr
);
3305 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3307 uint32_t major
= 0, minor
= 0;
3312 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3314 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3317 p
= xdr_inline_decode(xdr
, 8);
3320 major
= be32_to_cpup(p
++);
3321 minor
= be32_to_cpup(p
);
3322 tmp
= MKDEV(major
, minor
);
3323 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3325 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3326 ret
= NFS_ATTR_FATTR_RDEV
;
3328 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3331 print_overflow_msg(__func__
, xdr
);
3335 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3341 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3343 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3344 p
= xdr_inline_decode(xdr
, 8);
3347 xdr_decode_hyper(p
, res
);
3348 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3350 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3353 print_overflow_msg(__func__
, xdr
);
3357 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3363 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3365 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3366 p
= xdr_inline_decode(xdr
, 8);
3369 xdr_decode_hyper(p
, res
);
3370 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3372 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3375 print_overflow_msg(__func__
, xdr
);
3379 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3385 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
3387 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
3388 p
= xdr_inline_decode(xdr
, 8);
3391 xdr_decode_hyper(p
, res
);
3392 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
3394 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
3397 print_overflow_msg(__func__
, xdr
);
3401 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
3407 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
3409 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
3410 p
= xdr_inline_decode(xdr
, 8);
3413 xdr_decode_hyper(p
, used
);
3414 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
3415 ret
= NFS_ATTR_FATTR_SPACE_USED
;
3417 dprintk("%s: space used=%Lu\n", __func__
,
3418 (unsigned long long)*used
);
3421 print_overflow_msg(__func__
, xdr
);
3425 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
3431 p
= xdr_inline_decode(xdr
, 12);
3434 p
= xdr_decode_hyper(p
, &sec
);
3435 nsec
= be32_to_cpup(p
);
3436 time
->tv_sec
= (time_t)sec
;
3437 time
->tv_nsec
= (long)nsec
;
3440 print_overflow_msg(__func__
, xdr
);
3444 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3450 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
3452 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
3453 status
= decode_attr_time(xdr
, time
);
3455 status
= NFS_ATTR_FATTR_ATIME
;
3456 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
3458 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
3462 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3468 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
3470 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
3471 status
= decode_attr_time(xdr
, time
);
3473 status
= NFS_ATTR_FATTR_CTIME
;
3474 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
3476 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
3480 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3486 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
3488 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
3489 status
= decode_attr_time(xdr
, time
);
3491 status
= NFS_ATTR_FATTR_MTIME
;
3492 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
3494 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
3498 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
3500 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
3501 unsigned int nwords
= xdr
->p
- savep
;
3503 if (unlikely(attrwords
!= nwords
)) {
3504 dprintk("%s: server returned incorrect attribute length: "
3508 (attrwords
< nwords
) ? '<' : '>',
3515 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3519 p
= xdr_inline_decode(xdr
, 20);
3522 cinfo
->atomic
= be32_to_cpup(p
++);
3523 p
= xdr_decode_hyper(p
, &cinfo
->before
);
3524 xdr_decode_hyper(p
, &cinfo
->after
);
3527 print_overflow_msg(__func__
, xdr
);
3531 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
3537 status
= decode_op_hdr(xdr
, OP_ACCESS
);
3540 p
= xdr_inline_decode(xdr
, 8);
3543 supp
= be32_to_cpup(p
++);
3544 acc
= be32_to_cpup(p
);
3545 access
->supported
= supp
;
3546 access
->access
= acc
;
3549 print_overflow_msg(__func__
, xdr
);
3553 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
3557 p
= xdr_inline_decode(xdr
, len
);
3559 memcpy(buf
, p
, len
);
3562 print_overflow_msg(__func__
, xdr
);
3566 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
3568 return decode_opaque_fixed(xdr
, stateid
->data
, NFS4_STATEID_SIZE
);
3571 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3575 status
= decode_op_hdr(xdr
, OP_CLOSE
);
3577 nfs_increment_open_seqid(status
, res
->seqid
);
3579 status
= decode_stateid(xdr
, &res
->stateid
);
3583 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
3585 return decode_opaque_fixed(xdr
, verifier
, 8);
3588 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3592 status
= decode_op_hdr(xdr
, OP_COMMIT
);
3594 status
= decode_verifier(xdr
, res
->verf
->verifier
);
3598 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3604 status
= decode_op_hdr(xdr
, OP_CREATE
);
3607 if ((status
= decode_change_info(xdr
, cinfo
)))
3609 p
= xdr_inline_decode(xdr
, 4);
3612 bmlen
= be32_to_cpup(p
);
3613 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
3617 print_overflow_msg(__func__
, xdr
);
3621 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
3624 uint32_t attrlen
, bitmap
[2] = {0};
3627 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3629 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3631 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3633 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
3635 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
3637 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
3639 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
3641 status
= verify_attr_len(xdr
, savep
, attrlen
);
3643 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3647 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
3650 uint32_t attrlen
, bitmap
[2] = {0};
3653 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3655 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3657 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3660 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
3662 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
3664 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
3666 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
3668 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
3670 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
3673 status
= verify_attr_len(xdr
, savep
, attrlen
);
3675 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3679 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
3682 uint32_t attrlen
, bitmap
[2] = {0};
3685 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3687 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3689 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3692 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
3694 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
3697 status
= verify_attr_len(xdr
, savep
, attrlen
);
3699 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3703 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
3704 const struct nfs_server
*server
, int may_sleep
)
3714 status
= decode_op_hdr(xdr
, OP_GETATTR
);
3718 status
= decode_attr_bitmap(xdr
, bitmap
);
3722 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
3727 status
= decode_attr_type(xdr
, bitmap
, &type
);
3732 fattr
->mode
|= nfs_type2fmt
[type
];
3733 fattr
->valid
|= status
;
3736 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
3739 fattr
->valid
|= status
;
3741 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
3744 fattr
->valid
|= status
;
3746 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
3749 fattr
->valid
|= status
;
3751 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
3754 fattr
->valid
|= status
;
3756 status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
3757 struct nfs4_fs_locations
,
3761 fattr
->valid
|= status
;
3763 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
3767 fattr
->mode
|= fmode
;
3768 fattr
->valid
|= status
;
3771 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
3774 fattr
->valid
|= status
;
3776 status
= decode_attr_owner(xdr
, bitmap
, server
->nfs_client
,
3777 &fattr
->uid
, may_sleep
);
3780 fattr
->valid
|= status
;
3782 status
= decode_attr_group(xdr
, bitmap
, server
->nfs_client
,
3783 &fattr
->gid
, may_sleep
);
3786 fattr
->valid
|= status
;
3788 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
3791 fattr
->valid
|= status
;
3793 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
3796 fattr
->valid
|= status
;
3798 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
3801 fattr
->valid
|= status
;
3803 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
3806 fattr
->valid
|= status
;
3808 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
3811 fattr
->valid
|= status
;
3813 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fileid
);
3816 if (status
!= 0 && !(fattr
->valid
& status
)) {
3817 fattr
->fileid
= fileid
;
3818 fattr
->valid
|= status
;
3821 status
= verify_attr_len(xdr
, savep
, attrlen
);
3823 dprintk("%s: xdr returned %d\n", __func__
, -status
);
3828 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
3831 uint32_t attrlen
, bitmap
[2];
3834 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3836 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3838 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3841 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
3843 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
3845 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
3847 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
3849 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
3850 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
3852 fsinfo
->wtpref
= fsinfo
->wtmax
;
3854 status
= verify_attr_len(xdr
, savep
, attrlen
);
3856 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
3860 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
3866 /* Zero handle first to allow comparisons */
3867 memset(fh
, 0, sizeof(*fh
));
3869 status
= decode_op_hdr(xdr
, OP_GETFH
);
3873 p
= xdr_inline_decode(xdr
, 4);
3876 len
= be32_to_cpup(p
);
3877 if (len
> NFS4_FHSIZE
)
3880 p
= xdr_inline_decode(xdr
, len
);
3883 memcpy(fh
->data
, p
, len
);
3886 print_overflow_msg(__func__
, xdr
);
3890 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3894 status
= decode_op_hdr(xdr
, OP_LINK
);
3897 return decode_change_info(xdr
, cinfo
);
3901 * We create the owner, so we know a proper owner.id length is 4.
3903 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
3905 uint64_t offset
, length
, clientid
;
3907 uint32_t namelen
, type
;
3909 p
= xdr_inline_decode(xdr
, 32);
3912 p
= xdr_decode_hyper(p
, &offset
);
3913 p
= xdr_decode_hyper(p
, &length
);
3914 type
= be32_to_cpup(p
++);
3916 fl
->fl_start
= (loff_t
)offset
;
3917 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
3918 if (length
== ~(uint64_t)0)
3919 fl
->fl_end
= OFFSET_MAX
;
3920 fl
->fl_type
= F_WRLCK
;
3922 fl
->fl_type
= F_RDLCK
;
3925 p
= xdr_decode_hyper(p
, &clientid
);
3926 namelen
= be32_to_cpup(p
);
3927 p
= xdr_inline_decode(xdr
, namelen
);
3929 return -NFS4ERR_DENIED
;
3931 print_overflow_msg(__func__
, xdr
);
3935 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
3939 status
= decode_op_hdr(xdr
, OP_LOCK
);
3943 status
= decode_stateid(xdr
, &res
->stateid
);
3944 if (unlikely(status
))
3946 } else if (status
== -NFS4ERR_DENIED
)
3947 status
= decode_lock_denied(xdr
, NULL
);
3948 if (res
->open_seqid
!= NULL
)
3949 nfs_increment_open_seqid(status
, res
->open_seqid
);
3950 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
3955 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
3958 status
= decode_op_hdr(xdr
, OP_LOCKT
);
3959 if (status
== -NFS4ERR_DENIED
)
3960 return decode_lock_denied(xdr
, res
->denied
);
3964 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
3968 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3970 nfs_increment_lock_seqid(status
, res
->seqid
);
3972 status
= decode_stateid(xdr
, &res
->stateid
);
3976 static int decode_lookup(struct xdr_stream
*xdr
)
3978 return decode_op_hdr(xdr
, OP_LOOKUP
);
3981 /* This is too sick! */
3982 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3985 uint32_t limit_type
, nblocks
, blocksize
;
3987 p
= xdr_inline_decode(xdr
, 12);
3990 limit_type
= be32_to_cpup(p
++);
3991 switch (limit_type
) {
3993 xdr_decode_hyper(p
, maxsize
);
3996 nblocks
= be32_to_cpup(p
++);
3997 blocksize
= be32_to_cpup(p
);
3998 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
4002 print_overflow_msg(__func__
, xdr
);
4006 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4009 uint32_t delegation_type
;
4012 p
= xdr_inline_decode(xdr
, 4);
4015 delegation_type
= be32_to_cpup(p
);
4016 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
4017 res
->delegation_type
= 0;
4020 status
= decode_stateid(xdr
, &res
->delegation
);
4021 if (unlikely(status
))
4023 p
= xdr_inline_decode(xdr
, 4);
4026 res
->do_recall
= be32_to_cpup(p
);
4028 switch (delegation_type
) {
4029 case NFS4_OPEN_DELEGATE_READ
:
4030 res
->delegation_type
= FMODE_READ
;
4032 case NFS4_OPEN_DELEGATE_WRITE
:
4033 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
4034 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
4037 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
4039 print_overflow_msg(__func__
, xdr
);
4043 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4046 uint32_t savewords
, bmlen
, i
;
4049 status
= decode_op_hdr(xdr
, OP_OPEN
);
4051 nfs_increment_open_seqid(status
, res
->seqid
);
4053 status
= decode_stateid(xdr
, &res
->stateid
);
4054 if (unlikely(status
))
4057 decode_change_info(xdr
, &res
->cinfo
);
4059 p
= xdr_inline_decode(xdr
, 8);
4062 res
->rflags
= be32_to_cpup(p
++);
4063 bmlen
= be32_to_cpup(p
);
4067 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4070 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
4071 for (i
= 0; i
< savewords
; ++i
)
4072 res
->attrset
[i
] = be32_to_cpup(p
++);
4073 for (; i
< NFS4_BITMAP_SIZE
; i
++)
4074 res
->attrset
[i
] = 0;
4076 return decode_delegation(xdr
, res
);
4078 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
4081 print_overflow_msg(__func__
, xdr
);
4085 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
4089 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
4091 nfs_increment_open_seqid(status
, res
->seqid
);
4093 status
= decode_stateid(xdr
, &res
->stateid
);
4097 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4101 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
4103 nfs_increment_open_seqid(status
, res
->seqid
);
4105 status
= decode_stateid(xdr
, &res
->stateid
);
4109 static int decode_putfh(struct xdr_stream
*xdr
)
4111 return decode_op_hdr(xdr
, OP_PUTFH
);
4114 static int decode_putrootfh(struct xdr_stream
*xdr
)
4116 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
4119 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
4121 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4123 uint32_t count
, eof
, recvd
, hdrlen
;
4126 status
= decode_op_hdr(xdr
, OP_READ
);
4129 p
= xdr_inline_decode(xdr
, 8);
4132 eof
= be32_to_cpup(p
++);
4133 count
= be32_to_cpup(p
);
4134 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
4135 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4136 if (count
> recvd
) {
4137 dprintk("NFS: server cheating in read reply: "
4138 "count %u > recvd %u\n", count
, recvd
);
4142 xdr_read_pages(xdr
, count
);
4147 print_overflow_msg(__func__
, xdr
);
4151 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
4153 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4154 struct page
*page
= *rcvbuf
->pages
;
4155 struct kvec
*iov
= rcvbuf
->head
;
4157 u32 recvd
, pglen
= rcvbuf
->page_len
;
4158 __be32
*end
, *entry
, *p
, *kaddr
;
4159 unsigned int nr
= 0;
4162 status
= decode_op_hdr(xdr
, OP_READDIR
);
4164 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
4165 if (unlikely(status
))
4167 dprintk("%s: verifier = %08x:%08x\n",
4169 ((u32
*)readdir
->verifier
.data
)[0],
4170 ((u32
*)readdir
->verifier
.data
)[1]);
4173 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4174 recvd
= rcvbuf
->len
- hdrlen
;
4177 xdr_read_pages(xdr
, pglen
);
4179 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
4180 kaddr
= p
= kmap_atomic(page
, KM_USER0
);
4181 end
= p
+ ((pglen
+ readdir
->pgbase
) >> 2);
4184 /* Make sure the packet actually has a value_follows and EOF entry */
4185 if ((entry
+ 1) > end
)
4188 for (; *p
++; nr
++) {
4189 u32 len
, attrlen
, xlen
;
4192 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
4193 p
+= 2; /* cookie */
4194 len
= ntohl(*p
++); /* filename length */
4195 if (len
> NFS4_MAXNAMLEN
) {
4196 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4200 xlen
= XDR_QUADLEN(len
);
4201 if (end
- p
< xlen
+ 1)
4203 dprintk("filename = %*s\n", len
, (char *)p
);
4205 len
= ntohl(*p
++); /* bitmap length */
4206 if (end
- p
< len
+ 1)
4209 attrlen
= XDR_QUADLEN(ntohl(*p
++));
4210 if (end
- p
< attrlen
+ 2)
4212 p
+= attrlen
; /* attributes */
4216 * Apparently some server sends responses that are a valid size, but
4217 * contain no entries, and have value_follows==0 and EOF==0. For
4218 * those, just set the EOF marker.
4220 if (!nr
&& entry
[1] == 0) {
4221 dprintk("NFS: readdir reply truncated!\n");
4225 kunmap_atomic(kaddr
, KM_USER0
);
4229 * When we get a short packet there are 2 possibilities. We can
4230 * return an error, or fix up the response to look like a valid
4231 * response and return what we have so far. If there are no
4232 * entries and the packet was short, then return -EIO. If there
4233 * are valid entries in the response, return them and pretend that
4234 * the call was successful, but incomplete. The caller can retry the
4235 * readdir starting at the last cookie.
4237 dprintk("%s: short packet at entry %d\n", __func__
, nr
);
4238 entry
[0] = entry
[1] = 0;
4242 kunmap_atomic(kaddr
, KM_USER0
);
4243 return -errno_NFSERR_IO
;
4246 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
4248 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4249 struct kvec
*iov
= rcvbuf
->head
;
4256 status
= decode_op_hdr(xdr
, OP_READLINK
);
4260 /* Convert length of symlink */
4261 p
= xdr_inline_decode(xdr
, 4);
4264 len
= be32_to_cpup(p
);
4265 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
4266 dprintk("nfs: server returned giant symlink!\n");
4267 return -ENAMETOOLONG
;
4269 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4270 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4272 dprintk("NFS: server cheating in readlink reply: "
4273 "count %u > recvd %u\n", len
, recvd
);
4276 xdr_read_pages(xdr
, len
);
4278 * The XDR encode routine has set things up so that
4279 * the link text will be copied directly into the
4280 * buffer. We just have to do overflow-checking,
4281 * and and null-terminate the text (the VFS expects
4282 * null-termination).
4284 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
4285 kaddr
[len
+rcvbuf
->page_base
] = '\0';
4286 kunmap_atomic(kaddr
, KM_USER0
);
4289 print_overflow_msg(__func__
, xdr
);
4293 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4297 status
= decode_op_hdr(xdr
, OP_REMOVE
);
4300 status
= decode_change_info(xdr
, cinfo
);
4305 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
4306 struct nfs4_change_info
*new_cinfo
)
4310 status
= decode_op_hdr(xdr
, OP_RENAME
);
4313 if ((status
= decode_change_info(xdr
, old_cinfo
)))
4315 status
= decode_change_info(xdr
, new_cinfo
);
4320 static int decode_renew(struct xdr_stream
*xdr
)
4322 return decode_op_hdr(xdr
, OP_RENEW
);
4326 decode_restorefh(struct xdr_stream
*xdr
)
4328 return decode_op_hdr(xdr
, OP_RESTOREFH
);
4331 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
4337 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4341 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4343 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4345 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4348 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
4350 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
4354 /* We ignore &savep and don't do consistency checks on
4355 * the attr length. Let userspace figure it out.... */
4356 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
4357 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4358 if (attrlen
> recvd
) {
4359 dprintk("NFS: server cheating in getattr"
4360 " acl reply: attrlen %u > recvd %u\n",
4364 xdr_read_pages(xdr
, attrlen
);
4367 status
= -EOPNOTSUPP
;
4374 decode_savefh(struct xdr_stream
*xdr
)
4376 return decode_op_hdr(xdr
, OP_SAVEFH
);
4379 static int decode_setattr(struct xdr_stream
*xdr
)
4385 status
= decode_op_hdr(xdr
, OP_SETATTR
);
4388 p
= xdr_inline_decode(xdr
, 4);
4391 bmlen
= be32_to_cpup(p
);
4392 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4396 print_overflow_msg(__func__
, xdr
);
4400 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
4406 p
= xdr_inline_decode(xdr
, 8);
4409 opnum
= be32_to_cpup(p
++);
4410 if (opnum
!= OP_SETCLIENTID
) {
4411 dprintk("nfs: decode_setclientid: Server returned operation"
4415 nfserr
= be32_to_cpup(p
);
4416 if (nfserr
== NFS_OK
) {
4417 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
4420 p
= xdr_decode_hyper(p
, &res
->clientid
);
4421 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
4422 } else if (nfserr
== NFSERR_CLID_INUSE
) {
4425 /* skip netid string */
4426 p
= xdr_inline_decode(xdr
, 4);
4429 len
= be32_to_cpup(p
);
4430 p
= xdr_inline_decode(xdr
, len
);
4434 /* skip uaddr string */
4435 p
= xdr_inline_decode(xdr
, 4);
4438 len
= be32_to_cpup(p
);
4439 p
= xdr_inline_decode(xdr
, len
);
4442 return -NFSERR_CLID_INUSE
;
4444 return nfs4_stat_to_errno(nfserr
);
4448 print_overflow_msg(__func__
, xdr
);
4452 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
4454 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
4457 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
4462 status
= decode_op_hdr(xdr
, OP_WRITE
);
4466 p
= xdr_inline_decode(xdr
, 16);
4469 res
->count
= be32_to_cpup(p
++);
4470 res
->verf
->committed
= be32_to_cpup(p
++);
4471 memcpy(res
->verf
->verifier
, p
, 8);
4474 print_overflow_msg(__func__
, xdr
);
4478 static int decode_delegreturn(struct xdr_stream
*xdr
)
4480 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
4483 #if defined(CONFIG_NFS_V4_1)
4484 static int decode_exchange_id(struct xdr_stream
*xdr
,
4485 struct nfs41_exchange_id_res
*res
)
4491 struct nfs_client
*clp
= res
->client
;
4493 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
4497 p
= xdr_inline_decode(xdr
, 8);
4500 xdr_decode_hyper(p
, &clp
->cl_ex_clid
);
4501 p
= xdr_inline_decode(xdr
, 12);
4504 clp
->cl_seqid
= be32_to_cpup(p
++);
4505 clp
->cl_exchange_flags
= be32_to_cpup(p
++);
4507 /* We ask for SP4_NONE */
4508 dummy
= be32_to_cpup(p
);
4509 if (dummy
!= SP4_NONE
)
4512 /* Throw away minor_id */
4513 p
= xdr_inline_decode(xdr
, 8);
4517 /* Throw away Major id */
4518 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4519 if (unlikely(status
))
4522 /* Throw away server_scope */
4523 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4524 if (unlikely(status
))
4527 /* Throw away Implementation id array */
4528 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
4529 if (unlikely(status
))
4534 print_overflow_msg(__func__
, xdr
);
4538 static int decode_chan_attrs(struct xdr_stream
*xdr
,
4539 struct nfs4_channel_attrs
*attrs
)
4544 p
= xdr_inline_decode(xdr
, 28);
4547 attrs
->headerpadsz
= be32_to_cpup(p
++);
4548 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
4549 attrs
->max_resp_sz
= be32_to_cpup(p
++);
4550 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
4551 attrs
->max_ops
= be32_to_cpup(p
++);
4552 attrs
->max_reqs
= be32_to_cpup(p
++);
4553 nr_attrs
= be32_to_cpup(p
);
4554 if (unlikely(nr_attrs
> 1)) {
4555 printk(KERN_WARNING
"%s: Invalid rdma channel attrs count %u\n",
4556 __func__
, nr_attrs
);
4559 if (nr_attrs
== 1) {
4560 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
4566 print_overflow_msg(__func__
, xdr
);
4570 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
4572 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
4575 static int decode_create_session(struct xdr_stream
*xdr
,
4576 struct nfs41_create_session_res
*res
)
4580 struct nfs_client
*clp
= res
->client
;
4581 struct nfs4_session
*session
= clp
->cl_session
;
4583 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
4585 status
= decode_sessionid(xdr
, &session
->sess_id
);
4586 if (unlikely(status
))
4590 p
= xdr_inline_decode(xdr
, 8);
4593 clp
->cl_seqid
= be32_to_cpup(p
++);
4594 session
->flags
= be32_to_cpup(p
);
4596 /* Channel attributes */
4597 status
= decode_chan_attrs(xdr
, &session
->fc_attrs
);
4599 status
= decode_chan_attrs(xdr
, &session
->bc_attrs
);
4602 print_overflow_msg(__func__
, xdr
);
4606 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
4608 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
4611 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
4613 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
4615 #endif /* CONFIG_NFS_V4_1 */
4617 static int decode_sequence(struct xdr_stream
*xdr
,
4618 struct nfs4_sequence_res
*res
,
4619 struct rpc_rqst
*rqstp
)
4621 #if defined(CONFIG_NFS_V4_1)
4622 struct nfs4_slot
*slot
;
4623 struct nfs4_sessionid id
;
4628 if (!res
->sr_session
)
4631 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
4633 status
= decode_sessionid(xdr
, &id
);
4634 if (unlikely(status
))
4638 * If the server returns different values for sessionID, slotID or
4639 * sequence number, the server is looney tunes.
4641 status
= -EREMOTEIO
;
4643 if (memcmp(id
.data
, res
->sr_session
->sess_id
.data
,
4644 NFS4_MAX_SESSIONID_LEN
)) {
4645 dprintk("%s Invalid session id\n", __func__
);
4649 p
= xdr_inline_decode(xdr
, 20);
4654 slot
= &res
->sr_session
->fc_slot_table
.slots
[res
->sr_slotid
];
4655 dummy
= be32_to_cpup(p
++);
4656 if (dummy
!= slot
->seq_nr
) {
4657 dprintk("%s Invalid sequence number\n", __func__
);
4661 dummy
= be32_to_cpup(p
++);
4662 if (dummy
!= res
->sr_slotid
) {
4663 dprintk("%s Invalid slot id\n", __func__
);
4666 /* highest slot id - currently not processed */
4667 dummy
= be32_to_cpup(p
++);
4668 /* target highest slot id - currently not processed */
4669 dummy
= be32_to_cpup(p
++);
4671 res
->sr_status_flags
= be32_to_cpup(p
);
4674 res
->sr_status
= status
;
4677 print_overflow_msg(__func__
, xdr
);
4680 #else /* CONFIG_NFS_V4_1 */
4682 #endif /* CONFIG_NFS_V4_1 */
4686 * END OF "GENERIC" DECODE ROUTINES.
4690 * Decode OPEN_DOWNGRADE response
4692 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*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 status
= decode_putfh(&xdr
);
4708 status
= decode_open_downgrade(&xdr
, res
);
4711 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4712 !RPC_IS_ASYNC(rqstp
->rq_task
));
4718 * Decode ACCESS response
4720 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_accessres
*res
)
4722 struct xdr_stream xdr
;
4723 struct compound_hdr hdr
;
4726 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4727 status
= decode_compound_hdr(&xdr
, &hdr
);
4730 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4733 status
= decode_putfh(&xdr
);
4736 status
= decode_access(&xdr
, res
);
4739 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4740 !RPC_IS_ASYNC(rqstp
->rq_task
));
4746 * Decode LOOKUP response
4748 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
4750 struct xdr_stream xdr
;
4751 struct compound_hdr hdr
;
4754 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4755 status
= decode_compound_hdr(&xdr
, &hdr
);
4758 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4761 if ((status
= decode_putfh(&xdr
)) != 0)
4763 if ((status
= decode_lookup(&xdr
)) != 0)
4765 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
4767 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
4768 ,!RPC_IS_ASYNC(rqstp
->rq_task
));
4774 * Decode LOOKUP_ROOT response
4776 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
4778 struct xdr_stream xdr
;
4779 struct compound_hdr hdr
;
4782 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4783 status
= decode_compound_hdr(&xdr
, &hdr
);
4786 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4789 if ((status
= decode_putrootfh(&xdr
)) != 0)
4791 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
4792 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4793 !RPC_IS_ASYNC(rqstp
->rq_task
));
4799 * Decode REMOVE response
4801 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_removeres
*res
)
4803 struct xdr_stream xdr
;
4804 struct compound_hdr hdr
;
4807 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4808 status
= decode_compound_hdr(&xdr
, &hdr
);
4811 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4814 if ((status
= decode_putfh(&xdr
)) != 0)
4816 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
4818 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
4819 !RPC_IS_ASYNC(rqstp
->rq_task
));
4825 * Decode RENAME response
4827 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_rename_res
*res
)
4829 struct xdr_stream xdr
;
4830 struct compound_hdr hdr
;
4833 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4834 status
= decode_compound_hdr(&xdr
, &hdr
);
4837 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4840 if ((status
= decode_putfh(&xdr
)) != 0)
4842 if ((status
= decode_savefh(&xdr
)) != 0)
4844 if ((status
= decode_putfh(&xdr
)) != 0)
4846 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
4848 /* Current FH is target directory */
4849 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
,
4850 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4852 if ((status
= decode_restorefh(&xdr
)) != 0)
4854 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
,
4855 !RPC_IS_ASYNC(rqstp
->rq_task
));
4861 * Decode LINK response
4863 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_link_res
*res
)
4865 struct xdr_stream xdr
;
4866 struct compound_hdr hdr
;
4869 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4870 status
= decode_compound_hdr(&xdr
, &hdr
);
4873 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4876 if ((status
= decode_putfh(&xdr
)) != 0)
4878 if ((status
= decode_savefh(&xdr
)) != 0)
4880 if ((status
= decode_putfh(&xdr
)) != 0)
4882 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
4885 * Note order: OP_LINK leaves the directory as the current
4888 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
4889 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4891 if ((status
= decode_restorefh(&xdr
)) != 0)
4893 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4894 !RPC_IS_ASYNC(rqstp
->rq_task
));
4900 * Decode CREATE response
4902 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
4904 struct xdr_stream xdr
;
4905 struct compound_hdr hdr
;
4908 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4909 status
= decode_compound_hdr(&xdr
, &hdr
);
4912 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4915 if ((status
= decode_putfh(&xdr
)) != 0)
4917 if ((status
= decode_savefh(&xdr
)) != 0)
4919 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
4921 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
4923 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4924 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
4926 if ((status
= decode_restorefh(&xdr
)) != 0)
4928 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
,
4929 !RPC_IS_ASYNC(rqstp
->rq_task
));
4935 * Decode SYMLINK response
4937 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
4939 return nfs4_xdr_dec_create(rqstp
, p
, res
);
4943 * Decode GETATTR response
4945 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_getattr_res
*res
)
4947 struct xdr_stream xdr
;
4948 struct compound_hdr hdr
;
4951 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4952 status
= decode_compound_hdr(&xdr
, &hdr
);
4955 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
4958 status
= decode_putfh(&xdr
);
4961 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
,
4962 !RPC_IS_ASYNC(rqstp
->rq_task
));
4968 * Encode an SETACL request
4971 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setaclargs
*args
)
4973 struct xdr_stream xdr
;
4974 struct compound_hdr hdr
= {
4975 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
4979 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
4980 encode_compound_hdr(&xdr
, req
, &hdr
);
4981 encode_sequence(&xdr
, &args
->seq_args
, &hdr
);
4982 encode_putfh(&xdr
, args
->fh
, &hdr
);
4983 status
= encode_setacl(&xdr
, args
, &hdr
);
4989 * Decode SETACL response
4992 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, __be32
*p
,
4993 struct nfs_setaclres
*res
)
4995 struct xdr_stream xdr
;
4996 struct compound_hdr hdr
;
4999 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5000 status
= decode_compound_hdr(&xdr
, &hdr
);
5003 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5006 status
= decode_putfh(&xdr
);
5009 status
= decode_setattr(&xdr
);
5015 * Decode GETACL response
5018 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, __be32
*p
,
5019 struct nfs_getaclres
*res
)
5021 struct xdr_stream xdr
;
5022 struct compound_hdr hdr
;
5025 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5026 status
= decode_compound_hdr(&xdr
, &hdr
);
5029 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5032 status
= decode_putfh(&xdr
);
5035 status
= decode_getacl(&xdr
, rqstp
, &res
->acl_len
);
5042 * Decode CLOSE response
5044 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
5046 struct xdr_stream xdr
;
5047 struct compound_hdr hdr
;
5050 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5051 status
= decode_compound_hdr(&xdr
, &hdr
);
5054 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5057 status
= decode_putfh(&xdr
);
5060 status
= decode_close(&xdr
, res
);
5064 * Note: Server may do delete on close for this file
5065 * in which case the getattr call will fail with
5066 * an ESTALE error. Shouldn't be a problem,
5067 * though, since fattr->valid will remain unset.
5069 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5070 !RPC_IS_ASYNC(rqstp
->rq_task
));
5076 * Decode OPEN response
5078 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
5080 struct xdr_stream xdr
;
5081 struct compound_hdr hdr
;
5084 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5085 status
= decode_compound_hdr(&xdr
, &hdr
);
5088 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5091 status
= decode_putfh(&xdr
);
5094 status
= decode_savefh(&xdr
);
5097 status
= decode_open(&xdr
, res
);
5100 if (decode_getfh(&xdr
, &res
->fh
) != 0)
5102 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
,
5103 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5105 if (decode_restorefh(&xdr
) != 0)
5107 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
,
5108 !RPC_IS_ASYNC(rqstp
->rq_task
));
5114 * Decode OPEN_CONFIRM response
5116 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_open_confirmres
*res
)
5118 struct xdr_stream xdr
;
5119 struct compound_hdr hdr
;
5122 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5123 status
= decode_compound_hdr(&xdr
, &hdr
);
5126 status
= decode_putfh(&xdr
);
5129 status
= decode_open_confirm(&xdr
, res
);
5135 * Decode OPEN response
5137 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
5139 struct xdr_stream xdr
;
5140 struct compound_hdr hdr
;
5143 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5144 status
= decode_compound_hdr(&xdr
, &hdr
);
5147 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5150 status
= decode_putfh(&xdr
);
5153 status
= decode_open(&xdr
, res
);
5156 decode_getfattr(&xdr
, res
->f_attr
, res
->server
,
5157 !RPC_IS_ASYNC(rqstp
->rq_task
));
5163 * Decode SETATTR response
5165 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_setattrres
*res
)
5167 struct xdr_stream xdr
;
5168 struct compound_hdr hdr
;
5171 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5172 status
= decode_compound_hdr(&xdr
, &hdr
);
5175 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5178 status
= decode_putfh(&xdr
);
5181 status
= decode_setattr(&xdr
);
5184 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5185 !RPC_IS_ASYNC(rqstp
->rq_task
));
5191 * Decode LOCK response
5193 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lock_res
*res
)
5195 struct xdr_stream xdr
;
5196 struct compound_hdr hdr
;
5199 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5200 status
= decode_compound_hdr(&xdr
, &hdr
);
5203 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5206 status
= decode_putfh(&xdr
);
5209 status
= decode_lock(&xdr
, res
);
5215 * Decode LOCKT response
5217 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lockt_res
*res
)
5219 struct xdr_stream xdr
;
5220 struct compound_hdr hdr
;
5223 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5224 status
= decode_compound_hdr(&xdr
, &hdr
);
5227 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5230 status
= decode_putfh(&xdr
);
5233 status
= decode_lockt(&xdr
, res
);
5239 * Decode LOCKU response
5241 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_locku_res
*res
)
5243 struct xdr_stream xdr
;
5244 struct compound_hdr hdr
;
5247 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5248 status
= decode_compound_hdr(&xdr
, &hdr
);
5251 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5254 status
= decode_putfh(&xdr
);
5257 status
= decode_locku(&xdr
, res
);
5263 * Decode READLINK response
5265 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, __be32
*p
,
5266 struct nfs4_readlink_res
*res
)
5268 struct xdr_stream xdr
;
5269 struct compound_hdr hdr
;
5272 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5273 status
= decode_compound_hdr(&xdr
, &hdr
);
5276 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5279 status
= decode_putfh(&xdr
);
5282 status
= decode_readlink(&xdr
, rqstp
);
5288 * Decode READDIR response
5290 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_readdir_res
*res
)
5292 struct xdr_stream xdr
;
5293 struct compound_hdr hdr
;
5296 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5297 status
= decode_compound_hdr(&xdr
, &hdr
);
5300 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5303 status
= decode_putfh(&xdr
);
5306 status
= decode_readdir(&xdr
, rqstp
, res
);
5312 * Decode Read response
5314 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_readres
*res
)
5316 struct xdr_stream xdr
;
5317 struct compound_hdr hdr
;
5320 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5321 status
= decode_compound_hdr(&xdr
, &hdr
);
5324 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5327 status
= decode_putfh(&xdr
);
5330 status
= decode_read(&xdr
, rqstp
, res
);
5332 status
= res
->count
;
5338 * Decode WRITE response
5340 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
5342 struct xdr_stream xdr
;
5343 struct compound_hdr hdr
;
5346 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5347 status
= decode_compound_hdr(&xdr
, &hdr
);
5350 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5353 status
= decode_putfh(&xdr
);
5356 status
= decode_write(&xdr
, res
);
5359 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5360 !RPC_IS_ASYNC(rqstp
->rq_task
));
5362 status
= res
->count
;
5368 * Decode COMMIT response
5370 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
5372 struct xdr_stream xdr
;
5373 struct compound_hdr hdr
;
5376 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5377 status
= decode_compound_hdr(&xdr
, &hdr
);
5380 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5383 status
= decode_putfh(&xdr
);
5386 status
= decode_commit(&xdr
, res
);
5389 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5390 !RPC_IS_ASYNC(rqstp
->rq_task
));
5396 * Decode FSINFO response
5398 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, __be32
*p
,
5399 struct nfs4_fsinfo_res
*res
)
5401 struct xdr_stream xdr
;
5402 struct compound_hdr hdr
;
5405 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5406 status
= decode_compound_hdr(&xdr
, &hdr
);
5408 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5410 status
= decode_putfh(&xdr
);
5412 status
= decode_fsinfo(&xdr
, res
->fsinfo
);
5417 * Decode PATHCONF response
5419 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, __be32
*p
,
5420 struct nfs4_pathconf_res
*res
)
5422 struct xdr_stream xdr
;
5423 struct compound_hdr hdr
;
5426 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5427 status
= decode_compound_hdr(&xdr
, &hdr
);
5429 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5431 status
= decode_putfh(&xdr
);
5433 status
= decode_pathconf(&xdr
, res
->pathconf
);
5438 * Decode STATFS response
5440 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, __be32
*p
,
5441 struct nfs4_statfs_res
*res
)
5443 struct xdr_stream xdr
;
5444 struct compound_hdr hdr
;
5447 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5448 status
= decode_compound_hdr(&xdr
, &hdr
);
5450 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5452 status
= decode_putfh(&xdr
);
5454 status
= decode_statfs(&xdr
, res
->fsstat
);
5459 * Decode GETATTR_BITMAP response
5461 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_server_caps_res
*res
)
5463 struct xdr_stream xdr
;
5464 struct compound_hdr hdr
;
5467 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5468 status
= decode_compound_hdr(&xdr
, &hdr
);
5471 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5474 if ((status
= decode_putfh(&xdr
)) != 0)
5476 status
= decode_server_caps(&xdr
, res
);
5482 * Decode RENEW response
5484 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, __be32
*p
, void *dummy
)
5486 struct xdr_stream xdr
;
5487 struct compound_hdr hdr
;
5490 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5491 status
= decode_compound_hdr(&xdr
, &hdr
);
5493 status
= decode_renew(&xdr
);
5498 * Decode SETCLIENTID response
5500 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, __be32
*p
,
5501 struct nfs4_setclientid_res
*res
)
5503 struct xdr_stream xdr
;
5504 struct compound_hdr hdr
;
5507 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5508 status
= decode_compound_hdr(&xdr
, &hdr
);
5510 status
= decode_setclientid(&xdr
, res
);
5515 * Decode SETCLIENTID_CONFIRM response
5517 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
5519 struct xdr_stream xdr
;
5520 struct compound_hdr hdr
;
5523 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5524 status
= decode_compound_hdr(&xdr
, &hdr
);
5526 status
= decode_setclientid_confirm(&xdr
);
5528 status
= decode_putrootfh(&xdr
);
5530 status
= decode_fsinfo(&xdr
, fsinfo
);
5535 * Decode DELEGRETURN response
5537 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_delegreturnres
*res
)
5539 struct xdr_stream xdr
;
5540 struct compound_hdr hdr
;
5543 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5544 status
= decode_compound_hdr(&xdr
, &hdr
);
5547 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5550 status
= decode_putfh(&xdr
);
5553 status
= decode_delegreturn(&xdr
);
5556 decode_getfattr(&xdr
, res
->fattr
, res
->server
,
5557 !RPC_IS_ASYNC(rqstp
->rq_task
));
5563 * Decode FS_LOCATIONS response
5565 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
, __be32
*p
,
5566 struct nfs4_fs_locations_res
*res
)
5568 struct xdr_stream xdr
;
5569 struct compound_hdr hdr
;
5572 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
5573 status
= decode_compound_hdr(&xdr
, &hdr
);
5576 status
= decode_sequence(&xdr
, &res
->seq_res
, req
);
5579 if ((status
= decode_putfh(&xdr
)) != 0)
5581 if ((status
= decode_lookup(&xdr
)) != 0)
5583 xdr_enter_page(&xdr
, PAGE_SIZE
);
5584 status
= decode_getfattr(&xdr
, &res
->fs_locations
->fattr
,
5585 res
->fs_locations
->server
,
5586 !RPC_IS_ASYNC(req
->rq_task
));
5591 #if defined(CONFIG_NFS_V4_1)
5593 * Decode EXCHANGE_ID response
5595 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
, uint32_t *p
,
5598 struct xdr_stream xdr
;
5599 struct compound_hdr hdr
;
5602 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5603 status
= decode_compound_hdr(&xdr
, &hdr
);
5605 status
= decode_exchange_id(&xdr
, res
);
5610 * Decode CREATE_SESSION response
5612 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
, uint32_t *p
,
5613 struct nfs41_create_session_res
*res
)
5615 struct xdr_stream xdr
;
5616 struct compound_hdr hdr
;
5619 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5620 status
= decode_compound_hdr(&xdr
, &hdr
);
5622 status
= decode_create_session(&xdr
, res
);
5627 * Decode DESTROY_SESSION response
5629 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
, uint32_t *p
,
5632 struct xdr_stream xdr
;
5633 struct compound_hdr hdr
;
5636 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5637 status
= decode_compound_hdr(&xdr
, &hdr
);
5639 status
= decode_destroy_session(&xdr
, dummy
);
5644 * Decode SEQUENCE response
5646 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
, uint32_t *p
,
5647 struct nfs4_sequence_res
*res
)
5649 struct xdr_stream xdr
;
5650 struct compound_hdr hdr
;
5653 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5654 status
= decode_compound_hdr(&xdr
, &hdr
);
5656 status
= decode_sequence(&xdr
, res
, rqstp
);
5661 * Decode GET_LEASE_TIME response
5663 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
, uint32_t *p
,
5664 struct nfs4_get_lease_time_res
*res
)
5666 struct xdr_stream xdr
;
5667 struct compound_hdr hdr
;
5670 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5671 status
= decode_compound_hdr(&xdr
, &hdr
);
5673 status
= decode_sequence(&xdr
, &res
->lr_seq_res
, rqstp
);
5675 status
= decode_putrootfh(&xdr
);
5677 status
= decode_fsinfo(&xdr
, res
->lr_fsinfo
);
5682 * Decode RECLAIM_COMPLETE response
5684 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
, uint32_t *p
,
5685 struct nfs41_reclaim_complete_res
*res
)
5687 struct xdr_stream xdr
;
5688 struct compound_hdr hdr
;
5691 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
5692 status
= decode_compound_hdr(&xdr
, &hdr
);
5694 status
= decode_sequence(&xdr
, &res
->seq_res
, rqstp
);
5696 status
= decode_reclaim_complete(&xdr
, (void *)NULL
);
5699 #endif /* CONFIG_NFS_V4_1 */
5701 __be32
*nfs4_decode_dirent(__be32
*p
, struct nfs_entry
*entry
, int plus
)
5703 uint32_t bitmap
[2] = {0};
5708 return ERR_PTR(-EAGAIN
);
5710 return ERR_PTR(-EBADCOOKIE
);
5713 entry
->prev_cookie
= entry
->cookie
;
5714 p
= xdr_decode_hyper(p
, &entry
->cookie
);
5715 entry
->len
= ntohl(*p
++);
5716 entry
->name
= (const char *) p
;
5717 p
+= XDR_QUADLEN(entry
->len
);
5720 * In case the server doesn't return an inode number,
5721 * we fake one here. (We don't use inode number 0,
5722 * since glibc seems to choke on it...)
5726 len
= ntohl(*p
++); /* bitmap length */
5728 bitmap
[0] = ntohl(*p
++);
5730 bitmap
[1] = ntohl(*p
++);
5734 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
5736 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
5737 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
5738 /* Ignore the return value of rdattr_error for now */
5742 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
5743 xdr_decode_hyper(p
, &entry
->ino
);
5744 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
5745 xdr_decode_hyper(p
, &entry
->ino
);
5749 entry
->eof
= !p
[0] && p
[1];
5754 * We need to translate between nfs status return values and
5755 * the local errno values which may not be the same.
5762 { NFS4ERR_PERM
, -EPERM
},
5763 { NFS4ERR_NOENT
, -ENOENT
},
5764 { NFS4ERR_IO
, -errno_NFSERR_IO
},
5765 { NFS4ERR_NXIO
, -ENXIO
},
5766 { NFS4ERR_ACCESS
, -EACCES
},
5767 { NFS4ERR_EXIST
, -EEXIST
},
5768 { NFS4ERR_XDEV
, -EXDEV
},
5769 { NFS4ERR_NOTDIR
, -ENOTDIR
},
5770 { NFS4ERR_ISDIR
, -EISDIR
},
5771 { NFS4ERR_INVAL
, -EINVAL
},
5772 { NFS4ERR_FBIG
, -EFBIG
},
5773 { NFS4ERR_NOSPC
, -ENOSPC
},
5774 { NFS4ERR_ROFS
, -EROFS
},
5775 { NFS4ERR_MLINK
, -EMLINK
},
5776 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
5777 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
5778 { NFS4ERR_DQUOT
, -EDQUOT
},
5779 { NFS4ERR_STALE
, -ESTALE
},
5780 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
5781 { NFS4ERR_BADOWNER
, -EINVAL
},
5782 { NFS4ERR_BADNAME
, -EINVAL
},
5783 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
5784 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
5785 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
5786 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
5787 { NFS4ERR_BADTYPE
, -EBADTYPE
},
5788 { NFS4ERR_LOCKED
, -EAGAIN
},
5789 { NFS4ERR_SYMLINK
, -ELOOP
},
5790 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
5791 { NFS4ERR_DEADLOCK
, -EDEADLK
},
5792 { NFS4ERR_WRONGSEC
, -EPERM
}, /* FIXME: this needs
5793 * to be handled by a
5800 * Convert an NFS error code to a local one.
5801 * This one is used jointly by NFSv2 and NFSv3.
5804 nfs4_stat_to_errno(int stat
)
5807 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
5808 if (nfs_errtbl
[i
].stat
== stat
)
5809 return nfs_errtbl
[i
].errno
;
5811 if (stat
<= 10000 || stat
> 10100) {
5812 /* The server is looney tunes. */
5815 /* If we cannot translate the error, the recovery routines should
5817 * Note: remaining NFSv4 error codes have values > 10000, so should
5818 * not conflict with native Linux error codes.
5823 #define PROC(proc, argtype, restype) \
5824 [NFSPROC4_CLNT_##proc] = { \
5825 .p_proc = NFSPROC4_COMPOUND, \
5826 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5827 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
5828 .p_arglen = NFS4_##argtype##_sz, \
5829 .p_replen = NFS4_##restype##_sz, \
5830 .p_statidx = NFSPROC4_CLNT_##proc, \
5834 struct rpc_procinfo nfs4_procedures
[] = {
5835 PROC(READ
, enc_read
, dec_read
),
5836 PROC(WRITE
, enc_write
, dec_write
),
5837 PROC(COMMIT
, enc_commit
, dec_commit
),
5838 PROC(OPEN
, enc_open
, dec_open
),
5839 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
5840 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
5841 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
5842 PROC(CLOSE
, enc_close
, dec_close
),
5843 PROC(SETATTR
, enc_setattr
, dec_setattr
),
5844 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
5845 PROC(RENEW
, enc_renew
, dec_renew
),
5846 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
5847 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
5848 PROC(LOCK
, enc_lock
, dec_lock
),
5849 PROC(LOCKT
, enc_lockt
, dec_lockt
),
5850 PROC(LOCKU
, enc_locku
, dec_locku
),
5851 PROC(ACCESS
, enc_access
, dec_access
),
5852 PROC(GETATTR
, enc_getattr
, dec_getattr
),
5853 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
5854 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
5855 PROC(REMOVE
, enc_remove
, dec_remove
),
5856 PROC(RENAME
, enc_rename
, dec_rename
),
5857 PROC(LINK
, enc_link
, dec_link
),
5858 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
5859 PROC(CREATE
, enc_create
, dec_create
),
5860 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
5861 PROC(STATFS
, enc_statfs
, dec_statfs
),
5862 PROC(READLINK
, enc_readlink
, dec_readlink
),
5863 PROC(READDIR
, enc_readdir
, dec_readdir
),
5864 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
5865 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
5866 PROC(GETACL
, enc_getacl
, dec_getacl
),
5867 PROC(SETACL
, enc_setacl
, dec_setacl
),
5868 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
5869 #if defined(CONFIG_NFS_V4_1)
5870 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
5871 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
5872 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
5873 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
5874 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
5875 PROC(RECLAIM_COMPLETE
, enc_reclaim_complete
, dec_reclaim_complete
),
5876 #endif /* CONFIG_NFS_V4_1 */
5879 struct rpc_version nfs_version4
= {
5881 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
5882 .procs
= nfs4_procedures