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 4
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 + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
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 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
347 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
348 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
349 XDR_QUADLEN(NFS4_STATEID_SIZE))
350 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
351 #else /* CONFIG_NFS_V4_1 */
352 #define encode_sequence_maxsz 0
353 #define decode_sequence_maxsz 0
354 #endif /* CONFIG_NFS_V4_1 */
356 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
357 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
358 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
359 encode_sequence_maxsz + \
360 encode_putfh_maxsz + \
362 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
363 decode_sequence_maxsz + \
364 decode_putfh_maxsz + \
366 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
367 encode_sequence_maxsz + \
368 encode_putfh_maxsz + \
369 encode_readlink_maxsz)
370 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
371 decode_sequence_maxsz + \
372 decode_putfh_maxsz + \
373 decode_readlink_maxsz)
374 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
375 encode_sequence_maxsz + \
376 encode_putfh_maxsz + \
377 encode_readdir_maxsz)
378 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
379 decode_sequence_maxsz + \
380 decode_putfh_maxsz + \
381 decode_readdir_maxsz)
382 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
383 encode_sequence_maxsz + \
384 encode_putfh_maxsz + \
385 encode_write_maxsz + \
386 encode_getattr_maxsz)
387 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
388 decode_sequence_maxsz + \
389 decode_putfh_maxsz + \
390 decode_write_maxsz + \
391 decode_getattr_maxsz)
392 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
393 encode_sequence_maxsz + \
394 encode_putfh_maxsz + \
395 encode_commit_maxsz + \
396 encode_getattr_maxsz)
397 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
398 decode_sequence_maxsz + \
399 decode_putfh_maxsz + \
400 decode_commit_maxsz + \
401 decode_getattr_maxsz)
402 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
403 encode_sequence_maxsz + \
404 encode_putfh_maxsz + \
405 encode_savefh_maxsz + \
406 encode_open_maxsz + \
407 encode_getfh_maxsz + \
408 encode_getattr_maxsz + \
409 encode_restorefh_maxsz + \
410 encode_getattr_maxsz)
411 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
412 decode_sequence_maxsz + \
413 decode_putfh_maxsz + \
414 decode_savefh_maxsz + \
415 decode_open_maxsz + \
416 decode_getfh_maxsz + \
417 decode_getattr_maxsz + \
418 decode_restorefh_maxsz + \
419 decode_getattr_maxsz)
420 #define NFS4_enc_open_confirm_sz \
421 (compound_encode_hdr_maxsz + \
422 encode_putfh_maxsz + \
423 encode_open_confirm_maxsz)
424 #define NFS4_dec_open_confirm_sz \
425 (compound_decode_hdr_maxsz + \
426 decode_putfh_maxsz + \
427 decode_open_confirm_maxsz)
428 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
429 encode_sequence_maxsz + \
430 encode_putfh_maxsz + \
431 encode_open_maxsz + \
432 encode_getattr_maxsz)
433 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
434 decode_sequence_maxsz + \
435 decode_putfh_maxsz + \
436 decode_open_maxsz + \
437 decode_getattr_maxsz)
438 #define NFS4_enc_open_downgrade_sz \
439 (compound_encode_hdr_maxsz + \
440 encode_sequence_maxsz + \
441 encode_putfh_maxsz + \
442 encode_open_downgrade_maxsz + \
443 encode_getattr_maxsz)
444 #define NFS4_dec_open_downgrade_sz \
445 (compound_decode_hdr_maxsz + \
446 decode_sequence_maxsz + \
447 decode_putfh_maxsz + \
448 decode_open_downgrade_maxsz + \
449 decode_getattr_maxsz)
450 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
451 encode_sequence_maxsz + \
452 encode_putfh_maxsz + \
453 encode_close_maxsz + \
454 encode_getattr_maxsz)
455 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
456 decode_sequence_maxsz + \
457 decode_putfh_maxsz + \
458 decode_close_maxsz + \
459 decode_getattr_maxsz)
460 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
461 encode_sequence_maxsz + \
462 encode_putfh_maxsz + \
463 encode_setattr_maxsz + \
464 encode_getattr_maxsz)
465 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
466 decode_sequence_maxsz + \
467 decode_putfh_maxsz + \
468 decode_setattr_maxsz + \
469 decode_getattr_maxsz)
470 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
471 encode_sequence_maxsz + \
472 encode_putfh_maxsz + \
474 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
475 decode_sequence_maxsz + \
476 decode_putfh_maxsz + \
478 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
480 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
482 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
483 encode_setclientid_maxsz)
484 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
485 decode_setclientid_maxsz)
486 #define NFS4_enc_setclientid_confirm_sz \
487 (compound_encode_hdr_maxsz + \
488 encode_setclientid_confirm_maxsz + \
489 encode_putrootfh_maxsz + \
491 #define NFS4_dec_setclientid_confirm_sz \
492 (compound_decode_hdr_maxsz + \
493 decode_setclientid_confirm_maxsz + \
494 decode_putrootfh_maxsz + \
496 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
497 encode_sequence_maxsz + \
498 encode_putfh_maxsz + \
500 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
501 decode_sequence_maxsz + \
502 decode_putfh_maxsz + \
504 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
505 encode_sequence_maxsz + \
506 encode_putfh_maxsz + \
508 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
509 decode_sequence_maxsz + \
510 decode_putfh_maxsz + \
512 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
513 encode_sequence_maxsz + \
514 encode_putfh_maxsz + \
516 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
517 decode_sequence_maxsz + \
518 decode_putfh_maxsz + \
520 #define NFS4_enc_release_lockowner_sz \
521 (compound_encode_hdr_maxsz + \
522 encode_lockowner_maxsz)
523 #define NFS4_dec_release_lockowner_sz \
524 (compound_decode_hdr_maxsz + \
525 decode_lockowner_maxsz)
526 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
527 encode_sequence_maxsz + \
528 encode_putfh_maxsz + \
529 encode_access_maxsz + \
530 encode_getattr_maxsz)
531 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
532 decode_sequence_maxsz + \
533 decode_putfh_maxsz + \
534 decode_access_maxsz + \
535 decode_getattr_maxsz)
536 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
537 encode_sequence_maxsz + \
538 encode_putfh_maxsz + \
539 encode_getattr_maxsz)
540 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
541 decode_sequence_maxsz + \
542 decode_putfh_maxsz + \
543 decode_getattr_maxsz)
544 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
545 encode_sequence_maxsz + \
546 encode_putfh_maxsz + \
547 encode_lookup_maxsz + \
548 encode_getattr_maxsz + \
550 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
551 decode_sequence_maxsz + \
552 decode_putfh_maxsz + \
553 decode_lookup_maxsz + \
554 decode_getattr_maxsz + \
556 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
557 encode_sequence_maxsz + \
558 encode_putrootfh_maxsz + \
559 encode_getattr_maxsz + \
561 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
562 decode_sequence_maxsz + \
563 decode_putrootfh_maxsz + \
564 decode_getattr_maxsz + \
566 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
567 encode_sequence_maxsz + \
568 encode_putfh_maxsz + \
569 encode_remove_maxsz + \
570 encode_getattr_maxsz)
571 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
572 decode_sequence_maxsz + \
573 decode_putfh_maxsz + \
574 decode_remove_maxsz + \
575 decode_getattr_maxsz)
576 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
577 encode_sequence_maxsz + \
578 encode_putfh_maxsz + \
579 encode_savefh_maxsz + \
580 encode_putfh_maxsz + \
581 encode_rename_maxsz + \
582 encode_getattr_maxsz + \
583 encode_restorefh_maxsz + \
584 encode_getattr_maxsz)
585 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
586 decode_sequence_maxsz + \
587 decode_putfh_maxsz + \
588 decode_savefh_maxsz + \
589 decode_putfh_maxsz + \
590 decode_rename_maxsz + \
591 decode_getattr_maxsz + \
592 decode_restorefh_maxsz + \
593 decode_getattr_maxsz)
594 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
595 encode_sequence_maxsz + \
596 encode_putfh_maxsz + \
597 encode_savefh_maxsz + \
598 encode_putfh_maxsz + \
599 encode_link_maxsz + \
600 decode_getattr_maxsz + \
601 encode_restorefh_maxsz + \
602 decode_getattr_maxsz)
603 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
604 decode_sequence_maxsz + \
605 decode_putfh_maxsz + \
606 decode_savefh_maxsz + \
607 decode_putfh_maxsz + \
608 decode_link_maxsz + \
609 decode_getattr_maxsz + \
610 decode_restorefh_maxsz + \
611 decode_getattr_maxsz)
612 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
613 encode_sequence_maxsz + \
614 encode_putfh_maxsz + \
615 encode_symlink_maxsz + \
616 encode_getattr_maxsz + \
618 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
619 decode_sequence_maxsz + \
620 decode_putfh_maxsz + \
621 decode_symlink_maxsz + \
622 decode_getattr_maxsz + \
624 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
625 encode_sequence_maxsz + \
626 encode_putfh_maxsz + \
627 encode_savefh_maxsz + \
628 encode_create_maxsz + \
629 encode_getfh_maxsz + \
630 encode_getattr_maxsz + \
631 encode_restorefh_maxsz + \
632 encode_getattr_maxsz)
633 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
634 decode_sequence_maxsz + \
635 decode_putfh_maxsz + \
636 decode_savefh_maxsz + \
637 decode_create_maxsz + \
638 decode_getfh_maxsz + \
639 decode_getattr_maxsz + \
640 decode_restorefh_maxsz + \
641 decode_getattr_maxsz)
642 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
643 encode_sequence_maxsz + \
644 encode_putfh_maxsz + \
645 encode_getattr_maxsz)
646 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
647 decode_sequence_maxsz + \
648 decode_putfh_maxsz + \
649 decode_getattr_maxsz)
650 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
651 encode_sequence_maxsz + \
652 encode_putfh_maxsz + \
654 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
655 decode_sequence_maxsz + \
656 decode_putfh_maxsz + \
658 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
659 encode_sequence_maxsz + \
660 encode_putfh_maxsz + \
661 encode_getattr_maxsz)
662 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
663 decode_sequence_maxsz + \
664 decode_putfh_maxsz + \
665 decode_getattr_maxsz)
666 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
667 encode_sequence_maxsz + \
668 encode_putfh_maxsz + \
669 encode_delegreturn_maxsz + \
670 encode_getattr_maxsz)
671 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
672 decode_sequence_maxsz + \
673 decode_delegreturn_maxsz + \
674 decode_getattr_maxsz)
675 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
676 encode_sequence_maxsz + \
677 encode_putfh_maxsz + \
679 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
680 decode_sequence_maxsz + \
681 decode_putfh_maxsz + \
683 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
684 encode_sequence_maxsz + \
685 encode_putfh_maxsz + \
687 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
688 decode_sequence_maxsz + \
689 decode_putfh_maxsz + \
691 #define NFS4_enc_fs_locations_sz \
692 (compound_encode_hdr_maxsz + \
693 encode_sequence_maxsz + \
694 encode_putfh_maxsz + \
695 encode_lookup_maxsz + \
696 encode_fs_locations_maxsz)
697 #define NFS4_dec_fs_locations_sz \
698 (compound_decode_hdr_maxsz + \
699 decode_sequence_maxsz + \
700 decode_putfh_maxsz + \
701 decode_lookup_maxsz + \
702 decode_fs_locations_maxsz)
703 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
704 encode_sequence_maxsz + \
705 encode_putfh_maxsz + \
706 encode_secinfo_maxsz)
707 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
708 decode_sequence_maxsz + \
709 decode_putfh_maxsz + \
710 decode_secinfo_maxsz)
711 #if defined(CONFIG_NFS_V4_1)
712 #define NFS4_enc_exchange_id_sz \
713 (compound_encode_hdr_maxsz + \
714 encode_exchange_id_maxsz)
715 #define NFS4_dec_exchange_id_sz \
716 (compound_decode_hdr_maxsz + \
717 decode_exchange_id_maxsz)
718 #define NFS4_enc_create_session_sz \
719 (compound_encode_hdr_maxsz + \
720 encode_create_session_maxsz)
721 #define NFS4_dec_create_session_sz \
722 (compound_decode_hdr_maxsz + \
723 decode_create_session_maxsz)
724 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
725 encode_destroy_session_maxsz)
726 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
727 decode_destroy_session_maxsz)
728 #define NFS4_enc_sequence_sz \
729 (compound_decode_hdr_maxsz + \
730 encode_sequence_maxsz)
731 #define NFS4_dec_sequence_sz \
732 (compound_decode_hdr_maxsz + \
733 decode_sequence_maxsz)
734 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
735 encode_sequence_maxsz + \
736 encode_putrootfh_maxsz + \
738 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
739 decode_sequence_maxsz + \
740 decode_putrootfh_maxsz + \
742 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz + \
744 encode_reclaim_complete_maxsz)
745 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
746 decode_sequence_maxsz + \
747 decode_reclaim_complete_maxsz)
748 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
749 encode_sequence_maxsz +\
750 encode_getdeviceinfo_maxsz)
751 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
752 decode_sequence_maxsz + \
753 decode_getdeviceinfo_maxsz)
754 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
755 encode_sequence_maxsz + \
756 encode_putfh_maxsz + \
757 encode_layoutget_maxsz)
758 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
759 decode_sequence_maxsz + \
760 decode_putfh_maxsz + \
761 decode_layoutget_maxsz)
762 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
763 encode_sequence_maxsz +\
764 encode_putfh_maxsz + \
765 encode_layoutcommit_maxsz + \
766 encode_getattr_maxsz)
767 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putfh_maxsz + \
770 decode_layoutcommit_maxsz + \
771 decode_getattr_maxsz)
772 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
773 encode_sequence_maxsz + \
774 encode_putfh_maxsz + \
775 encode_layoutreturn_maxsz)
776 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
777 decode_sequence_maxsz + \
778 decode_putfh_maxsz + \
779 decode_layoutreturn_maxsz)
780 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz + \
782 encode_putrootfh_maxsz +\
783 encode_secinfo_no_name_maxsz)
784 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_putrootfh_maxsz + \
787 decode_secinfo_no_name_maxsz)
788 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
789 encode_sequence_maxsz + \
790 encode_test_stateid_maxsz)
791 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_test_stateid_maxsz)
795 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
796 compound_encode_hdr_maxsz +
797 encode_sequence_maxsz +
799 encode_getattr_maxsz) *
802 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
803 compound_decode_hdr_maxsz +
804 decode_sequence_maxsz +
805 decode_putfh_maxsz) *
807 #endif /* CONFIG_NFS_V4_1 */
809 static const umode_t nfs_type2fmt[] = {
816 [NF4SOCK] = S_IFSOCK,
822 struct compound_hdr {
828 uint32_t replen; /* expected reply words */
832 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
834 __be32 *p = xdr_reserve_space(xdr, nbytes);
839 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
843 p = xdr_reserve_space(xdr, 4 + len);
845 xdr_encode_opaque(p, str, len);
848 static void encode_compound_hdr(struct xdr_stream *xdr,
849 struct rpc_rqst *req,
850 struct compound_hdr *hdr)
853 struct rpc_auth *auth = req->rq_cred->cr_auth;
855 /* initialize running count of expected bytes in reply.
856 * NOTE: the replied tag SHOULD be the same is the one sent,
857 * but this is not required as a MUST for the server to do so. */
858 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
860 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
861 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
862 p = reserve_space(xdr, 4 + hdr->taglen + 8);
863 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
864 *p++ = cpu_to_be32(hdr->minorversion);
866 *p = cpu_to_be32(hdr->nops);
869 static void encode_nops(struct compound_hdr *hdr)
871 BUG_ON(hdr->nops > NFS4_MAX_OPS);
872 *hdr->nops_p = htonl(hdr->nops);
875 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
879 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
881 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
884 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
886 char owner_name[IDMAP_NAMESZ];
887 char owner_group[IDMAP_NAMESZ];
888 int owner_namelen = 0;
889 int owner_grouplen = 0;
897 * We reserve enough space to write the entire attribute buffer at once.
898 * In the worst-case, this would be
899 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
900 * = 36 bytes, plus any contribution from variable-length fields
901 * such as owner/group.
906 if (iap->ia_valid & ATTR_SIZE)
908 if (iap->ia_valid & ATTR_MODE)
910 if (iap->ia_valid & ATTR_UID) {
911 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
912 if (owner_namelen < 0) {
913 dprintk("nfs: couldn't resolve uid %d to string\n",
916 strcpy(owner_name, "nobody");
917 owner_namelen = sizeof("nobody") - 1;
920 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
922 if (iap->ia_valid & ATTR_GID) {
923 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
924 if (owner_grouplen < 0) {
925 dprintk("nfs: couldn't resolve gid %d to string\n",
927 strcpy(owner_group, "nobody");
928 owner_grouplen = sizeof("nobody") - 1;
931 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
933 if (iap->ia_valid & ATTR_ATIME_SET)
935 else if (iap->ia_valid & ATTR_ATIME)
937 if (iap->ia_valid & ATTR_MTIME_SET)
939 else if (iap->ia_valid & ATTR_MTIME)
941 p = reserve_space(xdr, len);
944 * We write the bitmap length now, but leave the bitmap and the attribute
945 * buffer length to be backfilled at the end of this routine.
947 *p++ = cpu_to_be32(2);
951 if (iap->ia_valid & ATTR_SIZE) {
952 bmval0 |= FATTR4_WORD0_SIZE;
953 p = xdr_encode_hyper(p, iap->ia_size);
955 if (iap->ia_valid & ATTR_MODE) {
956 bmval1 |= FATTR4_WORD1_MODE;
957 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
959 if (iap->ia_valid & ATTR_UID) {
960 bmval1 |= FATTR4_WORD1_OWNER;
961 p = xdr_encode_opaque(p, owner_name, owner_namelen);
963 if (iap->ia_valid & ATTR_GID) {
964 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
965 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
967 if (iap->ia_valid & ATTR_ATIME_SET) {
968 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
969 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
970 *p++ = cpu_to_be32(0);
971 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
972 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
974 else if (iap->ia_valid & ATTR_ATIME) {
975 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
976 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
978 if (iap->ia_valid & ATTR_MTIME_SET) {
979 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
980 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
981 *p++ = cpu_to_be32(0);
982 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
983 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
985 else if (iap->ia_valid & ATTR_MTIME) {
986 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
987 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
991 * Now we backfill the bitmap and the attribute buffer length.
993 if (len != ((char *)p - (char *)q) + 4) {
994 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
995 len, ((char *)p - (char *)q) + 4);
998 len = (char *)p - (char *)q - 12;
999 *q++ = htonl(bmval0);
1000 *q++ = htonl(bmval1);
1006 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1010 p = reserve_space(xdr, 8);
1011 *p++ = cpu_to_be32(OP_ACCESS);
1012 *p = cpu_to_be32(access);
1014 hdr->replen += decode_access_maxsz;
1017 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1021 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1022 *p++ = cpu_to_be32(OP_CLOSE);
1023 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1024 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1026 hdr->replen += decode_close_maxsz;
1029 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1033 p = reserve_space(xdr, 16);
1034 *p++ = cpu_to_be32(OP_COMMIT);
1035 p = xdr_encode_hyper(p, args->offset);
1036 *p = cpu_to_be32(args->count);
1038 hdr->replen += decode_commit_maxsz;
1041 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1045 p = reserve_space(xdr, 8);
1046 *p++ = cpu_to_be32(OP_CREATE);
1047 *p = cpu_to_be32(create->ftype);
1049 switch (create->ftype) {
1051 p = reserve_space(xdr, 4);
1052 *p = cpu_to_be32(create->u.symlink.len);
1053 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1056 case NF4BLK: case NF4CHR:
1057 p = reserve_space(xdr, 8);
1058 *p++ = cpu_to_be32(create->u.device.specdata1);
1059 *p = cpu_to_be32(create->u.device.specdata2);
1066 encode_string(xdr, create->name->len, create->name->name);
1068 hdr->replen += decode_create_maxsz;
1070 encode_attrs(xdr, create->attrs, create->server);
1073 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1077 p = reserve_space(xdr, 12);
1078 *p++ = cpu_to_be32(OP_GETATTR);
1079 *p++ = cpu_to_be32(1);
1080 *p = cpu_to_be32(bitmap);
1082 hdr->replen += decode_getattr_maxsz;
1085 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1089 p = reserve_space(xdr, 16);
1090 *p++ = cpu_to_be32(OP_GETATTR);
1091 *p++ = cpu_to_be32(2);
1092 *p++ = cpu_to_be32(bm0);
1093 *p = cpu_to_be32(bm1);
1095 hdr->replen += decode_getattr_maxsz;
1098 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1100 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1101 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1104 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1106 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1107 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1110 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1112 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1113 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1116 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1120 p = reserve_space(xdr, 4);
1121 *p = cpu_to_be32(OP_GETFH);
1123 hdr->replen += decode_getfh_maxsz;
1126 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1130 p = reserve_space(xdr, 8 + name->len);
1131 *p++ = cpu_to_be32(OP_LINK);
1132 xdr_encode_opaque(p, name->name, name->len);
1134 hdr->replen += decode_link_maxsz;
1137 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1139 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1140 return block ? NFS4_READW_LT : NFS4_READ_LT;
1141 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1144 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1146 if (fl->fl_end == OFFSET_MAX)
1147 return ~(uint64_t)0;
1148 return fl->fl_end - fl->fl_start + 1;
1151 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1155 p = reserve_space(xdr, 32);
1156 p = xdr_encode_hyper(p, lowner->clientid);
1157 *p++ = cpu_to_be32(20);
1158 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1159 *p++ = cpu_to_be32(lowner->s_dev);
1160 xdr_encode_hyper(p, lowner->id);
1164 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1165 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1167 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1171 p = reserve_space(xdr, 32);
1172 *p++ = cpu_to_be32(OP_LOCK);
1173 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1174 *p++ = cpu_to_be32(args->reclaim);
1175 p = xdr_encode_hyper(p, args->fl->fl_start);
1176 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1177 *p = cpu_to_be32(args->new_lock_owner);
1178 if (args->new_lock_owner){
1179 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1180 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1181 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1182 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1183 encode_lockowner(xdr, &args->lock_owner);
1186 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1187 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1188 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1191 hdr->replen += decode_lock_maxsz;
1194 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1198 p = reserve_space(xdr, 24);
1199 *p++ = cpu_to_be32(OP_LOCKT);
1200 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1201 p = xdr_encode_hyper(p, args->fl->fl_start);
1202 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1203 encode_lockowner(xdr, &args->lock_owner);
1205 hdr->replen += decode_lockt_maxsz;
1208 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1212 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1213 *p++ = cpu_to_be32(OP_LOCKU);
1214 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1215 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1216 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1217 p = xdr_encode_hyper(p, args->fl->fl_start);
1218 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1220 hdr->replen += decode_locku_maxsz;
1223 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1227 p = reserve_space(xdr, 4);
1228 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1229 encode_lockowner(xdr, lowner);
1231 hdr->replen += decode_release_lockowner_maxsz;
1234 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1236 int len = name->len;
1239 p = reserve_space(xdr, 8 + len);
1240 *p++ = cpu_to_be32(OP_LOOKUP);
1241 xdr_encode_opaque(p, name->name, len);
1243 hdr->replen += decode_lookup_maxsz;
1246 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1250 p = reserve_space(xdr, 8);
1251 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1253 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1256 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1258 case FMODE_READ|FMODE_WRITE:
1259 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1262 *p++ = cpu_to_be32(0);
1264 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1267 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1271 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1274 p = reserve_space(xdr, 8);
1275 *p++ = cpu_to_be32(OP_OPEN);
1276 *p = cpu_to_be32(arg->seqid->sequence->counter);
1277 encode_share_access(xdr, arg->fmode);
1278 p = reserve_space(xdr, 32);
1279 p = xdr_encode_hyper(p, arg->clientid);
1280 *p++ = cpu_to_be32(20);
1281 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1282 *p++ = cpu_to_be32(arg->server->s_dev);
1283 xdr_encode_hyper(p, arg->id);
1286 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1289 struct nfs_client *clp;
1291 p = reserve_space(xdr, 4);
1292 switch(arg->open_flags & O_EXCL) {
1294 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1295 encode_attrs(xdr, arg->u.attrs, arg->server);
1298 clp = arg->server->nfs_client;
1299 if (clp->cl_mvops->minor_version > 0) {
1300 if (nfs4_has_persistent_session(clp)) {
1301 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1302 encode_attrs(xdr, arg->u.attrs, arg->server);
1306 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1307 encode_nfs4_verifier(xdr, &arg->u.verifier);
1309 encode_attrs(xdr, &dummy, arg->server);
1312 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1313 encode_nfs4_verifier(xdr, &arg->u.verifier);
1318 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1322 p = reserve_space(xdr, 4);
1323 switch (arg->open_flags & O_CREAT) {
1325 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1328 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1329 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1330 encode_createmode(xdr, arg);
1334 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1338 p = reserve_space(xdr, 4);
1339 switch (delegation_type) {
1341 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1344 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1346 case FMODE_WRITE|FMODE_READ:
1347 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1354 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1358 p = reserve_space(xdr, 4);
1359 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1360 encode_string(xdr, name->len, name->name);
1363 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1367 p = reserve_space(xdr, 4);
1368 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1369 encode_delegation_type(xdr, type);
1372 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1376 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1377 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1378 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1379 encode_string(xdr, name->len, name->name);
1382 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1384 encode_openhdr(xdr, arg);
1385 encode_opentype(xdr, arg);
1386 switch (arg->claim) {
1387 case NFS4_OPEN_CLAIM_NULL:
1388 encode_claim_null(xdr, arg->name);
1390 case NFS4_OPEN_CLAIM_PREVIOUS:
1391 encode_claim_previous(xdr, arg->u.delegation_type);
1393 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1394 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1400 hdr->replen += decode_open_maxsz;
1403 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1407 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1408 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1409 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1410 *p = cpu_to_be32(arg->seqid->sequence->counter);
1412 hdr->replen += decode_open_confirm_maxsz;
1415 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1419 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1420 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1421 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1422 *p = cpu_to_be32(arg->seqid->sequence->counter);
1423 encode_share_access(xdr, arg->fmode);
1425 hdr->replen += decode_open_downgrade_maxsz;
1429 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1434 p = reserve_space(xdr, 8 + len);
1435 *p++ = cpu_to_be32(OP_PUTFH);
1436 xdr_encode_opaque(p, fh->data, len);
1438 hdr->replen += decode_putfh_maxsz;
1441 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1445 p = reserve_space(xdr, 4);
1446 *p = cpu_to_be32(OP_PUTROOTFH);
1448 hdr->replen += decode_putrootfh_maxsz;
1451 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
1453 nfs4_stateid stateid;
1456 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1457 if (ctx->state != NULL) {
1458 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1460 stateid.stateid.seqid = 0;
1461 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1463 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1466 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1470 p = reserve_space(xdr, 4);
1471 *p = cpu_to_be32(OP_READ);
1473 encode_stateid(xdr, args->context, args->lock_context,
1476 p = reserve_space(xdr, 12);
1477 p = xdr_encode_hyper(p, args->offset);
1478 *p = cpu_to_be32(args->count);
1480 hdr->replen += decode_read_maxsz;
1483 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1485 uint32_t attrs[2] = {
1486 FATTR4_WORD0_RDATTR_ERROR,
1487 FATTR4_WORD1_MOUNTED_ON_FILEID,
1489 uint32_t dircount = readdir->count >> 1;
1492 if (readdir->plus) {
1493 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1494 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1495 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1496 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1497 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1498 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1501 /* Use mounted_on_fileid only if the server supports it */
1502 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1503 attrs[0] |= FATTR4_WORD0_FILEID;
1505 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1506 *p++ = cpu_to_be32(OP_READDIR);
1507 p = xdr_encode_hyper(p, readdir->cookie);
1508 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1509 *p++ = cpu_to_be32(dircount);
1510 *p++ = cpu_to_be32(readdir->count);
1511 *p++ = cpu_to_be32(2);
1513 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1514 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1516 hdr->replen += decode_readdir_maxsz;
1517 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1519 (unsigned long long)readdir->cookie,
1520 ((u32 *)readdir->verifier.data)[0],
1521 ((u32 *)readdir->verifier.data)[1],
1522 attrs[0] & readdir->bitmask[0],
1523 attrs[1] & readdir->bitmask[1]);
1526 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1530 p = reserve_space(xdr, 4);
1531 *p = cpu_to_be32(OP_READLINK);
1533 hdr->replen += decode_readlink_maxsz;
1536 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1540 p = reserve_space(xdr, 8 + name->len);
1541 *p++ = cpu_to_be32(OP_REMOVE);
1542 xdr_encode_opaque(p, name->name, name->len);
1544 hdr->replen += decode_remove_maxsz;
1547 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1551 p = reserve_space(xdr, 4);
1552 *p = cpu_to_be32(OP_RENAME);
1553 encode_string(xdr, oldname->len, oldname->name);
1554 encode_string(xdr, newname->len, newname->name);
1556 hdr->replen += decode_rename_maxsz;
1559 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1563 p = reserve_space(xdr, 12);
1564 *p++ = cpu_to_be32(OP_RENEW);
1565 xdr_encode_hyper(p, client_stateid->cl_clientid);
1567 hdr->replen += decode_renew_maxsz;
1571 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1575 p = reserve_space(xdr, 4);
1576 *p = cpu_to_be32(OP_RESTOREFH);
1578 hdr->replen += decode_restorefh_maxsz;
1582 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1586 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1587 *p++ = cpu_to_be32(OP_SETATTR);
1588 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1589 p = reserve_space(xdr, 2*4);
1590 *p++ = cpu_to_be32(1);
1591 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1592 BUG_ON(arg->acl_len % 4);
1593 p = reserve_space(xdr, 4);
1594 *p = cpu_to_be32(arg->acl_len);
1595 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1597 hdr->replen += decode_setacl_maxsz;
1601 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1605 p = reserve_space(xdr, 4);
1606 *p = cpu_to_be32(OP_SAVEFH);
1608 hdr->replen += decode_savefh_maxsz;
1611 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1615 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1616 *p++ = cpu_to_be32(OP_SETATTR);
1617 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1619 hdr->replen += decode_setattr_maxsz;
1620 encode_attrs(xdr, arg->iap, server);
1623 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1627 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1628 *p++ = cpu_to_be32(OP_SETCLIENTID);
1629 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1631 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1632 p = reserve_space(xdr, 4);
1633 *p = cpu_to_be32(setclientid->sc_prog);
1634 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1635 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1636 p = reserve_space(xdr, 4);
1637 *p = cpu_to_be32(setclientid->sc_cb_ident);
1639 hdr->replen += decode_setclientid_maxsz;
1642 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1646 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1647 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1648 p = xdr_encode_hyper(p, arg->clientid);
1649 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1651 hdr->replen += decode_setclientid_confirm_maxsz;
1654 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1658 p = reserve_space(xdr, 4);
1659 *p = cpu_to_be32(OP_WRITE);
1661 encode_stateid(xdr, args->context, args->lock_context,
1664 p = reserve_space(xdr, 16);
1665 p = xdr_encode_hyper(p, args->offset);
1666 *p++ = cpu_to_be32(args->stable);
1667 *p = cpu_to_be32(args->count);
1669 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1671 hdr->replen += decode_write_maxsz;
1674 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1678 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1680 *p++ = cpu_to_be32(OP_DELEGRETURN);
1681 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1683 hdr->replen += decode_delegreturn_maxsz;
1686 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1688 int len = name->len;
1691 p = reserve_space(xdr, 8 + len);
1692 *p++ = cpu_to_be32(OP_SECINFO);
1693 xdr_encode_opaque(p, name->name, len);
1695 hdr->replen += decode_secinfo_maxsz;
1698 #if defined(CONFIG_NFS_V4_1)
1699 /* NFSv4.1 operations */
1700 static void encode_exchange_id(struct xdr_stream *xdr,
1701 struct nfs41_exchange_id_args *args,
1702 struct compound_hdr *hdr)
1706 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1707 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1708 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1710 encode_string(xdr, args->id_len, args->id);
1712 p = reserve_space(xdr, 12);
1713 *p++ = cpu_to_be32(args->flags);
1714 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1715 *p = cpu_to_be32(0); /* zero length implementation id array */
1717 hdr->replen += decode_exchange_id_maxsz;
1720 static void encode_create_session(struct xdr_stream *xdr,
1721 struct nfs41_create_session_args *args,
1722 struct compound_hdr *hdr)
1725 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1727 struct nfs_client *clp = args->client;
1728 u32 max_resp_sz_cached;
1731 * Assumes OPEN is the biggest non-idempotent compound.
1732 * 2 is the verifier.
1734 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1735 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1737 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1740 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1741 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1742 p = xdr_encode_hyper(p, clp->cl_clientid);
1743 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1744 *p++ = cpu_to_be32(args->flags); /*flags */
1747 *p++ = cpu_to_be32(0); /* header padding size */
1748 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1749 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1750 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1751 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1752 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1753 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1756 *p++ = cpu_to_be32(0); /* header padding size */
1757 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1758 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1759 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1760 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1761 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1762 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1764 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1765 *p++ = cpu_to_be32(1);
1766 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1768 /* authsys_parms rfc1831 */
1769 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1770 p = xdr_encode_opaque(p, machine_name, len);
1771 *p++ = cpu_to_be32(0); /* UID */
1772 *p++ = cpu_to_be32(0); /* GID */
1773 *p = cpu_to_be32(0); /* No more gids */
1775 hdr->replen += decode_create_session_maxsz;
1778 static void encode_destroy_session(struct xdr_stream *xdr,
1779 struct nfs4_session *session,
1780 struct compound_hdr *hdr)
1783 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1784 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1785 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1787 hdr->replen += decode_destroy_session_maxsz;
1790 static void encode_reclaim_complete(struct xdr_stream *xdr,
1791 struct nfs41_reclaim_complete_args *args,
1792 struct compound_hdr *hdr)
1796 p = reserve_space(xdr, 8);
1797 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1798 *p++ = cpu_to_be32(args->one_fs);
1800 hdr->replen += decode_reclaim_complete_maxsz;
1802 #endif /* CONFIG_NFS_V4_1 */
1804 static void encode_sequence(struct xdr_stream *xdr,
1805 const struct nfs4_sequence_args *args,
1806 struct compound_hdr *hdr)
1808 #if defined(CONFIG_NFS_V4_1)
1809 struct nfs4_session *session = args->sa_session;
1810 struct nfs4_slot_table *tp;
1811 struct nfs4_slot *slot;
1817 tp = &session->fc_slot_table;
1819 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1820 slot = tp->slots + args->sa_slotid;
1822 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1823 *p++ = cpu_to_be32(OP_SEQUENCE);
1826 * Sessionid + seqid + slotid + max slotid + cache_this
1828 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1829 "max_slotid=%d cache_this=%d\n",
1831 ((u32 *)session->sess_id.data)[0],
1832 ((u32 *)session->sess_id.data)[1],
1833 ((u32 *)session->sess_id.data)[2],
1834 ((u32 *)session->sess_id.data)[3],
1835 slot->seq_nr, args->sa_slotid,
1836 tp->highest_used_slotid, args->sa_cache_this);
1837 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1838 *p++ = cpu_to_be32(slot->seq_nr);
1839 *p++ = cpu_to_be32(args->sa_slotid);
1840 *p++ = cpu_to_be32(tp->highest_used_slotid);
1841 *p = cpu_to_be32(args->sa_cache_this);
1843 hdr->replen += decode_sequence_maxsz;
1844 #endif /* CONFIG_NFS_V4_1 */
1847 #ifdef CONFIG_NFS_V4_1
1849 encode_getdeviceinfo(struct xdr_stream *xdr,
1850 const struct nfs4_getdeviceinfo_args *args,
1851 struct compound_hdr *hdr)
1855 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1856 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1857 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1858 NFS4_DEVICEID4_SIZE);
1859 *p++ = cpu_to_be32(args->pdev->layout_type);
1860 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1861 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1863 hdr->replen += decode_getdeviceinfo_maxsz;
1867 encode_layoutget(struct xdr_stream *xdr,
1868 const struct nfs4_layoutget_args *args,
1869 struct compound_hdr *hdr)
1873 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1874 *p++ = cpu_to_be32(OP_LAYOUTGET);
1875 *p++ = cpu_to_be32(0); /* Signal layout available */
1876 *p++ = cpu_to_be32(args->type);
1877 *p++ = cpu_to_be32(args->range.iomode);
1878 p = xdr_encode_hyper(p, args->range.offset);
1879 p = xdr_encode_hyper(p, args->range.length);
1880 p = xdr_encode_hyper(p, args->minlength);
1881 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1882 *p = cpu_to_be32(args->maxcount);
1884 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1888 (unsigned long)args->range.offset,
1889 (unsigned long)args->range.length,
1892 hdr->replen += decode_layoutget_maxsz;
1896 encode_layoutcommit(struct xdr_stream *xdr,
1897 struct inode *inode,
1898 const struct nfs4_layoutcommit_args *args,
1899 struct compound_hdr *hdr)
1903 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1904 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1906 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1907 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1908 /* Only whole file layouts */
1909 p = xdr_encode_hyper(p, 0); /* offset */
1910 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1911 *p++ = cpu_to_be32(0); /* reclaim */
1912 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1913 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1914 p = xdr_encode_hyper(p, args->lastbytewritten);
1915 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1916 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1918 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1919 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1920 NFS_I(inode)->layout, xdr, args);
1922 p = reserve_space(xdr, 4);
1923 *p = cpu_to_be32(0); /* no layout-type payload */
1927 hdr->replen += decode_layoutcommit_maxsz;
1932 encode_layoutreturn(struct xdr_stream *xdr,
1933 const struct nfs4_layoutreturn_args *args,
1934 struct compound_hdr *hdr)
1938 p = reserve_space(xdr, 20);
1939 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1940 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1941 *p++ = cpu_to_be32(args->layout_type);
1942 *p++ = cpu_to_be32(IOMODE_ANY);
1943 *p = cpu_to_be32(RETURN_FILE);
1944 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1945 p = xdr_encode_hyper(p, 0);
1946 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1947 spin_lock(&args->inode->i_lock);
1948 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1949 spin_unlock(&args->inode->i_lock);
1950 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1951 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1952 NFS_I(args->inode)->layout, xdr, args);
1954 p = reserve_space(xdr, 4);
1955 *p = cpu_to_be32(0);
1958 hdr->replen += decode_layoutreturn_maxsz;
1962 encode_secinfo_no_name(struct xdr_stream *xdr,
1963 const struct nfs41_secinfo_no_name_args *args,
1964 struct compound_hdr *hdr)
1967 p = reserve_space(xdr, 8);
1968 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
1969 *p++ = cpu_to_be32(args->style);
1971 hdr->replen += decode_secinfo_no_name_maxsz;
1975 static void encode_test_stateid(struct xdr_stream *xdr,
1976 struct nfs41_test_stateid_args *args,
1977 struct compound_hdr *hdr)
1981 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
1982 *p++ = cpu_to_be32(OP_TEST_STATEID);
1983 *p++ = cpu_to_be32(1);
1984 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1986 hdr->replen += decode_test_stateid_maxsz;
1988 #endif /* CONFIG_NFS_V4_1 */
1991 * END OF "GENERIC" ENCODE ROUTINES.
1994 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1996 #if defined(CONFIG_NFS_V4_1)
1997 if (args->sa_session)
1998 return args->sa_session->clp->cl_mvops->minor_version;
1999 #endif /* CONFIG_NFS_V4_1 */
2004 * Encode an ACCESS request
2006 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2007 const struct nfs4_accessargs *args)
2009 struct compound_hdr hdr = {
2010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2013 encode_compound_hdr(xdr, req, &hdr);
2014 encode_sequence(xdr, &args->seq_args, &hdr);
2015 encode_putfh(xdr, args->fh, &hdr);
2016 encode_access(xdr, args->access, &hdr);
2017 encode_getfattr(xdr, args->bitmask, &hdr);
2022 * Encode LOOKUP request
2024 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2025 const struct nfs4_lookup_arg *args)
2027 struct compound_hdr hdr = {
2028 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2031 encode_compound_hdr(xdr, req, &hdr);
2032 encode_sequence(xdr, &args->seq_args, &hdr);
2033 encode_putfh(xdr, args->dir_fh, &hdr);
2034 encode_lookup(xdr, args->name, &hdr);
2035 encode_getfh(xdr, &hdr);
2036 encode_getfattr(xdr, args->bitmask, &hdr);
2041 * Encode LOOKUP_ROOT request
2043 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2044 struct xdr_stream *xdr,
2045 const struct nfs4_lookup_root_arg *args)
2047 struct compound_hdr hdr = {
2048 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2051 encode_compound_hdr(xdr, req, &hdr);
2052 encode_sequence(xdr, &args->seq_args, &hdr);
2053 encode_putrootfh(xdr, &hdr);
2054 encode_getfh(xdr, &hdr);
2055 encode_getfattr(xdr, args->bitmask, &hdr);
2060 * Encode REMOVE request
2062 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2063 const struct nfs_removeargs *args)
2065 struct compound_hdr hdr = {
2066 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2069 encode_compound_hdr(xdr, req, &hdr);
2070 encode_sequence(xdr, &args->seq_args, &hdr);
2071 encode_putfh(xdr, args->fh, &hdr);
2072 encode_remove(xdr, &args->name, &hdr);
2073 encode_getfattr(xdr, args->bitmask, &hdr);
2078 * Encode RENAME request
2080 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2081 const struct nfs_renameargs *args)
2083 struct compound_hdr hdr = {
2084 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2087 encode_compound_hdr(xdr, req, &hdr);
2088 encode_sequence(xdr, &args->seq_args, &hdr);
2089 encode_putfh(xdr, args->old_dir, &hdr);
2090 encode_savefh(xdr, &hdr);
2091 encode_putfh(xdr, args->new_dir, &hdr);
2092 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2093 encode_getfattr(xdr, args->bitmask, &hdr);
2094 encode_restorefh(xdr, &hdr);
2095 encode_getfattr(xdr, args->bitmask, &hdr);
2100 * Encode LINK request
2102 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2103 const struct nfs4_link_arg *args)
2105 struct compound_hdr hdr = {
2106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2109 encode_compound_hdr(xdr, req, &hdr);
2110 encode_sequence(xdr, &args->seq_args, &hdr);
2111 encode_putfh(xdr, args->fh, &hdr);
2112 encode_savefh(xdr, &hdr);
2113 encode_putfh(xdr, args->dir_fh, &hdr);
2114 encode_link(xdr, args->name, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
2116 encode_restorefh(xdr, &hdr);
2117 encode_getfattr(xdr, args->bitmask, &hdr);
2122 * Encode CREATE request
2124 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2125 const struct nfs4_create_arg *args)
2127 struct compound_hdr hdr = {
2128 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2131 encode_compound_hdr(xdr, req, &hdr);
2132 encode_sequence(xdr, &args->seq_args, &hdr);
2133 encode_putfh(xdr, args->dir_fh, &hdr);
2134 encode_savefh(xdr, &hdr);
2135 encode_create(xdr, args, &hdr);
2136 encode_getfh(xdr, &hdr);
2137 encode_getfattr(xdr, args->bitmask, &hdr);
2138 encode_restorefh(xdr, &hdr);
2139 encode_getfattr(xdr, args->bitmask, &hdr);
2144 * Encode SYMLINK request
2146 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2147 const struct nfs4_create_arg *args)
2149 nfs4_xdr_enc_create(req, xdr, args);
2153 * Encode GETATTR request
2155 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 const struct nfs4_getattr_arg *args)
2158 struct compound_hdr hdr = {
2159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->fh, &hdr);
2165 encode_getfattr(xdr, args->bitmask, &hdr);
2170 * Encode a CLOSE request
2172 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2173 struct nfs_closeargs *args)
2175 struct compound_hdr hdr = {
2176 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2179 encode_compound_hdr(xdr, req, &hdr);
2180 encode_sequence(xdr, &args->seq_args, &hdr);
2181 encode_putfh(xdr, args->fh, &hdr);
2182 encode_close(xdr, args, &hdr);
2183 encode_getfattr(xdr, args->bitmask, &hdr);
2188 * Encode an OPEN request
2190 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2191 struct nfs_openargs *args)
2193 struct compound_hdr hdr = {
2194 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2197 encode_compound_hdr(xdr, req, &hdr);
2198 encode_sequence(xdr, &args->seq_args, &hdr);
2199 encode_putfh(xdr, args->fh, &hdr);
2200 encode_savefh(xdr, &hdr);
2201 encode_open(xdr, args, &hdr);
2202 encode_getfh(xdr, &hdr);
2203 encode_getfattr(xdr, args->bitmask, &hdr);
2204 encode_restorefh(xdr, &hdr);
2205 encode_getfattr(xdr, args->bitmask, &hdr);
2210 * Encode an OPEN_CONFIRM request
2212 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2213 struct xdr_stream *xdr,
2214 struct nfs_open_confirmargs *args)
2216 struct compound_hdr hdr = {
2220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_putfh(xdr, args->fh, &hdr);
2222 encode_open_confirm(xdr, args, &hdr);
2227 * Encode an OPEN request with no attributes.
2229 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2230 struct xdr_stream *xdr,
2231 struct nfs_openargs *args)
2233 struct compound_hdr hdr = {
2234 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2237 encode_compound_hdr(xdr, req, &hdr);
2238 encode_sequence(xdr, &args->seq_args, &hdr);
2239 encode_putfh(xdr, args->fh, &hdr);
2240 encode_open(xdr, args, &hdr);
2241 encode_getfattr(xdr, args->bitmask, &hdr);
2246 * Encode an OPEN_DOWNGRADE request
2248 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2249 struct xdr_stream *xdr,
2250 struct nfs_closeargs *args)
2252 struct compound_hdr hdr = {
2253 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2256 encode_compound_hdr(xdr, req, &hdr);
2257 encode_sequence(xdr, &args->seq_args, &hdr);
2258 encode_putfh(xdr, args->fh, &hdr);
2259 encode_open_downgrade(xdr, args, &hdr);
2260 encode_getfattr(xdr, args->bitmask, &hdr);
2265 * Encode a LOCK request
2267 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2268 struct nfs_lock_args *args)
2270 struct compound_hdr hdr = {
2271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2274 encode_compound_hdr(xdr, req, &hdr);
2275 encode_sequence(xdr, &args->seq_args, &hdr);
2276 encode_putfh(xdr, args->fh, &hdr);
2277 encode_lock(xdr, args, &hdr);
2282 * Encode a LOCKT request
2284 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2285 struct nfs_lockt_args *args)
2287 struct compound_hdr hdr = {
2288 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2291 encode_compound_hdr(xdr, req, &hdr);
2292 encode_sequence(xdr, &args->seq_args, &hdr);
2293 encode_putfh(xdr, args->fh, &hdr);
2294 encode_lockt(xdr, args, &hdr);
2299 * Encode a LOCKU request
2301 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2302 struct nfs_locku_args *args)
2304 struct compound_hdr hdr = {
2305 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2308 encode_compound_hdr(xdr, req, &hdr);
2309 encode_sequence(xdr, &args->seq_args, &hdr);
2310 encode_putfh(xdr, args->fh, &hdr);
2311 encode_locku(xdr, args, &hdr);
2315 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2316 struct xdr_stream *xdr,
2317 struct nfs_release_lockowner_args *args)
2319 struct compound_hdr hdr = {
2323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2329 * Encode a READLINK request
2331 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2332 const struct nfs4_readlink *args)
2334 struct compound_hdr hdr = {
2335 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2338 encode_compound_hdr(xdr, req, &hdr);
2339 encode_sequence(xdr, &args->seq_args, &hdr);
2340 encode_putfh(xdr, args->fh, &hdr);
2341 encode_readlink(xdr, args, req, &hdr);
2343 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2344 args->pgbase, args->pglen);
2349 * Encode a READDIR request
2351 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2352 const struct nfs4_readdir_arg *args)
2354 struct compound_hdr hdr = {
2355 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2358 encode_compound_hdr(xdr, req, &hdr);
2359 encode_sequence(xdr, &args->seq_args, &hdr);
2360 encode_putfh(xdr, args->fh, &hdr);
2361 encode_readdir(xdr, args, req, &hdr);
2363 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2364 args->pgbase, args->count);
2365 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2366 __func__, hdr.replen << 2, args->pages,
2367 args->pgbase, args->count);
2372 * Encode a READ request
2374 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2375 struct nfs_readargs *args)
2377 struct compound_hdr hdr = {
2378 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2381 encode_compound_hdr(xdr, req, &hdr);
2382 encode_sequence(xdr, &args->seq_args, &hdr);
2383 encode_putfh(xdr, args->fh, &hdr);
2384 encode_read(xdr, args, &hdr);
2386 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2387 args->pages, args->pgbase, args->count);
2388 req->rq_rcv_buf.flags |= XDRBUF_READ;
2393 * Encode an SETATTR request
2395 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2396 struct nfs_setattrargs *args)
2398 struct compound_hdr hdr = {
2399 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2402 encode_compound_hdr(xdr, req, &hdr);
2403 encode_sequence(xdr, &args->seq_args, &hdr);
2404 encode_putfh(xdr, args->fh, &hdr);
2405 encode_setattr(xdr, args, args->server, &hdr);
2406 encode_getfattr(xdr, args->bitmask, &hdr);
2411 * Encode a GETACL request
2413 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2414 struct nfs_getaclargs *args)
2416 struct compound_hdr hdr = {
2417 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_sequence(xdr, &args->seq_args, &hdr);
2423 encode_putfh(xdr, args->fh, &hdr);
2424 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2425 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2427 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2428 args->acl_pages, args->acl_pgbase, args->acl_len);
2433 * Encode a WRITE request
2435 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2436 struct nfs_writeargs *args)
2438 struct compound_hdr hdr = {
2439 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2442 encode_compound_hdr(xdr, req, &hdr);
2443 encode_sequence(xdr, &args->seq_args, &hdr);
2444 encode_putfh(xdr, args->fh, &hdr);
2445 encode_write(xdr, args, &hdr);
2446 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2448 encode_getfattr(xdr, args->bitmask, &hdr);
2455 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2456 struct nfs_writeargs *args)
2458 struct compound_hdr hdr = {
2459 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2462 encode_compound_hdr(xdr, req, &hdr);
2463 encode_sequence(xdr, &args->seq_args, &hdr);
2464 encode_putfh(xdr, args->fh, &hdr);
2465 encode_commit(xdr, args, &hdr);
2467 encode_getfattr(xdr, args->bitmask, &hdr);
2474 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2475 struct nfs4_fsinfo_arg *args)
2477 struct compound_hdr hdr = {
2478 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2481 encode_compound_hdr(xdr, req, &hdr);
2482 encode_sequence(xdr, &args->seq_args, &hdr);
2483 encode_putfh(xdr, args->fh, &hdr);
2484 encode_fsinfo(xdr, args->bitmask, &hdr);
2489 * a PATHCONF request
2491 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2492 const struct nfs4_pathconf_arg *args)
2494 struct compound_hdr hdr = {
2495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2509 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2510 const struct nfs4_statfs_arg *args)
2512 struct compound_hdr hdr = {
2513 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2516 encode_compound_hdr(xdr, req, &hdr);
2517 encode_sequence(xdr, &args->seq_args, &hdr);
2518 encode_putfh(xdr, args->fh, &hdr);
2519 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2520 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2525 * GETATTR_BITMAP request
2527 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2528 struct xdr_stream *xdr,
2529 struct nfs4_server_caps_arg *args)
2531 struct compound_hdr hdr = {
2532 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2535 encode_compound_hdr(xdr, req, &hdr);
2536 encode_sequence(xdr, &args->seq_args, &hdr);
2537 encode_putfh(xdr, args->fhandle, &hdr);
2538 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2539 FATTR4_WORD0_LINK_SUPPORT|
2540 FATTR4_WORD0_SYMLINK_SUPPORT|
2541 FATTR4_WORD0_ACLSUPPORT, &hdr);
2548 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2549 struct nfs_client *clp)
2551 struct compound_hdr hdr = {
2555 encode_compound_hdr(xdr, req, &hdr);
2556 encode_renew(xdr, clp, &hdr);
2561 * a SETCLIENTID request
2563 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2564 struct xdr_stream *xdr,
2565 struct nfs4_setclientid *sc)
2567 struct compound_hdr hdr = {
2571 encode_compound_hdr(xdr, req, &hdr);
2572 encode_setclientid(xdr, sc, &hdr);
2577 * a SETCLIENTID_CONFIRM request
2579 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2580 struct xdr_stream *xdr,
2581 struct nfs4_setclientid_res *arg)
2583 struct compound_hdr hdr = {
2586 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_setclientid_confirm(xdr, arg, &hdr);
2590 encode_putrootfh(xdr, &hdr);
2591 encode_fsinfo(xdr, lease_bitmap, &hdr);
2596 * DELEGRETURN request
2598 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2599 struct xdr_stream *xdr,
2600 const struct nfs4_delegreturnargs *args)
2602 struct compound_hdr hdr = {
2603 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2606 encode_compound_hdr(xdr, req, &hdr);
2607 encode_sequence(xdr, &args->seq_args, &hdr);
2608 encode_putfh(xdr, args->fhandle, &hdr);
2609 encode_delegreturn(xdr, args->stateid, &hdr);
2610 encode_getfattr(xdr, args->bitmask, &hdr);
2615 * Encode FS_LOCATIONS request
2617 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2618 struct xdr_stream *xdr,
2619 struct nfs4_fs_locations_arg *args)
2621 struct compound_hdr hdr = {
2622 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_sequence(xdr, &args->seq_args, &hdr);
2628 encode_putfh(xdr, args->dir_fh, &hdr);
2629 encode_lookup(xdr, args->name, &hdr);
2630 replen = hdr.replen; /* get the attribute into args->page */
2631 encode_fs_locations(xdr, args->bitmask, &hdr);
2633 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2639 * Encode SECINFO request
2641 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2642 struct xdr_stream *xdr,
2643 struct nfs4_secinfo_arg *args)
2645 struct compound_hdr hdr = {
2646 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2649 encode_compound_hdr(xdr, req, &hdr);
2650 encode_sequence(xdr, &args->seq_args, &hdr);
2651 encode_putfh(xdr, args->dir_fh, &hdr);
2652 encode_secinfo(xdr, args->name, &hdr);
2656 #if defined(CONFIG_NFS_V4_1)
2658 * EXCHANGE_ID request
2660 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2661 struct xdr_stream *xdr,
2662 struct nfs41_exchange_id_args *args)
2664 struct compound_hdr hdr = {
2665 .minorversion = args->client->cl_mvops->minor_version,
2668 encode_compound_hdr(xdr, req, &hdr);
2669 encode_exchange_id(xdr, args, &hdr);
2674 * a CREATE_SESSION request
2676 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2677 struct xdr_stream *xdr,
2678 struct nfs41_create_session_args *args)
2680 struct compound_hdr hdr = {
2681 .minorversion = args->client->cl_mvops->minor_version,
2684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_create_session(xdr, args, &hdr);
2690 * a DESTROY_SESSION request
2692 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2693 struct xdr_stream *xdr,
2694 struct nfs4_session *session)
2696 struct compound_hdr hdr = {
2697 .minorversion = session->clp->cl_mvops->minor_version,
2700 encode_compound_hdr(xdr, req, &hdr);
2701 encode_destroy_session(xdr, session, &hdr);
2706 * a SEQUENCE request
2708 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2709 struct nfs4_sequence_args *args)
2711 struct compound_hdr hdr = {
2712 .minorversion = nfs4_xdr_minorversion(args),
2715 encode_compound_hdr(xdr, req, &hdr);
2716 encode_sequence(xdr, args, &hdr);
2721 * a GET_LEASE_TIME request
2723 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2724 struct xdr_stream *xdr,
2725 struct nfs4_get_lease_time_args *args)
2727 struct compound_hdr hdr = {
2728 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2730 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2732 encode_compound_hdr(xdr, req, &hdr);
2733 encode_sequence(xdr, &args->la_seq_args, &hdr);
2734 encode_putrootfh(xdr, &hdr);
2735 encode_fsinfo(xdr, lease_bitmap, &hdr);
2740 * a RECLAIM_COMPLETE request
2742 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2743 struct xdr_stream *xdr,
2744 struct nfs41_reclaim_complete_args *args)
2746 struct compound_hdr hdr = {
2747 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2750 encode_compound_hdr(xdr, req, &hdr);
2751 encode_sequence(xdr, &args->seq_args, &hdr);
2752 encode_reclaim_complete(xdr, args, &hdr);
2757 * Encode GETDEVICEINFO request
2759 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2760 struct xdr_stream *xdr,
2761 struct nfs4_getdeviceinfo_args *args)
2763 struct compound_hdr hdr = {
2764 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2767 encode_compound_hdr(xdr, req, &hdr);
2768 encode_sequence(xdr, &args->seq_args, &hdr);
2769 encode_getdeviceinfo(xdr, args, &hdr);
2771 /* set up reply kvec. Subtract notification bitmap max size (2)
2772 * so that notification bitmap is put in xdr_buf tail */
2773 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2774 args->pdev->pages, args->pdev->pgbase,
2781 * Encode LAYOUTGET request
2783 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2784 struct xdr_stream *xdr,
2785 struct nfs4_layoutget_args *args)
2787 struct compound_hdr hdr = {
2788 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2791 encode_compound_hdr(xdr, req, &hdr);
2792 encode_sequence(xdr, &args->seq_args, &hdr);
2793 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2794 encode_layoutget(xdr, args, &hdr);
2796 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2797 args->layout.pages, 0, args->layout.pglen);
2803 * Encode LAYOUTCOMMIT request
2805 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2806 struct xdr_stream *xdr,
2807 struct nfs4_layoutcommit_args *args)
2809 struct nfs4_layoutcommit_data *data =
2810 container_of(args, struct nfs4_layoutcommit_data, args);
2811 struct compound_hdr hdr = {
2812 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2815 encode_compound_hdr(xdr, req, &hdr);
2816 encode_sequence(xdr, &args->seq_args, &hdr);
2817 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2818 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2819 encode_getfattr(xdr, args->bitmask, &hdr);
2824 * Encode LAYOUTRETURN request
2826 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2827 struct xdr_stream *xdr,
2828 struct nfs4_layoutreturn_args *args)
2830 struct compound_hdr hdr = {
2831 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2834 encode_compound_hdr(xdr, req, &hdr);
2835 encode_sequence(xdr, &args->seq_args, &hdr);
2836 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2837 encode_layoutreturn(xdr, args, &hdr);
2842 * Encode SECINFO_NO_NAME request
2844 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2845 struct xdr_stream *xdr,
2846 struct nfs41_secinfo_no_name_args *args)
2848 struct compound_hdr hdr = {
2849 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2852 encode_compound_hdr(xdr, req, &hdr);
2853 encode_sequence(xdr, &args->seq_args, &hdr);
2854 encode_putrootfh(xdr, &hdr);
2855 encode_secinfo_no_name(xdr, args, &hdr);
2861 * Encode TEST_STATEID request
2863 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2864 struct xdr_stream *xdr,
2865 struct nfs41_test_stateid_args *args)
2867 struct compound_hdr hdr = {
2868 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2871 encode_compound_hdr(xdr, req, &hdr);
2872 encode_sequence(xdr, &args->seq_args, &hdr);
2873 encode_test_stateid(xdr, args, &hdr);
2876 #endif /* CONFIG_NFS_V4_1 */
2878 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2880 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2881 "Remaining buffer length is %tu words.\n",
2882 func, xdr->end - xdr->p);
2885 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2889 p = xdr_inline_decode(xdr, 4);
2892 *len = be32_to_cpup(p);
2893 p = xdr_inline_decode(xdr, *len);
2896 *string = (char *)p;
2899 print_overflow_msg(__func__, xdr);
2903 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2907 p = xdr_inline_decode(xdr, 8);
2910 hdr->status = be32_to_cpup(p++);
2911 hdr->taglen = be32_to_cpup(p);
2913 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2916 hdr->tag = (char *)p;
2917 p += XDR_QUADLEN(hdr->taglen);
2918 hdr->nops = be32_to_cpup(p);
2919 if (unlikely(hdr->nops < 1))
2920 return nfs4_stat_to_errno(hdr->status);
2923 print_overflow_msg(__func__, xdr);
2927 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2933 p = xdr_inline_decode(xdr, 8);
2936 opnum = be32_to_cpup(p++);
2937 if (opnum != expected) {
2938 dprintk("nfs: Server returned operation"
2939 " %d but we issued a request for %d\n",
2943 nfserr = be32_to_cpup(p);
2944 if (nfserr != NFS_OK)
2945 return nfs4_stat_to_errno(nfserr);
2948 print_overflow_msg(__func__, xdr);
2953 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2956 unsigned int strlen;
2959 p = xdr_inline_decode(xdr, 12);
2961 return decode_opaque_inline(xdr, &strlen, &str);
2962 print_overflow_msg(__func__, xdr);
2966 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2971 p = xdr_inline_decode(xdr, 4);
2974 bmlen = be32_to_cpup(p);
2976 bitmap[0] = bitmap[1] = 0;
2977 p = xdr_inline_decode(xdr, (bmlen << 2));
2981 bitmap[0] = be32_to_cpup(p++);
2983 bitmap[1] = be32_to_cpup(p);
2987 print_overflow_msg(__func__, xdr);
2991 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2995 p = xdr_inline_decode(xdr, 4);
2998 *attrlen = be32_to_cpup(p);
3002 print_overflow_msg(__func__, xdr);
3006 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3008 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3010 ret = decode_attr_bitmap(xdr, bitmask);
3011 if (unlikely(ret < 0))
3013 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3015 bitmask[0] = bitmask[1] = 0;
3016 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
3020 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3026 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3028 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3029 p = xdr_inline_decode(xdr, 4);
3032 *type = be32_to_cpup(p);
3033 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3034 dprintk("%s: bad type %d\n", __func__, *type);
3037 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3038 ret = NFS_ATTR_FATTR_TYPE;
3040 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3043 print_overflow_msg(__func__, xdr);
3047 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3053 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3055 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3056 p = xdr_inline_decode(xdr, 8);
3059 xdr_decode_hyper(p, change);
3060 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3061 ret = NFS_ATTR_FATTR_CHANGE;
3063 dprintk("%s: change attribute=%Lu\n", __func__,
3064 (unsigned long long)*change);
3067 print_overflow_msg(__func__, xdr);
3071 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3077 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3079 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3080 p = xdr_inline_decode(xdr, 8);
3083 xdr_decode_hyper(p, size);
3084 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3085 ret = NFS_ATTR_FATTR_SIZE;
3087 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3090 print_overflow_msg(__func__, xdr);
3094 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3099 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3101 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3102 p = xdr_inline_decode(xdr, 4);
3105 *res = be32_to_cpup(p);
3106 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3108 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3111 print_overflow_msg(__func__, xdr);
3115 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3120 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3122 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3123 p = xdr_inline_decode(xdr, 4);
3126 *res = be32_to_cpup(p);
3127 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3129 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3132 print_overflow_msg(__func__, xdr);
3136 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3143 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3145 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3146 p = xdr_inline_decode(xdr, 16);
3149 p = xdr_decode_hyper(p, &fsid->major);
3150 xdr_decode_hyper(p, &fsid->minor);
3151 bitmap[0] &= ~FATTR4_WORD0_FSID;
3152 ret = NFS_ATTR_FATTR_FSID;
3154 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3155 (unsigned long long)fsid->major,
3156 (unsigned long long)fsid->minor);
3159 print_overflow_msg(__func__, xdr);
3163 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3168 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3170 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3171 p = xdr_inline_decode(xdr, 4);
3174 *res = be32_to_cpup(p);
3175 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3177 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3180 print_overflow_msg(__func__, xdr);
3184 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3188 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3190 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3191 p = xdr_inline_decode(xdr, 4);
3194 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3195 *res = -be32_to_cpup(p);
3199 print_overflow_msg(__func__, xdr);
3203 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3209 memset(fh, 0, sizeof(*fh));
3211 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3213 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3214 p = xdr_inline_decode(xdr, 4);
3217 len = be32_to_cpup(p);
3218 if (len > NFS4_FHSIZE)
3220 p = xdr_inline_decode(xdr, len);
3224 memcpy(fh->data, p, len);
3227 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3231 print_overflow_msg(__func__, xdr);
3235 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3239 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3240 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3242 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3243 p = xdr_inline_decode(xdr, 4);
3246 *res = be32_to_cpup(p);
3247 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3249 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3252 print_overflow_msg(__func__, xdr);
3256 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3262 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3264 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3265 p = xdr_inline_decode(xdr, 8);
3268 xdr_decode_hyper(p, fileid);
3269 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3270 ret = NFS_ATTR_FATTR_FILEID;
3272 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3275 print_overflow_msg(__func__, xdr);
3279 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3285 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3287 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3288 p = xdr_inline_decode(xdr, 8);
3291 xdr_decode_hyper(p, fileid);
3292 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3293 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3295 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3298 print_overflow_msg(__func__, xdr);
3302 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3308 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3310 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3311 p = xdr_inline_decode(xdr, 8);
3314 xdr_decode_hyper(p, res);
3315 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3317 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3320 print_overflow_msg(__func__, xdr);
3324 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3330 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3332 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3333 p = xdr_inline_decode(xdr, 8);
3336 xdr_decode_hyper(p, res);
3337 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3339 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3342 print_overflow_msg(__func__, xdr);
3346 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3352 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3354 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3355 p = xdr_inline_decode(xdr, 8);
3358 xdr_decode_hyper(p, res);
3359 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3361 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3364 print_overflow_msg(__func__, xdr);
3368 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3374 p = xdr_inline_decode(xdr, 4);
3377 n = be32_to_cpup(p);
3381 path->ncomponents = 0;
3382 while (path->ncomponents < n) {
3383 struct nfs4_string *component = &path->components[path->ncomponents];
3384 status = decode_opaque_inline(xdr, &component->len, &component->data);
3385 if (unlikely(status != 0))
3387 if (path->ncomponents != n)
3389 dprintk("%s", component->data);
3390 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3391 path->ncomponents++;
3393 dprintk("cannot parse %d components in path\n", n);
3401 /* a root pathname is sent as a zero component4 */
3402 path->ncomponents = 1;
3403 path->components[0].len=0;
3404 path->components[0].data=NULL;
3405 dprintk("path /\n");
3408 dprintk(" status %d", status);
3412 print_overflow_msg(__func__, xdr);
3416 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3422 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3425 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3427 dprintk("%s: fsroot ", __func__);
3428 status = decode_pathname(xdr, &res->fs_path);
3429 if (unlikely(status != 0))
3431 p = xdr_inline_decode(xdr, 4);
3434 n = be32_to_cpup(p);
3437 res->nlocations = 0;
3438 while (res->nlocations < n) {
3440 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3442 p = xdr_inline_decode(xdr, 4);
3445 m = be32_to_cpup(p);
3448 dprintk("%s: servers ", __func__);
3449 while (loc->nservers < m) {
3450 struct nfs4_string *server = &loc->servers[loc->nservers];
3451 status = decode_opaque_inline(xdr, &server->len, &server->data);
3452 if (unlikely(status != 0))
3454 dprintk("%s ", server->data);
3455 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3459 dprintk("%s: using first %u of %u servers "
3460 "returned for location %u\n",
3462 NFS4_FS_LOCATION_MAXSERVERS,
3463 m, res->nlocations);
3464 for (i = loc->nservers; i < m; i++) {
3467 status = decode_opaque_inline(xdr, &len, &data);
3468 if (unlikely(status != 0))
3473 status = decode_pathname(xdr, &loc->rootpath);
3474 if (unlikely(status != 0))
3476 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3479 if (res->nlocations != 0)
3480 status = NFS_ATTR_FATTR_V4_REFERRAL;
3482 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3485 print_overflow_msg(__func__, xdr);
3491 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3497 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3499 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3500 p = xdr_inline_decode(xdr, 8);
3503 xdr_decode_hyper(p, res);
3504 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3506 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3509 print_overflow_msg(__func__, xdr);
3513 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3519 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3521 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3522 p = xdr_inline_decode(xdr, 4);
3525 *maxlink = be32_to_cpup(p);
3526 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3528 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3531 print_overflow_msg(__func__, xdr);
3535 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3541 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3543 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3544 p = xdr_inline_decode(xdr, 4);
3547 *maxname = be32_to_cpup(p);
3548 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3550 dprintk("%s: maxname=%u\n", __func__, *maxname);
3553 print_overflow_msg(__func__, xdr);
3557 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3563 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3565 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3567 p = xdr_inline_decode(xdr, 8);
3570 xdr_decode_hyper(p, &maxread);
3571 if (maxread > 0x7FFFFFFF)
3572 maxread = 0x7FFFFFFF;
3573 *res = (uint32_t)maxread;
3574 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3576 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3579 print_overflow_msg(__func__, xdr);
3583 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3589 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3591 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3593 p = xdr_inline_decode(xdr, 8);
3596 xdr_decode_hyper(p, &maxwrite);
3597 if (maxwrite > 0x7FFFFFFF)
3598 maxwrite = 0x7FFFFFFF;
3599 *res = (uint32_t)maxwrite;
3600 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3602 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3605 print_overflow_msg(__func__, xdr);
3609 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3616 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3618 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3619 p = xdr_inline_decode(xdr, 4);
3622 tmp = be32_to_cpup(p);
3623 *mode = tmp & ~S_IFMT;
3624 bitmap[1] &= ~FATTR4_WORD1_MODE;
3625 ret = NFS_ATTR_FATTR_MODE;
3627 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3630 print_overflow_msg(__func__, xdr);
3634 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3640 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3642 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3643 p = xdr_inline_decode(xdr, 4);
3646 *nlink = be32_to_cpup(p);
3647 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3648 ret = NFS_ATTR_FATTR_NLINK;
3650 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3653 print_overflow_msg(__func__, xdr);
3657 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3658 const struct nfs_server *server, uint32_t *uid, int may_sleep)
3665 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3667 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3668 p = xdr_inline_decode(xdr, 4);
3671 len = be32_to_cpup(p);
3672 p = xdr_inline_decode(xdr, len);
3677 } else if (len < XDR_MAX_NETOBJ) {
3678 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3679 ret = NFS_ATTR_FATTR_OWNER;
3681 dprintk("%s: nfs_map_name_to_uid failed!\n",
3684 dprintk("%s: name too long (%u)!\n",
3686 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3688 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3691 print_overflow_msg(__func__, xdr);
3695 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3696 const struct nfs_server *server, uint32_t *gid, int may_sleep)
3703 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3705 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3706 p = xdr_inline_decode(xdr, 4);
3709 len = be32_to_cpup(p);
3710 p = xdr_inline_decode(xdr, len);
3715 } else if (len < XDR_MAX_NETOBJ) {
3716 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3717 ret = NFS_ATTR_FATTR_GROUP;
3719 dprintk("%s: nfs_map_group_to_gid failed!\n",
3722 dprintk("%s: name too long (%u)!\n",
3724 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3726 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3729 print_overflow_msg(__func__, xdr);
3733 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3735 uint32_t major = 0, minor = 0;
3740 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3742 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3745 p = xdr_inline_decode(xdr, 8);
3748 major = be32_to_cpup(p++);
3749 minor = be32_to_cpup(p);
3750 tmp = MKDEV(major, minor);
3751 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3753 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3754 ret = NFS_ATTR_FATTR_RDEV;
3756 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3759 print_overflow_msg(__func__, xdr);
3763 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3769 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3771 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3772 p = xdr_inline_decode(xdr, 8);
3775 xdr_decode_hyper(p, res);
3776 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3778 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3781 print_overflow_msg(__func__, xdr);
3785 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3791 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3793 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3794 p = xdr_inline_decode(xdr, 8);
3797 xdr_decode_hyper(p, res);
3798 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3800 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3803 print_overflow_msg(__func__, xdr);
3807 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3813 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3815 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3816 p = xdr_inline_decode(xdr, 8);
3819 xdr_decode_hyper(p, res);
3820 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3822 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3825 print_overflow_msg(__func__, xdr);
3829 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3835 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3837 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3838 p = xdr_inline_decode(xdr, 8);
3841 xdr_decode_hyper(p, used);
3842 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3843 ret = NFS_ATTR_FATTR_SPACE_USED;
3845 dprintk("%s: space used=%Lu\n", __func__,
3846 (unsigned long long)*used);
3849 print_overflow_msg(__func__, xdr);
3853 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3859 p = xdr_inline_decode(xdr, 12);
3862 p = xdr_decode_hyper(p, &sec);
3863 nsec = be32_to_cpup(p);
3864 time->tv_sec = (time_t)sec;
3865 time->tv_nsec = (long)nsec;
3868 print_overflow_msg(__func__, xdr);
3872 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3878 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3880 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3881 status = decode_attr_time(xdr, time);
3883 status = NFS_ATTR_FATTR_ATIME;
3884 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3886 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3890 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3896 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3898 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3899 status = decode_attr_time(xdr, time);
3901 status = NFS_ATTR_FATTR_CTIME;
3902 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3904 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3908 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3909 struct timespec *time)
3915 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3917 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3918 status = decode_attr_time(xdr, time);
3919 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3921 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3922 (long)time->tv_nsec);
3926 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3932 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3934 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3935 status = decode_attr_time(xdr, time);
3937 status = NFS_ATTR_FATTR_MTIME;
3938 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3940 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3944 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3946 unsigned int attrwords = XDR_QUADLEN(attrlen);
3947 unsigned int nwords = xdr->p - savep;
3949 if (unlikely(attrwords != nwords)) {
3950 dprintk("%s: server returned incorrect attribute length: "
3954 (attrwords < nwords) ? '<' : '>',
3961 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3965 p = xdr_inline_decode(xdr, 20);
3968 cinfo->atomic = be32_to_cpup(p++);
3969 p = xdr_decode_hyper(p, &cinfo->before);
3970 xdr_decode_hyper(p, &cinfo->after);
3973 print_overflow_msg(__func__, xdr);
3977 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3983 status = decode_op_hdr(xdr, OP_ACCESS);
3986 p = xdr_inline_decode(xdr, 8);
3989 supp = be32_to_cpup(p++);
3990 acc = be32_to_cpup(p);
3991 access->supported = supp;
3992 access->access = acc;
3995 print_overflow_msg(__func__, xdr);
3999 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4003 p = xdr_inline_decode(xdr, len);
4005 memcpy(buf, p, len);
4008 print_overflow_msg(__func__, xdr);
4012 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4014 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
4017 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4021 status = decode_op_hdr(xdr, OP_CLOSE);
4023 nfs_increment_open_seqid(status, res->seqid);
4025 status = decode_stateid(xdr, &res->stateid);
4029 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4031 return decode_opaque_fixed(xdr, verifier, 8);
4034 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4038 status = decode_op_hdr(xdr, OP_COMMIT);
4040 status = decode_verifier(xdr, res->verf->verifier);
4044 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4050 status = decode_op_hdr(xdr, OP_CREATE);
4053 if ((status = decode_change_info(xdr, cinfo)))
4055 p = xdr_inline_decode(xdr, 4);
4058 bmlen = be32_to_cpup(p);
4059 p = xdr_inline_decode(xdr, bmlen << 2);
4063 print_overflow_msg(__func__, xdr);
4067 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4070 uint32_t attrlen, bitmap[2] = {0};
4073 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4075 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4077 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4079 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4081 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4083 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4085 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4087 status = verify_attr_len(xdr, savep, attrlen);
4089 dprintk("%s: xdr returned %d!\n", __func__, -status);
4093 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4096 uint32_t attrlen, bitmap[2] = {0};
4099 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4101 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4103 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4106 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4108 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4110 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4112 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4114 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4116 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4119 status = verify_attr_len(xdr, savep, attrlen);
4121 dprintk("%s: xdr returned %d!\n", __func__, -status);
4125 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4128 uint32_t attrlen, bitmap[2] = {0};
4131 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4133 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4135 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4138 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4140 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4143 status = verify_attr_len(xdr, savep, attrlen);
4145 dprintk("%s: xdr returned %d!\n", __func__, -status);
4149 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4150 struct nfs_fattr *fattr, struct nfs_fh *fh,
4151 const struct nfs_server *server, int may_sleep)
4158 status = decode_attr_type(xdr, bitmap, &type);
4163 fattr->mode |= nfs_type2fmt[type];
4164 fattr->valid |= status;
4167 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4170 fattr->valid |= status;
4172 status = decode_attr_size(xdr, bitmap, &fattr->size);
4175 fattr->valid |= status;
4177 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4180 fattr->valid |= status;
4183 status = decode_attr_error(xdr, bitmap, &err);
4186 if (err == -NFS4ERR_WRONGSEC)
4187 nfs_fixup_secinfo_attributes(fattr, fh);
4189 status = decode_attr_filehandle(xdr, bitmap, fh);
4193 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4196 fattr->valid |= status;
4198 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
4199 struct nfs4_fs_locations,
4203 fattr->valid |= status;
4205 status = decode_attr_mode(xdr, bitmap, &fmode);
4209 fattr->mode |= fmode;
4210 fattr->valid |= status;
4213 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4216 fattr->valid |= status;
4218 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
4221 fattr->valid |= status;
4223 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
4226 fattr->valid |= status;
4228 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4231 fattr->valid |= status;
4233 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4236 fattr->valid |= status;
4238 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4241 fattr->valid |= status;
4243 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4246 fattr->valid |= status;
4248 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4251 fattr->valid |= status;
4253 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4256 fattr->valid |= status;
4259 dprintk("%s: xdr returned %d\n", __func__, -status);
4263 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4264 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4271 status = decode_op_hdr(xdr, OP_GETATTR);
4275 status = decode_attr_bitmap(xdr, bitmap);
4279 status = decode_attr_length(xdr, &attrlen, &savep);
4283 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4287 status = verify_attr_len(xdr, savep, attrlen);
4289 dprintk("%s: xdr returned %d\n", __func__, -status);
4293 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4294 const struct nfs_server *server, int may_sleep)
4296 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4300 * Decode potentially multiple layout types. Currently we only support
4301 * one layout driver per file system.
4303 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4304 uint32_t *layouttype)
4309 p = xdr_inline_decode(xdr, 4);
4312 num = be32_to_cpup(p);
4314 /* pNFS is not supported by the underlying file system */
4320 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4321 "per filesystem not supported\n", __func__);
4323 /* Decode and set first layout type, move xdr->p past unused types */
4324 p = xdr_inline_decode(xdr, num * 4);
4327 *layouttype = be32_to_cpup(p);
4330 print_overflow_msg(__func__, xdr);
4335 * The type of file system exported.
4336 * Note we must ensure that layouttype is set in any non-error case.
4338 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4339 uint32_t *layouttype)
4343 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4344 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4346 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4347 status = decode_first_pnfs_layout_type(xdr, layouttype);
4348 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4354 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4357 uint32_t attrlen, bitmap[2];
4360 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4362 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4364 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4367 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4369 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4371 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4373 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4375 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4376 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4378 fsinfo->wtpref = fsinfo->wtmax;
4379 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4382 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4386 status = verify_attr_len(xdr, savep, attrlen);
4388 dprintk("%s: xdr returned %d!\n", __func__, -status);
4392 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4398 /* Zero handle first to allow comparisons */
4399 memset(fh, 0, sizeof(*fh));
4401 status = decode_op_hdr(xdr, OP_GETFH);
4405 p = xdr_inline_decode(xdr, 4);
4408 len = be32_to_cpup(p);
4409 if (len > NFS4_FHSIZE)
4412 p = xdr_inline_decode(xdr, len);
4415 memcpy(fh->data, p, len);
4418 print_overflow_msg(__func__, xdr);
4422 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4426 status = decode_op_hdr(xdr, OP_LINK);
4429 return decode_change_info(xdr, cinfo);
4433 * We create the owner, so we know a proper owner.id length is 4.
4435 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4437 uint64_t offset, length, clientid;
4439 uint32_t namelen, type;
4441 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4444 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4445 p = xdr_decode_hyper(p, &length);
4446 type = be32_to_cpup(p++); /* 4 byte read */
4447 if (fl != NULL) { /* manipulate file lock */
4448 fl->fl_start = (loff_t)offset;
4449 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4450 if (length == ~(uint64_t)0)
4451 fl->fl_end = OFFSET_MAX;
4452 fl->fl_type = F_WRLCK;
4454 fl->fl_type = F_RDLCK;
4457 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4458 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4459 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4461 return -NFS4ERR_DENIED;
4463 print_overflow_msg(__func__, xdr);
4467 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4471 status = decode_op_hdr(xdr, OP_LOCK);
4475 status = decode_stateid(xdr, &res->stateid);
4476 if (unlikely(status))
4478 } else if (status == -NFS4ERR_DENIED)
4479 status = decode_lock_denied(xdr, NULL);
4480 if (res->open_seqid != NULL)
4481 nfs_increment_open_seqid(status, res->open_seqid);
4482 nfs_increment_lock_seqid(status, res->lock_seqid);
4487 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4490 status = decode_op_hdr(xdr, OP_LOCKT);
4491 if (status == -NFS4ERR_DENIED)
4492 return decode_lock_denied(xdr, res->denied);
4496 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4500 status = decode_op_hdr(xdr, OP_LOCKU);
4502 nfs_increment_lock_seqid(status, res->seqid);
4504 status = decode_stateid(xdr, &res->stateid);
4508 static int decode_release_lockowner(struct xdr_stream *xdr)
4510 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4513 static int decode_lookup(struct xdr_stream *xdr)
4515 return decode_op_hdr(xdr, OP_LOOKUP);
4518 /* This is too sick! */
4519 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4522 uint32_t limit_type, nblocks, blocksize;
4524 p = xdr_inline_decode(xdr, 12);
4527 limit_type = be32_to_cpup(p++);
4528 switch (limit_type) {
4530 xdr_decode_hyper(p, maxsize);
4533 nblocks = be32_to_cpup(p++);
4534 blocksize = be32_to_cpup(p);
4535 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4539 print_overflow_msg(__func__, xdr);
4543 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4546 uint32_t delegation_type;
4549 p = xdr_inline_decode(xdr, 4);
4552 delegation_type = be32_to_cpup(p);
4553 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4554 res->delegation_type = 0;
4557 status = decode_stateid(xdr, &res->delegation);
4558 if (unlikely(status))
4560 p = xdr_inline_decode(xdr, 4);
4563 res->do_recall = be32_to_cpup(p);
4565 switch (delegation_type) {
4566 case NFS4_OPEN_DELEGATE_READ:
4567 res->delegation_type = FMODE_READ;
4569 case NFS4_OPEN_DELEGATE_WRITE:
4570 res->delegation_type = FMODE_WRITE|FMODE_READ;
4571 if (decode_space_limit(xdr, &res->maxsize) < 0)
4574 return decode_ace(xdr, NULL, res->server->nfs_client);
4576 print_overflow_msg(__func__, xdr);
4580 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4583 uint32_t savewords, bmlen, i;
4586 status = decode_op_hdr(xdr, OP_OPEN);
4588 nfs_increment_open_seqid(status, res->seqid);
4590 status = decode_stateid(xdr, &res->stateid);
4591 if (unlikely(status))
4594 decode_change_info(xdr, &res->cinfo);
4596 p = xdr_inline_decode(xdr, 8);
4599 res->rflags = be32_to_cpup(p++);
4600 bmlen = be32_to_cpup(p);
4604 p = xdr_inline_decode(xdr, bmlen << 2);
4607 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4608 for (i = 0; i < savewords; ++i)
4609 res->attrset[i] = be32_to_cpup(p++);
4610 for (; i < NFS4_BITMAP_SIZE; i++)
4611 res->attrset[i] = 0;
4613 return decode_delegation(xdr, res);
4615 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4618 print_overflow_msg(__func__, xdr);
4622 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4626 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4628 nfs_increment_open_seqid(status, res->seqid);
4630 status = decode_stateid(xdr, &res->stateid);
4634 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4638 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4640 nfs_increment_open_seqid(status, res->seqid);
4642 status = decode_stateid(xdr, &res->stateid);
4646 static int decode_putfh(struct xdr_stream *xdr)
4648 return decode_op_hdr(xdr, OP_PUTFH);
4651 static int decode_putrootfh(struct xdr_stream *xdr)
4653 return decode_op_hdr(xdr, OP_PUTROOTFH);
4656 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4658 struct kvec *iov = req->rq_rcv_buf.head;
4660 uint32_t count, eof, recvd, hdrlen;
4663 status = decode_op_hdr(xdr, OP_READ);
4666 p = xdr_inline_decode(xdr, 8);
4669 eof = be32_to_cpup(p++);
4670 count = be32_to_cpup(p);
4671 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4672 recvd = req->rq_rcv_buf.len - hdrlen;
4673 if (count > recvd) {
4674 dprintk("NFS: server cheating in read reply: "
4675 "count %u > recvd %u\n", count, recvd);
4679 xdr_read_pages(xdr, count);
4684 print_overflow_msg(__func__, xdr);
4688 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4690 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4691 struct kvec *iov = rcvbuf->head;
4693 u32 recvd, pglen = rcvbuf->page_len;
4696 status = decode_op_hdr(xdr, OP_READDIR);
4698 status = decode_verifier(xdr, readdir->verifier.data);
4699 if (unlikely(status))
4701 dprintk("%s: verifier = %08x:%08x\n",
4703 ((u32 *)readdir->verifier.data)[0],
4704 ((u32 *)readdir->verifier.data)[1]);
4707 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4708 recvd = rcvbuf->len - hdrlen;
4711 xdr_read_pages(xdr, pglen);
4717 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4719 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4720 struct kvec *iov = rcvbuf->head;
4726 status = decode_op_hdr(xdr, OP_READLINK);
4730 /* Convert length of symlink */
4731 p = xdr_inline_decode(xdr, 4);
4734 len = be32_to_cpup(p);
4735 if (len >= rcvbuf->page_len || len <= 0) {
4736 dprintk("nfs: server returned giant symlink!\n");
4737 return -ENAMETOOLONG;
4739 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4740 recvd = req->rq_rcv_buf.len - hdrlen;
4742 dprintk("NFS: server cheating in readlink reply: "
4743 "count %u > recvd %u\n", len, recvd);
4746 xdr_read_pages(xdr, len);
4748 * The XDR encode routine has set things up so that
4749 * the link text will be copied directly into the
4750 * buffer. We just have to do overflow-checking,
4751 * and and null-terminate the text (the VFS expects
4752 * null-termination).
4754 xdr_terminate_string(rcvbuf, len);
4757 print_overflow_msg(__func__, xdr);
4761 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4765 status = decode_op_hdr(xdr, OP_REMOVE);
4768 status = decode_change_info(xdr, cinfo);
4773 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4774 struct nfs4_change_info *new_cinfo)
4778 status = decode_op_hdr(xdr, OP_RENAME);
4781 if ((status = decode_change_info(xdr, old_cinfo)))
4783 status = decode_change_info(xdr, new_cinfo);
4788 static int decode_renew(struct xdr_stream *xdr)
4790 return decode_op_hdr(xdr, OP_RENEW);
4794 decode_restorefh(struct xdr_stream *xdr)
4796 return decode_op_hdr(xdr, OP_RESTOREFH);
4799 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4805 struct kvec *iov = req->rq_rcv_buf.head;
4809 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4811 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4813 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4816 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4818 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4822 /* We ignore &savep and don't do consistency checks on
4823 * the attr length. Let userspace figure it out.... */
4824 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4825 recvd = req->rq_rcv_buf.len - hdrlen;
4826 if (attrlen > recvd) {
4827 dprintk("NFS: server cheating in getattr"
4828 " acl reply: attrlen %u > recvd %u\n",
4832 xdr_read_pages(xdr, attrlen);
4835 status = -EOPNOTSUPP;
4842 decode_savefh(struct xdr_stream *xdr)
4844 return decode_op_hdr(xdr, OP_SAVEFH);
4847 static int decode_setattr(struct xdr_stream *xdr)
4853 status = decode_op_hdr(xdr, OP_SETATTR);
4856 p = xdr_inline_decode(xdr, 4);
4859 bmlen = be32_to_cpup(p);
4860 p = xdr_inline_decode(xdr, bmlen << 2);
4864 print_overflow_msg(__func__, xdr);
4868 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
4874 p = xdr_inline_decode(xdr, 8);
4877 opnum = be32_to_cpup(p++);
4878 if (opnum != OP_SETCLIENTID) {
4879 dprintk("nfs: decode_setclientid: Server returned operation"
4883 nfserr = be32_to_cpup(p);
4884 if (nfserr == NFS_OK) {
4885 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4888 p = xdr_decode_hyper(p, &res->clientid);
4889 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
4890 } else if (nfserr == NFSERR_CLID_INUSE) {
4893 /* skip netid string */
4894 p = xdr_inline_decode(xdr, 4);
4897 len = be32_to_cpup(p);
4898 p = xdr_inline_decode(xdr, len);
4902 /* skip uaddr string */
4903 p = xdr_inline_decode(xdr, 4);
4906 len = be32_to_cpup(p);
4907 p = xdr_inline_decode(xdr, len);
4910 return -NFSERR_CLID_INUSE;
4912 return nfs4_stat_to_errno(nfserr);
4916 print_overflow_msg(__func__, xdr);
4920 static int decode_setclientid_confirm(struct xdr_stream *xdr)
4922 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4925 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4930 status = decode_op_hdr(xdr, OP_WRITE);
4934 p = xdr_inline_decode(xdr, 16);
4937 res->count = be32_to_cpup(p++);
4938 res->verf->committed = be32_to_cpup(p++);
4939 memcpy(res->verf->verifier, p, 8);
4942 print_overflow_msg(__func__, xdr);
4946 static int decode_delegreturn(struct xdr_stream *xdr)
4948 return decode_op_hdr(xdr, OP_DELEGRETURN);
4951 static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4955 p = xdr_inline_decode(xdr, 4);
4958 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4959 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4962 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4965 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4967 p = xdr_inline_decode(xdr, 8);
4970 flavor->gss.qop4 = be32_to_cpup(p++);
4971 flavor->gss.service = be32_to_cpup(p);
4976 print_overflow_msg(__func__, xdr);
4982 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4984 struct nfs4_secinfo_flavor *sec_flavor;
4989 status = decode_op_hdr(xdr, OP_SECINFO);
4992 p = xdr_inline_decode(xdr, 4);
4996 res->flavors->num_flavors = 0;
4997 num_flavors = be32_to_cpup(p);
4999 for (i = 0; i < num_flavors; i++) {
5000 sec_flavor = &res->flavors->flavors[i];
5001 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5004 p = xdr_inline_decode(xdr, 4);
5007 sec_flavor->flavor = be32_to_cpup(p);
5009 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5010 status = decode_secinfo_gss(xdr, sec_flavor);
5014 res->flavors->num_flavors++;
5020 print_overflow_msg(__func__, xdr);
5024 #if defined(CONFIG_NFS_V4_1)
5025 static int decode_exchange_id(struct xdr_stream *xdr,
5026 struct nfs41_exchange_id_res *res)
5032 struct nfs_client *clp = res->client;
5034 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5038 p = xdr_inline_decode(xdr, 8);
5041 xdr_decode_hyper(p, &clp->cl_clientid);
5042 p = xdr_inline_decode(xdr, 12);
5045 clp->cl_seqid = be32_to_cpup(p++);
5046 clp->cl_exchange_flags = be32_to_cpup(p++);
5048 /* We ask for SP4_NONE */
5049 dummy = be32_to_cpup(p);
5050 if (dummy != SP4_NONE)
5053 /* Throw away minor_id */
5054 p = xdr_inline_decode(xdr, 8);
5058 /* Throw away Major id */
5059 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5060 if (unlikely(status))
5063 /* Save server_scope */
5064 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5065 if (unlikely(status))
5068 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5071 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5072 res->server_scope->server_scope_sz = dummy;
5074 /* Throw away Implementation id array */
5075 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5076 if (unlikely(status))
5081 print_overflow_msg(__func__, xdr);
5085 static int decode_chan_attrs(struct xdr_stream *xdr,
5086 struct nfs4_channel_attrs *attrs)
5091 p = xdr_inline_decode(xdr, 28);
5094 val = be32_to_cpup(p++); /* headerpadsz */
5096 return -EINVAL; /* no support for header padding yet */
5097 attrs->max_rqst_sz = be32_to_cpup(p++);
5098 attrs->max_resp_sz = be32_to_cpup(p++);
5099 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5100 attrs->max_ops = be32_to_cpup(p++);
5101 attrs->max_reqs = be32_to_cpup(p++);
5102 nr_attrs = be32_to_cpup(p);
5103 if (unlikely(nr_attrs > 1)) {
5104 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5105 __func__, nr_attrs);
5108 if (nr_attrs == 1) {
5109 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5115 print_overflow_msg(__func__, xdr);
5119 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5121 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5124 static int decode_create_session(struct xdr_stream *xdr,
5125 struct nfs41_create_session_res *res)
5129 struct nfs_client *clp = res->client;
5130 struct nfs4_session *session = clp->cl_session;
5132 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5134 status = decode_sessionid(xdr, &session->sess_id);
5135 if (unlikely(status))
5139 p = xdr_inline_decode(xdr, 8);
5142 clp->cl_seqid = be32_to_cpup(p++);
5143 session->flags = be32_to_cpup(p);
5145 /* Channel attributes */
5146 status = decode_chan_attrs(xdr, &session->fc_attrs);
5148 status = decode_chan_attrs(xdr, &session->bc_attrs);
5151 print_overflow_msg(__func__, xdr);
5155 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5157 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5160 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5162 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5164 #endif /* CONFIG_NFS_V4_1 */
5166 static int decode_sequence(struct xdr_stream *xdr,
5167 struct nfs4_sequence_res *res,
5168 struct rpc_rqst *rqstp)
5170 #if defined(CONFIG_NFS_V4_1)
5171 struct nfs4_sessionid id;
5176 if (!res->sr_session)
5179 status = decode_op_hdr(xdr, OP_SEQUENCE);
5181 status = decode_sessionid(xdr, &id);
5182 if (unlikely(status))
5186 * If the server returns different values for sessionID, slotID or
5187 * sequence number, the server is looney tunes.
5189 status = -EREMOTEIO;
5191 if (memcmp(id.data, res->sr_session->sess_id.data,
5192 NFS4_MAX_SESSIONID_LEN)) {
5193 dprintk("%s Invalid session id\n", __func__);
5197 p = xdr_inline_decode(xdr, 20);
5202 dummy = be32_to_cpup(p++);
5203 if (dummy != res->sr_slot->seq_nr) {
5204 dprintk("%s Invalid sequence number\n", __func__);
5208 dummy = be32_to_cpup(p++);
5209 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5210 dprintk("%s Invalid slot id\n", __func__);
5213 /* highest slot id - currently not processed */
5214 dummy = be32_to_cpup(p++);
5215 /* target highest slot id - currently not processed */
5216 dummy = be32_to_cpup(p++);
5218 res->sr_status_flags = be32_to_cpup(p);
5221 res->sr_status = status;
5224 print_overflow_msg(__func__, xdr);
5227 #else /* CONFIG_NFS_V4_1 */
5229 #endif /* CONFIG_NFS_V4_1 */
5232 #if defined(CONFIG_NFS_V4_1)
5234 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5235 struct pnfs_device *pdev)
5241 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5243 if (status == -ETOOSMALL) {
5244 p = xdr_inline_decode(xdr, 4);
5247 pdev->mincount = be32_to_cpup(p);
5248 dprintk("%s: Min count too small. mincnt = %u\n",
5249 __func__, pdev->mincount);
5254 p = xdr_inline_decode(xdr, 8);
5257 type = be32_to_cpup(p++);
5258 if (type != pdev->layout_type) {
5259 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5260 __func__, pdev->layout_type, type);
5264 * Get the length of the opaque device_addr4. xdr_read_pages places
5265 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5266 * and places the remaining xdr data in xdr_buf->tail
5268 pdev->mincount = be32_to_cpup(p);
5269 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5271 /* Parse notification bitmap, verifying that it is zero. */
5272 p = xdr_inline_decode(xdr, 4);
5275 len = be32_to_cpup(p);
5279 p = xdr_inline_decode(xdr, 4 * len);
5282 for (i = 0; i < len; i++, p++) {
5283 if (be32_to_cpup(p)) {
5284 dprintk("%s: notifications not supported\n",
5292 print_overflow_msg(__func__, xdr);
5296 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5297 struct nfs4_layoutget_res *res)
5302 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5303 struct kvec *iov = rcvbuf->head;
5306 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5309 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5312 res->return_on_close = be32_to_cpup(p++);
5313 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5314 layout_count = be32_to_cpup(p);
5315 if (!layout_count) {
5316 dprintk("%s: server responded with empty layout array\n",
5321 p = xdr_inline_decode(xdr, 28);
5324 p = xdr_decode_hyper(p, &res->range.offset);
5325 p = xdr_decode_hyper(p, &res->range.length);
5326 res->range.iomode = be32_to_cpup(p++);
5327 res->type = be32_to_cpup(p++);
5328 res->layoutp->len = be32_to_cpup(p);
5330 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5332 (unsigned long)res->range.offset,
5333 (unsigned long)res->range.length,
5338 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5339 recvd = req->rq_rcv_buf.len - hdrlen;
5340 if (res->layoutp->len > recvd) {
5341 dprintk("NFS: server cheating in layoutget reply: "
5342 "layout len %u > recvd %u\n",
5343 res->layoutp->len, recvd);
5347 xdr_read_pages(xdr, res->layoutp->len);
5349 if (layout_count > 1) {
5350 /* We only handle a length one array at the moment. Any
5351 * further entries are just ignored. Note that this means
5352 * the client may see a response that is less than the
5353 * minimum it requested.
5355 dprintk("%s: server responded with %d layouts, dropping tail\n",
5356 __func__, layout_count);
5361 print_overflow_msg(__func__, xdr);
5365 static int decode_layoutreturn(struct xdr_stream *xdr,
5366 struct nfs4_layoutreturn_res *res)
5371 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5374 p = xdr_inline_decode(xdr, 4);
5377 res->lrs_present = be32_to_cpup(p);
5378 if (res->lrs_present)
5379 status = decode_stateid(xdr, &res->stateid);
5382 print_overflow_msg(__func__, xdr);
5386 static int decode_layoutcommit(struct xdr_stream *xdr,
5387 struct rpc_rqst *req,
5388 struct nfs4_layoutcommit_res *res)
5394 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5398 p = xdr_inline_decode(xdr, 4);
5401 sizechanged = be32_to_cpup(p);
5404 /* throw away new size */
5405 p = xdr_inline_decode(xdr, 8);
5411 print_overflow_msg(__func__, xdr);
5415 static int decode_test_stateid(struct xdr_stream *xdr,
5416 struct nfs41_test_stateid_res *res)
5422 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5426 p = xdr_inline_decode(xdr, 4);
5429 num_res = be32_to_cpup(p++);
5433 p = xdr_inline_decode(xdr, 4);
5436 res->status = be32_to_cpup(p++);
5439 print_overflow_msg(__func__, xdr);
5443 #endif /* CONFIG_NFS_V4_1 */
5446 * END OF "GENERIC" DECODE ROUTINES.
5450 * Decode OPEN_DOWNGRADE response
5452 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5453 struct xdr_stream *xdr,
5454 struct nfs_closeres *res)
5456 struct compound_hdr hdr;
5459 status = decode_compound_hdr(xdr, &hdr);
5462 status = decode_sequence(xdr, &res->seq_res, rqstp);
5465 status = decode_putfh(xdr);
5468 status = decode_open_downgrade(xdr, res);
5471 decode_getfattr(xdr, res->fattr, res->server,
5472 !RPC_IS_ASYNC(rqstp->rq_task));
5478 * Decode ACCESS response
5480 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5481 struct nfs4_accessres *res)
5483 struct compound_hdr hdr;
5486 status = decode_compound_hdr(xdr, &hdr);
5489 status = decode_sequence(xdr, &res->seq_res, rqstp);
5492 status = decode_putfh(xdr);
5495 status = decode_access(xdr, res);
5498 decode_getfattr(xdr, res->fattr, res->server,
5499 !RPC_IS_ASYNC(rqstp->rq_task));
5505 * Decode LOOKUP response
5507 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5508 struct nfs4_lookup_res *res)
5510 struct compound_hdr hdr;
5513 status = decode_compound_hdr(xdr, &hdr);
5516 status = decode_sequence(xdr, &res->seq_res, rqstp);
5519 status = decode_putfh(xdr);
5522 status = decode_lookup(xdr);
5525 status = decode_getfh(xdr, res->fh);
5528 status = decode_getfattr(xdr, res->fattr, res->server
5529 ,!RPC_IS_ASYNC(rqstp->rq_task));
5535 * Decode LOOKUP_ROOT response
5537 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5538 struct xdr_stream *xdr,
5539 struct nfs4_lookup_res *res)
5541 struct compound_hdr hdr;
5544 status = decode_compound_hdr(xdr, &hdr);
5547 status = decode_sequence(xdr, &res->seq_res, rqstp);
5550 status = decode_putrootfh(xdr);
5553 status = decode_getfh(xdr, res->fh);
5555 status = decode_getfattr(xdr, res->fattr, res->server,
5556 !RPC_IS_ASYNC(rqstp->rq_task));
5562 * Decode REMOVE response
5564 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5565 struct nfs_removeres *res)
5567 struct compound_hdr hdr;
5570 status = decode_compound_hdr(xdr, &hdr);
5573 status = decode_sequence(xdr, &res->seq_res, rqstp);
5576 status = decode_putfh(xdr);
5579 status = decode_remove(xdr, &res->cinfo);
5582 decode_getfattr(xdr, res->dir_attr, res->server,
5583 !RPC_IS_ASYNC(rqstp->rq_task));
5589 * Decode RENAME response
5591 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5592 struct nfs_renameres *res)
5594 struct compound_hdr hdr;
5597 status = decode_compound_hdr(xdr, &hdr);
5600 status = decode_sequence(xdr, &res->seq_res, rqstp);
5603 status = decode_putfh(xdr);
5606 status = decode_savefh(xdr);
5609 status = decode_putfh(xdr);
5612 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5615 /* Current FH is target directory */
5616 if (decode_getfattr(xdr, res->new_fattr, res->server,
5617 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5619 status = decode_restorefh(xdr);
5622 decode_getfattr(xdr, res->old_fattr, res->server,
5623 !RPC_IS_ASYNC(rqstp->rq_task));
5629 * Decode LINK response
5631 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5632 struct nfs4_link_res *res)
5634 struct compound_hdr hdr;
5637 status = decode_compound_hdr(xdr, &hdr);
5640 status = decode_sequence(xdr, &res->seq_res, rqstp);
5643 status = decode_putfh(xdr);
5646 status = decode_savefh(xdr);
5649 status = decode_putfh(xdr);
5652 status = decode_link(xdr, &res->cinfo);
5656 * Note order: OP_LINK leaves the directory as the current
5659 if (decode_getfattr(xdr, res->dir_attr, res->server,
5660 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5662 status = decode_restorefh(xdr);
5665 decode_getfattr(xdr, res->fattr, res->server,
5666 !RPC_IS_ASYNC(rqstp->rq_task));
5672 * Decode CREATE response
5674 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5675 struct nfs4_create_res *res)
5677 struct compound_hdr hdr;
5680 status = decode_compound_hdr(xdr, &hdr);
5683 status = decode_sequence(xdr, &res->seq_res, rqstp);
5686 status = decode_putfh(xdr);
5689 status = decode_savefh(xdr);
5692 status = decode_create(xdr, &res->dir_cinfo);
5695 status = decode_getfh(xdr, res->fh);
5698 if (decode_getfattr(xdr, res->fattr, res->server,
5699 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5701 status = decode_restorefh(xdr);
5704 decode_getfattr(xdr, res->dir_fattr, res->server,
5705 !RPC_IS_ASYNC(rqstp->rq_task));
5711 * Decode SYMLINK response
5713 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5714 struct nfs4_create_res *res)
5716 return nfs4_xdr_dec_create(rqstp, xdr, res);
5720 * Decode GETATTR response
5722 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5723 struct nfs4_getattr_res *res)
5725 struct compound_hdr hdr;
5728 status = decode_compound_hdr(xdr, &hdr);
5731 status = decode_sequence(xdr, &res->seq_res, rqstp);
5734 status = decode_putfh(xdr);
5737 status = decode_getfattr(xdr, res->fattr, res->server,
5738 !RPC_IS_ASYNC(rqstp->rq_task));
5744 * Encode an SETACL request
5746 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5747 struct nfs_setaclargs *args)
5749 struct compound_hdr hdr = {
5750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
5753 encode_compound_hdr(xdr, req, &hdr);
5754 encode_sequence(xdr, &args->seq_args, &hdr);
5755 encode_putfh(xdr, args->fh, &hdr);
5756 encode_setacl(xdr, args, &hdr);
5761 * Decode SETACL response
5764 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5765 struct nfs_setaclres *res)
5767 struct compound_hdr hdr;
5770 status = decode_compound_hdr(xdr, &hdr);
5773 status = decode_sequence(xdr, &res->seq_res, rqstp);
5776 status = decode_putfh(xdr);
5779 status = decode_setattr(xdr);
5785 * Decode GETACL response
5788 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5789 struct nfs_getaclres *res)
5791 struct compound_hdr hdr;
5794 status = decode_compound_hdr(xdr, &hdr);
5797 status = decode_sequence(xdr, &res->seq_res, rqstp);
5800 status = decode_putfh(xdr);
5803 status = decode_getacl(xdr, rqstp, &res->acl_len);
5810 * Decode CLOSE response
5812 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5813 struct nfs_closeres *res)
5815 struct compound_hdr hdr;
5818 status = decode_compound_hdr(xdr, &hdr);
5821 status = decode_sequence(xdr, &res->seq_res, rqstp);
5824 status = decode_putfh(xdr);
5827 status = decode_close(xdr, res);
5831 * Note: Server may do delete on close for this file
5832 * in which case the getattr call will fail with
5833 * an ESTALE error. Shouldn't be a problem,
5834 * though, since fattr->valid will remain unset.
5836 decode_getfattr(xdr, res->fattr, res->server,
5837 !RPC_IS_ASYNC(rqstp->rq_task));
5843 * Decode OPEN response
5845 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5846 struct nfs_openres *res)
5848 struct compound_hdr hdr;
5851 status = decode_compound_hdr(xdr, &hdr);
5854 status = decode_sequence(xdr, &res->seq_res, rqstp);
5857 status = decode_putfh(xdr);
5860 status = decode_savefh(xdr);
5863 status = decode_open(xdr, res);
5866 if (decode_getfh(xdr, &res->fh) != 0)
5868 if (decode_getfattr(xdr, res->f_attr, res->server,
5869 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5871 if (decode_restorefh(xdr) != 0)
5873 decode_getfattr(xdr, res->dir_attr, res->server,
5874 !RPC_IS_ASYNC(rqstp->rq_task));
5880 * Decode OPEN_CONFIRM response
5882 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5883 struct xdr_stream *xdr,
5884 struct nfs_open_confirmres *res)
5886 struct compound_hdr hdr;
5889 status = decode_compound_hdr(xdr, &hdr);
5892 status = decode_putfh(xdr);
5895 status = decode_open_confirm(xdr, res);
5901 * Decode OPEN response
5903 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5904 struct xdr_stream *xdr,
5905 struct nfs_openres *res)
5907 struct compound_hdr hdr;
5910 status = decode_compound_hdr(xdr, &hdr);
5913 status = decode_sequence(xdr, &res->seq_res, rqstp);
5916 status = decode_putfh(xdr);
5919 status = decode_open(xdr, res);
5922 decode_getfattr(xdr, res->f_attr, res->server,
5923 !RPC_IS_ASYNC(rqstp->rq_task));
5929 * Decode SETATTR response
5931 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5932 struct xdr_stream *xdr,
5933 struct nfs_setattrres *res)
5935 struct compound_hdr hdr;
5938 status = decode_compound_hdr(xdr, &hdr);
5941 status = decode_sequence(xdr, &res->seq_res, rqstp);
5944 status = decode_putfh(xdr);
5947 status = decode_setattr(xdr);
5950 decode_getfattr(xdr, res->fattr, res->server,
5951 !RPC_IS_ASYNC(rqstp->rq_task));
5957 * Decode LOCK response
5959 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5960 struct nfs_lock_res *res)
5962 struct compound_hdr hdr;
5965 status = decode_compound_hdr(xdr, &hdr);
5968 status = decode_sequence(xdr, &res->seq_res, rqstp);
5971 status = decode_putfh(xdr);
5974 status = decode_lock(xdr, res);
5980 * Decode LOCKT response
5982 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5983 struct nfs_lockt_res *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_lockt(xdr, res);
6003 * Decode LOCKU response
6005 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6006 struct nfs_locku_res *res)
6008 struct compound_hdr hdr;
6011 status = decode_compound_hdr(xdr, &hdr);
6014 status = decode_sequence(xdr, &res->seq_res, rqstp);
6017 status = decode_putfh(xdr);
6020 status = decode_locku(xdr, res);
6025 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6026 struct xdr_stream *xdr, void *dummy)
6028 struct compound_hdr hdr;
6031 status = decode_compound_hdr(xdr, &hdr);
6033 status = decode_release_lockowner(xdr);
6038 * Decode READLINK response
6040 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6041 struct xdr_stream *xdr,
6042 struct nfs4_readlink_res *res)
6044 struct compound_hdr hdr;
6047 status = decode_compound_hdr(xdr, &hdr);
6050 status = decode_sequence(xdr, &res->seq_res, rqstp);
6053 status = decode_putfh(xdr);
6056 status = decode_readlink(xdr, rqstp);
6062 * Decode READDIR response
6064 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6065 struct nfs4_readdir_res *res)
6067 struct compound_hdr hdr;
6070 status = decode_compound_hdr(xdr, &hdr);
6073 status = decode_sequence(xdr, &res->seq_res, rqstp);
6076 status = decode_putfh(xdr);
6079 status = decode_readdir(xdr, rqstp, res);
6085 * Decode Read response
6087 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6088 struct nfs_readres *res)
6090 struct compound_hdr hdr;
6093 status = decode_compound_hdr(xdr, &hdr);
6096 status = decode_sequence(xdr, &res->seq_res, rqstp);
6099 status = decode_putfh(xdr);
6102 status = decode_read(xdr, rqstp, res);
6104 status = res->count;
6110 * Decode WRITE response
6112 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6113 struct nfs_writeres *res)
6115 struct compound_hdr hdr;
6118 status = decode_compound_hdr(xdr, &hdr);
6121 status = decode_sequence(xdr, &res->seq_res, rqstp);
6124 status = decode_putfh(xdr);
6127 status = decode_write(xdr, res);
6131 decode_getfattr(xdr, res->fattr, res->server,
6132 !RPC_IS_ASYNC(rqstp->rq_task));
6134 status = res->count;
6140 * Decode COMMIT response
6142 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6143 struct nfs_writeres *res)
6145 struct compound_hdr hdr;
6148 status = decode_compound_hdr(xdr, &hdr);
6151 status = decode_sequence(xdr, &res->seq_res, rqstp);
6154 status = decode_putfh(xdr);
6157 status = decode_commit(xdr, res);
6161 decode_getfattr(xdr, res->fattr, res->server,
6162 !RPC_IS_ASYNC(rqstp->rq_task));
6168 * Decode FSINFO response
6170 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6171 struct nfs4_fsinfo_res *res)
6173 struct compound_hdr hdr;
6176 status = decode_compound_hdr(xdr, &hdr);
6178 status = decode_sequence(xdr, &res->seq_res, req);
6180 status = decode_putfh(xdr);
6182 status = decode_fsinfo(xdr, res->fsinfo);
6187 * Decode PATHCONF response
6189 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6190 struct nfs4_pathconf_res *res)
6192 struct compound_hdr hdr;
6195 status = decode_compound_hdr(xdr, &hdr);
6197 status = decode_sequence(xdr, &res->seq_res, req);
6199 status = decode_putfh(xdr);
6201 status = decode_pathconf(xdr, res->pathconf);
6206 * Decode STATFS response
6208 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6209 struct nfs4_statfs_res *res)
6211 struct compound_hdr hdr;
6214 status = decode_compound_hdr(xdr, &hdr);
6216 status = decode_sequence(xdr, &res->seq_res, req);
6218 status = decode_putfh(xdr);
6220 status = decode_statfs(xdr, res->fsstat);
6225 * Decode GETATTR_BITMAP response
6227 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6228 struct xdr_stream *xdr,
6229 struct nfs4_server_caps_res *res)
6231 struct compound_hdr hdr;
6234 status = decode_compound_hdr(xdr, &hdr);
6237 status = decode_sequence(xdr, &res->seq_res, req);
6240 status = decode_putfh(xdr);
6243 status = decode_server_caps(xdr, res);
6249 * Decode RENEW response
6251 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6254 struct compound_hdr hdr;
6257 status = decode_compound_hdr(xdr, &hdr);
6259 status = decode_renew(xdr);
6264 * Decode SETCLIENTID response
6266 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6267 struct xdr_stream *xdr,
6268 struct nfs4_setclientid_res *res)
6270 struct compound_hdr hdr;
6273 status = decode_compound_hdr(xdr, &hdr);
6275 status = decode_setclientid(xdr, res);
6280 * Decode SETCLIENTID_CONFIRM response
6282 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6283 struct xdr_stream *xdr,
6284 struct nfs_fsinfo *fsinfo)
6286 struct compound_hdr hdr;
6289 status = decode_compound_hdr(xdr, &hdr);
6291 status = decode_setclientid_confirm(xdr);
6293 status = decode_putrootfh(xdr);
6295 status = decode_fsinfo(xdr, fsinfo);
6300 * Decode DELEGRETURN response
6302 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6303 struct xdr_stream *xdr,
6304 struct nfs4_delegreturnres *res)
6306 struct compound_hdr hdr;
6309 status = decode_compound_hdr(xdr, &hdr);
6312 status = decode_sequence(xdr, &res->seq_res, rqstp);
6315 status = decode_putfh(xdr);
6318 status = decode_delegreturn(xdr);
6321 decode_getfattr(xdr, res->fattr, res->server,
6322 !RPC_IS_ASYNC(rqstp->rq_task));
6328 * Decode FS_LOCATIONS response
6330 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6331 struct xdr_stream *xdr,
6332 struct nfs4_fs_locations_res *res)
6334 struct compound_hdr hdr;
6337 status = decode_compound_hdr(xdr, &hdr);
6340 status = decode_sequence(xdr, &res->seq_res, req);
6343 status = decode_putfh(xdr);
6346 status = decode_lookup(xdr);
6349 xdr_enter_page(xdr, PAGE_SIZE);
6350 status = decode_getfattr(xdr, &res->fs_locations->fattr,
6351 res->fs_locations->server,
6352 !RPC_IS_ASYNC(req->rq_task));
6358 * Decode SECINFO response
6360 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6361 struct xdr_stream *xdr,
6362 struct nfs4_secinfo_res *res)
6364 struct compound_hdr hdr;
6367 status = decode_compound_hdr(xdr, &hdr);
6370 status = decode_sequence(xdr, &res->seq_res, rqstp);
6373 status = decode_putfh(xdr);
6376 status = decode_secinfo(xdr, res);
6383 #if defined(CONFIG_NFS_V4_1)
6385 * Decode EXCHANGE_ID response
6387 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6388 struct xdr_stream *xdr,
6391 struct compound_hdr hdr;
6394 status = decode_compound_hdr(xdr, &hdr);
6396 status = decode_exchange_id(xdr, res);
6401 * Decode CREATE_SESSION response
6403 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6404 struct xdr_stream *xdr,
6405 struct nfs41_create_session_res *res)
6407 struct compound_hdr hdr;
6410 status = decode_compound_hdr(xdr, &hdr);
6412 status = decode_create_session(xdr, res);
6417 * Decode DESTROY_SESSION response
6419 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6420 struct xdr_stream *xdr,
6423 struct compound_hdr hdr;
6426 status = decode_compound_hdr(xdr, &hdr);
6428 status = decode_destroy_session(xdr, res);
6433 * Decode SEQUENCE response
6435 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6436 struct xdr_stream *xdr,
6437 struct nfs4_sequence_res *res)
6439 struct compound_hdr hdr;
6442 status = decode_compound_hdr(xdr, &hdr);
6444 status = decode_sequence(xdr, res, rqstp);
6449 * Decode GET_LEASE_TIME response
6451 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6452 struct xdr_stream *xdr,
6453 struct nfs4_get_lease_time_res *res)
6455 struct compound_hdr hdr;
6458 status = decode_compound_hdr(xdr, &hdr);
6460 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6462 status = decode_putrootfh(xdr);
6464 status = decode_fsinfo(xdr, res->lr_fsinfo);
6469 * Decode RECLAIM_COMPLETE response
6471 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6472 struct xdr_stream *xdr,
6473 struct nfs41_reclaim_complete_res *res)
6475 struct compound_hdr hdr;
6478 status = decode_compound_hdr(xdr, &hdr);
6480 status = decode_sequence(xdr, &res->seq_res, rqstp);
6482 status = decode_reclaim_complete(xdr, (void *)NULL);
6487 * Decode GETDEVINFO response
6489 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6490 struct xdr_stream *xdr,
6491 struct nfs4_getdeviceinfo_res *res)
6493 struct compound_hdr hdr;
6496 status = decode_compound_hdr(xdr, &hdr);
6499 status = decode_sequence(xdr, &res->seq_res, rqstp);
6502 status = decode_getdeviceinfo(xdr, res->pdev);
6508 * Decode LAYOUTGET response
6510 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6511 struct xdr_stream *xdr,
6512 struct nfs4_layoutget_res *res)
6514 struct compound_hdr hdr;
6517 status = decode_compound_hdr(xdr, &hdr);
6520 status = decode_sequence(xdr, &res->seq_res, rqstp);
6523 status = decode_putfh(xdr);
6526 status = decode_layoutget(xdr, rqstp, res);
6532 * Decode LAYOUTRETURN response
6534 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6535 struct xdr_stream *xdr,
6536 struct nfs4_layoutreturn_res *res)
6538 struct compound_hdr hdr;
6541 status = decode_compound_hdr(xdr, &hdr);
6544 status = decode_sequence(xdr, &res->seq_res, rqstp);
6547 status = decode_putfh(xdr);
6550 status = decode_layoutreturn(xdr, res);
6556 * Decode LAYOUTCOMMIT response
6558 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6559 struct xdr_stream *xdr,
6560 struct nfs4_layoutcommit_res *res)
6562 struct compound_hdr hdr;
6565 status = decode_compound_hdr(xdr, &hdr);
6568 status = decode_sequence(xdr, &res->seq_res, rqstp);
6571 status = decode_putfh(xdr);
6574 status = decode_layoutcommit(xdr, rqstp, res);
6577 decode_getfattr(xdr, res->fattr, res->server,
6578 !RPC_IS_ASYNC(rqstp->rq_task));
6584 * Decode SECINFO_NO_NAME response
6586 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6587 struct xdr_stream *xdr,
6588 struct nfs4_secinfo_res *res)
6590 struct compound_hdr hdr;
6593 status = decode_compound_hdr(xdr, &hdr);
6596 status = decode_sequence(xdr, &res->seq_res, rqstp);
6599 status = decode_putrootfh(xdr);
6602 status = decode_secinfo(xdr, res);
6608 * Decode TEST_STATEID response
6610 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6611 struct xdr_stream *xdr,
6612 struct nfs41_test_stateid_res *res)
6614 struct compound_hdr hdr;
6617 status = decode_compound_hdr(xdr, &hdr);
6620 status = decode_sequence(xdr, &res->seq_res, rqstp);
6623 status = decode_test_stateid(xdr, res);
6627 #endif /* CONFIG_NFS_V4_1 */
6630 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6631 * the local page cache.
6632 * @xdr: XDR stream where entry resides
6633 * @entry: buffer to fill in with entry data
6634 * @plus: boolean indicating whether this should be a readdirplus entry
6636 * Returns zero if successful, otherwise a negative errno value is
6639 * This function is not invoked during READDIR reply decoding, but
6640 * rather whenever an application invokes the getdents(2) system call
6641 * on a directory already in our cache.
6643 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6646 uint32_t bitmap[2] = {0};
6648 __be32 *p = xdr_inline_decode(xdr, 4);
6651 if (*p == xdr_zero) {
6652 p = xdr_inline_decode(xdr, 4);
6661 p = xdr_inline_decode(xdr, 12);
6664 entry->prev_cookie = entry->cookie;
6665 p = xdr_decode_hyper(p, &entry->cookie);
6666 entry->len = be32_to_cpup(p);
6668 p = xdr_inline_decode(xdr, entry->len);
6671 entry->name = (const char *) p;
6674 * In case the server doesn't return an inode number,
6675 * we fake one here. (We don't use inode number 0,
6676 * since glibc seems to choke on it...)
6679 entry->fattr->valid = 0;
6681 if (decode_attr_bitmap(xdr, bitmap) < 0)
6684 if (decode_attr_length(xdr, &len, &p) < 0)
6687 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6688 entry->server, 1) < 0)
6690 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6691 entry->ino = entry->fattr->mounted_on_fileid;
6692 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6693 entry->ino = entry->fattr->fileid;
6695 entry->d_type = DT_UNKNOWN;
6696 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6697 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6702 print_overflow_msg(__func__, xdr);
6707 * We need to translate between nfs status return values and
6708 * the local errno values which may not be the same.
6715 { NFS4ERR_PERM, -EPERM },
6716 { NFS4ERR_NOENT, -ENOENT },
6717 { NFS4ERR_IO, -errno_NFSERR_IO},
6718 { NFS4ERR_NXIO, -ENXIO },
6719 { NFS4ERR_ACCESS, -EACCES },
6720 { NFS4ERR_EXIST, -EEXIST },
6721 { NFS4ERR_XDEV, -EXDEV },
6722 { NFS4ERR_NOTDIR, -ENOTDIR },
6723 { NFS4ERR_ISDIR, -EISDIR },
6724 { NFS4ERR_INVAL, -EINVAL },
6725 { NFS4ERR_FBIG, -EFBIG },
6726 { NFS4ERR_NOSPC, -ENOSPC },
6727 { NFS4ERR_ROFS, -EROFS },
6728 { NFS4ERR_MLINK, -EMLINK },
6729 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6730 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6731 { NFS4ERR_DQUOT, -EDQUOT },
6732 { NFS4ERR_STALE, -ESTALE },
6733 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6734 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6735 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6736 { NFS4ERR_TOOSMALL, -ETOOSMALL },
6737 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
6738 { NFS4ERR_BADTYPE, -EBADTYPE },
6739 { NFS4ERR_LOCKED, -EAGAIN },
6740 { NFS4ERR_SYMLINK, -ELOOP },
6741 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6742 { NFS4ERR_DEADLOCK, -EDEADLK },
6747 * Convert an NFS error code to a local one.
6748 * This one is used jointly by NFSv2 and NFSv3.
6751 nfs4_stat_to_errno(int stat)
6754 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6755 if (nfs_errtbl[i].stat == stat)
6756 return nfs_errtbl[i].errno;
6758 if (stat <= 10000 || stat > 10100) {
6759 /* The server is looney tunes. */
6762 /* If we cannot translate the error, the recovery routines should
6764 * Note: remaining NFSv4 error codes have values > 10000, so should
6765 * not conflict with native Linux error codes.
6770 #define PROC(proc, argtype, restype) \
6771 [NFSPROC4_CLNT_##proc] = { \
6772 .p_proc = NFSPROC4_COMPOUND, \
6773 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6774 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6775 .p_arglen = NFS4_##argtype##_sz, \
6776 .p_replen = NFS4_##restype##_sz, \
6777 .p_statidx = NFSPROC4_CLNT_##proc, \
6781 struct rpc_procinfo nfs4_procedures[] = {
6782 PROC(READ, enc_read, dec_read),
6783 PROC(WRITE, enc_write, dec_write),
6784 PROC(COMMIT, enc_commit, dec_commit),
6785 PROC(OPEN, enc_open, dec_open),
6786 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6787 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6788 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6789 PROC(CLOSE, enc_close, dec_close),
6790 PROC(SETATTR, enc_setattr, dec_setattr),
6791 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6792 PROC(RENEW, enc_renew, dec_renew),
6793 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6794 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6795 PROC(LOCK, enc_lock, dec_lock),
6796 PROC(LOCKT, enc_lockt, dec_lockt),
6797 PROC(LOCKU, enc_locku, dec_locku),
6798 PROC(ACCESS, enc_access, dec_access),
6799 PROC(GETATTR, enc_getattr, dec_getattr),
6800 PROC(LOOKUP, enc_lookup, dec_lookup),
6801 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6802 PROC(REMOVE, enc_remove, dec_remove),
6803 PROC(RENAME, enc_rename, dec_rename),
6804 PROC(LINK, enc_link, dec_link),
6805 PROC(SYMLINK, enc_symlink, dec_symlink),
6806 PROC(CREATE, enc_create, dec_create),
6807 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6808 PROC(STATFS, enc_statfs, dec_statfs),
6809 PROC(READLINK, enc_readlink, dec_readlink),
6810 PROC(READDIR, enc_readdir, dec_readdir),
6811 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6812 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6813 PROC(GETACL, enc_getacl, dec_getacl),
6814 PROC(SETACL, enc_setacl, dec_setacl),
6815 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6816 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
6817 PROC(SECINFO, enc_secinfo, dec_secinfo),
6818 #if defined(CONFIG_NFS_V4_1)
6819 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6820 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6821 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6822 PROC(SEQUENCE, enc_sequence, dec_sequence),
6823 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6824 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6825 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6826 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
6827 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
6828 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
6829 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
6830 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
6831 #endif /* CONFIG_NFS_V4_1 */
6834 struct rpc_version nfs_version4 = {
6836 .nrprocs = ARRAY_SIZE(nfs4_procedures),
6837 .procs = nfs4_procedures