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/sunrpc/gss_api.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
58 #define NFSDBG_FACILITY NFSDBG_XDR
60 /* Mapping from NFS error code to "errno" error code. */
61 #define errno_NFSERR_IO EIO
63 static int nfs4_stat_to_errno(int);
65 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
67 #define NFS4_MAXTAGLEN 20
69 #define NFS4_MAXTAGLEN 0
72 /* lock,open owner id:
73 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
75 #define open_owner_id_maxsz (1 + 1 + 4)
76 #define lock_owner_id_maxsz (1 + 1 + 4)
77 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
78 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80 #define op_encode_hdr_maxsz (1)
81 #define op_decode_hdr_maxsz (2)
82 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
86 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
88 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
92 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
94 #define nfs4_fattr_bitmap_maxsz 3
95 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
96 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
98 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
100 /* This is based on getfattr, which uses the most attributes: */
101 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
103 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
106 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
111 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
115 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
116 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
117 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118 #define decode_renew_maxsz (op_decode_hdr_maxsz)
119 #define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
127 #define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
130 1024) /* large value for CLID_INUSE */
131 #define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134 #define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
136 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
138 #define encode_share_access_maxsz \
140 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
141 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143 #define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
149 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
151 #define decode_change_info_maxsz (5)
152 #define decode_open_maxsz (op_decode_hdr_maxsz + \
153 decode_stateid_maxsz + \
154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
157 #define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160 #define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163 #define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167 #define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170 #define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172 #define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
177 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179 #define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
187 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188 #define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190 #define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
195 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
197 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
199 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
201 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
204 #define encode_link_maxsz (op_encode_hdr_maxsz + \
206 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
207 #define encode_lockowner_maxsz (7)
208 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
212 #define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
216 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
218 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
223 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
225 #define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228 #define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
230 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
232 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
236 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237 #define encode_create_maxsz (op_encode_hdr_maxsz + \
238 1 + 2 + nfs4_name_maxsz + \
240 #define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
243 #define encode_statfs_maxsz (encode_getattr_maxsz)
244 #define decode_statfs_maxsz (decode_getattr_maxsz)
245 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
247 #define encode_getacl_maxsz (encode_getattr_maxsz)
248 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252 #define decode_setacl_maxsz (decode_setattr_maxsz)
253 #define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255 #define decode_fs_locations_maxsz \
257 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
258 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 4 + (NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)))
260 #if defined(CONFIG_NFS_V4_1)
261 #define NFS4_MAX_MACHINE_NAME_LEN (64)
263 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
284 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285 #define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
288 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
302 1 /* gids.len (0) */)
303 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
309 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
311 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
315 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
317 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
330 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
334 encode_stateid_maxsz + \
335 1 /* new offset (true) */ + \
336 2 /* last byte written */ + \
337 1 /* nt_timechanged (false) */ + \
338 1 /* layoutupdate4 layout type */ + \
339 1 /* NULL filelayout layoutupdate4 payload */)
340 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
341 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
342 encode_stateid_maxsz + \
343 1 /* FIXME: opaque lrf_body always empty at the moment */)
344 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
345 1 + decode_stateid_maxsz)
346 #else /* CONFIG_NFS_V4_1 */
347 #define encode_sequence_maxsz 0
348 #define decode_sequence_maxsz 0
349 #endif /* CONFIG_NFS_V4_1 */
351 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
352 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
353 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
354 encode_sequence_maxsz + \
355 encode_putfh_maxsz + \
357 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
358 decode_sequence_maxsz + \
359 decode_putfh_maxsz + \
361 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
362 encode_sequence_maxsz + \
363 encode_putfh_maxsz + \
364 encode_readlink_maxsz)
365 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
366 decode_sequence_maxsz + \
367 decode_putfh_maxsz + \
368 decode_readlink_maxsz)
369 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
370 encode_sequence_maxsz + \
371 encode_putfh_maxsz + \
372 encode_readdir_maxsz)
373 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
374 decode_sequence_maxsz + \
375 decode_putfh_maxsz + \
376 decode_readdir_maxsz)
377 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
378 encode_sequence_maxsz + \
379 encode_putfh_maxsz + \
380 encode_write_maxsz + \
381 encode_getattr_maxsz)
382 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
383 decode_sequence_maxsz + \
384 decode_putfh_maxsz + \
385 decode_write_maxsz + \
386 decode_getattr_maxsz)
387 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
388 encode_sequence_maxsz + \
389 encode_putfh_maxsz + \
390 encode_commit_maxsz + \
391 encode_getattr_maxsz)
392 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
393 decode_sequence_maxsz + \
394 decode_putfh_maxsz + \
395 decode_commit_maxsz + \
396 decode_getattr_maxsz)
397 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
398 encode_sequence_maxsz + \
399 encode_putfh_maxsz + \
400 encode_savefh_maxsz + \
401 encode_open_maxsz + \
402 encode_getfh_maxsz + \
403 encode_getattr_maxsz + \
404 encode_restorefh_maxsz + \
405 encode_getattr_maxsz)
406 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
407 decode_sequence_maxsz + \
408 decode_putfh_maxsz + \
409 decode_savefh_maxsz + \
410 decode_open_maxsz + \
411 decode_getfh_maxsz + \
412 decode_getattr_maxsz + \
413 decode_restorefh_maxsz + \
414 decode_getattr_maxsz)
415 #define NFS4_enc_open_confirm_sz \
416 (compound_encode_hdr_maxsz + \
417 encode_putfh_maxsz + \
418 encode_open_confirm_maxsz)
419 #define NFS4_dec_open_confirm_sz \
420 (compound_decode_hdr_maxsz + \
421 decode_putfh_maxsz + \
422 decode_open_confirm_maxsz)
423 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
424 encode_sequence_maxsz + \
425 encode_putfh_maxsz + \
426 encode_open_maxsz + \
427 encode_getattr_maxsz)
428 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
429 decode_sequence_maxsz + \
430 decode_putfh_maxsz + \
431 decode_open_maxsz + \
432 decode_getattr_maxsz)
433 #define NFS4_enc_open_downgrade_sz \
434 (compound_encode_hdr_maxsz + \
435 encode_sequence_maxsz + \
436 encode_putfh_maxsz + \
437 encode_open_downgrade_maxsz + \
438 encode_getattr_maxsz)
439 #define NFS4_dec_open_downgrade_sz \
440 (compound_decode_hdr_maxsz + \
441 decode_sequence_maxsz + \
442 decode_putfh_maxsz + \
443 decode_open_downgrade_maxsz + \
444 decode_getattr_maxsz)
445 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
446 encode_sequence_maxsz + \
447 encode_putfh_maxsz + \
448 encode_close_maxsz + \
449 encode_getattr_maxsz)
450 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
451 decode_sequence_maxsz + \
452 decode_putfh_maxsz + \
453 decode_close_maxsz + \
454 decode_getattr_maxsz)
455 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
456 encode_sequence_maxsz + \
457 encode_putfh_maxsz + \
458 encode_setattr_maxsz + \
459 encode_getattr_maxsz)
460 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
461 decode_sequence_maxsz + \
462 decode_putfh_maxsz + \
463 decode_setattr_maxsz + \
464 decode_getattr_maxsz)
465 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
466 encode_sequence_maxsz + \
467 encode_putfh_maxsz + \
469 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
470 decode_sequence_maxsz + \
471 decode_putfh_maxsz + \
473 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
475 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
477 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
478 encode_setclientid_maxsz)
479 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
480 decode_setclientid_maxsz)
481 #define NFS4_enc_setclientid_confirm_sz \
482 (compound_encode_hdr_maxsz + \
483 encode_setclientid_confirm_maxsz + \
484 encode_putrootfh_maxsz + \
486 #define NFS4_dec_setclientid_confirm_sz \
487 (compound_decode_hdr_maxsz + \
488 decode_setclientid_confirm_maxsz + \
489 decode_putrootfh_maxsz + \
491 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
492 encode_sequence_maxsz + \
493 encode_putfh_maxsz + \
495 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
496 decode_sequence_maxsz + \
497 decode_putfh_maxsz + \
499 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
500 encode_sequence_maxsz + \
501 encode_putfh_maxsz + \
503 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
504 decode_sequence_maxsz + \
505 decode_putfh_maxsz + \
507 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
508 encode_sequence_maxsz + \
509 encode_putfh_maxsz + \
511 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
512 decode_sequence_maxsz + \
513 decode_putfh_maxsz + \
515 #define NFS4_enc_release_lockowner_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_lockowner_maxsz)
518 #define NFS4_dec_release_lockowner_sz \
519 (compound_decode_hdr_maxsz + \
520 decode_lockowner_maxsz)
521 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
522 encode_sequence_maxsz + \
523 encode_putfh_maxsz + \
524 encode_access_maxsz + \
525 encode_getattr_maxsz)
526 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
527 decode_sequence_maxsz + \
528 decode_putfh_maxsz + \
529 decode_access_maxsz + \
530 decode_getattr_maxsz)
531 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
532 encode_sequence_maxsz + \
533 encode_putfh_maxsz + \
534 encode_getattr_maxsz)
535 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
536 decode_sequence_maxsz + \
537 decode_putfh_maxsz + \
538 decode_getattr_maxsz)
539 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
540 encode_sequence_maxsz + \
541 encode_putfh_maxsz + \
542 encode_lookup_maxsz + \
543 encode_getattr_maxsz + \
545 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
546 decode_sequence_maxsz + \
547 decode_putfh_maxsz + \
548 decode_lookup_maxsz + \
549 decode_getattr_maxsz + \
551 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
552 encode_sequence_maxsz + \
553 encode_putrootfh_maxsz + \
554 encode_getattr_maxsz + \
556 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
557 decode_sequence_maxsz + \
558 decode_putrootfh_maxsz + \
559 decode_getattr_maxsz + \
561 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
562 encode_sequence_maxsz + \
563 encode_putfh_maxsz + \
564 encode_remove_maxsz + \
565 encode_getattr_maxsz)
566 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
567 decode_sequence_maxsz + \
568 decode_putfh_maxsz + \
569 decode_remove_maxsz + \
570 decode_getattr_maxsz)
571 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
572 encode_sequence_maxsz + \
573 encode_putfh_maxsz + \
574 encode_savefh_maxsz + \
575 encode_putfh_maxsz + \
576 encode_rename_maxsz + \
577 encode_getattr_maxsz + \
578 encode_restorefh_maxsz + \
579 encode_getattr_maxsz)
580 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
581 decode_sequence_maxsz + \
582 decode_putfh_maxsz + \
583 decode_savefh_maxsz + \
584 decode_putfh_maxsz + \
585 decode_rename_maxsz + \
586 decode_getattr_maxsz + \
587 decode_restorefh_maxsz + \
588 decode_getattr_maxsz)
589 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
590 encode_sequence_maxsz + \
591 encode_putfh_maxsz + \
592 encode_savefh_maxsz + \
593 encode_putfh_maxsz + \
594 encode_link_maxsz + \
595 decode_getattr_maxsz + \
596 encode_restorefh_maxsz + \
597 decode_getattr_maxsz)
598 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
599 decode_sequence_maxsz + \
600 decode_putfh_maxsz + \
601 decode_savefh_maxsz + \
602 decode_putfh_maxsz + \
603 decode_link_maxsz + \
604 decode_getattr_maxsz + \
605 decode_restorefh_maxsz + \
606 decode_getattr_maxsz)
607 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
608 encode_sequence_maxsz + \
609 encode_putfh_maxsz + \
610 encode_symlink_maxsz + \
611 encode_getattr_maxsz + \
613 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
614 decode_sequence_maxsz + \
615 decode_putfh_maxsz + \
616 decode_symlink_maxsz + \
617 decode_getattr_maxsz + \
619 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
620 encode_sequence_maxsz + \
621 encode_putfh_maxsz + \
622 encode_savefh_maxsz + \
623 encode_create_maxsz + \
624 encode_getfh_maxsz + \
625 encode_getattr_maxsz + \
626 encode_restorefh_maxsz + \
627 encode_getattr_maxsz)
628 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
629 decode_sequence_maxsz + \
630 decode_putfh_maxsz + \
631 decode_savefh_maxsz + \
632 decode_create_maxsz + \
633 decode_getfh_maxsz + \
634 decode_getattr_maxsz + \
635 decode_restorefh_maxsz + \
636 decode_getattr_maxsz)
637 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
638 encode_sequence_maxsz + \
639 encode_putfh_maxsz + \
640 encode_getattr_maxsz)
641 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
642 decode_sequence_maxsz + \
643 decode_putfh_maxsz + \
644 decode_getattr_maxsz)
645 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
646 encode_sequence_maxsz + \
647 encode_putfh_maxsz + \
649 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
650 decode_sequence_maxsz + \
651 decode_putfh_maxsz + \
653 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
654 encode_sequence_maxsz + \
655 encode_putfh_maxsz + \
656 encode_getattr_maxsz)
657 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
658 decode_sequence_maxsz + \
659 decode_putfh_maxsz + \
660 decode_getattr_maxsz)
661 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
662 encode_sequence_maxsz + \
663 encode_putfh_maxsz + \
664 encode_delegreturn_maxsz + \
665 encode_getattr_maxsz)
666 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
667 decode_sequence_maxsz + \
668 decode_delegreturn_maxsz + \
669 decode_getattr_maxsz)
670 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
671 encode_sequence_maxsz + \
672 encode_putfh_maxsz + \
674 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
675 decode_sequence_maxsz + \
676 decode_putfh_maxsz + \
678 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
679 encode_sequence_maxsz + \
680 encode_putfh_maxsz + \
682 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
683 decode_sequence_maxsz + \
684 decode_putfh_maxsz + \
686 #define NFS4_enc_fs_locations_sz \
687 (compound_encode_hdr_maxsz + \
688 encode_sequence_maxsz + \
689 encode_putfh_maxsz + \
690 encode_lookup_maxsz + \
691 encode_fs_locations_maxsz)
692 #define NFS4_dec_fs_locations_sz \
693 (compound_decode_hdr_maxsz + \
694 decode_sequence_maxsz + \
695 decode_putfh_maxsz + \
696 decode_lookup_maxsz + \
697 decode_fs_locations_maxsz)
698 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
699 encode_sequence_maxsz + \
700 encode_putfh_maxsz + \
701 encode_secinfo_maxsz)
702 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
703 decode_sequence_maxsz + \
704 decode_putfh_maxsz + \
705 decode_secinfo_maxsz)
706 #if defined(CONFIG_NFS_V4_1)
707 #define NFS4_enc_exchange_id_sz \
708 (compound_encode_hdr_maxsz + \
709 encode_exchange_id_maxsz)
710 #define NFS4_dec_exchange_id_sz \
711 (compound_decode_hdr_maxsz + \
712 decode_exchange_id_maxsz)
713 #define NFS4_enc_create_session_sz \
714 (compound_encode_hdr_maxsz + \
715 encode_create_session_maxsz)
716 #define NFS4_dec_create_session_sz \
717 (compound_decode_hdr_maxsz + \
718 decode_create_session_maxsz)
719 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
720 encode_destroy_session_maxsz)
721 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
722 decode_destroy_session_maxsz)
723 #define NFS4_enc_sequence_sz \
724 (compound_decode_hdr_maxsz + \
725 encode_sequence_maxsz)
726 #define NFS4_dec_sequence_sz \
727 (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz)
729 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
730 encode_sequence_maxsz + \
731 encode_putrootfh_maxsz + \
733 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
734 decode_sequence_maxsz + \
735 decode_putrootfh_maxsz + \
737 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
738 encode_sequence_maxsz + \
739 encode_reclaim_complete_maxsz)
740 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
741 decode_sequence_maxsz + \
742 decode_reclaim_complete_maxsz)
743 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
744 encode_sequence_maxsz +\
745 encode_getdeviceinfo_maxsz)
746 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz + \
748 decode_getdeviceinfo_maxsz)
749 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
750 encode_sequence_maxsz + \
751 encode_putfh_maxsz + \
752 encode_layoutget_maxsz)
753 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
754 decode_sequence_maxsz + \
755 decode_putfh_maxsz + \
756 decode_layoutget_maxsz)
757 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz +\
759 encode_putfh_maxsz + \
760 encode_layoutcommit_maxsz + \
761 encode_getattr_maxsz)
762 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
763 decode_sequence_maxsz + \
764 decode_putfh_maxsz + \
765 decode_layoutcommit_maxsz + \
766 decode_getattr_maxsz)
767 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
768 encode_sequence_maxsz + \
769 encode_putfh_maxsz + \
770 encode_layoutreturn_maxsz)
771 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz + \
773 decode_putfh_maxsz + \
774 decode_layoutreturn_maxsz)
776 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
777 compound_encode_hdr_maxsz +
778 encode_sequence_maxsz +
780 encode_getattr_maxsz) *
783 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
784 compound_decode_hdr_maxsz +
785 decode_sequence_maxsz +
786 decode_putfh_maxsz) *
788 #endif /* CONFIG_NFS_V4_1 */
790 static const umode_t nfs_type2fmt[] = {
797 [NF4SOCK] = S_IFSOCK,
803 struct compound_hdr {
809 uint32_t replen; /* expected reply words */
813 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
815 __be32 *p = xdr_reserve_space(xdr, nbytes);
820 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
824 p = xdr_reserve_space(xdr, 4 + len);
826 xdr_encode_opaque(p, str, len);
829 static void encode_compound_hdr(struct xdr_stream *xdr,
830 struct rpc_rqst *req,
831 struct compound_hdr *hdr)
834 struct rpc_auth *auth = req->rq_cred->cr_auth;
836 /* initialize running count of expected bytes in reply.
837 * NOTE: the replied tag SHOULD be the same is the one sent,
838 * but this is not required as a MUST for the server to do so. */
839 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
841 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
842 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
843 p = reserve_space(xdr, 4 + hdr->taglen + 8);
844 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
845 *p++ = cpu_to_be32(hdr->minorversion);
847 *p = cpu_to_be32(hdr->nops);
850 static void encode_nops(struct compound_hdr *hdr)
852 BUG_ON(hdr->nops > NFS4_MAX_OPS);
853 *hdr->nops_p = htonl(hdr->nops);
856 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
860 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
862 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
865 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
867 char owner_name[IDMAP_NAMESZ];
868 char owner_group[IDMAP_NAMESZ];
869 int owner_namelen = 0;
870 int owner_grouplen = 0;
878 * We reserve enough space to write the entire attribute buffer at once.
879 * In the worst-case, this would be
880 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
881 * = 36 bytes, plus any contribution from variable-length fields
882 * such as owner/group.
887 if (iap->ia_valid & ATTR_SIZE)
889 if (iap->ia_valid & ATTR_MODE)
891 if (iap->ia_valid & ATTR_UID) {
892 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
893 if (owner_namelen < 0) {
894 dprintk("nfs: couldn't resolve uid %d to string\n",
897 strcpy(owner_name, "nobody");
898 owner_namelen = sizeof("nobody") - 1;
901 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
903 if (iap->ia_valid & ATTR_GID) {
904 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
905 if (owner_grouplen < 0) {
906 dprintk("nfs: couldn't resolve gid %d to string\n",
908 strcpy(owner_group, "nobody");
909 owner_grouplen = sizeof("nobody") - 1;
912 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
914 if (iap->ia_valid & ATTR_ATIME_SET)
916 else if (iap->ia_valid & ATTR_ATIME)
918 if (iap->ia_valid & ATTR_MTIME_SET)
920 else if (iap->ia_valid & ATTR_MTIME)
922 p = reserve_space(xdr, len);
925 * We write the bitmap length now, but leave the bitmap and the attribute
926 * buffer length to be backfilled at the end of this routine.
928 *p++ = cpu_to_be32(2);
932 if (iap->ia_valid & ATTR_SIZE) {
933 bmval0 |= FATTR4_WORD0_SIZE;
934 p = xdr_encode_hyper(p, iap->ia_size);
936 if (iap->ia_valid & ATTR_MODE) {
937 bmval1 |= FATTR4_WORD1_MODE;
938 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
940 if (iap->ia_valid & ATTR_UID) {
941 bmval1 |= FATTR4_WORD1_OWNER;
942 p = xdr_encode_opaque(p, owner_name, owner_namelen);
944 if (iap->ia_valid & ATTR_GID) {
945 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
946 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
948 if (iap->ia_valid & ATTR_ATIME_SET) {
949 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
950 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
951 *p++ = cpu_to_be32(0);
952 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
953 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
955 else if (iap->ia_valid & ATTR_ATIME) {
956 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
957 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
959 if (iap->ia_valid & ATTR_MTIME_SET) {
960 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
961 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
962 *p++ = cpu_to_be32(0);
963 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
964 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
966 else if (iap->ia_valid & ATTR_MTIME) {
967 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
968 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
972 * Now we backfill the bitmap and the attribute buffer length.
974 if (len != ((char *)p - (char *)q) + 4) {
975 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
976 len, ((char *)p - (char *)q) + 4);
979 len = (char *)p - (char *)q - 12;
980 *q++ = htonl(bmval0);
981 *q++ = htonl(bmval1);
987 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
991 p = reserve_space(xdr, 8);
992 *p++ = cpu_to_be32(OP_ACCESS);
993 *p = cpu_to_be32(access);
995 hdr->replen += decode_access_maxsz;
998 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1002 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1003 *p++ = cpu_to_be32(OP_CLOSE);
1004 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1005 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1007 hdr->replen += decode_close_maxsz;
1010 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1014 p = reserve_space(xdr, 16);
1015 *p++ = cpu_to_be32(OP_COMMIT);
1016 p = xdr_encode_hyper(p, args->offset);
1017 *p = cpu_to_be32(args->count);
1019 hdr->replen += decode_commit_maxsz;
1022 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1026 p = reserve_space(xdr, 8);
1027 *p++ = cpu_to_be32(OP_CREATE);
1028 *p = cpu_to_be32(create->ftype);
1030 switch (create->ftype) {
1032 p = reserve_space(xdr, 4);
1033 *p = cpu_to_be32(create->u.symlink.len);
1034 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1037 case NF4BLK: case NF4CHR:
1038 p = reserve_space(xdr, 8);
1039 *p++ = cpu_to_be32(create->u.device.specdata1);
1040 *p = cpu_to_be32(create->u.device.specdata2);
1047 encode_string(xdr, create->name->len, create->name->name);
1049 hdr->replen += decode_create_maxsz;
1051 encode_attrs(xdr, create->attrs, create->server);
1054 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1058 p = reserve_space(xdr, 12);
1059 *p++ = cpu_to_be32(OP_GETATTR);
1060 *p++ = cpu_to_be32(1);
1061 *p = cpu_to_be32(bitmap);
1063 hdr->replen += decode_getattr_maxsz;
1066 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1070 p = reserve_space(xdr, 16);
1071 *p++ = cpu_to_be32(OP_GETATTR);
1072 *p++ = cpu_to_be32(2);
1073 *p++ = cpu_to_be32(bm0);
1074 *p = cpu_to_be32(bm1);
1076 hdr->replen += decode_getattr_maxsz;
1079 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1081 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1082 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1085 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1087 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1088 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1091 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1093 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1094 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1097 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1101 p = reserve_space(xdr, 4);
1102 *p = cpu_to_be32(OP_GETFH);
1104 hdr->replen += decode_getfh_maxsz;
1107 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1111 p = reserve_space(xdr, 8 + name->len);
1112 *p++ = cpu_to_be32(OP_LINK);
1113 xdr_encode_opaque(p, name->name, name->len);
1115 hdr->replen += decode_link_maxsz;
1118 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1120 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1121 return block ? NFS4_READW_LT : NFS4_READ_LT;
1122 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1125 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1127 if (fl->fl_end == OFFSET_MAX)
1128 return ~(uint64_t)0;
1129 return fl->fl_end - fl->fl_start + 1;
1132 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1136 p = reserve_space(xdr, 32);
1137 p = xdr_encode_hyper(p, lowner->clientid);
1138 *p++ = cpu_to_be32(20);
1139 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1140 *p++ = cpu_to_be32(lowner->s_dev);
1141 xdr_encode_hyper(p, lowner->id);
1145 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1146 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1148 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1152 p = reserve_space(xdr, 32);
1153 *p++ = cpu_to_be32(OP_LOCK);
1154 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1155 *p++ = cpu_to_be32(args->reclaim);
1156 p = xdr_encode_hyper(p, args->fl->fl_start);
1157 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1158 *p = cpu_to_be32(args->new_lock_owner);
1159 if (args->new_lock_owner){
1160 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1161 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1162 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1163 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1164 encode_lockowner(xdr, &args->lock_owner);
1167 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1168 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1169 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1172 hdr->replen += decode_lock_maxsz;
1175 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1179 p = reserve_space(xdr, 24);
1180 *p++ = cpu_to_be32(OP_LOCKT);
1181 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1182 p = xdr_encode_hyper(p, args->fl->fl_start);
1183 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1184 encode_lockowner(xdr, &args->lock_owner);
1186 hdr->replen += decode_lockt_maxsz;
1189 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1193 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1194 *p++ = cpu_to_be32(OP_LOCKU);
1195 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1196 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1197 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1198 p = xdr_encode_hyper(p, args->fl->fl_start);
1199 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1201 hdr->replen += decode_locku_maxsz;
1204 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1208 p = reserve_space(xdr, 4);
1209 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1210 encode_lockowner(xdr, lowner);
1212 hdr->replen += decode_release_lockowner_maxsz;
1215 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1217 int len = name->len;
1220 p = reserve_space(xdr, 8 + len);
1221 *p++ = cpu_to_be32(OP_LOOKUP);
1222 xdr_encode_opaque(p, name->name, len);
1224 hdr->replen += decode_lookup_maxsz;
1227 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1231 p = reserve_space(xdr, 8);
1232 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1234 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1237 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1239 case FMODE_READ|FMODE_WRITE:
1240 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1243 *p++ = cpu_to_be32(0);
1245 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1248 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1252 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1255 p = reserve_space(xdr, 8);
1256 *p++ = cpu_to_be32(OP_OPEN);
1257 *p = cpu_to_be32(arg->seqid->sequence->counter);
1258 encode_share_access(xdr, arg->fmode);
1259 p = reserve_space(xdr, 32);
1260 p = xdr_encode_hyper(p, arg->clientid);
1261 *p++ = cpu_to_be32(20);
1262 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1263 *p++ = cpu_to_be32(arg->server->s_dev);
1264 xdr_encode_hyper(p, arg->id);
1267 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1270 struct nfs_client *clp;
1272 p = reserve_space(xdr, 4);
1273 switch(arg->open_flags & O_EXCL) {
1275 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1276 encode_attrs(xdr, arg->u.attrs, arg->server);
1279 clp = arg->server->nfs_client;
1280 if (clp->cl_mvops->minor_version > 0) {
1281 if (nfs4_has_persistent_session(clp)) {
1282 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1283 encode_attrs(xdr, arg->u.attrs, arg->server);
1287 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1288 encode_nfs4_verifier(xdr, &arg->u.verifier);
1290 encode_attrs(xdr, &dummy, arg->server);
1293 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1294 encode_nfs4_verifier(xdr, &arg->u.verifier);
1299 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1303 p = reserve_space(xdr, 4);
1304 switch (arg->open_flags & O_CREAT) {
1306 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1309 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1310 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1311 encode_createmode(xdr, arg);
1315 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1319 p = reserve_space(xdr, 4);
1320 switch (delegation_type) {
1322 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1325 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1327 case FMODE_WRITE|FMODE_READ:
1328 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1335 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1339 p = reserve_space(xdr, 4);
1340 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1341 encode_string(xdr, name->len, name->name);
1344 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1348 p = reserve_space(xdr, 4);
1349 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1350 encode_delegation_type(xdr, type);
1353 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1357 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1358 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1359 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1360 encode_string(xdr, name->len, name->name);
1363 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1365 encode_openhdr(xdr, arg);
1366 encode_opentype(xdr, arg);
1367 switch (arg->claim) {
1368 case NFS4_OPEN_CLAIM_NULL:
1369 encode_claim_null(xdr, arg->name);
1371 case NFS4_OPEN_CLAIM_PREVIOUS:
1372 encode_claim_previous(xdr, arg->u.delegation_type);
1374 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1375 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1381 hdr->replen += decode_open_maxsz;
1384 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1388 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1389 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1390 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1391 *p = cpu_to_be32(arg->seqid->sequence->counter);
1393 hdr->replen += decode_open_confirm_maxsz;
1396 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1400 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1401 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1402 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1403 *p = cpu_to_be32(arg->seqid->sequence->counter);
1404 encode_share_access(xdr, arg->fmode);
1406 hdr->replen += decode_open_downgrade_maxsz;
1410 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1415 p = reserve_space(xdr, 8 + len);
1416 *p++ = cpu_to_be32(OP_PUTFH);
1417 xdr_encode_opaque(p, fh->data, len);
1419 hdr->replen += decode_putfh_maxsz;
1422 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1426 p = reserve_space(xdr, 4);
1427 *p = cpu_to_be32(OP_PUTROOTFH);
1429 hdr->replen += decode_putrootfh_maxsz;
1432 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
1434 nfs4_stateid stateid;
1437 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1438 if (ctx->state != NULL) {
1439 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1441 stateid.stateid.seqid = 0;
1442 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1444 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1447 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1451 p = reserve_space(xdr, 4);
1452 *p = cpu_to_be32(OP_READ);
1454 encode_stateid(xdr, args->context, args->lock_context,
1457 p = reserve_space(xdr, 12);
1458 p = xdr_encode_hyper(p, args->offset);
1459 *p = cpu_to_be32(args->count);
1461 hdr->replen += decode_read_maxsz;
1464 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1466 uint32_t attrs[2] = {
1467 FATTR4_WORD0_RDATTR_ERROR,
1468 FATTR4_WORD1_MOUNTED_ON_FILEID,
1470 uint32_t dircount = readdir->count >> 1;
1473 if (readdir->plus) {
1474 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1475 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1476 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1477 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1478 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1479 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1482 /* Use mounted_on_fileid only if the server supports it */
1483 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1484 attrs[0] |= FATTR4_WORD0_FILEID;
1486 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1487 *p++ = cpu_to_be32(OP_READDIR);
1488 p = xdr_encode_hyper(p, readdir->cookie);
1489 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1490 *p++ = cpu_to_be32(dircount);
1491 *p++ = cpu_to_be32(readdir->count);
1492 *p++ = cpu_to_be32(2);
1494 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1495 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1497 hdr->replen += decode_readdir_maxsz;
1498 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1500 (unsigned long long)readdir->cookie,
1501 ((u32 *)readdir->verifier.data)[0],
1502 ((u32 *)readdir->verifier.data)[1],
1503 attrs[0] & readdir->bitmask[0],
1504 attrs[1] & readdir->bitmask[1]);
1507 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(OP_READLINK);
1514 hdr->replen += decode_readlink_maxsz;
1517 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1521 p = reserve_space(xdr, 8 + name->len);
1522 *p++ = cpu_to_be32(OP_REMOVE);
1523 xdr_encode_opaque(p, name->name, name->len);
1525 hdr->replen += decode_remove_maxsz;
1528 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1532 p = reserve_space(xdr, 4);
1533 *p = cpu_to_be32(OP_RENAME);
1534 encode_string(xdr, oldname->len, oldname->name);
1535 encode_string(xdr, newname->len, newname->name);
1537 hdr->replen += decode_rename_maxsz;
1540 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1544 p = reserve_space(xdr, 12);
1545 *p++ = cpu_to_be32(OP_RENEW);
1546 xdr_encode_hyper(p, client_stateid->cl_clientid);
1548 hdr->replen += decode_renew_maxsz;
1552 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1556 p = reserve_space(xdr, 4);
1557 *p = cpu_to_be32(OP_RESTOREFH);
1559 hdr->replen += decode_restorefh_maxsz;
1563 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1567 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1568 *p++ = cpu_to_be32(OP_SETATTR);
1569 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1570 p = reserve_space(xdr, 2*4);
1571 *p++ = cpu_to_be32(1);
1572 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1573 BUG_ON(arg->acl_len % 4);
1574 p = reserve_space(xdr, 4);
1575 *p = cpu_to_be32(arg->acl_len);
1576 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1578 hdr->replen += decode_setacl_maxsz;
1582 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1586 p = reserve_space(xdr, 4);
1587 *p = cpu_to_be32(OP_SAVEFH);
1589 hdr->replen += decode_savefh_maxsz;
1592 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1596 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1597 *p++ = cpu_to_be32(OP_SETATTR);
1598 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1600 hdr->replen += decode_setattr_maxsz;
1601 encode_attrs(xdr, arg->iap, server);
1604 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1608 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1609 *p++ = cpu_to_be32(OP_SETCLIENTID);
1610 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1612 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1613 p = reserve_space(xdr, 4);
1614 *p = cpu_to_be32(setclientid->sc_prog);
1615 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1616 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1617 p = reserve_space(xdr, 4);
1618 *p = cpu_to_be32(setclientid->sc_cb_ident);
1620 hdr->replen += decode_setclientid_maxsz;
1623 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1627 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1628 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1629 p = xdr_encode_hyper(p, arg->clientid);
1630 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1632 hdr->replen += decode_setclientid_confirm_maxsz;
1635 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1639 p = reserve_space(xdr, 4);
1640 *p = cpu_to_be32(OP_WRITE);
1642 encode_stateid(xdr, args->context, args->lock_context,
1645 p = reserve_space(xdr, 16);
1646 p = xdr_encode_hyper(p, args->offset);
1647 *p++ = cpu_to_be32(args->stable);
1648 *p = cpu_to_be32(args->count);
1650 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1652 hdr->replen += decode_write_maxsz;
1655 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1659 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1661 *p++ = cpu_to_be32(OP_DELEGRETURN);
1662 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1664 hdr->replen += decode_delegreturn_maxsz;
1667 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1669 int len = name->len;
1672 p = reserve_space(xdr, 8 + len);
1673 *p++ = cpu_to_be32(OP_SECINFO);
1674 xdr_encode_opaque(p, name->name, len);
1676 hdr->replen += decode_secinfo_maxsz;
1679 #if defined(CONFIG_NFS_V4_1)
1680 /* NFSv4.1 operations */
1681 static void encode_exchange_id(struct xdr_stream *xdr,
1682 struct nfs41_exchange_id_args *args,
1683 struct compound_hdr *hdr)
1687 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1688 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1689 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1691 encode_string(xdr, args->id_len, args->id);
1693 p = reserve_space(xdr, 12);
1694 *p++ = cpu_to_be32(args->flags);
1695 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1696 *p = cpu_to_be32(0); /* zero length implementation id array */
1698 hdr->replen += decode_exchange_id_maxsz;
1701 static void encode_create_session(struct xdr_stream *xdr,
1702 struct nfs41_create_session_args *args,
1703 struct compound_hdr *hdr)
1706 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1708 struct nfs_client *clp = args->client;
1709 u32 max_resp_sz_cached;
1712 * Assumes OPEN is the biggest non-idempotent compound.
1713 * 2 is the verifier.
1715 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1716 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1718 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1721 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1722 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1723 p = xdr_encode_hyper(p, clp->cl_clientid);
1724 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1725 *p++ = cpu_to_be32(args->flags); /*flags */
1728 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1729 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1730 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1731 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1732 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1733 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1734 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1737 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1738 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1739 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1740 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1741 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1742 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1743 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1745 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1746 *p++ = cpu_to_be32(1);
1747 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1749 /* authsys_parms rfc1831 */
1750 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1751 p = xdr_encode_opaque(p, machine_name, len);
1752 *p++ = cpu_to_be32(0); /* UID */
1753 *p++ = cpu_to_be32(0); /* GID */
1754 *p = cpu_to_be32(0); /* No more gids */
1756 hdr->replen += decode_create_session_maxsz;
1759 static void encode_destroy_session(struct xdr_stream *xdr,
1760 struct nfs4_session *session,
1761 struct compound_hdr *hdr)
1764 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1765 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1766 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1768 hdr->replen += decode_destroy_session_maxsz;
1771 static void encode_reclaim_complete(struct xdr_stream *xdr,
1772 struct nfs41_reclaim_complete_args *args,
1773 struct compound_hdr *hdr)
1777 p = reserve_space(xdr, 8);
1778 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1779 *p++ = cpu_to_be32(args->one_fs);
1781 hdr->replen += decode_reclaim_complete_maxsz;
1783 #endif /* CONFIG_NFS_V4_1 */
1785 static void encode_sequence(struct xdr_stream *xdr,
1786 const struct nfs4_sequence_args *args,
1787 struct compound_hdr *hdr)
1789 #if defined(CONFIG_NFS_V4_1)
1790 struct nfs4_session *session = args->sa_session;
1791 struct nfs4_slot_table *tp;
1792 struct nfs4_slot *slot;
1798 tp = &session->fc_slot_table;
1800 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1801 slot = tp->slots + args->sa_slotid;
1803 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1804 *p++ = cpu_to_be32(OP_SEQUENCE);
1807 * Sessionid + seqid + slotid + max slotid + cache_this
1809 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1810 "max_slotid=%d cache_this=%d\n",
1812 ((u32 *)session->sess_id.data)[0],
1813 ((u32 *)session->sess_id.data)[1],
1814 ((u32 *)session->sess_id.data)[2],
1815 ((u32 *)session->sess_id.data)[3],
1816 slot->seq_nr, args->sa_slotid,
1817 tp->highest_used_slotid, args->sa_cache_this);
1818 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1819 *p++ = cpu_to_be32(slot->seq_nr);
1820 *p++ = cpu_to_be32(args->sa_slotid);
1821 *p++ = cpu_to_be32(tp->highest_used_slotid);
1822 *p = cpu_to_be32(args->sa_cache_this);
1824 hdr->replen += decode_sequence_maxsz;
1825 #endif /* CONFIG_NFS_V4_1 */
1828 #ifdef CONFIG_NFS_V4_1
1830 encode_getdeviceinfo(struct xdr_stream *xdr,
1831 const struct nfs4_getdeviceinfo_args *args,
1832 struct compound_hdr *hdr)
1836 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1837 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1838 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1839 NFS4_DEVICEID4_SIZE);
1840 *p++ = cpu_to_be32(args->pdev->layout_type);
1841 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1842 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1844 hdr->replen += decode_getdeviceinfo_maxsz;
1848 encode_layoutget(struct xdr_stream *xdr,
1849 const struct nfs4_layoutget_args *args,
1850 struct compound_hdr *hdr)
1854 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1855 *p++ = cpu_to_be32(OP_LAYOUTGET);
1856 *p++ = cpu_to_be32(0); /* Signal layout available */
1857 *p++ = cpu_to_be32(args->type);
1858 *p++ = cpu_to_be32(args->range.iomode);
1859 p = xdr_encode_hyper(p, args->range.offset);
1860 p = xdr_encode_hyper(p, args->range.length);
1861 p = xdr_encode_hyper(p, args->minlength);
1862 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1863 *p = cpu_to_be32(args->maxcount);
1865 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1869 (unsigned long)args->range.offset,
1870 (unsigned long)args->range.length,
1873 hdr->replen += decode_layoutget_maxsz;
1877 encode_layoutcommit(struct xdr_stream *xdr,
1878 const struct nfs4_layoutcommit_args *args,
1879 struct compound_hdr *hdr)
1883 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1884 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1886 p = reserve_space(xdr, 48 + NFS4_STATEID_SIZE);
1887 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1888 /* Only whole file layouts */
1889 p = xdr_encode_hyper(p, 0); /* offset */
1890 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1891 *p++ = cpu_to_be32(0); /* reclaim */
1892 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1893 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1894 p = xdr_encode_hyper(p, args->lastbytewritten);
1895 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1896 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1897 *p++ = cpu_to_be32(0); /* no file layout payload */
1900 hdr->replen += decode_layoutcommit_maxsz;
1905 encode_layoutreturn(struct xdr_stream *xdr,
1906 const struct nfs4_layoutreturn_args *args,
1907 struct compound_hdr *hdr)
1911 p = reserve_space(xdr, 20);
1912 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1913 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1914 *p++ = cpu_to_be32(args->layout_type);
1915 *p++ = cpu_to_be32(IOMODE_ANY);
1916 *p = cpu_to_be32(RETURN_FILE);
1917 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1918 p = xdr_encode_hyper(p, 0);
1919 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1920 spin_lock(&args->inode->i_lock);
1921 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1922 spin_unlock(&args->inode->i_lock);
1923 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1924 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1925 NFS_I(args->inode)->layout, xdr, args);
1927 p = reserve_space(xdr, 4);
1928 *p = cpu_to_be32(0);
1931 hdr->replen += decode_layoutreturn_maxsz;
1933 #endif /* CONFIG_NFS_V4_1 */
1936 * END OF "GENERIC" ENCODE ROUTINES.
1939 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1941 #if defined(CONFIG_NFS_V4_1)
1942 if (args->sa_session)
1943 return args->sa_session->clp->cl_mvops->minor_version;
1944 #endif /* CONFIG_NFS_V4_1 */
1949 * Encode an ACCESS request
1951 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1952 const struct nfs4_accessargs *args)
1954 struct compound_hdr hdr = {
1955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1958 encode_compound_hdr(xdr, req, &hdr);
1959 encode_sequence(xdr, &args->seq_args, &hdr);
1960 encode_putfh(xdr, args->fh, &hdr);
1961 encode_access(xdr, args->access, &hdr);
1962 encode_getfattr(xdr, args->bitmask, &hdr);
1967 * Encode LOOKUP request
1969 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1970 const struct nfs4_lookup_arg *args)
1972 struct compound_hdr hdr = {
1973 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1976 encode_compound_hdr(xdr, req, &hdr);
1977 encode_sequence(xdr, &args->seq_args, &hdr);
1978 encode_putfh(xdr, args->dir_fh, &hdr);
1979 encode_lookup(xdr, args->name, &hdr);
1980 encode_getfh(xdr, &hdr);
1981 encode_getfattr(xdr, args->bitmask, &hdr);
1986 * Encode LOOKUP_ROOT request
1988 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1989 struct xdr_stream *xdr,
1990 const struct nfs4_lookup_root_arg *args)
1992 struct compound_hdr hdr = {
1993 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1996 encode_compound_hdr(xdr, req, &hdr);
1997 encode_sequence(xdr, &args->seq_args, &hdr);
1998 encode_putrootfh(xdr, &hdr);
1999 encode_getfh(xdr, &hdr);
2000 encode_getfattr(xdr, args->bitmask, &hdr);
2005 * Encode REMOVE request
2007 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2008 const struct nfs_removeargs *args)
2010 struct compound_hdr hdr = {
2011 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2014 encode_compound_hdr(xdr, req, &hdr);
2015 encode_sequence(xdr, &args->seq_args, &hdr);
2016 encode_putfh(xdr, args->fh, &hdr);
2017 encode_remove(xdr, &args->name, &hdr);
2018 encode_getfattr(xdr, args->bitmask, &hdr);
2023 * Encode RENAME request
2025 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2026 const struct nfs_renameargs *args)
2028 struct compound_hdr hdr = {
2029 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2032 encode_compound_hdr(xdr, req, &hdr);
2033 encode_sequence(xdr, &args->seq_args, &hdr);
2034 encode_putfh(xdr, args->old_dir, &hdr);
2035 encode_savefh(xdr, &hdr);
2036 encode_putfh(xdr, args->new_dir, &hdr);
2037 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2038 encode_getfattr(xdr, args->bitmask, &hdr);
2039 encode_restorefh(xdr, &hdr);
2040 encode_getfattr(xdr, args->bitmask, &hdr);
2045 * Encode LINK request
2047 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2048 const struct nfs4_link_arg *args)
2050 struct compound_hdr hdr = {
2051 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2054 encode_compound_hdr(xdr, req, &hdr);
2055 encode_sequence(xdr, &args->seq_args, &hdr);
2056 encode_putfh(xdr, args->fh, &hdr);
2057 encode_savefh(xdr, &hdr);
2058 encode_putfh(xdr, args->dir_fh, &hdr);
2059 encode_link(xdr, args->name, &hdr);
2060 encode_getfattr(xdr, args->bitmask, &hdr);
2061 encode_restorefh(xdr, &hdr);
2062 encode_getfattr(xdr, args->bitmask, &hdr);
2067 * Encode CREATE request
2069 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2070 const struct nfs4_create_arg *args)
2072 struct compound_hdr hdr = {
2073 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2076 encode_compound_hdr(xdr, req, &hdr);
2077 encode_sequence(xdr, &args->seq_args, &hdr);
2078 encode_putfh(xdr, args->dir_fh, &hdr);
2079 encode_savefh(xdr, &hdr);
2080 encode_create(xdr, args, &hdr);
2081 encode_getfh(xdr, &hdr);
2082 encode_getfattr(xdr, args->bitmask, &hdr);
2083 encode_restorefh(xdr, &hdr);
2084 encode_getfattr(xdr, args->bitmask, &hdr);
2089 * Encode SYMLINK request
2091 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2092 const struct nfs4_create_arg *args)
2094 nfs4_xdr_enc_create(req, xdr, args);
2098 * Encode GETATTR request
2100 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2101 const struct nfs4_getattr_arg *args)
2103 struct compound_hdr hdr = {
2104 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2107 encode_compound_hdr(xdr, req, &hdr);
2108 encode_sequence(xdr, &args->seq_args, &hdr);
2109 encode_putfh(xdr, args->fh, &hdr);
2110 encode_getfattr(xdr, args->bitmask, &hdr);
2115 * Encode a CLOSE request
2117 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2118 struct nfs_closeargs *args)
2120 struct compound_hdr hdr = {
2121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2124 encode_compound_hdr(xdr, req, &hdr);
2125 encode_sequence(xdr, &args->seq_args, &hdr);
2126 encode_putfh(xdr, args->fh, &hdr);
2127 encode_close(xdr, args, &hdr);
2128 encode_getfattr(xdr, args->bitmask, &hdr);
2133 * Encode an OPEN request
2135 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2136 struct nfs_openargs *args)
2138 struct compound_hdr hdr = {
2139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2142 encode_compound_hdr(xdr, req, &hdr);
2143 encode_sequence(xdr, &args->seq_args, &hdr);
2144 encode_putfh(xdr, args->fh, &hdr);
2145 encode_savefh(xdr, &hdr);
2146 encode_open(xdr, args, &hdr);
2147 encode_getfh(xdr, &hdr);
2148 encode_getfattr(xdr, args->bitmask, &hdr);
2149 encode_restorefh(xdr, &hdr);
2150 encode_getfattr(xdr, args->bitmask, &hdr);
2155 * Encode an OPEN_CONFIRM request
2157 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2158 struct xdr_stream *xdr,
2159 struct nfs_open_confirmargs *args)
2161 struct compound_hdr hdr = {
2165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_putfh(xdr, args->fh, &hdr);
2167 encode_open_confirm(xdr, args, &hdr);
2172 * Encode an OPEN request with no attributes.
2174 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2175 struct xdr_stream *xdr,
2176 struct nfs_openargs *args)
2178 struct compound_hdr hdr = {
2179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_sequence(xdr, &args->seq_args, &hdr);
2184 encode_putfh(xdr, args->fh, &hdr);
2185 encode_open(xdr, args, &hdr);
2186 encode_getfattr(xdr, args->bitmask, &hdr);
2191 * Encode an OPEN_DOWNGRADE request
2193 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2194 struct xdr_stream *xdr,
2195 struct nfs_closeargs *args)
2197 struct compound_hdr hdr = {
2198 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2201 encode_compound_hdr(xdr, req, &hdr);
2202 encode_sequence(xdr, &args->seq_args, &hdr);
2203 encode_putfh(xdr, args->fh, &hdr);
2204 encode_open_downgrade(xdr, args, &hdr);
2205 encode_getfattr(xdr, args->bitmask, &hdr);
2210 * Encode a LOCK request
2212 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2213 struct nfs_lock_args *args)
2215 struct compound_hdr hdr = {
2216 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2219 encode_compound_hdr(xdr, req, &hdr);
2220 encode_sequence(xdr, &args->seq_args, &hdr);
2221 encode_putfh(xdr, args->fh, &hdr);
2222 encode_lock(xdr, args, &hdr);
2227 * Encode a LOCKT request
2229 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2230 struct nfs_lockt_args *args)
2232 struct compound_hdr hdr = {
2233 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2236 encode_compound_hdr(xdr, req, &hdr);
2237 encode_sequence(xdr, &args->seq_args, &hdr);
2238 encode_putfh(xdr, args->fh, &hdr);
2239 encode_lockt(xdr, args, &hdr);
2244 * Encode a LOCKU request
2246 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2247 struct nfs_locku_args *args)
2249 struct compound_hdr hdr = {
2250 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2253 encode_compound_hdr(xdr, req, &hdr);
2254 encode_sequence(xdr, &args->seq_args, &hdr);
2255 encode_putfh(xdr, args->fh, &hdr);
2256 encode_locku(xdr, args, &hdr);
2260 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2261 struct xdr_stream *xdr,
2262 struct nfs_release_lockowner_args *args)
2264 struct compound_hdr hdr = {
2268 encode_compound_hdr(xdr, req, &hdr);
2269 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2274 * Encode a READLINK request
2276 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2277 const struct nfs4_readlink *args)
2279 struct compound_hdr hdr = {
2280 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2283 encode_compound_hdr(xdr, req, &hdr);
2284 encode_sequence(xdr, &args->seq_args, &hdr);
2285 encode_putfh(xdr, args->fh, &hdr);
2286 encode_readlink(xdr, args, req, &hdr);
2288 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2289 args->pgbase, args->pglen);
2294 * Encode a READDIR request
2296 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2297 const struct nfs4_readdir_arg *args)
2299 struct compound_hdr hdr = {
2300 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2303 encode_compound_hdr(xdr, req, &hdr);
2304 encode_sequence(xdr, &args->seq_args, &hdr);
2305 encode_putfh(xdr, args->fh, &hdr);
2306 encode_readdir(xdr, args, req, &hdr);
2308 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2309 args->pgbase, args->count);
2310 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2311 __func__, hdr.replen << 2, args->pages,
2312 args->pgbase, args->count);
2317 * Encode a READ request
2319 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2320 struct nfs_readargs *args)
2322 struct compound_hdr hdr = {
2323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
2329 encode_read(xdr, args, &hdr);
2331 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2332 args->pages, args->pgbase, args->count);
2333 req->rq_rcv_buf.flags |= XDRBUF_READ;
2338 * Encode an SETATTR request
2340 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2341 struct nfs_setattrargs *args)
2343 struct compound_hdr hdr = {
2344 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2347 encode_compound_hdr(xdr, req, &hdr);
2348 encode_sequence(xdr, &args->seq_args, &hdr);
2349 encode_putfh(xdr, args->fh, &hdr);
2350 encode_setattr(xdr, args, args->server, &hdr);
2351 encode_getfattr(xdr, args->bitmask, &hdr);
2356 * Encode a GETACL request
2358 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2359 struct nfs_getaclargs *args)
2361 struct compound_hdr hdr = {
2362 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2366 encode_compound_hdr(xdr, req, &hdr);
2367 encode_sequence(xdr, &args->seq_args, &hdr);
2368 encode_putfh(xdr, args->fh, &hdr);
2369 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2370 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2372 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2373 args->acl_pages, args->acl_pgbase, args->acl_len);
2378 * Encode a WRITE request
2380 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2381 struct nfs_writeargs *args)
2383 struct compound_hdr hdr = {
2384 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2387 encode_compound_hdr(xdr, req, &hdr);
2388 encode_sequence(xdr, &args->seq_args, &hdr);
2389 encode_putfh(xdr, args->fh, &hdr);
2390 encode_write(xdr, args, &hdr);
2391 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2393 encode_getfattr(xdr, args->bitmask, &hdr);
2400 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 struct nfs_writeargs *args)
2403 struct compound_hdr hdr = {
2404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_sequence(xdr, &args->seq_args, &hdr);
2409 encode_putfh(xdr, args->fh, &hdr);
2410 encode_commit(xdr, args, &hdr);
2412 encode_getfattr(xdr, args->bitmask, &hdr);
2419 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2420 struct nfs4_fsinfo_arg *args)
2422 struct compound_hdr hdr = {
2423 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2426 encode_compound_hdr(xdr, req, &hdr);
2427 encode_sequence(xdr, &args->seq_args, &hdr);
2428 encode_putfh(xdr, args->fh, &hdr);
2429 encode_fsinfo(xdr, args->bitmask, &hdr);
2434 * a PATHCONF request
2436 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2437 const struct nfs4_pathconf_arg *args)
2439 struct compound_hdr hdr = {
2440 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2443 encode_compound_hdr(xdr, req, &hdr);
2444 encode_sequence(xdr, &args->seq_args, &hdr);
2445 encode_putfh(xdr, args->fh, &hdr);
2446 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2454 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2455 const struct nfs4_statfs_arg *args)
2457 struct compound_hdr hdr = {
2458 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2461 encode_compound_hdr(xdr, req, &hdr);
2462 encode_sequence(xdr, &args->seq_args, &hdr);
2463 encode_putfh(xdr, args->fh, &hdr);
2464 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2465 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2470 * GETATTR_BITMAP request
2472 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2473 struct xdr_stream *xdr,
2474 struct nfs4_server_caps_arg *args)
2476 struct compound_hdr hdr = {
2477 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2480 encode_compound_hdr(xdr, req, &hdr);
2481 encode_sequence(xdr, &args->seq_args, &hdr);
2482 encode_putfh(xdr, args->fhandle, &hdr);
2483 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2484 FATTR4_WORD0_LINK_SUPPORT|
2485 FATTR4_WORD0_SYMLINK_SUPPORT|
2486 FATTR4_WORD0_ACLSUPPORT, &hdr);
2493 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2494 struct nfs_client *clp)
2496 struct compound_hdr hdr = {
2500 encode_compound_hdr(xdr, req, &hdr);
2501 encode_renew(xdr, clp, &hdr);
2506 * a SETCLIENTID request
2508 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2509 struct xdr_stream *xdr,
2510 struct nfs4_setclientid *sc)
2512 struct compound_hdr hdr = {
2516 encode_compound_hdr(xdr, req, &hdr);
2517 encode_setclientid(xdr, sc, &hdr);
2522 * a SETCLIENTID_CONFIRM request
2524 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2525 struct xdr_stream *xdr,
2526 struct nfs4_setclientid_res *arg)
2528 struct compound_hdr hdr = {
2531 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_setclientid_confirm(xdr, arg, &hdr);
2535 encode_putrootfh(xdr, &hdr);
2536 encode_fsinfo(xdr, lease_bitmap, &hdr);
2541 * DELEGRETURN request
2543 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2544 struct xdr_stream *xdr,
2545 const struct nfs4_delegreturnargs *args)
2547 struct compound_hdr hdr = {
2548 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2551 encode_compound_hdr(xdr, req, &hdr);
2552 encode_sequence(xdr, &args->seq_args, &hdr);
2553 encode_putfh(xdr, args->fhandle, &hdr);
2554 encode_delegreturn(xdr, args->stateid, &hdr);
2555 encode_getfattr(xdr, args->bitmask, &hdr);
2560 * Encode FS_LOCATIONS request
2562 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2563 struct xdr_stream *xdr,
2564 struct nfs4_fs_locations_arg *args)
2566 struct compound_hdr hdr = {
2567 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2571 encode_compound_hdr(xdr, req, &hdr);
2572 encode_sequence(xdr, &args->seq_args, &hdr);
2573 encode_putfh(xdr, args->dir_fh, &hdr);
2574 encode_lookup(xdr, args->name, &hdr);
2575 replen = hdr.replen; /* get the attribute into args->page */
2576 encode_fs_locations(xdr, args->bitmask, &hdr);
2578 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2584 * Encode SECINFO request
2586 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2587 struct xdr_stream *xdr,
2588 struct nfs4_secinfo_arg *args)
2590 struct compound_hdr hdr = {
2591 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2594 encode_compound_hdr(xdr, req, &hdr);
2595 encode_sequence(xdr, &args->seq_args, &hdr);
2596 encode_putfh(xdr, args->dir_fh, &hdr);
2597 encode_secinfo(xdr, args->name, &hdr);
2601 #if defined(CONFIG_NFS_V4_1)
2603 * EXCHANGE_ID request
2605 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2606 struct xdr_stream *xdr,
2607 struct nfs41_exchange_id_args *args)
2609 struct compound_hdr hdr = {
2610 .minorversion = args->client->cl_mvops->minor_version,
2613 encode_compound_hdr(xdr, req, &hdr);
2614 encode_exchange_id(xdr, args, &hdr);
2619 * a CREATE_SESSION request
2621 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2622 struct xdr_stream *xdr,
2623 struct nfs41_create_session_args *args)
2625 struct compound_hdr hdr = {
2626 .minorversion = args->client->cl_mvops->minor_version,
2629 encode_compound_hdr(xdr, req, &hdr);
2630 encode_create_session(xdr, args, &hdr);
2635 * a DESTROY_SESSION request
2637 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2638 struct xdr_stream *xdr,
2639 struct nfs4_session *session)
2641 struct compound_hdr hdr = {
2642 .minorversion = session->clp->cl_mvops->minor_version,
2645 encode_compound_hdr(xdr, req, &hdr);
2646 encode_destroy_session(xdr, session, &hdr);
2651 * a SEQUENCE request
2653 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2654 struct nfs4_sequence_args *args)
2656 struct compound_hdr hdr = {
2657 .minorversion = nfs4_xdr_minorversion(args),
2660 encode_compound_hdr(xdr, req, &hdr);
2661 encode_sequence(xdr, args, &hdr);
2666 * a GET_LEASE_TIME request
2668 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2669 struct xdr_stream *xdr,
2670 struct nfs4_get_lease_time_args *args)
2672 struct compound_hdr hdr = {
2673 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2675 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, &args->la_seq_args, &hdr);
2679 encode_putrootfh(xdr, &hdr);
2680 encode_fsinfo(xdr, lease_bitmap, &hdr);
2685 * a RECLAIM_COMPLETE request
2687 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2688 struct xdr_stream *xdr,
2689 struct nfs41_reclaim_complete_args *args)
2691 struct compound_hdr hdr = {
2692 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2695 encode_compound_hdr(xdr, req, &hdr);
2696 encode_sequence(xdr, &args->seq_args, &hdr);
2697 encode_reclaim_complete(xdr, args, &hdr);
2702 * Encode GETDEVICEINFO request
2704 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2705 struct xdr_stream *xdr,
2706 struct nfs4_getdeviceinfo_args *args)
2708 struct compound_hdr hdr = {
2709 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2712 encode_compound_hdr(xdr, req, &hdr);
2713 encode_sequence(xdr, &args->seq_args, &hdr);
2714 encode_getdeviceinfo(xdr, args, &hdr);
2716 /* set up reply kvec. Subtract notification bitmap max size (2)
2717 * so that notification bitmap is put in xdr_buf tail */
2718 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2719 args->pdev->pages, args->pdev->pgbase,
2726 * Encode LAYOUTGET request
2728 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2729 struct xdr_stream *xdr,
2730 struct nfs4_layoutget_args *args)
2732 struct compound_hdr hdr = {
2733 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2736 encode_compound_hdr(xdr, req, &hdr);
2737 encode_sequence(xdr, &args->seq_args, &hdr);
2738 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2739 encode_layoutget(xdr, args, &hdr);
2741 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2742 args->layout.pages, 0, args->layout.pglen);
2748 * Encode LAYOUTCOMMIT request
2750 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2751 struct xdr_stream *xdr,
2752 struct nfs4_layoutcommit_args *args)
2754 struct compound_hdr hdr = {
2755 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2758 encode_compound_hdr(xdr, req, &hdr);
2759 encode_sequence(xdr, &args->seq_args, &hdr);
2760 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2761 encode_layoutcommit(xdr, args, &hdr);
2762 encode_getfattr(xdr, args->bitmask, &hdr);
2767 * Encode LAYOUTRETURN request
2769 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2770 struct xdr_stream *xdr,
2771 struct nfs4_layoutreturn_args *args)
2773 struct compound_hdr hdr = {
2774 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2777 encode_compound_hdr(xdr, req, &hdr);
2778 encode_sequence(xdr, &args->seq_args, &hdr);
2779 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2780 encode_layoutreturn(xdr, args, &hdr);
2783 #endif /* CONFIG_NFS_V4_1 */
2785 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2787 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2788 "Remaining buffer length is %tu words.\n",
2789 func, xdr->end - xdr->p);
2792 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2796 p = xdr_inline_decode(xdr, 4);
2799 *len = be32_to_cpup(p);
2800 p = xdr_inline_decode(xdr, *len);
2803 *string = (char *)p;
2806 print_overflow_msg(__func__, xdr);
2810 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2814 p = xdr_inline_decode(xdr, 8);
2817 hdr->status = be32_to_cpup(p++);
2818 hdr->taglen = be32_to_cpup(p);
2820 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2823 hdr->tag = (char *)p;
2824 p += XDR_QUADLEN(hdr->taglen);
2825 hdr->nops = be32_to_cpup(p);
2826 if (unlikely(hdr->nops < 1))
2827 return nfs4_stat_to_errno(hdr->status);
2830 print_overflow_msg(__func__, xdr);
2834 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2840 p = xdr_inline_decode(xdr, 8);
2843 opnum = be32_to_cpup(p++);
2844 if (opnum != expected) {
2845 dprintk("nfs: Server returned operation"
2846 " %d but we issued a request for %d\n",
2850 nfserr = be32_to_cpup(p);
2851 if (nfserr != NFS_OK)
2852 return nfs4_stat_to_errno(nfserr);
2855 print_overflow_msg(__func__, xdr);
2860 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2863 unsigned int strlen;
2866 p = xdr_inline_decode(xdr, 12);
2868 return decode_opaque_inline(xdr, &strlen, &str);
2869 print_overflow_msg(__func__, xdr);
2873 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2878 p = xdr_inline_decode(xdr, 4);
2881 bmlen = be32_to_cpup(p);
2883 bitmap[0] = bitmap[1] = 0;
2884 p = xdr_inline_decode(xdr, (bmlen << 2));
2888 bitmap[0] = be32_to_cpup(p++);
2890 bitmap[1] = be32_to_cpup(p);
2894 print_overflow_msg(__func__, xdr);
2898 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2902 p = xdr_inline_decode(xdr, 4);
2905 *attrlen = be32_to_cpup(p);
2909 print_overflow_msg(__func__, xdr);
2913 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2915 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2917 ret = decode_attr_bitmap(xdr, bitmask);
2918 if (unlikely(ret < 0))
2920 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2922 bitmask[0] = bitmask[1] = 0;
2923 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2927 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2933 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2935 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2936 p = xdr_inline_decode(xdr, 4);
2939 *type = be32_to_cpup(p);
2940 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2941 dprintk("%s: bad type %d\n", __func__, *type);
2944 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2945 ret = NFS_ATTR_FATTR_TYPE;
2947 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2950 print_overflow_msg(__func__, xdr);
2954 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2960 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2962 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2963 p = xdr_inline_decode(xdr, 8);
2966 xdr_decode_hyper(p, change);
2967 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2968 ret = NFS_ATTR_FATTR_CHANGE;
2970 dprintk("%s: change attribute=%Lu\n", __func__,
2971 (unsigned long long)*change);
2974 print_overflow_msg(__func__, xdr);
2978 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2984 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2986 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2987 p = xdr_inline_decode(xdr, 8);
2990 xdr_decode_hyper(p, size);
2991 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2992 ret = NFS_ATTR_FATTR_SIZE;
2994 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2997 print_overflow_msg(__func__, xdr);
3001 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3006 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3008 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3009 p = xdr_inline_decode(xdr, 4);
3012 *res = be32_to_cpup(p);
3013 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3015 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3018 print_overflow_msg(__func__, xdr);
3022 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3027 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3029 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3030 p = xdr_inline_decode(xdr, 4);
3033 *res = be32_to_cpup(p);
3034 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3036 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3039 print_overflow_msg(__func__, xdr);
3043 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3050 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3052 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3053 p = xdr_inline_decode(xdr, 16);
3056 p = xdr_decode_hyper(p, &fsid->major);
3057 xdr_decode_hyper(p, &fsid->minor);
3058 bitmap[0] &= ~FATTR4_WORD0_FSID;
3059 ret = NFS_ATTR_FATTR_FSID;
3061 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3062 (unsigned long long)fsid->major,
3063 (unsigned long long)fsid->minor);
3066 print_overflow_msg(__func__, xdr);
3070 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3075 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3077 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3078 p = xdr_inline_decode(xdr, 4);
3081 *res = be32_to_cpup(p);
3082 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3084 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3087 print_overflow_msg(__func__, xdr);
3091 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
3095 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3097 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3098 p = xdr_inline_decode(xdr, 4);
3101 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3102 return -be32_to_cpup(p);
3106 print_overflow_msg(__func__, xdr);
3110 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3116 memset(fh, 0, sizeof(*fh));
3118 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3120 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3121 p = xdr_inline_decode(xdr, 4);
3124 len = be32_to_cpup(p);
3125 if (len > NFS4_FHSIZE)
3127 p = xdr_inline_decode(xdr, len);
3131 memcpy(fh->data, p, len);
3134 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3138 print_overflow_msg(__func__, xdr);
3142 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3146 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3147 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3149 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3150 p = xdr_inline_decode(xdr, 4);
3153 *res = be32_to_cpup(p);
3154 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3156 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3159 print_overflow_msg(__func__, xdr);
3163 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3169 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3171 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3172 p = xdr_inline_decode(xdr, 8);
3175 xdr_decode_hyper(p, fileid);
3176 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3177 ret = NFS_ATTR_FATTR_FILEID;
3179 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3182 print_overflow_msg(__func__, xdr);
3186 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3192 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3194 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3195 p = xdr_inline_decode(xdr, 8);
3198 xdr_decode_hyper(p, fileid);
3199 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3200 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3202 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3205 print_overflow_msg(__func__, xdr);
3209 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3215 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3217 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3218 p = xdr_inline_decode(xdr, 8);
3221 xdr_decode_hyper(p, res);
3222 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3224 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3227 print_overflow_msg(__func__, xdr);
3231 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3237 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3239 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3240 p = xdr_inline_decode(xdr, 8);
3243 xdr_decode_hyper(p, res);
3244 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3246 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3249 print_overflow_msg(__func__, xdr);
3253 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3259 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3261 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3262 p = xdr_inline_decode(xdr, 8);
3265 xdr_decode_hyper(p, res);
3266 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3268 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3271 print_overflow_msg(__func__, xdr);
3275 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3281 p = xdr_inline_decode(xdr, 4);
3284 n = be32_to_cpup(p);
3288 path->ncomponents = 0;
3289 while (path->ncomponents < n) {
3290 struct nfs4_string *component = &path->components[path->ncomponents];
3291 status = decode_opaque_inline(xdr, &component->len, &component->data);
3292 if (unlikely(status != 0))
3294 if (path->ncomponents != n)
3296 dprintk("%s", component->data);
3297 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3298 path->ncomponents++;
3300 dprintk("cannot parse %d components in path\n", n);
3308 /* a root pathname is sent as a zero component4 */
3309 path->ncomponents = 1;
3310 path->components[0].len=0;
3311 path->components[0].data=NULL;
3312 dprintk("path /\n");
3315 dprintk(" status %d", status);
3319 print_overflow_msg(__func__, xdr);
3323 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3329 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3332 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3334 dprintk("%s: fsroot ", __func__);
3335 status = decode_pathname(xdr, &res->fs_path);
3336 if (unlikely(status != 0))
3338 p = xdr_inline_decode(xdr, 4);
3341 n = be32_to_cpup(p);
3344 res->nlocations = 0;
3345 while (res->nlocations < n) {
3347 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3349 p = xdr_inline_decode(xdr, 4);
3352 m = be32_to_cpup(p);
3355 dprintk("%s: servers ", __func__);
3356 while (loc->nservers < m) {
3357 struct nfs4_string *server = &loc->servers[loc->nservers];
3358 status = decode_opaque_inline(xdr, &server->len, &server->data);
3359 if (unlikely(status != 0))
3361 dprintk("%s ", server->data);
3362 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3366 dprintk("%s: using first %u of %u servers "
3367 "returned for location %u\n",
3369 NFS4_FS_LOCATION_MAXSERVERS,
3370 m, res->nlocations);
3371 for (i = loc->nservers; i < m; i++) {
3374 status = decode_opaque_inline(xdr, &len, &data);
3375 if (unlikely(status != 0))
3380 status = decode_pathname(xdr, &loc->rootpath);
3381 if (unlikely(status != 0))
3383 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3386 if (res->nlocations != 0)
3387 status = NFS_ATTR_FATTR_V4_REFERRAL;
3389 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3392 print_overflow_msg(__func__, xdr);
3398 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3404 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3406 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3407 p = xdr_inline_decode(xdr, 8);
3410 xdr_decode_hyper(p, res);
3411 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3413 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3416 print_overflow_msg(__func__, xdr);
3420 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3426 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3428 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3429 p = xdr_inline_decode(xdr, 4);
3432 *maxlink = be32_to_cpup(p);
3433 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3435 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3438 print_overflow_msg(__func__, xdr);
3442 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3448 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3450 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3451 p = xdr_inline_decode(xdr, 4);
3454 *maxname = be32_to_cpup(p);
3455 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3457 dprintk("%s: maxname=%u\n", __func__, *maxname);
3460 print_overflow_msg(__func__, xdr);
3464 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3470 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3472 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3474 p = xdr_inline_decode(xdr, 8);
3477 xdr_decode_hyper(p, &maxread);
3478 if (maxread > 0x7FFFFFFF)
3479 maxread = 0x7FFFFFFF;
3480 *res = (uint32_t)maxread;
3481 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3483 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3486 print_overflow_msg(__func__, xdr);
3490 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3496 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3498 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3500 p = xdr_inline_decode(xdr, 8);
3503 xdr_decode_hyper(p, &maxwrite);
3504 if (maxwrite > 0x7FFFFFFF)
3505 maxwrite = 0x7FFFFFFF;
3506 *res = (uint32_t)maxwrite;
3507 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3509 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3512 print_overflow_msg(__func__, xdr);
3516 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3523 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3525 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3526 p = xdr_inline_decode(xdr, 4);
3529 tmp = be32_to_cpup(p);
3530 *mode = tmp & ~S_IFMT;
3531 bitmap[1] &= ~FATTR4_WORD1_MODE;
3532 ret = NFS_ATTR_FATTR_MODE;
3534 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3537 print_overflow_msg(__func__, xdr);
3541 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3547 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3549 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3550 p = xdr_inline_decode(xdr, 4);
3553 *nlink = be32_to_cpup(p);
3554 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3555 ret = NFS_ATTR_FATTR_NLINK;
3557 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3560 print_overflow_msg(__func__, xdr);
3564 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3565 const struct nfs_server *server, uint32_t *uid, int may_sleep)
3572 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3574 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3575 p = xdr_inline_decode(xdr, 4);
3578 len = be32_to_cpup(p);
3579 p = xdr_inline_decode(xdr, len);
3584 } else if (len < XDR_MAX_NETOBJ) {
3585 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3586 ret = NFS_ATTR_FATTR_OWNER;
3588 dprintk("%s: nfs_map_name_to_uid failed!\n",
3591 dprintk("%s: name too long (%u)!\n",
3593 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3595 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3598 print_overflow_msg(__func__, xdr);
3602 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3603 const struct nfs_server *server, uint32_t *gid, int may_sleep)
3610 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3612 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3613 p = xdr_inline_decode(xdr, 4);
3616 len = be32_to_cpup(p);
3617 p = xdr_inline_decode(xdr, len);
3622 } else if (len < XDR_MAX_NETOBJ) {
3623 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3624 ret = NFS_ATTR_FATTR_GROUP;
3626 dprintk("%s: nfs_map_group_to_gid failed!\n",
3629 dprintk("%s: name too long (%u)!\n",
3631 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3633 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3636 print_overflow_msg(__func__, xdr);
3640 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3642 uint32_t major = 0, minor = 0;
3647 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3649 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3652 p = xdr_inline_decode(xdr, 8);
3655 major = be32_to_cpup(p++);
3656 minor = be32_to_cpup(p);
3657 tmp = MKDEV(major, minor);
3658 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3660 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3661 ret = NFS_ATTR_FATTR_RDEV;
3663 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3666 print_overflow_msg(__func__, xdr);
3670 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3676 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3678 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3679 p = xdr_inline_decode(xdr, 8);
3682 xdr_decode_hyper(p, res);
3683 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3685 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3688 print_overflow_msg(__func__, xdr);
3692 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3698 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3700 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3701 p = xdr_inline_decode(xdr, 8);
3704 xdr_decode_hyper(p, res);
3705 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3707 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3710 print_overflow_msg(__func__, xdr);
3714 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3720 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3722 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3723 p = xdr_inline_decode(xdr, 8);
3726 xdr_decode_hyper(p, res);
3727 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3729 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3732 print_overflow_msg(__func__, xdr);
3736 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3742 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3744 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3745 p = xdr_inline_decode(xdr, 8);
3748 xdr_decode_hyper(p, used);
3749 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3750 ret = NFS_ATTR_FATTR_SPACE_USED;
3752 dprintk("%s: space used=%Lu\n", __func__,
3753 (unsigned long long)*used);
3756 print_overflow_msg(__func__, xdr);
3760 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3766 p = xdr_inline_decode(xdr, 12);
3769 p = xdr_decode_hyper(p, &sec);
3770 nsec = be32_to_cpup(p);
3771 time->tv_sec = (time_t)sec;
3772 time->tv_nsec = (long)nsec;
3775 print_overflow_msg(__func__, xdr);
3779 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3785 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3787 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3788 status = decode_attr_time(xdr, time);
3790 status = NFS_ATTR_FATTR_ATIME;
3791 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3793 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3797 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3803 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3805 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3806 status = decode_attr_time(xdr, time);
3808 status = NFS_ATTR_FATTR_CTIME;
3809 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3811 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3815 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3816 struct timespec *time)
3822 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3824 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3825 status = decode_attr_time(xdr, time);
3826 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3828 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3829 (long)time->tv_nsec);
3833 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3839 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3841 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3842 status = decode_attr_time(xdr, time);
3844 status = NFS_ATTR_FATTR_MTIME;
3845 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3847 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3851 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3853 unsigned int attrwords = XDR_QUADLEN(attrlen);
3854 unsigned int nwords = xdr->p - savep;
3856 if (unlikely(attrwords != nwords)) {
3857 dprintk("%s: server returned incorrect attribute length: "
3861 (attrwords < nwords) ? '<' : '>',
3868 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3872 p = xdr_inline_decode(xdr, 20);
3875 cinfo->atomic = be32_to_cpup(p++);
3876 p = xdr_decode_hyper(p, &cinfo->before);
3877 xdr_decode_hyper(p, &cinfo->after);
3880 print_overflow_msg(__func__, xdr);
3884 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3890 status = decode_op_hdr(xdr, OP_ACCESS);
3893 p = xdr_inline_decode(xdr, 8);
3896 supp = be32_to_cpup(p++);
3897 acc = be32_to_cpup(p);
3898 access->supported = supp;
3899 access->access = acc;
3902 print_overflow_msg(__func__, xdr);
3906 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
3910 p = xdr_inline_decode(xdr, len);
3912 memcpy(buf, p, len);
3915 print_overflow_msg(__func__, xdr);
3919 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3921 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
3924 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3928 status = decode_op_hdr(xdr, OP_CLOSE);
3930 nfs_increment_open_seqid(status, res->seqid);
3932 status = decode_stateid(xdr, &res->stateid);
3936 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3938 return decode_opaque_fixed(xdr, verifier, 8);
3941 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3945 status = decode_op_hdr(xdr, OP_COMMIT);
3947 status = decode_verifier(xdr, res->verf->verifier);
3951 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3957 status = decode_op_hdr(xdr, OP_CREATE);
3960 if ((status = decode_change_info(xdr, cinfo)))
3962 p = xdr_inline_decode(xdr, 4);
3965 bmlen = be32_to_cpup(p);
3966 p = xdr_inline_decode(xdr, bmlen << 2);
3970 print_overflow_msg(__func__, xdr);
3974 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3977 uint32_t attrlen, bitmap[2] = {0};
3980 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3982 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3984 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3986 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3988 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3990 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3992 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3994 status = verify_attr_len(xdr, savep, attrlen);
3996 dprintk("%s: xdr returned %d!\n", __func__, -status);
4000 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4003 uint32_t attrlen, bitmap[2] = {0};
4006 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4008 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4010 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4013 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4015 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4017 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4019 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4021 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4023 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4026 status = verify_attr_len(xdr, savep, attrlen);
4028 dprintk("%s: xdr returned %d!\n", __func__, -status);
4032 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4035 uint32_t attrlen, bitmap[2] = {0};
4038 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4040 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4042 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4045 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4047 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4050 status = verify_attr_len(xdr, savep, attrlen);
4052 dprintk("%s: xdr returned %d!\n", __func__, -status);
4056 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4057 struct nfs_fattr *fattr, struct nfs_fh *fh,
4058 const struct nfs_server *server, int may_sleep)
4064 status = decode_attr_type(xdr, bitmap, &type);
4069 fattr->mode |= nfs_type2fmt[type];
4070 fattr->valid |= status;
4073 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4076 fattr->valid |= status;
4078 status = decode_attr_size(xdr, bitmap, &fattr->size);
4081 fattr->valid |= status;
4083 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4086 fattr->valid |= status;
4088 status = decode_attr_error(xdr, bitmap);
4089 if (status == -NFS4ERR_WRONGSEC) {
4090 nfs_fixup_secinfo_attributes(fattr, fh);
4096 status = decode_attr_filehandle(xdr, bitmap, fh);
4100 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4103 fattr->valid |= status;
4105 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
4106 struct nfs4_fs_locations,
4110 fattr->valid |= status;
4112 status = decode_attr_mode(xdr, bitmap, &fmode);
4116 fattr->mode |= fmode;
4117 fattr->valid |= status;
4120 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4123 fattr->valid |= status;
4125 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
4128 fattr->valid |= status;
4130 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
4133 fattr->valid |= status;
4135 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4138 fattr->valid |= status;
4140 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4143 fattr->valid |= status;
4145 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4148 fattr->valid |= status;
4150 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4153 fattr->valid |= status;
4155 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4158 fattr->valid |= status;
4160 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4163 fattr->valid |= status;
4166 dprintk("%s: xdr returned %d\n", __func__, -status);
4170 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4171 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4178 status = decode_op_hdr(xdr, OP_GETATTR);
4182 status = decode_attr_bitmap(xdr, bitmap);
4186 status = decode_attr_length(xdr, &attrlen, &savep);
4190 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4194 status = verify_attr_len(xdr, savep, attrlen);
4196 dprintk("%s: xdr returned %d\n", __func__, -status);
4200 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4201 const struct nfs_server *server, int may_sleep)
4203 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4207 * Decode potentially multiple layout types. Currently we only support
4208 * one layout driver per file system.
4210 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4211 uint32_t *layouttype)
4216 p = xdr_inline_decode(xdr, 4);
4219 num = be32_to_cpup(p);
4221 /* pNFS is not supported by the underlying file system */
4227 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4228 "per filesystem not supported\n", __func__);
4230 /* Decode and set first layout type, move xdr->p past unused types */
4231 p = xdr_inline_decode(xdr, num * 4);
4234 *layouttype = be32_to_cpup(p);
4237 print_overflow_msg(__func__, xdr);
4242 * The type of file system exported.
4243 * Note we must ensure that layouttype is set in any non-error case.
4245 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4246 uint32_t *layouttype)
4250 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4251 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4253 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4254 status = decode_first_pnfs_layout_type(xdr, layouttype);
4255 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4261 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4264 uint32_t attrlen, bitmap[2];
4267 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4269 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4271 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4274 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4276 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4278 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4280 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4282 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4283 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4285 fsinfo->wtpref = fsinfo->wtmax;
4286 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4289 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4293 status = verify_attr_len(xdr, savep, attrlen);
4295 dprintk("%s: xdr returned %d!\n", __func__, -status);
4299 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4305 /* Zero handle first to allow comparisons */
4306 memset(fh, 0, sizeof(*fh));
4308 status = decode_op_hdr(xdr, OP_GETFH);
4312 p = xdr_inline_decode(xdr, 4);
4315 len = be32_to_cpup(p);
4316 if (len > NFS4_FHSIZE)
4319 p = xdr_inline_decode(xdr, len);
4322 memcpy(fh->data, p, len);
4325 print_overflow_msg(__func__, xdr);
4329 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4333 status = decode_op_hdr(xdr, OP_LINK);
4336 return decode_change_info(xdr, cinfo);
4340 * We create the owner, so we know a proper owner.id length is 4.
4342 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4344 uint64_t offset, length, clientid;
4346 uint32_t namelen, type;
4348 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4351 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4352 p = xdr_decode_hyper(p, &length);
4353 type = be32_to_cpup(p++); /* 4 byte read */
4354 if (fl != NULL) { /* manipulate file lock */
4355 fl->fl_start = (loff_t)offset;
4356 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4357 if (length == ~(uint64_t)0)
4358 fl->fl_end = OFFSET_MAX;
4359 fl->fl_type = F_WRLCK;
4361 fl->fl_type = F_RDLCK;
4364 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4365 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4366 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4368 return -NFS4ERR_DENIED;
4370 print_overflow_msg(__func__, xdr);
4374 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4378 status = decode_op_hdr(xdr, OP_LOCK);
4382 status = decode_stateid(xdr, &res->stateid);
4383 if (unlikely(status))
4385 } else if (status == -NFS4ERR_DENIED)
4386 status = decode_lock_denied(xdr, NULL);
4387 if (res->open_seqid != NULL)
4388 nfs_increment_open_seqid(status, res->open_seqid);
4389 nfs_increment_lock_seqid(status, res->lock_seqid);
4394 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4397 status = decode_op_hdr(xdr, OP_LOCKT);
4398 if (status == -NFS4ERR_DENIED)
4399 return decode_lock_denied(xdr, res->denied);
4403 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4407 status = decode_op_hdr(xdr, OP_LOCKU);
4409 nfs_increment_lock_seqid(status, res->seqid);
4411 status = decode_stateid(xdr, &res->stateid);
4415 static int decode_release_lockowner(struct xdr_stream *xdr)
4417 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4420 static int decode_lookup(struct xdr_stream *xdr)
4422 return decode_op_hdr(xdr, OP_LOOKUP);
4425 /* This is too sick! */
4426 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4429 uint32_t limit_type, nblocks, blocksize;
4431 p = xdr_inline_decode(xdr, 12);
4434 limit_type = be32_to_cpup(p++);
4435 switch (limit_type) {
4437 xdr_decode_hyper(p, maxsize);
4440 nblocks = be32_to_cpup(p++);
4441 blocksize = be32_to_cpup(p);
4442 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4446 print_overflow_msg(__func__, xdr);
4450 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4453 uint32_t delegation_type;
4456 p = xdr_inline_decode(xdr, 4);
4459 delegation_type = be32_to_cpup(p);
4460 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4461 res->delegation_type = 0;
4464 status = decode_stateid(xdr, &res->delegation);
4465 if (unlikely(status))
4467 p = xdr_inline_decode(xdr, 4);
4470 res->do_recall = be32_to_cpup(p);
4472 switch (delegation_type) {
4473 case NFS4_OPEN_DELEGATE_READ:
4474 res->delegation_type = FMODE_READ;
4476 case NFS4_OPEN_DELEGATE_WRITE:
4477 res->delegation_type = FMODE_WRITE|FMODE_READ;
4478 if (decode_space_limit(xdr, &res->maxsize) < 0)
4481 return decode_ace(xdr, NULL, res->server->nfs_client);
4483 print_overflow_msg(__func__, xdr);
4487 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4490 uint32_t savewords, bmlen, i;
4493 status = decode_op_hdr(xdr, OP_OPEN);
4495 nfs_increment_open_seqid(status, res->seqid);
4497 status = decode_stateid(xdr, &res->stateid);
4498 if (unlikely(status))
4501 decode_change_info(xdr, &res->cinfo);
4503 p = xdr_inline_decode(xdr, 8);
4506 res->rflags = be32_to_cpup(p++);
4507 bmlen = be32_to_cpup(p);
4511 p = xdr_inline_decode(xdr, bmlen << 2);
4514 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4515 for (i = 0; i < savewords; ++i)
4516 res->attrset[i] = be32_to_cpup(p++);
4517 for (; i < NFS4_BITMAP_SIZE; i++)
4518 res->attrset[i] = 0;
4520 return decode_delegation(xdr, res);
4522 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4525 print_overflow_msg(__func__, xdr);
4529 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4533 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4535 nfs_increment_open_seqid(status, res->seqid);
4537 status = decode_stateid(xdr, &res->stateid);
4541 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4545 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4547 nfs_increment_open_seqid(status, res->seqid);
4549 status = decode_stateid(xdr, &res->stateid);
4553 static int decode_putfh(struct xdr_stream *xdr)
4555 return decode_op_hdr(xdr, OP_PUTFH);
4558 static int decode_putrootfh(struct xdr_stream *xdr)
4560 return decode_op_hdr(xdr, OP_PUTROOTFH);
4563 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4565 struct kvec *iov = req->rq_rcv_buf.head;
4567 uint32_t count, eof, recvd, hdrlen;
4570 status = decode_op_hdr(xdr, OP_READ);
4573 p = xdr_inline_decode(xdr, 8);
4576 eof = be32_to_cpup(p++);
4577 count = be32_to_cpup(p);
4578 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4579 recvd = req->rq_rcv_buf.len - hdrlen;
4580 if (count > recvd) {
4581 dprintk("NFS: server cheating in read reply: "
4582 "count %u > recvd %u\n", count, recvd);
4586 xdr_read_pages(xdr, count);
4591 print_overflow_msg(__func__, xdr);
4595 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4597 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4598 struct kvec *iov = rcvbuf->head;
4600 u32 recvd, pglen = rcvbuf->page_len;
4603 status = decode_op_hdr(xdr, OP_READDIR);
4605 status = decode_verifier(xdr, readdir->verifier.data);
4606 if (unlikely(status))
4608 dprintk("%s: verifier = %08x:%08x\n",
4610 ((u32 *)readdir->verifier.data)[0],
4611 ((u32 *)readdir->verifier.data)[1]);
4614 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4615 recvd = rcvbuf->len - hdrlen;
4618 xdr_read_pages(xdr, pglen);
4624 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4626 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4627 struct kvec *iov = rcvbuf->head;
4633 status = decode_op_hdr(xdr, OP_READLINK);
4637 /* Convert length of symlink */
4638 p = xdr_inline_decode(xdr, 4);
4641 len = be32_to_cpup(p);
4642 if (len >= rcvbuf->page_len || len <= 0) {
4643 dprintk("nfs: server returned giant symlink!\n");
4644 return -ENAMETOOLONG;
4646 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4647 recvd = req->rq_rcv_buf.len - hdrlen;
4649 dprintk("NFS: server cheating in readlink reply: "
4650 "count %u > recvd %u\n", len, recvd);
4653 xdr_read_pages(xdr, len);
4655 * The XDR encode routine has set things up so that
4656 * the link text will be copied directly into the
4657 * buffer. We just have to do overflow-checking,
4658 * and and null-terminate the text (the VFS expects
4659 * null-termination).
4661 xdr_terminate_string(rcvbuf, len);
4664 print_overflow_msg(__func__, xdr);
4668 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4672 status = decode_op_hdr(xdr, OP_REMOVE);
4675 status = decode_change_info(xdr, cinfo);
4680 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4681 struct nfs4_change_info *new_cinfo)
4685 status = decode_op_hdr(xdr, OP_RENAME);
4688 if ((status = decode_change_info(xdr, old_cinfo)))
4690 status = decode_change_info(xdr, new_cinfo);
4695 static int decode_renew(struct xdr_stream *xdr)
4697 return decode_op_hdr(xdr, OP_RENEW);
4701 decode_restorefh(struct xdr_stream *xdr)
4703 return decode_op_hdr(xdr, OP_RESTOREFH);
4706 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4712 struct kvec *iov = req->rq_rcv_buf.head;
4716 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4718 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4720 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4723 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4725 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4729 /* We ignore &savep and don't do consistency checks on
4730 * the attr length. Let userspace figure it out.... */
4731 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4732 recvd = req->rq_rcv_buf.len - hdrlen;
4733 if (attrlen > recvd) {
4734 dprintk("NFS: server cheating in getattr"
4735 " acl reply: attrlen %u > recvd %u\n",
4739 xdr_read_pages(xdr, attrlen);
4742 status = -EOPNOTSUPP;
4749 decode_savefh(struct xdr_stream *xdr)
4751 return decode_op_hdr(xdr, OP_SAVEFH);
4754 static int decode_setattr(struct xdr_stream *xdr)
4760 status = decode_op_hdr(xdr, OP_SETATTR);
4763 p = xdr_inline_decode(xdr, 4);
4766 bmlen = be32_to_cpup(p);
4767 p = xdr_inline_decode(xdr, bmlen << 2);
4771 print_overflow_msg(__func__, xdr);
4775 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
4781 p = xdr_inline_decode(xdr, 8);
4784 opnum = be32_to_cpup(p++);
4785 if (opnum != OP_SETCLIENTID) {
4786 dprintk("nfs: decode_setclientid: Server returned operation"
4790 nfserr = be32_to_cpup(p);
4791 if (nfserr == NFS_OK) {
4792 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4795 p = xdr_decode_hyper(p, &res->clientid);
4796 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
4797 } else if (nfserr == NFSERR_CLID_INUSE) {
4800 /* skip netid string */
4801 p = xdr_inline_decode(xdr, 4);
4804 len = be32_to_cpup(p);
4805 p = xdr_inline_decode(xdr, len);
4809 /* skip uaddr string */
4810 p = xdr_inline_decode(xdr, 4);
4813 len = be32_to_cpup(p);
4814 p = xdr_inline_decode(xdr, len);
4817 return -NFSERR_CLID_INUSE;
4819 return nfs4_stat_to_errno(nfserr);
4823 print_overflow_msg(__func__, xdr);
4827 static int decode_setclientid_confirm(struct xdr_stream *xdr)
4829 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4832 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4837 status = decode_op_hdr(xdr, OP_WRITE);
4841 p = xdr_inline_decode(xdr, 16);
4844 res->count = be32_to_cpup(p++);
4845 res->verf->committed = be32_to_cpup(p++);
4846 memcpy(res->verf->verifier, p, 8);
4849 print_overflow_msg(__func__, xdr);
4853 static int decode_delegreturn(struct xdr_stream *xdr)
4855 return decode_op_hdr(xdr, OP_DELEGRETURN);
4858 static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4862 p = xdr_inline_decode(xdr, 4);
4865 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4866 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4869 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4872 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4874 p = xdr_inline_decode(xdr, 8);
4877 flavor->gss.qop4 = be32_to_cpup(p++);
4878 flavor->gss.service = be32_to_cpup(p);
4883 print_overflow_msg(__func__, xdr);
4889 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4891 struct nfs4_secinfo_flavor *sec_flavor;
4896 status = decode_op_hdr(xdr, OP_SECINFO);
4899 p = xdr_inline_decode(xdr, 4);
4903 res->flavors->num_flavors = 0;
4904 num_flavors = be32_to_cpup(p);
4906 for (i = 0; i < num_flavors; i++) {
4907 sec_flavor = &res->flavors->flavors[i];
4908 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
4911 p = xdr_inline_decode(xdr, 4);
4914 sec_flavor->flavor = be32_to_cpup(p);
4916 if (sec_flavor->flavor == RPC_AUTH_GSS) {
4917 status = decode_secinfo_gss(xdr, sec_flavor);
4921 res->flavors->num_flavors++;
4927 print_overflow_msg(__func__, xdr);
4931 #if defined(CONFIG_NFS_V4_1)
4932 static int decode_exchange_id(struct xdr_stream *xdr,
4933 struct nfs41_exchange_id_res *res)
4939 struct nfs_client *clp = res->client;
4941 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4945 p = xdr_inline_decode(xdr, 8);
4948 xdr_decode_hyper(p, &clp->cl_clientid);
4949 p = xdr_inline_decode(xdr, 12);
4952 clp->cl_seqid = be32_to_cpup(p++);
4953 clp->cl_exchange_flags = be32_to_cpup(p++);
4955 /* We ask for SP4_NONE */
4956 dummy = be32_to_cpup(p);
4957 if (dummy != SP4_NONE)
4960 /* Throw away minor_id */
4961 p = xdr_inline_decode(xdr, 8);
4965 /* Throw away Major id */
4966 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4967 if (unlikely(status))
4970 /* Throw away server_scope */
4971 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4972 if (unlikely(status))
4975 /* Throw away Implementation id array */
4976 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4977 if (unlikely(status))
4982 print_overflow_msg(__func__, xdr);
4986 static int decode_chan_attrs(struct xdr_stream *xdr,
4987 struct nfs4_channel_attrs *attrs)
4992 p = xdr_inline_decode(xdr, 28);
4995 attrs->headerpadsz = be32_to_cpup(p++);
4996 attrs->max_rqst_sz = be32_to_cpup(p++);
4997 attrs->max_resp_sz = be32_to_cpup(p++);
4998 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4999 attrs->max_ops = be32_to_cpup(p++);
5000 attrs->max_reqs = be32_to_cpup(p++);
5001 nr_attrs = be32_to_cpup(p);
5002 if (unlikely(nr_attrs > 1)) {
5003 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5004 __func__, nr_attrs);
5007 if (nr_attrs == 1) {
5008 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5014 print_overflow_msg(__func__, xdr);
5018 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5020 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5023 static int decode_create_session(struct xdr_stream *xdr,
5024 struct nfs41_create_session_res *res)
5028 struct nfs_client *clp = res->client;
5029 struct nfs4_session *session = clp->cl_session;
5031 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5033 status = decode_sessionid(xdr, &session->sess_id);
5034 if (unlikely(status))
5038 p = xdr_inline_decode(xdr, 8);
5041 clp->cl_seqid = be32_to_cpup(p++);
5042 session->flags = be32_to_cpup(p);
5044 /* Channel attributes */
5045 status = decode_chan_attrs(xdr, &session->fc_attrs);
5047 status = decode_chan_attrs(xdr, &session->bc_attrs);
5050 print_overflow_msg(__func__, xdr);
5054 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5056 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5059 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5061 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5063 #endif /* CONFIG_NFS_V4_1 */
5065 static int decode_sequence(struct xdr_stream *xdr,
5066 struct nfs4_sequence_res *res,
5067 struct rpc_rqst *rqstp)
5069 #if defined(CONFIG_NFS_V4_1)
5070 struct nfs4_sessionid id;
5075 if (!res->sr_session)
5078 status = decode_op_hdr(xdr, OP_SEQUENCE);
5080 status = decode_sessionid(xdr, &id);
5081 if (unlikely(status))
5085 * If the server returns different values for sessionID, slotID or
5086 * sequence number, the server is looney tunes.
5088 status = -EREMOTEIO;
5090 if (memcmp(id.data, res->sr_session->sess_id.data,
5091 NFS4_MAX_SESSIONID_LEN)) {
5092 dprintk("%s Invalid session id\n", __func__);
5096 p = xdr_inline_decode(xdr, 20);
5101 dummy = be32_to_cpup(p++);
5102 if (dummy != res->sr_slot->seq_nr) {
5103 dprintk("%s Invalid sequence number\n", __func__);
5107 dummy = be32_to_cpup(p++);
5108 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5109 dprintk("%s Invalid slot id\n", __func__);
5112 /* highest slot id - currently not processed */
5113 dummy = be32_to_cpup(p++);
5114 /* target highest slot id - currently not processed */
5115 dummy = be32_to_cpup(p++);
5117 res->sr_status_flags = be32_to_cpup(p);
5120 res->sr_status = status;
5123 print_overflow_msg(__func__, xdr);
5126 #else /* CONFIG_NFS_V4_1 */
5128 #endif /* CONFIG_NFS_V4_1 */
5131 #if defined(CONFIG_NFS_V4_1)
5133 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5134 struct pnfs_device *pdev)
5140 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5142 if (status == -ETOOSMALL) {
5143 p = xdr_inline_decode(xdr, 4);
5146 pdev->mincount = be32_to_cpup(p);
5147 dprintk("%s: Min count too small. mincnt = %u\n",
5148 __func__, pdev->mincount);
5153 p = xdr_inline_decode(xdr, 8);
5156 type = be32_to_cpup(p++);
5157 if (type != pdev->layout_type) {
5158 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5159 __func__, pdev->layout_type, type);
5163 * Get the length of the opaque device_addr4. xdr_read_pages places
5164 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5165 * and places the remaining xdr data in xdr_buf->tail
5167 pdev->mincount = be32_to_cpup(p);
5168 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5170 /* Parse notification bitmap, verifying that it is zero. */
5171 p = xdr_inline_decode(xdr, 4);
5174 len = be32_to_cpup(p);
5178 p = xdr_inline_decode(xdr, 4 * len);
5181 for (i = 0; i < len; i++, p++) {
5182 if (be32_to_cpup(p)) {
5183 dprintk("%s: notifications not supported\n",
5191 print_overflow_msg(__func__, xdr);
5195 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5196 struct nfs4_layoutget_res *res)
5201 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5202 struct kvec *iov = rcvbuf->head;
5205 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5208 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5211 res->return_on_close = be32_to_cpup(p++);
5212 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5213 layout_count = be32_to_cpup(p);
5214 if (!layout_count) {
5215 dprintk("%s: server responded with empty layout array\n",
5220 p = xdr_inline_decode(xdr, 28);
5223 p = xdr_decode_hyper(p, &res->range.offset);
5224 p = xdr_decode_hyper(p, &res->range.length);
5225 res->range.iomode = be32_to_cpup(p++);
5226 res->type = be32_to_cpup(p++);
5227 res->layoutp->len = be32_to_cpup(p);
5229 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5231 (unsigned long)res->range.offset,
5232 (unsigned long)res->range.length,
5237 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5238 recvd = req->rq_rcv_buf.len - hdrlen;
5239 if (res->layoutp->len > recvd) {
5240 dprintk("NFS: server cheating in layoutget reply: "
5241 "layout len %u > recvd %u\n",
5242 res->layoutp->len, recvd);
5246 xdr_read_pages(xdr, res->layoutp->len);
5248 if (layout_count > 1) {
5249 /* We only handle a length one array at the moment. Any
5250 * further entries are just ignored. Note that this means
5251 * the client may see a response that is less than the
5252 * minimum it requested.
5254 dprintk("%s: server responded with %d layouts, dropping tail\n",
5255 __func__, layout_count);
5260 print_overflow_msg(__func__, xdr);
5264 static int decode_layoutreturn(struct xdr_stream *xdr,
5265 struct nfs4_layoutreturn_res *res)
5270 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5273 p = xdr_inline_decode(xdr, 4);
5276 res->lrs_present = be32_to_cpup(p);
5277 if (res->lrs_present)
5278 status = decode_stateid(xdr, &res->stateid);
5281 print_overflow_msg(__func__, xdr);
5285 static int decode_layoutcommit(struct xdr_stream *xdr,
5286 struct rpc_rqst *req,
5287 struct nfs4_layoutcommit_res *res)
5293 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5297 p = xdr_inline_decode(xdr, 4);
5300 sizechanged = be32_to_cpup(p);
5303 /* throw away new size */
5304 p = xdr_inline_decode(xdr, 8);
5310 print_overflow_msg(__func__, xdr);
5313 #endif /* CONFIG_NFS_V4_1 */
5316 * END OF "GENERIC" DECODE ROUTINES.
5320 * Decode OPEN_DOWNGRADE response
5322 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5323 struct xdr_stream *xdr,
5324 struct nfs_closeres *res)
5326 struct compound_hdr hdr;
5329 status = decode_compound_hdr(xdr, &hdr);
5332 status = decode_sequence(xdr, &res->seq_res, rqstp);
5335 status = decode_putfh(xdr);
5338 status = decode_open_downgrade(xdr, res);
5341 decode_getfattr(xdr, res->fattr, res->server,
5342 !RPC_IS_ASYNC(rqstp->rq_task));
5348 * Decode ACCESS response
5350 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5351 struct nfs4_accessres *res)
5353 struct compound_hdr hdr;
5356 status = decode_compound_hdr(xdr, &hdr);
5359 status = decode_sequence(xdr, &res->seq_res, rqstp);
5362 status = decode_putfh(xdr);
5365 status = decode_access(xdr, res);
5368 decode_getfattr(xdr, res->fattr, res->server,
5369 !RPC_IS_ASYNC(rqstp->rq_task));
5375 * Decode LOOKUP response
5377 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5378 struct nfs4_lookup_res *res)
5380 struct compound_hdr hdr;
5383 status = decode_compound_hdr(xdr, &hdr);
5386 status = decode_sequence(xdr, &res->seq_res, rqstp);
5389 status = decode_putfh(xdr);
5392 status = decode_lookup(xdr);
5395 status = decode_getfh(xdr, res->fh);
5398 status = decode_getfattr(xdr, res->fattr, res->server
5399 ,!RPC_IS_ASYNC(rqstp->rq_task));
5405 * Decode LOOKUP_ROOT response
5407 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5408 struct xdr_stream *xdr,
5409 struct nfs4_lookup_res *res)
5411 struct compound_hdr hdr;
5414 status = decode_compound_hdr(xdr, &hdr);
5417 status = decode_sequence(xdr, &res->seq_res, rqstp);
5420 status = decode_putrootfh(xdr);
5423 status = decode_getfh(xdr, res->fh);
5425 status = decode_getfattr(xdr, res->fattr, res->server,
5426 !RPC_IS_ASYNC(rqstp->rq_task));
5432 * Decode REMOVE response
5434 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5435 struct nfs_removeres *res)
5437 struct compound_hdr hdr;
5440 status = decode_compound_hdr(xdr, &hdr);
5443 status = decode_sequence(xdr, &res->seq_res, rqstp);
5446 status = decode_putfh(xdr);
5449 status = decode_remove(xdr, &res->cinfo);
5452 decode_getfattr(xdr, res->dir_attr, res->server,
5453 !RPC_IS_ASYNC(rqstp->rq_task));
5459 * Decode RENAME response
5461 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5462 struct nfs_renameres *res)
5464 struct compound_hdr hdr;
5467 status = decode_compound_hdr(xdr, &hdr);
5470 status = decode_sequence(xdr, &res->seq_res, rqstp);
5473 status = decode_putfh(xdr);
5476 status = decode_savefh(xdr);
5479 status = decode_putfh(xdr);
5482 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5485 /* Current FH is target directory */
5486 if (decode_getfattr(xdr, res->new_fattr, res->server,
5487 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5489 status = decode_restorefh(xdr);
5492 decode_getfattr(xdr, res->old_fattr, res->server,
5493 !RPC_IS_ASYNC(rqstp->rq_task));
5499 * Decode LINK response
5501 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5502 struct nfs4_link_res *res)
5504 struct compound_hdr hdr;
5507 status = decode_compound_hdr(xdr, &hdr);
5510 status = decode_sequence(xdr, &res->seq_res, rqstp);
5513 status = decode_putfh(xdr);
5516 status = decode_savefh(xdr);
5519 status = decode_putfh(xdr);
5522 status = decode_link(xdr, &res->cinfo);
5526 * Note order: OP_LINK leaves the directory as the current
5529 if (decode_getfattr(xdr, res->dir_attr, res->server,
5530 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5532 status = decode_restorefh(xdr);
5535 decode_getfattr(xdr, res->fattr, res->server,
5536 !RPC_IS_ASYNC(rqstp->rq_task));
5542 * Decode CREATE response
5544 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5545 struct nfs4_create_res *res)
5547 struct compound_hdr hdr;
5550 status = decode_compound_hdr(xdr, &hdr);
5553 status = decode_sequence(xdr, &res->seq_res, rqstp);
5556 status = decode_putfh(xdr);
5559 status = decode_savefh(xdr);
5562 status = decode_create(xdr, &res->dir_cinfo);
5565 status = decode_getfh(xdr, res->fh);
5568 if (decode_getfattr(xdr, res->fattr, res->server,
5569 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5571 status = decode_restorefh(xdr);
5574 decode_getfattr(xdr, res->dir_fattr, res->server,
5575 !RPC_IS_ASYNC(rqstp->rq_task));
5581 * Decode SYMLINK response
5583 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5584 struct nfs4_create_res *res)
5586 return nfs4_xdr_dec_create(rqstp, xdr, res);
5590 * Decode GETATTR response
5592 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5593 struct nfs4_getattr_res *res)
5595 struct compound_hdr hdr;
5598 status = decode_compound_hdr(xdr, &hdr);
5601 status = decode_sequence(xdr, &res->seq_res, rqstp);
5604 status = decode_putfh(xdr);
5607 status = decode_getfattr(xdr, res->fattr, res->server,
5608 !RPC_IS_ASYNC(rqstp->rq_task));
5614 * Encode an SETACL request
5616 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5617 struct nfs_setaclargs *args)
5619 struct compound_hdr hdr = {
5620 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
5623 encode_compound_hdr(xdr, req, &hdr);
5624 encode_sequence(xdr, &args->seq_args, &hdr);
5625 encode_putfh(xdr, args->fh, &hdr);
5626 encode_setacl(xdr, args, &hdr);
5631 * Decode SETACL response
5634 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5635 struct nfs_setaclres *res)
5637 struct compound_hdr hdr;
5640 status = decode_compound_hdr(xdr, &hdr);
5643 status = decode_sequence(xdr, &res->seq_res, rqstp);
5646 status = decode_putfh(xdr);
5649 status = decode_setattr(xdr);
5655 * Decode GETACL response
5658 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5659 struct nfs_getaclres *res)
5661 struct compound_hdr hdr;
5664 status = decode_compound_hdr(xdr, &hdr);
5667 status = decode_sequence(xdr, &res->seq_res, rqstp);
5670 status = decode_putfh(xdr);
5673 status = decode_getacl(xdr, rqstp, &res->acl_len);
5680 * Decode CLOSE response
5682 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5683 struct nfs_closeres *res)
5685 struct compound_hdr hdr;
5688 status = decode_compound_hdr(xdr, &hdr);
5691 status = decode_sequence(xdr, &res->seq_res, rqstp);
5694 status = decode_putfh(xdr);
5697 status = decode_close(xdr, res);
5701 * Note: Server may do delete on close for this file
5702 * in which case the getattr call will fail with
5703 * an ESTALE error. Shouldn't be a problem,
5704 * though, since fattr->valid will remain unset.
5706 decode_getfattr(xdr, res->fattr, res->server,
5707 !RPC_IS_ASYNC(rqstp->rq_task));
5713 * Decode OPEN response
5715 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5716 struct nfs_openres *res)
5718 struct compound_hdr hdr;
5721 status = decode_compound_hdr(xdr, &hdr);
5724 status = decode_sequence(xdr, &res->seq_res, rqstp);
5727 status = decode_putfh(xdr);
5730 status = decode_savefh(xdr);
5733 status = decode_open(xdr, res);
5736 if (decode_getfh(xdr, &res->fh) != 0)
5738 if (decode_getfattr(xdr, res->f_attr, res->server,
5739 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5741 if (decode_restorefh(xdr) != 0)
5743 decode_getfattr(xdr, res->dir_attr, res->server,
5744 !RPC_IS_ASYNC(rqstp->rq_task));
5750 * Decode OPEN_CONFIRM response
5752 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5753 struct xdr_stream *xdr,
5754 struct nfs_open_confirmres *res)
5756 struct compound_hdr hdr;
5759 status = decode_compound_hdr(xdr, &hdr);
5762 status = decode_putfh(xdr);
5765 status = decode_open_confirm(xdr, res);
5771 * Decode OPEN response
5773 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5774 struct xdr_stream *xdr,
5775 struct nfs_openres *res)
5777 struct compound_hdr hdr;
5780 status = decode_compound_hdr(xdr, &hdr);
5783 status = decode_sequence(xdr, &res->seq_res, rqstp);
5786 status = decode_putfh(xdr);
5789 status = decode_open(xdr, res);
5792 decode_getfattr(xdr, res->f_attr, res->server,
5793 !RPC_IS_ASYNC(rqstp->rq_task));
5799 * Decode SETATTR response
5801 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5802 struct xdr_stream *xdr,
5803 struct nfs_setattrres *res)
5805 struct compound_hdr hdr;
5808 status = decode_compound_hdr(xdr, &hdr);
5811 status = decode_sequence(xdr, &res->seq_res, rqstp);
5814 status = decode_putfh(xdr);
5817 status = decode_setattr(xdr);
5820 decode_getfattr(xdr, res->fattr, res->server,
5821 !RPC_IS_ASYNC(rqstp->rq_task));
5827 * Decode LOCK response
5829 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5830 struct nfs_lock_res *res)
5832 struct compound_hdr hdr;
5835 status = decode_compound_hdr(xdr, &hdr);
5838 status = decode_sequence(xdr, &res->seq_res, rqstp);
5841 status = decode_putfh(xdr);
5844 status = decode_lock(xdr, res);
5850 * Decode LOCKT response
5852 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5853 struct nfs_lockt_res *res)
5855 struct compound_hdr hdr;
5858 status = decode_compound_hdr(xdr, &hdr);
5861 status = decode_sequence(xdr, &res->seq_res, rqstp);
5864 status = decode_putfh(xdr);
5867 status = decode_lockt(xdr, res);
5873 * Decode LOCKU response
5875 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5876 struct nfs_locku_res *res)
5878 struct compound_hdr hdr;
5881 status = decode_compound_hdr(xdr, &hdr);
5884 status = decode_sequence(xdr, &res->seq_res, rqstp);
5887 status = decode_putfh(xdr);
5890 status = decode_locku(xdr, res);
5895 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5896 struct xdr_stream *xdr, void *dummy)
5898 struct compound_hdr hdr;
5901 status = decode_compound_hdr(xdr, &hdr);
5903 status = decode_release_lockowner(xdr);
5908 * Decode READLINK response
5910 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5911 struct xdr_stream *xdr,
5912 struct nfs4_readlink_res *res)
5914 struct compound_hdr hdr;
5917 status = decode_compound_hdr(xdr, &hdr);
5920 status = decode_sequence(xdr, &res->seq_res, rqstp);
5923 status = decode_putfh(xdr);
5926 status = decode_readlink(xdr, rqstp);
5932 * Decode READDIR response
5934 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5935 struct nfs4_readdir_res *res)
5937 struct compound_hdr hdr;
5940 status = decode_compound_hdr(xdr, &hdr);
5943 status = decode_sequence(xdr, &res->seq_res, rqstp);
5946 status = decode_putfh(xdr);
5949 status = decode_readdir(xdr, rqstp, res);
5955 * Decode Read response
5957 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5958 struct nfs_readres *res)
5960 struct compound_hdr hdr;
5963 status = decode_compound_hdr(xdr, &hdr);
5966 status = decode_sequence(xdr, &res->seq_res, rqstp);
5969 status = decode_putfh(xdr);
5972 status = decode_read(xdr, rqstp, res);
5974 status = res->count;
5980 * Decode WRITE response
5982 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5983 struct nfs_writeres *res)
5985 struct compound_hdr hdr;
5988 status = decode_compound_hdr(xdr, &hdr);
5991 status = decode_sequence(xdr, &res->seq_res, rqstp);
5994 status = decode_putfh(xdr);
5997 status = decode_write(xdr, res);
6001 decode_getfattr(xdr, res->fattr, res->server,
6002 !RPC_IS_ASYNC(rqstp->rq_task));
6004 status = res->count;
6010 * Decode COMMIT response
6012 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6013 struct nfs_writeres *res)
6015 struct compound_hdr hdr;
6018 status = decode_compound_hdr(xdr, &hdr);
6021 status = decode_sequence(xdr, &res->seq_res, rqstp);
6024 status = decode_putfh(xdr);
6027 status = decode_commit(xdr, res);
6031 decode_getfattr(xdr, res->fattr, res->server,
6032 !RPC_IS_ASYNC(rqstp->rq_task));
6038 * Decode FSINFO response
6040 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6041 struct nfs4_fsinfo_res *res)
6043 struct compound_hdr hdr;
6046 status = decode_compound_hdr(xdr, &hdr);
6048 status = decode_sequence(xdr, &res->seq_res, req);
6050 status = decode_putfh(xdr);
6052 status = decode_fsinfo(xdr, res->fsinfo);
6057 * Decode PATHCONF response
6059 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6060 struct nfs4_pathconf_res *res)
6062 struct compound_hdr hdr;
6065 status = decode_compound_hdr(xdr, &hdr);
6067 status = decode_sequence(xdr, &res->seq_res, req);
6069 status = decode_putfh(xdr);
6071 status = decode_pathconf(xdr, res->pathconf);
6076 * Decode STATFS response
6078 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6079 struct nfs4_statfs_res *res)
6081 struct compound_hdr hdr;
6084 status = decode_compound_hdr(xdr, &hdr);
6086 status = decode_sequence(xdr, &res->seq_res, req);
6088 status = decode_putfh(xdr);
6090 status = decode_statfs(xdr, res->fsstat);
6095 * Decode GETATTR_BITMAP response
6097 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6098 struct xdr_stream *xdr,
6099 struct nfs4_server_caps_res *res)
6101 struct compound_hdr hdr;
6104 status = decode_compound_hdr(xdr, &hdr);
6107 status = decode_sequence(xdr, &res->seq_res, req);
6110 status = decode_putfh(xdr);
6113 status = decode_server_caps(xdr, res);
6119 * Decode RENEW response
6121 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6124 struct compound_hdr hdr;
6127 status = decode_compound_hdr(xdr, &hdr);
6129 status = decode_renew(xdr);
6134 * Decode SETCLIENTID response
6136 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6137 struct xdr_stream *xdr,
6138 struct nfs4_setclientid_res *res)
6140 struct compound_hdr hdr;
6143 status = decode_compound_hdr(xdr, &hdr);
6145 status = decode_setclientid(xdr, res);
6150 * Decode SETCLIENTID_CONFIRM response
6152 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6153 struct xdr_stream *xdr,
6154 struct nfs_fsinfo *fsinfo)
6156 struct compound_hdr hdr;
6159 status = decode_compound_hdr(xdr, &hdr);
6161 status = decode_setclientid_confirm(xdr);
6163 status = decode_putrootfh(xdr);
6165 status = decode_fsinfo(xdr, fsinfo);
6170 * Decode DELEGRETURN response
6172 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6173 struct xdr_stream *xdr,
6174 struct nfs4_delegreturnres *res)
6176 struct compound_hdr hdr;
6179 status = decode_compound_hdr(xdr, &hdr);
6182 status = decode_sequence(xdr, &res->seq_res, rqstp);
6185 status = decode_putfh(xdr);
6188 status = decode_delegreturn(xdr);
6191 decode_getfattr(xdr, res->fattr, res->server,
6192 !RPC_IS_ASYNC(rqstp->rq_task));
6198 * Decode FS_LOCATIONS response
6200 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6201 struct xdr_stream *xdr,
6202 struct nfs4_fs_locations_res *res)
6204 struct compound_hdr hdr;
6207 status = decode_compound_hdr(xdr, &hdr);
6210 status = decode_sequence(xdr, &res->seq_res, req);
6213 status = decode_putfh(xdr);
6216 status = decode_lookup(xdr);
6219 xdr_enter_page(xdr, PAGE_SIZE);
6220 status = decode_getfattr(xdr, &res->fs_locations->fattr,
6221 res->fs_locations->server,
6222 !RPC_IS_ASYNC(req->rq_task));
6228 * Decode SECINFO response
6230 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6231 struct xdr_stream *xdr,
6232 struct nfs4_secinfo_res *res)
6234 struct compound_hdr hdr;
6237 status = decode_compound_hdr(xdr, &hdr);
6240 status = decode_sequence(xdr, &res->seq_res, rqstp);
6243 status = decode_putfh(xdr);
6246 status = decode_secinfo(xdr, res);
6253 #if defined(CONFIG_NFS_V4_1)
6255 * Decode EXCHANGE_ID response
6257 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6258 struct xdr_stream *xdr,
6261 struct compound_hdr hdr;
6264 status = decode_compound_hdr(xdr, &hdr);
6266 status = decode_exchange_id(xdr, res);
6271 * Decode CREATE_SESSION response
6273 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6274 struct xdr_stream *xdr,
6275 struct nfs41_create_session_res *res)
6277 struct compound_hdr hdr;
6280 status = decode_compound_hdr(xdr, &hdr);
6282 status = decode_create_session(xdr, res);
6287 * Decode DESTROY_SESSION response
6289 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6290 struct xdr_stream *xdr,
6293 struct compound_hdr hdr;
6296 status = decode_compound_hdr(xdr, &hdr);
6298 status = decode_destroy_session(xdr, res);
6303 * Decode SEQUENCE response
6305 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6306 struct xdr_stream *xdr,
6307 struct nfs4_sequence_res *res)
6309 struct compound_hdr hdr;
6312 status = decode_compound_hdr(xdr, &hdr);
6314 status = decode_sequence(xdr, res, rqstp);
6319 * Decode GET_LEASE_TIME response
6321 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6322 struct xdr_stream *xdr,
6323 struct nfs4_get_lease_time_res *res)
6325 struct compound_hdr hdr;
6328 status = decode_compound_hdr(xdr, &hdr);
6330 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6332 status = decode_putrootfh(xdr);
6334 status = decode_fsinfo(xdr, res->lr_fsinfo);
6339 * Decode RECLAIM_COMPLETE response
6341 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6342 struct xdr_stream *xdr,
6343 struct nfs41_reclaim_complete_res *res)
6345 struct compound_hdr hdr;
6348 status = decode_compound_hdr(xdr, &hdr);
6350 status = decode_sequence(xdr, &res->seq_res, rqstp);
6352 status = decode_reclaim_complete(xdr, (void *)NULL);
6357 * Decode GETDEVINFO response
6359 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6360 struct xdr_stream *xdr,
6361 struct nfs4_getdeviceinfo_res *res)
6363 struct compound_hdr hdr;
6366 status = decode_compound_hdr(xdr, &hdr);
6369 status = decode_sequence(xdr, &res->seq_res, rqstp);
6372 status = decode_getdeviceinfo(xdr, res->pdev);
6378 * Decode LAYOUTGET response
6380 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6381 struct xdr_stream *xdr,
6382 struct nfs4_layoutget_res *res)
6384 struct compound_hdr hdr;
6387 status = decode_compound_hdr(xdr, &hdr);
6390 status = decode_sequence(xdr, &res->seq_res, rqstp);
6393 status = decode_putfh(xdr);
6396 status = decode_layoutget(xdr, rqstp, res);
6402 * Decode LAYOUTRETURN response
6404 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6405 struct xdr_stream *xdr,
6406 struct nfs4_layoutreturn_res *res)
6408 struct compound_hdr hdr;
6411 status = decode_compound_hdr(xdr, &hdr);
6414 status = decode_sequence(xdr, &res->seq_res, rqstp);
6417 status = decode_putfh(xdr);
6420 status = decode_layoutreturn(xdr, res);
6426 * Decode LAYOUTCOMMIT response
6428 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6429 struct xdr_stream *xdr,
6430 struct nfs4_layoutcommit_res *res)
6432 struct compound_hdr hdr;
6435 status = decode_compound_hdr(xdr, &hdr);
6438 status = decode_sequence(xdr, &res->seq_res, rqstp);
6441 status = decode_putfh(xdr);
6444 status = decode_layoutcommit(xdr, rqstp, res);
6447 decode_getfattr(xdr, res->fattr, res->server,
6448 !RPC_IS_ASYNC(rqstp->rq_task));
6452 #endif /* CONFIG_NFS_V4_1 */
6455 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6456 * the local page cache.
6457 * @xdr: XDR stream where entry resides
6458 * @entry: buffer to fill in with entry data
6459 * @plus: boolean indicating whether this should be a readdirplus entry
6461 * Returns zero if successful, otherwise a negative errno value is
6464 * This function is not invoked during READDIR reply decoding, but
6465 * rather whenever an application invokes the getdents(2) system call
6466 * on a directory already in our cache.
6468 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6471 uint32_t bitmap[2] = {0};
6473 __be32 *p = xdr_inline_decode(xdr, 4);
6476 if (*p == xdr_zero) {
6477 p = xdr_inline_decode(xdr, 4);
6486 p = xdr_inline_decode(xdr, 12);
6489 entry->prev_cookie = entry->cookie;
6490 p = xdr_decode_hyper(p, &entry->cookie);
6491 entry->len = be32_to_cpup(p);
6493 p = xdr_inline_decode(xdr, entry->len);
6496 entry->name = (const char *) p;
6499 * In case the server doesn't return an inode number,
6500 * we fake one here. (We don't use inode number 0,
6501 * since glibc seems to choke on it...)
6504 entry->fattr->valid = 0;
6506 if (decode_attr_bitmap(xdr, bitmap) < 0)
6509 if (decode_attr_length(xdr, &len, &p) < 0)
6512 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6513 entry->server, 1) < 0)
6515 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6516 entry->ino = entry->fattr->mounted_on_fileid;
6517 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6518 entry->ino = entry->fattr->fileid;
6520 entry->d_type = DT_UNKNOWN;
6521 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6522 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6527 print_overflow_msg(__func__, xdr);
6532 * We need to translate between nfs status return values and
6533 * the local errno values which may not be the same.
6540 { NFS4ERR_PERM, -EPERM },
6541 { NFS4ERR_NOENT, -ENOENT },
6542 { NFS4ERR_IO, -errno_NFSERR_IO},
6543 { NFS4ERR_NXIO, -ENXIO },
6544 { NFS4ERR_ACCESS, -EACCES },
6545 { NFS4ERR_EXIST, -EEXIST },
6546 { NFS4ERR_XDEV, -EXDEV },
6547 { NFS4ERR_NOTDIR, -ENOTDIR },
6548 { NFS4ERR_ISDIR, -EISDIR },
6549 { NFS4ERR_INVAL, -EINVAL },
6550 { NFS4ERR_FBIG, -EFBIG },
6551 { NFS4ERR_NOSPC, -ENOSPC },
6552 { NFS4ERR_ROFS, -EROFS },
6553 { NFS4ERR_MLINK, -EMLINK },
6554 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6555 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6556 { NFS4ERR_DQUOT, -EDQUOT },
6557 { NFS4ERR_STALE, -ESTALE },
6558 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6559 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6560 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6561 { NFS4ERR_TOOSMALL, -ETOOSMALL },
6562 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
6563 { NFS4ERR_BADTYPE, -EBADTYPE },
6564 { NFS4ERR_LOCKED, -EAGAIN },
6565 { NFS4ERR_SYMLINK, -ELOOP },
6566 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6567 { NFS4ERR_DEADLOCK, -EDEADLK },
6572 * Convert an NFS error code to a local one.
6573 * This one is used jointly by NFSv2 and NFSv3.
6576 nfs4_stat_to_errno(int stat)
6579 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6580 if (nfs_errtbl[i].stat == stat)
6581 return nfs_errtbl[i].errno;
6583 if (stat <= 10000 || stat > 10100) {
6584 /* The server is looney tunes. */
6587 /* If we cannot translate the error, the recovery routines should
6589 * Note: remaining NFSv4 error codes have values > 10000, so should
6590 * not conflict with native Linux error codes.
6595 #define PROC(proc, argtype, restype) \
6596 [NFSPROC4_CLNT_##proc] = { \
6597 .p_proc = NFSPROC4_COMPOUND, \
6598 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6599 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6600 .p_arglen = NFS4_##argtype##_sz, \
6601 .p_replen = NFS4_##restype##_sz, \
6602 .p_statidx = NFSPROC4_CLNT_##proc, \
6606 struct rpc_procinfo nfs4_procedures[] = {
6607 PROC(READ, enc_read, dec_read),
6608 PROC(WRITE, enc_write, dec_write),
6609 PROC(COMMIT, enc_commit, dec_commit),
6610 PROC(OPEN, enc_open, dec_open),
6611 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6612 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6613 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6614 PROC(CLOSE, enc_close, dec_close),
6615 PROC(SETATTR, enc_setattr, dec_setattr),
6616 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6617 PROC(RENEW, enc_renew, dec_renew),
6618 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6619 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6620 PROC(LOCK, enc_lock, dec_lock),
6621 PROC(LOCKT, enc_lockt, dec_lockt),
6622 PROC(LOCKU, enc_locku, dec_locku),
6623 PROC(ACCESS, enc_access, dec_access),
6624 PROC(GETATTR, enc_getattr, dec_getattr),
6625 PROC(LOOKUP, enc_lookup, dec_lookup),
6626 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6627 PROC(REMOVE, enc_remove, dec_remove),
6628 PROC(RENAME, enc_rename, dec_rename),
6629 PROC(LINK, enc_link, dec_link),
6630 PROC(SYMLINK, enc_symlink, dec_symlink),
6631 PROC(CREATE, enc_create, dec_create),
6632 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6633 PROC(STATFS, enc_statfs, dec_statfs),
6634 PROC(READLINK, enc_readlink, dec_readlink),
6635 PROC(READDIR, enc_readdir, dec_readdir),
6636 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6637 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6638 PROC(GETACL, enc_getacl, dec_getacl),
6639 PROC(SETACL, enc_setacl, dec_setacl),
6640 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6641 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
6642 PROC(SECINFO, enc_secinfo, dec_secinfo),
6643 #if defined(CONFIG_NFS_V4_1)
6644 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6645 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6646 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6647 PROC(SEQUENCE, enc_sequence, dec_sequence),
6648 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6649 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6650 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6651 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
6652 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
6653 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
6654 #endif /* CONFIG_NFS_V4_1 */
6657 struct rpc_version nfs_version4 = {
6659 .nrprocs = ARRAY_SIZE(nfs4_procedures),
6660 .procs = nfs4_procedures