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_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
318 encode_verifier_maxsz)
319 #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
320 2 /* nfs_cookie4 gdlr_cookie */ + \
321 decode_verifier_maxsz \
322 /* verifier4 gdlr_verifier */ + \
323 1 /* gdlr_deviceid_list count */ + \
324 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
325 NFS4_DEVICEID4_SIZE) \
326 /* gdlr_deviceid_list */ + \
327 1 /* bool gdlr_eof */)
328 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
329 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
330 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
331 1 /* layout type */ + \
332 1 /* opaque devaddr4 length */ + \
333 /* devaddr4 payload is read into page */ \
334 1 /* notification bitmap length */ + \
335 1 /* notification bitmap */)
336 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
337 encode_stateid_maxsz)
338 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
339 decode_stateid_maxsz + \
340 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
341 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
345 encode_stateid_maxsz + \
346 1 /* new offset (true) */ + \
347 2 /* last byte written */ + \
348 1 /* nt_timechanged (false) */ + \
349 1 /* layoutupdate4 layout type */ + \
350 1 /* NULL filelayout layoutupdate4 payload */)
351 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
352 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
353 encode_stateid_maxsz + \
354 1 /* FIXME: opaque lrf_body always empty at the moment */)
355 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
356 1 + decode_stateid_maxsz)
357 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
358 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
359 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
360 XDR_QUADLEN(NFS4_STATEID_SIZE))
361 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
362 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
363 XDR_QUADLEN(NFS4_STATEID_SIZE))
364 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
365 #else /* CONFIG_NFS_V4_1 */
366 #define encode_sequence_maxsz 0
367 #define decode_sequence_maxsz 0
368 #endif /* CONFIG_NFS_V4_1 */
370 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
371 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
372 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
373 encode_sequence_maxsz + \
374 encode_putfh_maxsz + \
376 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
377 decode_sequence_maxsz + \
378 decode_putfh_maxsz + \
380 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
381 encode_sequence_maxsz + \
382 encode_putfh_maxsz + \
383 encode_readlink_maxsz)
384 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
385 decode_sequence_maxsz + \
386 decode_putfh_maxsz + \
387 decode_readlink_maxsz)
388 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
389 encode_sequence_maxsz + \
390 encode_putfh_maxsz + \
391 encode_readdir_maxsz)
392 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
393 decode_sequence_maxsz + \
394 decode_putfh_maxsz + \
395 decode_readdir_maxsz)
396 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
397 encode_sequence_maxsz + \
398 encode_putfh_maxsz + \
399 encode_write_maxsz + \
400 encode_getattr_maxsz)
401 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
402 decode_sequence_maxsz + \
403 decode_putfh_maxsz + \
404 decode_write_maxsz + \
405 decode_getattr_maxsz)
406 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
407 encode_sequence_maxsz + \
408 encode_putfh_maxsz + \
409 encode_commit_maxsz + \
410 encode_getattr_maxsz)
411 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
412 decode_sequence_maxsz + \
413 decode_putfh_maxsz + \
414 decode_commit_maxsz + \
415 decode_getattr_maxsz)
416 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
417 encode_sequence_maxsz + \
418 encode_putfh_maxsz + \
419 encode_savefh_maxsz + \
420 encode_open_maxsz + \
421 encode_getfh_maxsz + \
422 encode_getattr_maxsz + \
423 encode_restorefh_maxsz + \
424 encode_getattr_maxsz)
425 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
426 decode_sequence_maxsz + \
427 decode_putfh_maxsz + \
428 decode_savefh_maxsz + \
429 decode_open_maxsz + \
430 decode_getfh_maxsz + \
431 decode_getattr_maxsz + \
432 decode_restorefh_maxsz + \
433 decode_getattr_maxsz)
434 #define NFS4_enc_open_confirm_sz \
435 (compound_encode_hdr_maxsz + \
436 encode_putfh_maxsz + \
437 encode_open_confirm_maxsz)
438 #define NFS4_dec_open_confirm_sz \
439 (compound_decode_hdr_maxsz + \
440 decode_putfh_maxsz + \
441 decode_open_confirm_maxsz)
442 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
443 encode_sequence_maxsz + \
444 encode_putfh_maxsz + \
445 encode_open_maxsz + \
446 encode_getattr_maxsz)
447 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
448 decode_sequence_maxsz + \
449 decode_putfh_maxsz + \
450 decode_open_maxsz + \
451 decode_getattr_maxsz)
452 #define NFS4_enc_open_downgrade_sz \
453 (compound_encode_hdr_maxsz + \
454 encode_sequence_maxsz + \
455 encode_putfh_maxsz + \
456 encode_open_downgrade_maxsz + \
457 encode_getattr_maxsz)
458 #define NFS4_dec_open_downgrade_sz \
459 (compound_decode_hdr_maxsz + \
460 decode_sequence_maxsz + \
461 decode_putfh_maxsz + \
462 decode_open_downgrade_maxsz + \
463 decode_getattr_maxsz)
464 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
465 encode_sequence_maxsz + \
466 encode_putfh_maxsz + \
467 encode_close_maxsz + \
468 encode_getattr_maxsz)
469 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
470 decode_sequence_maxsz + \
471 decode_putfh_maxsz + \
472 decode_close_maxsz + \
473 decode_getattr_maxsz)
474 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
475 encode_sequence_maxsz + \
476 encode_putfh_maxsz + \
477 encode_setattr_maxsz + \
478 encode_getattr_maxsz)
479 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
480 decode_sequence_maxsz + \
481 decode_putfh_maxsz + \
482 decode_setattr_maxsz + \
483 decode_getattr_maxsz)
484 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
485 encode_sequence_maxsz + \
486 encode_putfh_maxsz + \
488 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
489 decode_sequence_maxsz + \
490 decode_putfh_maxsz + \
492 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
494 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
496 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
497 encode_setclientid_maxsz)
498 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
499 decode_setclientid_maxsz)
500 #define NFS4_enc_setclientid_confirm_sz \
501 (compound_encode_hdr_maxsz + \
502 encode_setclientid_confirm_maxsz + \
503 encode_putrootfh_maxsz + \
505 #define NFS4_dec_setclientid_confirm_sz \
506 (compound_decode_hdr_maxsz + \
507 decode_setclientid_confirm_maxsz + \
508 decode_putrootfh_maxsz + \
510 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
511 encode_sequence_maxsz + \
512 encode_putfh_maxsz + \
514 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
515 decode_sequence_maxsz + \
516 decode_putfh_maxsz + \
518 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
519 encode_sequence_maxsz + \
520 encode_putfh_maxsz + \
522 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
523 decode_sequence_maxsz + \
524 decode_putfh_maxsz + \
526 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
527 encode_sequence_maxsz + \
528 encode_putfh_maxsz + \
530 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
531 decode_sequence_maxsz + \
532 decode_putfh_maxsz + \
534 #define NFS4_enc_release_lockowner_sz \
535 (compound_encode_hdr_maxsz + \
536 encode_lockowner_maxsz)
537 #define NFS4_dec_release_lockowner_sz \
538 (compound_decode_hdr_maxsz + \
539 decode_lockowner_maxsz)
540 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
541 encode_sequence_maxsz + \
542 encode_putfh_maxsz + \
543 encode_access_maxsz + \
544 encode_getattr_maxsz)
545 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
546 decode_sequence_maxsz + \
547 decode_putfh_maxsz + \
548 decode_access_maxsz + \
549 decode_getattr_maxsz)
550 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
551 encode_sequence_maxsz + \
552 encode_putfh_maxsz + \
553 encode_getattr_maxsz)
554 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
555 decode_sequence_maxsz + \
556 decode_putfh_maxsz + \
557 decode_getattr_maxsz)
558 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
559 encode_sequence_maxsz + \
560 encode_putfh_maxsz + \
561 encode_lookup_maxsz + \
562 encode_getattr_maxsz + \
564 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
565 decode_sequence_maxsz + \
566 decode_putfh_maxsz + \
567 decode_lookup_maxsz + \
568 decode_getattr_maxsz + \
570 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
571 encode_sequence_maxsz + \
572 encode_putrootfh_maxsz + \
573 encode_getattr_maxsz + \
575 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
576 decode_sequence_maxsz + \
577 decode_putrootfh_maxsz + \
578 decode_getattr_maxsz + \
580 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
581 encode_sequence_maxsz + \
582 encode_putfh_maxsz + \
583 encode_remove_maxsz + \
584 encode_getattr_maxsz)
585 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
586 decode_sequence_maxsz + \
587 decode_putfh_maxsz + \
588 decode_remove_maxsz + \
589 decode_getattr_maxsz)
590 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
591 encode_sequence_maxsz + \
592 encode_putfh_maxsz + \
593 encode_savefh_maxsz + \
594 encode_putfh_maxsz + \
595 encode_rename_maxsz + \
596 encode_getattr_maxsz + \
597 encode_restorefh_maxsz + \
598 encode_getattr_maxsz)
599 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
600 decode_sequence_maxsz + \
601 decode_putfh_maxsz + \
602 decode_savefh_maxsz + \
603 decode_putfh_maxsz + \
604 decode_rename_maxsz + \
605 decode_getattr_maxsz + \
606 decode_restorefh_maxsz + \
607 decode_getattr_maxsz)
608 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
609 encode_sequence_maxsz + \
610 encode_putfh_maxsz + \
611 encode_savefh_maxsz + \
612 encode_putfh_maxsz + \
613 encode_link_maxsz + \
614 decode_getattr_maxsz + \
615 encode_restorefh_maxsz + \
616 decode_getattr_maxsz)
617 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
618 decode_sequence_maxsz + \
619 decode_putfh_maxsz + \
620 decode_savefh_maxsz + \
621 decode_putfh_maxsz + \
622 decode_link_maxsz + \
623 decode_getattr_maxsz + \
624 decode_restorefh_maxsz + \
625 decode_getattr_maxsz)
626 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
627 encode_sequence_maxsz + \
628 encode_putfh_maxsz + \
629 encode_symlink_maxsz + \
630 encode_getattr_maxsz + \
632 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
633 decode_sequence_maxsz + \
634 decode_putfh_maxsz + \
635 decode_symlink_maxsz + \
636 decode_getattr_maxsz + \
638 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
639 encode_sequence_maxsz + \
640 encode_putfh_maxsz + \
641 encode_savefh_maxsz + \
642 encode_create_maxsz + \
643 encode_getfh_maxsz + \
644 encode_getattr_maxsz + \
645 encode_restorefh_maxsz + \
646 encode_getattr_maxsz)
647 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
648 decode_sequence_maxsz + \
649 decode_putfh_maxsz + \
650 decode_savefh_maxsz + \
651 decode_create_maxsz + \
652 decode_getfh_maxsz + \
653 decode_getattr_maxsz + \
654 decode_restorefh_maxsz + \
655 decode_getattr_maxsz)
656 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
657 encode_sequence_maxsz + \
658 encode_putfh_maxsz + \
659 encode_getattr_maxsz)
660 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
661 decode_sequence_maxsz + \
662 decode_putfh_maxsz + \
663 decode_getattr_maxsz)
664 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
665 encode_sequence_maxsz + \
666 encode_putfh_maxsz + \
668 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
669 decode_sequence_maxsz + \
670 decode_putfh_maxsz + \
672 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
673 encode_sequence_maxsz + \
674 encode_putfh_maxsz + \
675 encode_getattr_maxsz)
676 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
677 decode_sequence_maxsz + \
678 decode_putfh_maxsz + \
679 decode_getattr_maxsz)
680 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
681 encode_sequence_maxsz + \
682 encode_putfh_maxsz + \
683 encode_delegreturn_maxsz + \
684 encode_getattr_maxsz)
685 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
686 decode_sequence_maxsz + \
687 decode_delegreturn_maxsz + \
688 decode_getattr_maxsz)
689 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
690 encode_sequence_maxsz + \
691 encode_putfh_maxsz + \
693 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
694 decode_sequence_maxsz + \
695 decode_putfh_maxsz + \
697 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
698 encode_sequence_maxsz + \
699 encode_putfh_maxsz + \
701 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
702 decode_sequence_maxsz + \
703 decode_putfh_maxsz + \
705 #define NFS4_enc_fs_locations_sz \
706 (compound_encode_hdr_maxsz + \
707 encode_sequence_maxsz + \
708 encode_putfh_maxsz + \
709 encode_lookup_maxsz + \
710 encode_fs_locations_maxsz)
711 #define NFS4_dec_fs_locations_sz \
712 (compound_decode_hdr_maxsz + \
713 decode_sequence_maxsz + \
714 decode_putfh_maxsz + \
715 decode_lookup_maxsz + \
716 decode_fs_locations_maxsz)
717 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
718 encode_sequence_maxsz + \
719 encode_putfh_maxsz + \
720 encode_secinfo_maxsz)
721 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
722 decode_sequence_maxsz + \
723 decode_putfh_maxsz + \
724 decode_secinfo_maxsz)
725 #if defined(CONFIG_NFS_V4_1)
726 #define NFS4_enc_exchange_id_sz \
727 (compound_encode_hdr_maxsz + \
728 encode_exchange_id_maxsz)
729 #define NFS4_dec_exchange_id_sz \
730 (compound_decode_hdr_maxsz + \
731 decode_exchange_id_maxsz)
732 #define NFS4_enc_create_session_sz \
733 (compound_encode_hdr_maxsz + \
734 encode_create_session_maxsz)
735 #define NFS4_dec_create_session_sz \
736 (compound_decode_hdr_maxsz + \
737 decode_create_session_maxsz)
738 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
739 encode_destroy_session_maxsz)
740 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
741 decode_destroy_session_maxsz)
742 #define NFS4_enc_sequence_sz \
743 (compound_decode_hdr_maxsz + \
744 encode_sequence_maxsz)
745 #define NFS4_dec_sequence_sz \
746 (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz)
748 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
749 encode_sequence_maxsz + \
750 encode_putrootfh_maxsz + \
752 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_putrootfh_maxsz + \
756 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
757 encode_sequence_maxsz + \
758 encode_reclaim_complete_maxsz)
759 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_reclaim_complete_maxsz)
762 #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
763 encode_sequence_maxsz + \
764 encode_putfh_maxsz + \
765 encode_getdevicelist_maxsz)
766 #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
767 decode_sequence_maxsz + \
768 decode_putfh_maxsz + \
769 decode_getdevicelist_maxsz)
770 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
771 encode_sequence_maxsz +\
772 encode_getdeviceinfo_maxsz)
773 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_getdeviceinfo_maxsz)
776 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
777 encode_sequence_maxsz + \
778 encode_putfh_maxsz + \
779 encode_layoutget_maxsz)
780 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
781 decode_sequence_maxsz + \
782 decode_putfh_maxsz + \
783 decode_layoutget_maxsz)
784 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
785 encode_sequence_maxsz +\
786 encode_putfh_maxsz + \
787 encode_layoutcommit_maxsz + \
788 encode_getattr_maxsz)
789 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
790 decode_sequence_maxsz + \
791 decode_putfh_maxsz + \
792 decode_layoutcommit_maxsz + \
793 decode_getattr_maxsz)
794 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
795 encode_sequence_maxsz + \
796 encode_putfh_maxsz + \
797 encode_layoutreturn_maxsz)
798 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
799 decode_sequence_maxsz + \
800 decode_putfh_maxsz + \
801 decode_layoutreturn_maxsz)
802 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
803 encode_sequence_maxsz + \
804 encode_putrootfh_maxsz +\
805 encode_secinfo_no_name_maxsz)
806 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz + \
808 decode_putrootfh_maxsz + \
809 decode_secinfo_no_name_maxsz)
810 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
811 encode_sequence_maxsz + \
812 encode_test_stateid_maxsz)
813 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_test_stateid_maxsz)
816 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
817 encode_sequence_maxsz + \
818 encode_free_stateid_maxsz)
819 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_free_stateid_maxsz)
823 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
824 compound_encode_hdr_maxsz +
825 encode_sequence_maxsz +
827 encode_getattr_maxsz) *
830 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
831 compound_decode_hdr_maxsz +
832 decode_sequence_maxsz +
833 decode_putfh_maxsz) *
835 #endif /* CONFIG_NFS_V4_1 */
837 static const umode_t nfs_type2fmt[] = {
844 [NF4SOCK] = S_IFSOCK,
850 struct compound_hdr {
856 uint32_t replen; /* expected reply words */
860 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
862 __be32 *p = xdr_reserve_space(xdr, nbytes);
867 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
871 p = xdr_reserve_space(xdr, 4 + len);
873 xdr_encode_opaque(p, str, len);
876 static void encode_compound_hdr(struct xdr_stream *xdr,
877 struct rpc_rqst *req,
878 struct compound_hdr *hdr)
881 struct rpc_auth *auth = req->rq_cred->cr_auth;
883 /* initialize running count of expected bytes in reply.
884 * NOTE: the replied tag SHOULD be the same is the one sent,
885 * but this is not required as a MUST for the server to do so. */
886 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
888 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
889 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
890 p = reserve_space(xdr, 4 + hdr->taglen + 8);
891 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
892 *p++ = cpu_to_be32(hdr->minorversion);
894 *p = cpu_to_be32(hdr->nops);
897 static void encode_nops(struct compound_hdr *hdr)
899 BUG_ON(hdr->nops > NFS4_MAX_OPS);
900 *hdr->nops_p = htonl(hdr->nops);
903 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
907 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
909 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
912 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
914 char owner_name[IDMAP_NAMESZ];
915 char owner_group[IDMAP_NAMESZ];
916 int owner_namelen = 0;
917 int owner_grouplen = 0;
925 * We reserve enough space to write the entire attribute buffer at once.
926 * In the worst-case, this would be
927 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
928 * = 36 bytes, plus any contribution from variable-length fields
929 * such as owner/group.
934 if (iap->ia_valid & ATTR_SIZE)
936 if (iap->ia_valid & ATTR_MODE)
938 if (iap->ia_valid & ATTR_UID) {
939 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
940 if (owner_namelen < 0) {
941 dprintk("nfs: couldn't resolve uid %d to string\n",
944 strcpy(owner_name, "nobody");
945 owner_namelen = sizeof("nobody") - 1;
948 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
950 if (iap->ia_valid & ATTR_GID) {
951 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
952 if (owner_grouplen < 0) {
953 dprintk("nfs: couldn't resolve gid %d to string\n",
955 strcpy(owner_group, "nobody");
956 owner_grouplen = sizeof("nobody") - 1;
959 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
961 if (iap->ia_valid & ATTR_ATIME_SET)
963 else if (iap->ia_valid & ATTR_ATIME)
965 if (iap->ia_valid & ATTR_MTIME_SET)
967 else if (iap->ia_valid & ATTR_MTIME)
969 p = reserve_space(xdr, len);
972 * We write the bitmap length now, but leave the bitmap and the attribute
973 * buffer length to be backfilled at the end of this routine.
975 *p++ = cpu_to_be32(2);
979 if (iap->ia_valid & ATTR_SIZE) {
980 bmval0 |= FATTR4_WORD0_SIZE;
981 p = xdr_encode_hyper(p, iap->ia_size);
983 if (iap->ia_valid & ATTR_MODE) {
984 bmval1 |= FATTR4_WORD1_MODE;
985 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
987 if (iap->ia_valid & ATTR_UID) {
988 bmval1 |= FATTR4_WORD1_OWNER;
989 p = xdr_encode_opaque(p, owner_name, owner_namelen);
991 if (iap->ia_valid & ATTR_GID) {
992 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
993 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
995 if (iap->ia_valid & ATTR_ATIME_SET) {
996 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
997 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
998 *p++ = cpu_to_be32(0);
999 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1000 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1002 else if (iap->ia_valid & ATTR_ATIME) {
1003 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1004 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1006 if (iap->ia_valid & ATTR_MTIME_SET) {
1007 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1008 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1009 *p++ = cpu_to_be32(0);
1010 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1011 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1013 else if (iap->ia_valid & ATTR_MTIME) {
1014 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1015 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1019 * Now we backfill the bitmap and the attribute buffer length.
1021 if (len != ((char *)p - (char *)q) + 4) {
1022 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
1023 len, ((char *)p - (char *)q) + 4);
1026 len = (char *)p - (char *)q - 12;
1027 *q++ = htonl(bmval0);
1028 *q++ = htonl(bmval1);
1034 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1038 p = reserve_space(xdr, 8);
1039 *p++ = cpu_to_be32(OP_ACCESS);
1040 *p = cpu_to_be32(access);
1042 hdr->replen += decode_access_maxsz;
1045 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1049 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1050 *p++ = cpu_to_be32(OP_CLOSE);
1051 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1052 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1054 hdr->replen += decode_close_maxsz;
1057 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1061 p = reserve_space(xdr, 16);
1062 *p++ = cpu_to_be32(OP_COMMIT);
1063 p = xdr_encode_hyper(p, args->offset);
1064 *p = cpu_to_be32(args->count);
1066 hdr->replen += decode_commit_maxsz;
1069 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1073 p = reserve_space(xdr, 8);
1074 *p++ = cpu_to_be32(OP_CREATE);
1075 *p = cpu_to_be32(create->ftype);
1077 switch (create->ftype) {
1079 p = reserve_space(xdr, 4);
1080 *p = cpu_to_be32(create->u.symlink.len);
1081 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1084 case NF4BLK: case NF4CHR:
1085 p = reserve_space(xdr, 8);
1086 *p++ = cpu_to_be32(create->u.device.specdata1);
1087 *p = cpu_to_be32(create->u.device.specdata2);
1094 encode_string(xdr, create->name->len, create->name->name);
1096 hdr->replen += decode_create_maxsz;
1098 encode_attrs(xdr, create->attrs, create->server);
1101 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1105 p = reserve_space(xdr, 12);
1106 *p++ = cpu_to_be32(OP_GETATTR);
1107 *p++ = cpu_to_be32(1);
1108 *p = cpu_to_be32(bitmap);
1110 hdr->replen += decode_getattr_maxsz;
1113 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1117 p = reserve_space(xdr, 16);
1118 *p++ = cpu_to_be32(OP_GETATTR);
1119 *p++ = cpu_to_be32(2);
1120 *p++ = cpu_to_be32(bm0);
1121 *p = cpu_to_be32(bm1);
1123 hdr->replen += decode_getattr_maxsz;
1126 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1128 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1129 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1132 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1134 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1135 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1138 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1140 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1141 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1144 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1148 p = reserve_space(xdr, 4);
1149 *p = cpu_to_be32(OP_GETFH);
1151 hdr->replen += decode_getfh_maxsz;
1154 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1158 p = reserve_space(xdr, 8 + name->len);
1159 *p++ = cpu_to_be32(OP_LINK);
1160 xdr_encode_opaque(p, name->name, name->len);
1162 hdr->replen += decode_link_maxsz;
1165 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1167 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1168 return block ? NFS4_READW_LT : NFS4_READ_LT;
1169 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1172 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1174 if (fl->fl_end == OFFSET_MAX)
1175 return ~(uint64_t)0;
1176 return fl->fl_end - fl->fl_start + 1;
1179 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1183 p = reserve_space(xdr, 32);
1184 p = xdr_encode_hyper(p, lowner->clientid);
1185 *p++ = cpu_to_be32(20);
1186 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1187 *p++ = cpu_to_be32(lowner->s_dev);
1188 xdr_encode_hyper(p, lowner->id);
1192 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1193 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1195 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1199 p = reserve_space(xdr, 32);
1200 *p++ = cpu_to_be32(OP_LOCK);
1201 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1202 *p++ = cpu_to_be32(args->reclaim);
1203 p = xdr_encode_hyper(p, args->fl->fl_start);
1204 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1205 *p = cpu_to_be32(args->new_lock_owner);
1206 if (args->new_lock_owner){
1207 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1208 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1209 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1210 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1211 encode_lockowner(xdr, &args->lock_owner);
1214 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1215 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1216 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1219 hdr->replen += decode_lock_maxsz;
1222 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1226 p = reserve_space(xdr, 24);
1227 *p++ = cpu_to_be32(OP_LOCKT);
1228 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1229 p = xdr_encode_hyper(p, args->fl->fl_start);
1230 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1231 encode_lockowner(xdr, &args->lock_owner);
1233 hdr->replen += decode_lockt_maxsz;
1236 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1240 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1241 *p++ = cpu_to_be32(OP_LOCKU);
1242 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1243 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1244 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1245 p = xdr_encode_hyper(p, args->fl->fl_start);
1246 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1248 hdr->replen += decode_locku_maxsz;
1251 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1255 p = reserve_space(xdr, 4);
1256 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1257 encode_lockowner(xdr, lowner);
1259 hdr->replen += decode_release_lockowner_maxsz;
1262 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1264 int len = name->len;
1267 p = reserve_space(xdr, 8 + len);
1268 *p++ = cpu_to_be32(OP_LOOKUP);
1269 xdr_encode_opaque(p, name->name, len);
1271 hdr->replen += decode_lookup_maxsz;
1274 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1278 p = reserve_space(xdr, 8);
1279 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1281 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1284 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1286 case FMODE_READ|FMODE_WRITE:
1287 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1290 *p++ = cpu_to_be32(0);
1292 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1295 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1299 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1302 p = reserve_space(xdr, 8);
1303 *p++ = cpu_to_be32(OP_OPEN);
1304 *p = cpu_to_be32(arg->seqid->sequence->counter);
1305 encode_share_access(xdr, arg->fmode);
1306 p = reserve_space(xdr, 32);
1307 p = xdr_encode_hyper(p, arg->clientid);
1308 *p++ = cpu_to_be32(20);
1309 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1310 *p++ = cpu_to_be32(arg->server->s_dev);
1311 xdr_encode_hyper(p, arg->id);
1314 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1317 struct nfs_client *clp;
1319 p = reserve_space(xdr, 4);
1320 switch(arg->open_flags & O_EXCL) {
1322 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1323 encode_attrs(xdr, arg->u.attrs, arg->server);
1326 clp = arg->server->nfs_client;
1327 if (clp->cl_mvops->minor_version > 0) {
1328 if (nfs4_has_persistent_session(clp)) {
1329 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1330 encode_attrs(xdr, arg->u.attrs, arg->server);
1334 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1335 encode_nfs4_verifier(xdr, &arg->u.verifier);
1337 encode_attrs(xdr, &dummy, arg->server);
1340 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1341 encode_nfs4_verifier(xdr, &arg->u.verifier);
1346 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1350 p = reserve_space(xdr, 4);
1351 switch (arg->open_flags & O_CREAT) {
1353 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1356 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1357 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1358 encode_createmode(xdr, arg);
1362 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1366 p = reserve_space(xdr, 4);
1367 switch (delegation_type) {
1369 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1372 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1374 case FMODE_WRITE|FMODE_READ:
1375 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1382 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1386 p = reserve_space(xdr, 4);
1387 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1388 encode_string(xdr, name->len, name->name);
1391 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1395 p = reserve_space(xdr, 4);
1396 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1397 encode_delegation_type(xdr, type);
1400 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1404 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1405 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1406 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1407 encode_string(xdr, name->len, name->name);
1410 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1412 encode_openhdr(xdr, arg);
1413 encode_opentype(xdr, arg);
1414 switch (arg->claim) {
1415 case NFS4_OPEN_CLAIM_NULL:
1416 encode_claim_null(xdr, arg->name);
1418 case NFS4_OPEN_CLAIM_PREVIOUS:
1419 encode_claim_previous(xdr, arg->u.delegation_type);
1421 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1422 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1428 hdr->replen += decode_open_maxsz;
1431 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1435 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1436 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1437 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1438 *p = cpu_to_be32(arg->seqid->sequence->counter);
1440 hdr->replen += decode_open_confirm_maxsz;
1443 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1447 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1448 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1449 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1450 *p = cpu_to_be32(arg->seqid->sequence->counter);
1451 encode_share_access(xdr, arg->fmode);
1453 hdr->replen += decode_open_downgrade_maxsz;
1457 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1462 p = reserve_space(xdr, 8 + len);
1463 *p++ = cpu_to_be32(OP_PUTFH);
1464 xdr_encode_opaque(p, fh->data, len);
1466 hdr->replen += decode_putfh_maxsz;
1469 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1473 p = reserve_space(xdr, 4);
1474 *p = cpu_to_be32(OP_PUTROOTFH);
1476 hdr->replen += decode_putrootfh_maxsz;
1479 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
1481 nfs4_stateid stateid;
1484 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1485 if (ctx->state != NULL) {
1486 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1488 stateid.stateid.seqid = 0;
1489 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1491 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1494 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1498 p = reserve_space(xdr, 4);
1499 *p = cpu_to_be32(OP_READ);
1501 encode_stateid(xdr, args->context, args->lock_context,
1504 p = reserve_space(xdr, 12);
1505 p = xdr_encode_hyper(p, args->offset);
1506 *p = cpu_to_be32(args->count);
1508 hdr->replen += decode_read_maxsz;
1511 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1513 uint32_t attrs[2] = {
1514 FATTR4_WORD0_RDATTR_ERROR,
1515 FATTR4_WORD1_MOUNTED_ON_FILEID,
1517 uint32_t dircount = readdir->count >> 1;
1520 if (readdir->plus) {
1521 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1522 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1523 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1524 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1525 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1526 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1529 /* Use mounted_on_fileid only if the server supports it */
1530 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1531 attrs[0] |= FATTR4_WORD0_FILEID;
1533 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1534 *p++ = cpu_to_be32(OP_READDIR);
1535 p = xdr_encode_hyper(p, readdir->cookie);
1536 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1537 *p++ = cpu_to_be32(dircount);
1538 *p++ = cpu_to_be32(readdir->count);
1539 *p++ = cpu_to_be32(2);
1541 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1542 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1544 hdr->replen += decode_readdir_maxsz;
1545 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1547 (unsigned long long)readdir->cookie,
1548 ((u32 *)readdir->verifier.data)[0],
1549 ((u32 *)readdir->verifier.data)[1],
1550 attrs[0] & readdir->bitmask[0],
1551 attrs[1] & readdir->bitmask[1]);
1554 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1558 p = reserve_space(xdr, 4);
1559 *p = cpu_to_be32(OP_READLINK);
1561 hdr->replen += decode_readlink_maxsz;
1564 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1568 p = reserve_space(xdr, 8 + name->len);
1569 *p++ = cpu_to_be32(OP_REMOVE);
1570 xdr_encode_opaque(p, name->name, name->len);
1572 hdr->replen += decode_remove_maxsz;
1575 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1579 p = reserve_space(xdr, 4);
1580 *p = cpu_to_be32(OP_RENAME);
1581 encode_string(xdr, oldname->len, oldname->name);
1582 encode_string(xdr, newname->len, newname->name);
1584 hdr->replen += decode_rename_maxsz;
1587 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1591 p = reserve_space(xdr, 12);
1592 *p++ = cpu_to_be32(OP_RENEW);
1593 xdr_encode_hyper(p, client_stateid->cl_clientid);
1595 hdr->replen += decode_renew_maxsz;
1599 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1603 p = reserve_space(xdr, 4);
1604 *p = cpu_to_be32(OP_RESTOREFH);
1606 hdr->replen += decode_restorefh_maxsz;
1610 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1614 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1615 *p++ = cpu_to_be32(OP_SETATTR);
1616 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1617 p = reserve_space(xdr, 2*4);
1618 *p++ = cpu_to_be32(1);
1619 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1620 BUG_ON(arg->acl_len % 4);
1621 p = reserve_space(xdr, 4);
1622 *p = cpu_to_be32(arg->acl_len);
1623 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1625 hdr->replen += decode_setacl_maxsz;
1629 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1633 p = reserve_space(xdr, 4);
1634 *p = cpu_to_be32(OP_SAVEFH);
1636 hdr->replen += decode_savefh_maxsz;
1639 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1643 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1644 *p++ = cpu_to_be32(OP_SETATTR);
1645 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1647 hdr->replen += decode_setattr_maxsz;
1648 encode_attrs(xdr, arg->iap, server);
1651 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1655 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1656 *p++ = cpu_to_be32(OP_SETCLIENTID);
1657 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1659 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1660 p = reserve_space(xdr, 4);
1661 *p = cpu_to_be32(setclientid->sc_prog);
1662 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1663 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1664 p = reserve_space(xdr, 4);
1665 *p = cpu_to_be32(setclientid->sc_cb_ident);
1667 hdr->replen += decode_setclientid_maxsz;
1670 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1674 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1675 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1676 p = xdr_encode_hyper(p, arg->clientid);
1677 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1679 hdr->replen += decode_setclientid_confirm_maxsz;
1682 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1686 p = reserve_space(xdr, 4);
1687 *p = cpu_to_be32(OP_WRITE);
1689 encode_stateid(xdr, args->context, args->lock_context,
1692 p = reserve_space(xdr, 16);
1693 p = xdr_encode_hyper(p, args->offset);
1694 *p++ = cpu_to_be32(args->stable);
1695 *p = cpu_to_be32(args->count);
1697 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1699 hdr->replen += decode_write_maxsz;
1702 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1706 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1708 *p++ = cpu_to_be32(OP_DELEGRETURN);
1709 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1711 hdr->replen += decode_delegreturn_maxsz;
1714 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1716 int len = name->len;
1719 p = reserve_space(xdr, 8 + len);
1720 *p++ = cpu_to_be32(OP_SECINFO);
1721 xdr_encode_opaque(p, name->name, len);
1723 hdr->replen += decode_secinfo_maxsz;
1726 #if defined(CONFIG_NFS_V4_1)
1727 /* NFSv4.1 operations */
1728 static void encode_exchange_id(struct xdr_stream *xdr,
1729 struct nfs41_exchange_id_args *args,
1730 struct compound_hdr *hdr)
1734 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1735 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1736 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1738 encode_string(xdr, args->id_len, args->id);
1740 p = reserve_space(xdr, 12);
1741 *p++ = cpu_to_be32(args->flags);
1742 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1743 *p = cpu_to_be32(0); /* zero length implementation id array */
1745 hdr->replen += decode_exchange_id_maxsz;
1748 static void encode_create_session(struct xdr_stream *xdr,
1749 struct nfs41_create_session_args *args,
1750 struct compound_hdr *hdr)
1753 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1755 struct nfs_client *clp = args->client;
1756 u32 max_resp_sz_cached;
1759 * Assumes OPEN is the biggest non-idempotent compound.
1760 * 2 is the verifier.
1762 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1763 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1765 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1768 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1769 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1770 p = xdr_encode_hyper(p, clp->cl_clientid);
1771 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1772 *p++ = cpu_to_be32(args->flags); /*flags */
1775 *p++ = cpu_to_be32(0); /* header padding size */
1776 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1777 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1778 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1779 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1780 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1781 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1784 *p++ = cpu_to_be32(0); /* header padding size */
1785 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1786 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1787 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1788 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1789 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1790 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1792 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1793 *p++ = cpu_to_be32(1);
1794 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1796 /* authsys_parms rfc1831 */
1797 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1798 p = xdr_encode_opaque(p, machine_name, len);
1799 *p++ = cpu_to_be32(0); /* UID */
1800 *p++ = cpu_to_be32(0); /* GID */
1801 *p = cpu_to_be32(0); /* No more gids */
1803 hdr->replen += decode_create_session_maxsz;
1806 static void encode_destroy_session(struct xdr_stream *xdr,
1807 struct nfs4_session *session,
1808 struct compound_hdr *hdr)
1811 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1812 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1813 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1815 hdr->replen += decode_destroy_session_maxsz;
1818 static void encode_reclaim_complete(struct xdr_stream *xdr,
1819 struct nfs41_reclaim_complete_args *args,
1820 struct compound_hdr *hdr)
1824 p = reserve_space(xdr, 8);
1825 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1826 *p++ = cpu_to_be32(args->one_fs);
1828 hdr->replen += decode_reclaim_complete_maxsz;
1830 #endif /* CONFIG_NFS_V4_1 */
1832 static void encode_sequence(struct xdr_stream *xdr,
1833 const struct nfs4_sequence_args *args,
1834 struct compound_hdr *hdr)
1836 #if defined(CONFIG_NFS_V4_1)
1837 struct nfs4_session *session = args->sa_session;
1838 struct nfs4_slot_table *tp;
1839 struct nfs4_slot *slot;
1845 tp = &session->fc_slot_table;
1847 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1848 slot = tp->slots + args->sa_slotid;
1850 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1851 *p++ = cpu_to_be32(OP_SEQUENCE);
1854 * Sessionid + seqid + slotid + max slotid + cache_this
1856 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1857 "max_slotid=%d cache_this=%d\n",
1859 ((u32 *)session->sess_id.data)[0],
1860 ((u32 *)session->sess_id.data)[1],
1861 ((u32 *)session->sess_id.data)[2],
1862 ((u32 *)session->sess_id.data)[3],
1863 slot->seq_nr, args->sa_slotid,
1864 tp->highest_used_slotid, args->sa_cache_this);
1865 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1866 *p++ = cpu_to_be32(slot->seq_nr);
1867 *p++ = cpu_to_be32(args->sa_slotid);
1868 *p++ = cpu_to_be32(tp->highest_used_slotid);
1869 *p = cpu_to_be32(args->sa_cache_this);
1871 hdr->replen += decode_sequence_maxsz;
1872 #endif /* CONFIG_NFS_V4_1 */
1875 #ifdef CONFIG_NFS_V4_1
1877 encode_getdevicelist(struct xdr_stream *xdr,
1878 const struct nfs4_getdevicelist_args *args,
1879 struct compound_hdr *hdr)
1882 nfs4_verifier dummy = {
1886 p = reserve_space(xdr, 20);
1887 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1888 *p++ = cpu_to_be32(args->layoutclass);
1889 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1890 xdr_encode_hyper(p, 0ULL); /* cookie */
1891 encode_nfs4_verifier(xdr, &dummy);
1893 hdr->replen += decode_getdevicelist_maxsz;
1897 encode_getdeviceinfo(struct xdr_stream *xdr,
1898 const struct nfs4_getdeviceinfo_args *args,
1899 struct compound_hdr *hdr)
1903 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1904 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1905 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1906 NFS4_DEVICEID4_SIZE);
1907 *p++ = cpu_to_be32(args->pdev->layout_type);
1908 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1909 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1911 hdr->replen += decode_getdeviceinfo_maxsz;
1915 encode_layoutget(struct xdr_stream *xdr,
1916 const struct nfs4_layoutget_args *args,
1917 struct compound_hdr *hdr)
1921 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1922 *p++ = cpu_to_be32(OP_LAYOUTGET);
1923 *p++ = cpu_to_be32(0); /* Signal layout available */
1924 *p++ = cpu_to_be32(args->type);
1925 *p++ = cpu_to_be32(args->range.iomode);
1926 p = xdr_encode_hyper(p, args->range.offset);
1927 p = xdr_encode_hyper(p, args->range.length);
1928 p = xdr_encode_hyper(p, args->minlength);
1929 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1930 *p = cpu_to_be32(args->maxcount);
1932 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1936 (unsigned long)args->range.offset,
1937 (unsigned long)args->range.length,
1940 hdr->replen += decode_layoutget_maxsz;
1944 encode_layoutcommit(struct xdr_stream *xdr,
1945 struct inode *inode,
1946 const struct nfs4_layoutcommit_args *args,
1947 struct compound_hdr *hdr)
1951 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1952 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1954 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1955 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1956 /* Only whole file layouts */
1957 p = xdr_encode_hyper(p, 0); /* offset */
1958 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1959 *p++ = cpu_to_be32(0); /* reclaim */
1960 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1961 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1962 p = xdr_encode_hyper(p, args->lastbytewritten);
1963 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1964 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1966 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1967 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1968 NFS_I(inode)->layout, xdr, args);
1970 p = reserve_space(xdr, 4);
1971 *p = cpu_to_be32(0); /* no layout-type payload */
1975 hdr->replen += decode_layoutcommit_maxsz;
1980 encode_layoutreturn(struct xdr_stream *xdr,
1981 const struct nfs4_layoutreturn_args *args,
1982 struct compound_hdr *hdr)
1986 p = reserve_space(xdr, 20);
1987 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1988 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1989 *p++ = cpu_to_be32(args->layout_type);
1990 *p++ = cpu_to_be32(IOMODE_ANY);
1991 *p = cpu_to_be32(RETURN_FILE);
1992 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1993 p = xdr_encode_hyper(p, 0);
1994 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1995 spin_lock(&args->inode->i_lock);
1996 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1997 spin_unlock(&args->inode->i_lock);
1998 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1999 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2000 NFS_I(args->inode)->layout, xdr, args);
2002 p = reserve_space(xdr, 4);
2003 *p = cpu_to_be32(0);
2006 hdr->replen += decode_layoutreturn_maxsz;
2010 encode_secinfo_no_name(struct xdr_stream *xdr,
2011 const struct nfs41_secinfo_no_name_args *args,
2012 struct compound_hdr *hdr)
2015 p = reserve_space(xdr, 8);
2016 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2017 *p++ = cpu_to_be32(args->style);
2019 hdr->replen += decode_secinfo_no_name_maxsz;
2023 static void encode_test_stateid(struct xdr_stream *xdr,
2024 struct nfs41_test_stateid_args *args,
2025 struct compound_hdr *hdr)
2029 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2030 *p++ = cpu_to_be32(OP_TEST_STATEID);
2031 *p++ = cpu_to_be32(1);
2032 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2034 hdr->replen += decode_test_stateid_maxsz;
2037 static void encode_free_stateid(struct xdr_stream *xdr,
2038 struct nfs41_free_stateid_args *args,
2039 struct compound_hdr *hdr)
2042 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2043 *p++ = cpu_to_be32(OP_FREE_STATEID);
2044 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2046 hdr->replen += decode_free_stateid_maxsz;
2048 #endif /* CONFIG_NFS_V4_1 */
2051 * END OF "GENERIC" ENCODE ROUTINES.
2054 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2056 #if defined(CONFIG_NFS_V4_1)
2057 if (args->sa_session)
2058 return args->sa_session->clp->cl_mvops->minor_version;
2059 #endif /* CONFIG_NFS_V4_1 */
2064 * Encode an ACCESS request
2066 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2067 const struct nfs4_accessargs *args)
2069 struct compound_hdr hdr = {
2070 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2073 encode_compound_hdr(xdr, req, &hdr);
2074 encode_sequence(xdr, &args->seq_args, &hdr);
2075 encode_putfh(xdr, args->fh, &hdr);
2076 encode_access(xdr, args->access, &hdr);
2077 encode_getfattr(xdr, args->bitmask, &hdr);
2082 * Encode LOOKUP request
2084 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2085 const struct nfs4_lookup_arg *args)
2087 struct compound_hdr hdr = {
2088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2091 encode_compound_hdr(xdr, req, &hdr);
2092 encode_sequence(xdr, &args->seq_args, &hdr);
2093 encode_putfh(xdr, args->dir_fh, &hdr);
2094 encode_lookup(xdr, args->name, &hdr);
2095 encode_getfh(xdr, &hdr);
2096 encode_getfattr(xdr, args->bitmask, &hdr);
2101 * Encode LOOKUP_ROOT request
2103 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2104 struct xdr_stream *xdr,
2105 const struct nfs4_lookup_root_arg *args)
2107 struct compound_hdr hdr = {
2108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putrootfh(xdr, &hdr);
2114 encode_getfh(xdr, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
2120 * Encode REMOVE request
2122 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2123 const struct nfs_removeargs *args)
2125 struct compound_hdr hdr = {
2126 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2129 encode_compound_hdr(xdr, req, &hdr);
2130 encode_sequence(xdr, &args->seq_args, &hdr);
2131 encode_putfh(xdr, args->fh, &hdr);
2132 encode_remove(xdr, &args->name, &hdr);
2133 encode_getfattr(xdr, args->bitmask, &hdr);
2138 * Encode RENAME request
2140 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2141 const struct nfs_renameargs *args)
2143 struct compound_hdr hdr = {
2144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2147 encode_compound_hdr(xdr, req, &hdr);
2148 encode_sequence(xdr, &args->seq_args, &hdr);
2149 encode_putfh(xdr, args->old_dir, &hdr);
2150 encode_savefh(xdr, &hdr);
2151 encode_putfh(xdr, args->new_dir, &hdr);
2152 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2153 encode_getfattr(xdr, args->bitmask, &hdr);
2154 encode_restorefh(xdr, &hdr);
2155 encode_getfattr(xdr, args->bitmask, &hdr);
2160 * Encode LINK request
2162 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2163 const struct nfs4_link_arg *args)
2165 struct compound_hdr hdr = {
2166 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2169 encode_compound_hdr(xdr, req, &hdr);
2170 encode_sequence(xdr, &args->seq_args, &hdr);
2171 encode_putfh(xdr, args->fh, &hdr);
2172 encode_savefh(xdr, &hdr);
2173 encode_putfh(xdr, args->dir_fh, &hdr);
2174 encode_link(xdr, args->name, &hdr);
2175 encode_getfattr(xdr, args->bitmask, &hdr);
2176 encode_restorefh(xdr, &hdr);
2177 encode_getfattr(xdr, args->bitmask, &hdr);
2182 * Encode CREATE request
2184 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2185 const struct nfs4_create_arg *args)
2187 struct compound_hdr hdr = {
2188 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2191 encode_compound_hdr(xdr, req, &hdr);
2192 encode_sequence(xdr, &args->seq_args, &hdr);
2193 encode_putfh(xdr, args->dir_fh, &hdr);
2194 encode_savefh(xdr, &hdr);
2195 encode_create(xdr, args, &hdr);
2196 encode_getfh(xdr, &hdr);
2197 encode_getfattr(xdr, args->bitmask, &hdr);
2198 encode_restorefh(xdr, &hdr);
2199 encode_getfattr(xdr, args->bitmask, &hdr);
2204 * Encode SYMLINK request
2206 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_create_arg *args)
2209 nfs4_xdr_enc_create(req, xdr, args);
2213 * Encode GETATTR request
2215 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2216 const struct nfs4_getattr_arg *args)
2218 struct compound_hdr hdr = {
2219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->fh, &hdr);
2225 encode_getfattr(xdr, args->bitmask, &hdr);
2230 * Encode a CLOSE request
2232 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2233 struct nfs_closeargs *args)
2235 struct compound_hdr hdr = {
2236 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2239 encode_compound_hdr(xdr, req, &hdr);
2240 encode_sequence(xdr, &args->seq_args, &hdr);
2241 encode_putfh(xdr, args->fh, &hdr);
2242 encode_close(xdr, args, &hdr);
2243 encode_getfattr(xdr, args->bitmask, &hdr);
2248 * Encode an OPEN request
2250 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2251 struct nfs_openargs *args)
2253 struct compound_hdr hdr = {
2254 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2257 encode_compound_hdr(xdr, req, &hdr);
2258 encode_sequence(xdr, &args->seq_args, &hdr);
2259 encode_putfh(xdr, args->fh, &hdr);
2260 encode_savefh(xdr, &hdr);
2261 encode_open(xdr, args, &hdr);
2262 encode_getfh(xdr, &hdr);
2263 encode_getfattr(xdr, args->bitmask, &hdr);
2264 encode_restorefh(xdr, &hdr);
2265 encode_getfattr(xdr, args->bitmask, &hdr);
2270 * Encode an OPEN_CONFIRM request
2272 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2273 struct xdr_stream *xdr,
2274 struct nfs_open_confirmargs *args)
2276 struct compound_hdr hdr = {
2280 encode_compound_hdr(xdr, req, &hdr);
2281 encode_putfh(xdr, args->fh, &hdr);
2282 encode_open_confirm(xdr, args, &hdr);
2287 * Encode an OPEN request with no attributes.
2289 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2290 struct xdr_stream *xdr,
2291 struct nfs_openargs *args)
2293 struct compound_hdr hdr = {
2294 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2297 encode_compound_hdr(xdr, req, &hdr);
2298 encode_sequence(xdr, &args->seq_args, &hdr);
2299 encode_putfh(xdr, args->fh, &hdr);
2300 encode_open(xdr, args, &hdr);
2301 encode_getfattr(xdr, args->bitmask, &hdr);
2306 * Encode an OPEN_DOWNGRADE request
2308 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2309 struct xdr_stream *xdr,
2310 struct nfs_closeargs *args)
2312 struct compound_hdr hdr = {
2313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_open_downgrade(xdr, args, &hdr);
2320 encode_getfattr(xdr, args->bitmask, &hdr);
2325 * Encode a LOCK request
2327 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_lock_args *args)
2330 struct compound_hdr hdr = {
2331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_lock(xdr, args, &hdr);
2342 * Encode a LOCKT request
2344 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2345 struct nfs_lockt_args *args)
2347 struct compound_hdr hdr = {
2348 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2351 encode_compound_hdr(xdr, req, &hdr);
2352 encode_sequence(xdr, &args->seq_args, &hdr);
2353 encode_putfh(xdr, args->fh, &hdr);
2354 encode_lockt(xdr, args, &hdr);
2359 * Encode a LOCKU request
2361 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2362 struct nfs_locku_args *args)
2364 struct compound_hdr hdr = {
2365 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2368 encode_compound_hdr(xdr, req, &hdr);
2369 encode_sequence(xdr, &args->seq_args, &hdr);
2370 encode_putfh(xdr, args->fh, &hdr);
2371 encode_locku(xdr, args, &hdr);
2375 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2376 struct xdr_stream *xdr,
2377 struct nfs_release_lockowner_args *args)
2379 struct compound_hdr hdr = {
2383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2389 * Encode a READLINK request
2391 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2392 const struct nfs4_readlink *args)
2394 struct compound_hdr hdr = {
2395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
2401 encode_readlink(xdr, args, req, &hdr);
2403 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2404 args->pgbase, args->pglen);
2409 * Encode a READDIR request
2411 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 const struct nfs4_readdir_arg *args)
2414 struct compound_hdr hdr = {
2415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_sequence(xdr, &args->seq_args, &hdr);
2420 encode_putfh(xdr, args->fh, &hdr);
2421 encode_readdir(xdr, args, req, &hdr);
2423 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2424 args->pgbase, args->count);
2425 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2426 __func__, hdr.replen << 2, args->pages,
2427 args->pgbase, args->count);
2432 * Encode a READ request
2434 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2435 struct nfs_readargs *args)
2437 struct compound_hdr hdr = {
2438 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_sequence(xdr, &args->seq_args, &hdr);
2443 encode_putfh(xdr, args->fh, &hdr);
2444 encode_read(xdr, args, &hdr);
2446 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2447 args->pages, args->pgbase, args->count);
2448 req->rq_rcv_buf.flags |= XDRBUF_READ;
2453 * Encode an SETATTR request
2455 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2456 struct nfs_setattrargs *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_setattr(xdr, args, args->server, &hdr);
2466 encode_getfattr(xdr, args->bitmask, &hdr);
2471 * Encode a GETACL request
2473 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2474 struct nfs_getaclargs *args)
2476 struct compound_hdr hdr = {
2477 .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 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2485 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2487 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2488 args->acl_pages, args->acl_pgbase, args->acl_len);
2493 * Encode a WRITE request
2495 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2496 struct nfs_writeargs *args)
2498 struct compound_hdr hdr = {
2499 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2502 encode_compound_hdr(xdr, req, &hdr);
2503 encode_sequence(xdr, &args->seq_args, &hdr);
2504 encode_putfh(xdr, args->fh, &hdr);
2505 encode_write(xdr, args, &hdr);
2506 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2508 encode_getfattr(xdr, args->bitmask, &hdr);
2515 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 struct nfs_writeargs *args)
2518 struct compound_hdr hdr = {
2519 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, &args->seq_args, &hdr);
2524 encode_putfh(xdr, args->fh, &hdr);
2525 encode_commit(xdr, args, &hdr);
2527 encode_getfattr(xdr, args->bitmask, &hdr);
2534 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2535 struct nfs4_fsinfo_arg *args)
2537 struct compound_hdr hdr = {
2538 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2541 encode_compound_hdr(xdr, req, &hdr);
2542 encode_sequence(xdr, &args->seq_args, &hdr);
2543 encode_putfh(xdr, args->fh, &hdr);
2544 encode_fsinfo(xdr, args->bitmask, &hdr);
2549 * a PATHCONF request
2551 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2552 const struct nfs4_pathconf_arg *args)
2554 struct compound_hdr hdr = {
2555 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_sequence(xdr, &args->seq_args, &hdr);
2560 encode_putfh(xdr, args->fh, &hdr);
2561 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2569 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2570 const struct nfs4_statfs_arg *args)
2572 struct compound_hdr hdr = {
2573 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2576 encode_compound_hdr(xdr, req, &hdr);
2577 encode_sequence(xdr, &args->seq_args, &hdr);
2578 encode_putfh(xdr, args->fh, &hdr);
2579 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2580 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2585 * GETATTR_BITMAP request
2587 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2588 struct xdr_stream *xdr,
2589 struct nfs4_server_caps_arg *args)
2591 struct compound_hdr hdr = {
2592 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2595 encode_compound_hdr(xdr, req, &hdr);
2596 encode_sequence(xdr, &args->seq_args, &hdr);
2597 encode_putfh(xdr, args->fhandle, &hdr);
2598 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2599 FATTR4_WORD0_LINK_SUPPORT|
2600 FATTR4_WORD0_SYMLINK_SUPPORT|
2601 FATTR4_WORD0_ACLSUPPORT, &hdr);
2608 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2609 struct nfs_client *clp)
2611 struct compound_hdr hdr = {
2615 encode_compound_hdr(xdr, req, &hdr);
2616 encode_renew(xdr, clp, &hdr);
2621 * a SETCLIENTID request
2623 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs4_setclientid *sc)
2627 struct compound_hdr hdr = {
2631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_setclientid(xdr, sc, &hdr);
2637 * a SETCLIENTID_CONFIRM request
2639 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2640 struct xdr_stream *xdr,
2641 struct nfs4_setclientid_res *arg)
2643 struct compound_hdr hdr = {
2646 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2648 encode_compound_hdr(xdr, req, &hdr);
2649 encode_setclientid_confirm(xdr, arg, &hdr);
2650 encode_putrootfh(xdr, &hdr);
2651 encode_fsinfo(xdr, lease_bitmap, &hdr);
2656 * DELEGRETURN request
2658 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2659 struct xdr_stream *xdr,
2660 const struct nfs4_delegreturnargs *args)
2662 struct compound_hdr hdr = {
2663 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2666 encode_compound_hdr(xdr, req, &hdr);
2667 encode_sequence(xdr, &args->seq_args, &hdr);
2668 encode_putfh(xdr, args->fhandle, &hdr);
2669 encode_delegreturn(xdr, args->stateid, &hdr);
2670 encode_getfattr(xdr, args->bitmask, &hdr);
2675 * Encode FS_LOCATIONS request
2677 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2678 struct xdr_stream *xdr,
2679 struct nfs4_fs_locations_arg *args)
2681 struct compound_hdr hdr = {
2682 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2686 encode_compound_hdr(xdr, req, &hdr);
2687 encode_sequence(xdr, &args->seq_args, &hdr);
2688 encode_putfh(xdr, args->dir_fh, &hdr);
2689 encode_lookup(xdr, args->name, &hdr);
2690 replen = hdr.replen; /* get the attribute into args->page */
2691 encode_fs_locations(xdr, args->bitmask, &hdr);
2693 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2699 * Encode SECINFO request
2701 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2702 struct xdr_stream *xdr,
2703 struct nfs4_secinfo_arg *args)
2705 struct compound_hdr hdr = {
2706 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2709 encode_compound_hdr(xdr, req, &hdr);
2710 encode_sequence(xdr, &args->seq_args, &hdr);
2711 encode_putfh(xdr, args->dir_fh, &hdr);
2712 encode_secinfo(xdr, args->name, &hdr);
2716 #if defined(CONFIG_NFS_V4_1)
2718 * EXCHANGE_ID request
2720 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2721 struct xdr_stream *xdr,
2722 struct nfs41_exchange_id_args *args)
2724 struct compound_hdr hdr = {
2725 .minorversion = args->client->cl_mvops->minor_version,
2728 encode_compound_hdr(xdr, req, &hdr);
2729 encode_exchange_id(xdr, args, &hdr);
2734 * a CREATE_SESSION request
2736 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2737 struct xdr_stream *xdr,
2738 struct nfs41_create_session_args *args)
2740 struct compound_hdr hdr = {
2741 .minorversion = args->client->cl_mvops->minor_version,
2744 encode_compound_hdr(xdr, req, &hdr);
2745 encode_create_session(xdr, args, &hdr);
2750 * a DESTROY_SESSION request
2752 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2753 struct xdr_stream *xdr,
2754 struct nfs4_session *session)
2756 struct compound_hdr hdr = {
2757 .minorversion = session->clp->cl_mvops->minor_version,
2760 encode_compound_hdr(xdr, req, &hdr);
2761 encode_destroy_session(xdr, session, &hdr);
2766 * a SEQUENCE request
2768 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2769 struct nfs4_sequence_args *args)
2771 struct compound_hdr hdr = {
2772 .minorversion = nfs4_xdr_minorversion(args),
2775 encode_compound_hdr(xdr, req, &hdr);
2776 encode_sequence(xdr, args, &hdr);
2781 * a GET_LEASE_TIME request
2783 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2784 struct xdr_stream *xdr,
2785 struct nfs4_get_lease_time_args *args)
2787 struct compound_hdr hdr = {
2788 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2790 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2792 encode_compound_hdr(xdr, req, &hdr);
2793 encode_sequence(xdr, &args->la_seq_args, &hdr);
2794 encode_putrootfh(xdr, &hdr);
2795 encode_fsinfo(xdr, lease_bitmap, &hdr);
2800 * a RECLAIM_COMPLETE request
2802 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
2804 struct nfs41_reclaim_complete_args *args)
2806 struct compound_hdr hdr = {
2807 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_sequence(xdr, &args->seq_args, &hdr);
2812 encode_reclaim_complete(xdr, args, &hdr);
2817 * Encode GETDEVICELIST request
2819 static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2820 struct xdr_stream *xdr,
2821 struct nfs4_getdevicelist_args *args)
2823 struct compound_hdr hdr = {
2824 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2827 encode_compound_hdr(xdr, req, &hdr);
2828 encode_sequence(xdr, &args->seq_args, &hdr);
2829 encode_putfh(xdr, args->fh, &hdr);
2830 encode_getdevicelist(xdr, args, &hdr);
2835 * Encode GETDEVICEINFO request
2837 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2838 struct xdr_stream *xdr,
2839 struct nfs4_getdeviceinfo_args *args)
2841 struct compound_hdr hdr = {
2842 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2845 encode_compound_hdr(xdr, req, &hdr);
2846 encode_sequence(xdr, &args->seq_args, &hdr);
2847 encode_getdeviceinfo(xdr, args, &hdr);
2849 /* set up reply kvec. Subtract notification bitmap max size (2)
2850 * so that notification bitmap is put in xdr_buf tail */
2851 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2852 args->pdev->pages, args->pdev->pgbase,
2859 * Encode LAYOUTGET request
2861 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
2863 struct nfs4_layoutget_args *args)
2865 struct compound_hdr hdr = {
2866 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2869 encode_compound_hdr(xdr, req, &hdr);
2870 encode_sequence(xdr, &args->seq_args, &hdr);
2871 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2872 encode_layoutget(xdr, args, &hdr);
2874 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2875 args->layout.pages, 0, args->layout.pglen);
2881 * Encode LAYOUTCOMMIT request
2883 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2884 struct xdr_stream *xdr,
2885 struct nfs4_layoutcommit_args *args)
2887 struct nfs4_layoutcommit_data *data =
2888 container_of(args, struct nfs4_layoutcommit_data, args);
2889 struct compound_hdr hdr = {
2890 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2893 encode_compound_hdr(xdr, req, &hdr);
2894 encode_sequence(xdr, &args->seq_args, &hdr);
2895 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2896 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2897 encode_getfattr(xdr, args->bitmask, &hdr);
2902 * Encode LAYOUTRETURN request
2904 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2905 struct xdr_stream *xdr,
2906 struct nfs4_layoutreturn_args *args)
2908 struct compound_hdr hdr = {
2909 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2912 encode_compound_hdr(xdr, req, &hdr);
2913 encode_sequence(xdr, &args->seq_args, &hdr);
2914 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2915 encode_layoutreturn(xdr, args, &hdr);
2920 * Encode SECINFO_NO_NAME request
2922 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2923 struct xdr_stream *xdr,
2924 struct nfs41_secinfo_no_name_args *args)
2926 struct compound_hdr hdr = {
2927 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2930 encode_compound_hdr(xdr, req, &hdr);
2931 encode_sequence(xdr, &args->seq_args, &hdr);
2932 encode_putrootfh(xdr, &hdr);
2933 encode_secinfo_no_name(xdr, args, &hdr);
2939 * Encode TEST_STATEID request
2941 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2942 struct xdr_stream *xdr,
2943 struct nfs41_test_stateid_args *args)
2945 struct compound_hdr hdr = {
2946 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2949 encode_compound_hdr(xdr, req, &hdr);
2950 encode_sequence(xdr, &args->seq_args, &hdr);
2951 encode_test_stateid(xdr, args, &hdr);
2956 * Encode FREE_STATEID request
2958 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2959 struct xdr_stream *xdr,
2960 struct nfs41_free_stateid_args *args)
2962 struct compound_hdr hdr = {
2963 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2966 encode_compound_hdr(xdr, req, &hdr);
2967 encode_sequence(xdr, &args->seq_args, &hdr);
2968 encode_free_stateid(xdr, args, &hdr);
2971 #endif /* CONFIG_NFS_V4_1 */
2973 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2975 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2976 "Remaining buffer length is %tu words.\n",
2977 func, xdr->end - xdr->p);
2980 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2984 p = xdr_inline_decode(xdr, 4);
2987 *len = be32_to_cpup(p);
2988 p = xdr_inline_decode(xdr, *len);
2991 *string = (char *)p;
2994 print_overflow_msg(__func__, xdr);
2998 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3002 p = xdr_inline_decode(xdr, 8);
3005 hdr->status = be32_to_cpup(p++);
3006 hdr->taglen = be32_to_cpup(p);
3008 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3011 hdr->tag = (char *)p;
3012 p += XDR_QUADLEN(hdr->taglen);
3013 hdr->nops = be32_to_cpup(p);
3014 if (unlikely(hdr->nops < 1))
3015 return nfs4_stat_to_errno(hdr->status);
3018 print_overflow_msg(__func__, xdr);
3022 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3028 p = xdr_inline_decode(xdr, 8);
3031 opnum = be32_to_cpup(p++);
3032 if (opnum != expected) {
3033 dprintk("nfs: Server returned operation"
3034 " %d but we issued a request for %d\n",
3038 nfserr = be32_to_cpup(p);
3039 if (nfserr != NFS_OK)
3040 return nfs4_stat_to_errno(nfserr);
3043 print_overflow_msg(__func__, xdr);
3048 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3051 unsigned int strlen;
3054 p = xdr_inline_decode(xdr, 12);
3056 return decode_opaque_inline(xdr, &strlen, &str);
3057 print_overflow_msg(__func__, xdr);
3061 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3066 p = xdr_inline_decode(xdr, 4);
3069 bmlen = be32_to_cpup(p);
3071 bitmap[0] = bitmap[1] = 0;
3072 p = xdr_inline_decode(xdr, (bmlen << 2));
3076 bitmap[0] = be32_to_cpup(p++);
3078 bitmap[1] = be32_to_cpup(p);
3082 print_overflow_msg(__func__, xdr);
3086 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
3090 p = xdr_inline_decode(xdr, 4);
3093 *attrlen = be32_to_cpup(p);
3097 print_overflow_msg(__func__, xdr);
3101 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3103 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3105 ret = decode_attr_bitmap(xdr, bitmask);
3106 if (unlikely(ret < 0))
3108 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3110 bitmask[0] = bitmask[1] = 0;
3111 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
3115 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3121 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3123 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3124 p = xdr_inline_decode(xdr, 4);
3127 *type = be32_to_cpup(p);
3128 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3129 dprintk("%s: bad type %d\n", __func__, *type);
3132 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3133 ret = NFS_ATTR_FATTR_TYPE;
3135 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3138 print_overflow_msg(__func__, xdr);
3142 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3148 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3150 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3151 p = xdr_inline_decode(xdr, 8);
3154 xdr_decode_hyper(p, change);
3155 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3156 ret = NFS_ATTR_FATTR_CHANGE;
3158 dprintk("%s: change attribute=%Lu\n", __func__,
3159 (unsigned long long)*change);
3162 print_overflow_msg(__func__, xdr);
3166 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3172 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3174 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3175 p = xdr_inline_decode(xdr, 8);
3178 xdr_decode_hyper(p, size);
3179 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3180 ret = NFS_ATTR_FATTR_SIZE;
3182 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3185 print_overflow_msg(__func__, xdr);
3189 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3194 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3196 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3197 p = xdr_inline_decode(xdr, 4);
3200 *res = be32_to_cpup(p);
3201 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3203 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3206 print_overflow_msg(__func__, xdr);
3210 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3215 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3217 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3218 p = xdr_inline_decode(xdr, 4);
3221 *res = be32_to_cpup(p);
3222 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3224 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3227 print_overflow_msg(__func__, xdr);
3231 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3238 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3240 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3241 p = xdr_inline_decode(xdr, 16);
3244 p = xdr_decode_hyper(p, &fsid->major);
3245 xdr_decode_hyper(p, &fsid->minor);
3246 bitmap[0] &= ~FATTR4_WORD0_FSID;
3247 ret = NFS_ATTR_FATTR_FSID;
3249 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3250 (unsigned long long)fsid->major,
3251 (unsigned long long)fsid->minor);
3254 print_overflow_msg(__func__, xdr);
3258 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3263 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3265 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3266 p = xdr_inline_decode(xdr, 4);
3269 *res = be32_to_cpup(p);
3270 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3272 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3275 print_overflow_msg(__func__, xdr);
3279 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3283 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3285 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3286 p = xdr_inline_decode(xdr, 4);
3289 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3290 *res = -be32_to_cpup(p);
3294 print_overflow_msg(__func__, xdr);
3298 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3304 memset(fh, 0, sizeof(*fh));
3306 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3308 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3309 p = xdr_inline_decode(xdr, 4);
3312 len = be32_to_cpup(p);
3313 if (len > NFS4_FHSIZE)
3315 p = xdr_inline_decode(xdr, len);
3319 memcpy(fh->data, p, len);
3322 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3326 print_overflow_msg(__func__, xdr);
3330 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3334 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3335 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3337 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3338 p = xdr_inline_decode(xdr, 4);
3341 *res = be32_to_cpup(p);
3342 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3344 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3347 print_overflow_msg(__func__, xdr);
3351 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3357 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3359 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3360 p = xdr_inline_decode(xdr, 8);
3363 xdr_decode_hyper(p, fileid);
3364 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3365 ret = NFS_ATTR_FATTR_FILEID;
3367 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3370 print_overflow_msg(__func__, xdr);
3374 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3380 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3382 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3383 p = xdr_inline_decode(xdr, 8);
3386 xdr_decode_hyper(p, fileid);
3387 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3388 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3390 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3393 print_overflow_msg(__func__, xdr);
3397 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3403 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3405 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3406 p = xdr_inline_decode(xdr, 8);
3409 xdr_decode_hyper(p, res);
3410 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3412 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3415 print_overflow_msg(__func__, xdr);
3419 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3425 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3427 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3428 p = xdr_inline_decode(xdr, 8);
3431 xdr_decode_hyper(p, res);
3432 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3434 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3437 print_overflow_msg(__func__, xdr);
3441 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3447 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3449 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3450 p = xdr_inline_decode(xdr, 8);
3453 xdr_decode_hyper(p, res);
3454 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3456 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3459 print_overflow_msg(__func__, xdr);
3463 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3469 p = xdr_inline_decode(xdr, 4);
3472 n = be32_to_cpup(p);
3476 path->ncomponents = 0;
3477 while (path->ncomponents < n) {
3478 struct nfs4_string *component = &path->components[path->ncomponents];
3479 status = decode_opaque_inline(xdr, &component->len, &component->data);
3480 if (unlikely(status != 0))
3482 if (path->ncomponents != n)
3484 dprintk("%s", component->data);
3485 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3486 path->ncomponents++;
3488 dprintk("cannot parse %d components in path\n", n);
3496 /* a root pathname is sent as a zero component4 */
3497 path->ncomponents = 1;
3498 path->components[0].len=0;
3499 path->components[0].data=NULL;
3500 dprintk("path /\n");
3503 dprintk(" status %d", status);
3507 print_overflow_msg(__func__, xdr);
3511 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3517 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3520 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3522 dprintk("%s: fsroot ", __func__);
3523 status = decode_pathname(xdr, &res->fs_path);
3524 if (unlikely(status != 0))
3526 p = xdr_inline_decode(xdr, 4);
3529 n = be32_to_cpup(p);
3532 res->nlocations = 0;
3533 while (res->nlocations < n) {
3535 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3537 p = xdr_inline_decode(xdr, 4);
3540 m = be32_to_cpup(p);
3543 dprintk("%s: servers ", __func__);
3544 while (loc->nservers < m) {
3545 struct nfs4_string *server = &loc->servers[loc->nservers];
3546 status = decode_opaque_inline(xdr, &server->len, &server->data);
3547 if (unlikely(status != 0))
3549 dprintk("%s ", server->data);
3550 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3554 dprintk("%s: using first %u of %u servers "
3555 "returned for location %u\n",
3557 NFS4_FS_LOCATION_MAXSERVERS,
3558 m, res->nlocations);
3559 for (i = loc->nservers; i < m; i++) {
3562 status = decode_opaque_inline(xdr, &len, &data);
3563 if (unlikely(status != 0))
3568 status = decode_pathname(xdr, &loc->rootpath);
3569 if (unlikely(status != 0))
3571 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3574 if (res->nlocations != 0)
3575 status = NFS_ATTR_FATTR_V4_REFERRAL;
3577 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3580 print_overflow_msg(__func__, xdr);
3586 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3592 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3594 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3595 p = xdr_inline_decode(xdr, 8);
3598 xdr_decode_hyper(p, res);
3599 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3601 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3604 print_overflow_msg(__func__, xdr);
3608 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3614 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3616 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3617 p = xdr_inline_decode(xdr, 4);
3620 *maxlink = be32_to_cpup(p);
3621 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3623 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3626 print_overflow_msg(__func__, xdr);
3630 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3636 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3638 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3639 p = xdr_inline_decode(xdr, 4);
3642 *maxname = be32_to_cpup(p);
3643 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3645 dprintk("%s: maxname=%u\n", __func__, *maxname);
3648 print_overflow_msg(__func__, xdr);
3652 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3658 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3660 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3662 p = xdr_inline_decode(xdr, 8);
3665 xdr_decode_hyper(p, &maxread);
3666 if (maxread > 0x7FFFFFFF)
3667 maxread = 0x7FFFFFFF;
3668 *res = (uint32_t)maxread;
3669 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3671 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3674 print_overflow_msg(__func__, xdr);
3678 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3684 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3686 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3688 p = xdr_inline_decode(xdr, 8);
3691 xdr_decode_hyper(p, &maxwrite);
3692 if (maxwrite > 0x7FFFFFFF)
3693 maxwrite = 0x7FFFFFFF;
3694 *res = (uint32_t)maxwrite;
3695 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3697 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3700 print_overflow_msg(__func__, xdr);
3704 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3711 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3713 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3714 p = xdr_inline_decode(xdr, 4);
3717 tmp = be32_to_cpup(p);
3718 *mode = tmp & ~S_IFMT;
3719 bitmap[1] &= ~FATTR4_WORD1_MODE;
3720 ret = NFS_ATTR_FATTR_MODE;
3722 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3725 print_overflow_msg(__func__, xdr);
3729 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3735 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3737 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3738 p = xdr_inline_decode(xdr, 4);
3741 *nlink = be32_to_cpup(p);
3742 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3743 ret = NFS_ATTR_FATTR_NLINK;
3745 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3748 print_overflow_msg(__func__, xdr);
3752 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3753 const struct nfs_server *server, uint32_t *uid, int may_sleep)
3760 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3762 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3763 p = xdr_inline_decode(xdr, 4);
3766 len = be32_to_cpup(p);
3767 p = xdr_inline_decode(xdr, len);
3772 } else if (len < XDR_MAX_NETOBJ) {
3773 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3774 ret = NFS_ATTR_FATTR_OWNER;
3776 dprintk("%s: nfs_map_name_to_uid failed!\n",
3779 dprintk("%s: name too long (%u)!\n",
3781 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3783 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3786 print_overflow_msg(__func__, xdr);
3790 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3791 const struct nfs_server *server, uint32_t *gid, int may_sleep)
3798 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3800 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3801 p = xdr_inline_decode(xdr, 4);
3804 len = be32_to_cpup(p);
3805 p = xdr_inline_decode(xdr, len);
3810 } else if (len < XDR_MAX_NETOBJ) {
3811 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3812 ret = NFS_ATTR_FATTR_GROUP;
3814 dprintk("%s: nfs_map_group_to_gid failed!\n",
3817 dprintk("%s: name too long (%u)!\n",
3819 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3821 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3824 print_overflow_msg(__func__, xdr);
3828 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3830 uint32_t major = 0, minor = 0;
3835 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3837 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3840 p = xdr_inline_decode(xdr, 8);
3843 major = be32_to_cpup(p++);
3844 minor = be32_to_cpup(p);
3845 tmp = MKDEV(major, minor);
3846 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3848 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3849 ret = NFS_ATTR_FATTR_RDEV;
3851 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3854 print_overflow_msg(__func__, xdr);
3858 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3864 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3866 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3867 p = xdr_inline_decode(xdr, 8);
3870 xdr_decode_hyper(p, res);
3871 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3873 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3876 print_overflow_msg(__func__, xdr);
3880 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3886 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3888 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3889 p = xdr_inline_decode(xdr, 8);
3892 xdr_decode_hyper(p, res);
3893 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3895 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3898 print_overflow_msg(__func__, xdr);
3902 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3908 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3910 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3911 p = xdr_inline_decode(xdr, 8);
3914 xdr_decode_hyper(p, res);
3915 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3917 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3920 print_overflow_msg(__func__, xdr);
3924 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3930 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3932 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3933 p = xdr_inline_decode(xdr, 8);
3936 xdr_decode_hyper(p, used);
3937 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3938 ret = NFS_ATTR_FATTR_SPACE_USED;
3940 dprintk("%s: space used=%Lu\n", __func__,
3941 (unsigned long long)*used);
3944 print_overflow_msg(__func__, xdr);
3948 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3954 p = xdr_inline_decode(xdr, 12);
3957 p = xdr_decode_hyper(p, &sec);
3958 nsec = be32_to_cpup(p);
3959 time->tv_sec = (time_t)sec;
3960 time->tv_nsec = (long)nsec;
3963 print_overflow_msg(__func__, xdr);
3967 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3973 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3975 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3976 status = decode_attr_time(xdr, time);
3978 status = NFS_ATTR_FATTR_ATIME;
3979 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3981 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3985 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3991 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3993 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3994 status = decode_attr_time(xdr, time);
3996 status = NFS_ATTR_FATTR_CTIME;
3997 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3999 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4003 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4004 struct timespec *time)
4010 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4012 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4013 status = decode_attr_time(xdr, time);
4014 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4016 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4017 (long)time->tv_nsec);
4021 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4027 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4029 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4030 status = decode_attr_time(xdr, time);
4032 status = NFS_ATTR_FATTR_MTIME;
4033 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4035 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4039 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
4041 unsigned int attrwords = XDR_QUADLEN(attrlen);
4042 unsigned int nwords = xdr->p - savep;
4044 if (unlikely(attrwords != nwords)) {
4045 dprintk("%s: server returned incorrect attribute length: "
4049 (attrwords < nwords) ? '<' : '>',
4056 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4060 p = xdr_inline_decode(xdr, 20);
4063 cinfo->atomic = be32_to_cpup(p++);
4064 p = xdr_decode_hyper(p, &cinfo->before);
4065 xdr_decode_hyper(p, &cinfo->after);
4068 print_overflow_msg(__func__, xdr);
4072 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4078 status = decode_op_hdr(xdr, OP_ACCESS);
4081 p = xdr_inline_decode(xdr, 8);
4084 supp = be32_to_cpup(p++);
4085 acc = be32_to_cpup(p);
4086 access->supported = supp;
4087 access->access = acc;
4090 print_overflow_msg(__func__, xdr);
4094 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4098 p = xdr_inline_decode(xdr, len);
4100 memcpy(buf, p, len);
4103 print_overflow_msg(__func__, xdr);
4107 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4109 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
4112 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4116 status = decode_op_hdr(xdr, OP_CLOSE);
4118 nfs_increment_open_seqid(status, res->seqid);
4120 status = decode_stateid(xdr, &res->stateid);
4124 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4126 return decode_opaque_fixed(xdr, verifier, 8);
4129 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4133 status = decode_op_hdr(xdr, OP_COMMIT);
4135 status = decode_verifier(xdr, res->verf->verifier);
4139 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4145 status = decode_op_hdr(xdr, OP_CREATE);
4148 if ((status = decode_change_info(xdr, cinfo)))
4150 p = xdr_inline_decode(xdr, 4);
4153 bmlen = be32_to_cpup(p);
4154 p = xdr_inline_decode(xdr, bmlen << 2);
4158 print_overflow_msg(__func__, xdr);
4162 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4165 uint32_t attrlen, bitmap[2] = {0};
4168 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4170 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4172 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4174 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4176 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4178 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4180 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4182 status = verify_attr_len(xdr, savep, attrlen);
4184 dprintk("%s: xdr returned %d!\n", __func__, -status);
4188 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4191 uint32_t attrlen, bitmap[2] = {0};
4194 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4196 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4198 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4201 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4203 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4205 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4207 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4209 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4211 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4214 status = verify_attr_len(xdr, savep, attrlen);
4216 dprintk("%s: xdr returned %d!\n", __func__, -status);
4220 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4223 uint32_t attrlen, bitmap[2] = {0};
4226 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4228 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4230 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4233 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4235 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4238 status = verify_attr_len(xdr, savep, attrlen);
4240 dprintk("%s: xdr returned %d!\n", __func__, -status);
4244 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4245 struct nfs_fattr *fattr, struct nfs_fh *fh,
4246 const struct nfs_server *server, int may_sleep)
4253 status = decode_attr_type(xdr, bitmap, &type);
4258 fattr->mode |= nfs_type2fmt[type];
4259 fattr->valid |= status;
4262 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4265 fattr->valid |= status;
4267 status = decode_attr_size(xdr, bitmap, &fattr->size);
4270 fattr->valid |= status;
4272 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4275 fattr->valid |= status;
4278 status = decode_attr_error(xdr, bitmap, &err);
4281 if (err == -NFS4ERR_WRONGSEC)
4282 nfs_fixup_secinfo_attributes(fattr, fh);
4284 status = decode_attr_filehandle(xdr, bitmap, fh);
4288 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4291 fattr->valid |= status;
4293 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
4294 struct nfs4_fs_locations,
4298 fattr->valid |= status;
4300 status = decode_attr_mode(xdr, bitmap, &fmode);
4304 fattr->mode |= fmode;
4305 fattr->valid |= status;
4308 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4311 fattr->valid |= status;
4313 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
4316 fattr->valid |= status;
4318 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
4321 fattr->valid |= status;
4323 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4326 fattr->valid |= status;
4328 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4331 fattr->valid |= status;
4333 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4336 fattr->valid |= status;
4338 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4341 fattr->valid |= status;
4343 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4346 fattr->valid |= status;
4348 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4351 fattr->valid |= status;
4354 dprintk("%s: xdr returned %d\n", __func__, -status);
4358 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4359 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4366 status = decode_op_hdr(xdr, OP_GETATTR);
4370 status = decode_attr_bitmap(xdr, bitmap);
4374 status = decode_attr_length(xdr, &attrlen, &savep);
4378 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4382 status = verify_attr_len(xdr, savep, attrlen);
4384 dprintk("%s: xdr returned %d\n", __func__, -status);
4388 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4389 const struct nfs_server *server, int may_sleep)
4391 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4395 * Decode potentially multiple layout types. Currently we only support
4396 * one layout driver per file system.
4398 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4399 uint32_t *layouttype)
4404 p = xdr_inline_decode(xdr, 4);
4407 num = be32_to_cpup(p);
4409 /* pNFS is not supported by the underlying file system */
4415 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4416 "per filesystem not supported\n", __func__);
4418 /* Decode and set first layout type, move xdr->p past unused types */
4419 p = xdr_inline_decode(xdr, num * 4);
4422 *layouttype = be32_to_cpup(p);
4425 print_overflow_msg(__func__, xdr);
4430 * The type of file system exported.
4431 * Note we must ensure that layouttype is set in any non-error case.
4433 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4434 uint32_t *layouttype)
4438 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4439 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4441 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4442 status = decode_first_pnfs_layout_type(xdr, layouttype);
4443 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4449 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4452 uint32_t attrlen, bitmap[2];
4455 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4457 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4459 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4462 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4464 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4466 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4468 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4470 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4471 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4473 fsinfo->wtpref = fsinfo->wtmax;
4474 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4477 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4481 status = verify_attr_len(xdr, savep, attrlen);
4483 dprintk("%s: xdr returned %d!\n", __func__, -status);
4487 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4493 /* Zero handle first to allow comparisons */
4494 memset(fh, 0, sizeof(*fh));
4496 status = decode_op_hdr(xdr, OP_GETFH);
4500 p = xdr_inline_decode(xdr, 4);
4503 len = be32_to_cpup(p);
4504 if (len > NFS4_FHSIZE)
4507 p = xdr_inline_decode(xdr, len);
4510 memcpy(fh->data, p, len);
4513 print_overflow_msg(__func__, xdr);
4517 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4521 status = decode_op_hdr(xdr, OP_LINK);
4524 return decode_change_info(xdr, cinfo);
4528 * We create the owner, so we know a proper owner.id length is 4.
4530 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4532 uint64_t offset, length, clientid;
4534 uint32_t namelen, type;
4536 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4539 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4540 p = xdr_decode_hyper(p, &length);
4541 type = be32_to_cpup(p++); /* 4 byte read */
4542 if (fl != NULL) { /* manipulate file lock */
4543 fl->fl_start = (loff_t)offset;
4544 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4545 if (length == ~(uint64_t)0)
4546 fl->fl_end = OFFSET_MAX;
4547 fl->fl_type = F_WRLCK;
4549 fl->fl_type = F_RDLCK;
4552 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4553 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4554 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4556 return -NFS4ERR_DENIED;
4558 print_overflow_msg(__func__, xdr);
4562 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4566 status = decode_op_hdr(xdr, OP_LOCK);
4570 status = decode_stateid(xdr, &res->stateid);
4571 if (unlikely(status))
4573 } else if (status == -NFS4ERR_DENIED)
4574 status = decode_lock_denied(xdr, NULL);
4575 if (res->open_seqid != NULL)
4576 nfs_increment_open_seqid(status, res->open_seqid);
4577 nfs_increment_lock_seqid(status, res->lock_seqid);
4582 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4585 status = decode_op_hdr(xdr, OP_LOCKT);
4586 if (status == -NFS4ERR_DENIED)
4587 return decode_lock_denied(xdr, res->denied);
4591 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4595 status = decode_op_hdr(xdr, OP_LOCKU);
4597 nfs_increment_lock_seqid(status, res->seqid);
4599 status = decode_stateid(xdr, &res->stateid);
4603 static int decode_release_lockowner(struct xdr_stream *xdr)
4605 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4608 static int decode_lookup(struct xdr_stream *xdr)
4610 return decode_op_hdr(xdr, OP_LOOKUP);
4613 /* This is too sick! */
4614 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4617 uint32_t limit_type, nblocks, blocksize;
4619 p = xdr_inline_decode(xdr, 12);
4622 limit_type = be32_to_cpup(p++);
4623 switch (limit_type) {
4625 xdr_decode_hyper(p, maxsize);
4628 nblocks = be32_to_cpup(p++);
4629 blocksize = be32_to_cpup(p);
4630 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4634 print_overflow_msg(__func__, xdr);
4638 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4641 uint32_t delegation_type;
4644 p = xdr_inline_decode(xdr, 4);
4647 delegation_type = be32_to_cpup(p);
4648 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4649 res->delegation_type = 0;
4652 status = decode_stateid(xdr, &res->delegation);
4653 if (unlikely(status))
4655 p = xdr_inline_decode(xdr, 4);
4658 res->do_recall = be32_to_cpup(p);
4660 switch (delegation_type) {
4661 case NFS4_OPEN_DELEGATE_READ:
4662 res->delegation_type = FMODE_READ;
4664 case NFS4_OPEN_DELEGATE_WRITE:
4665 res->delegation_type = FMODE_WRITE|FMODE_READ;
4666 if (decode_space_limit(xdr, &res->maxsize) < 0)
4669 return decode_ace(xdr, NULL, res->server->nfs_client);
4671 print_overflow_msg(__func__, xdr);
4675 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4678 uint32_t savewords, bmlen, i;
4681 status = decode_op_hdr(xdr, OP_OPEN);
4683 nfs_increment_open_seqid(status, res->seqid);
4685 status = decode_stateid(xdr, &res->stateid);
4686 if (unlikely(status))
4689 decode_change_info(xdr, &res->cinfo);
4691 p = xdr_inline_decode(xdr, 8);
4694 res->rflags = be32_to_cpup(p++);
4695 bmlen = be32_to_cpup(p);
4699 p = xdr_inline_decode(xdr, bmlen << 2);
4702 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4703 for (i = 0; i < savewords; ++i)
4704 res->attrset[i] = be32_to_cpup(p++);
4705 for (; i < NFS4_BITMAP_SIZE; i++)
4706 res->attrset[i] = 0;
4708 return decode_delegation(xdr, res);
4710 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4713 print_overflow_msg(__func__, xdr);
4717 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4721 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4723 nfs_increment_open_seqid(status, res->seqid);
4725 status = decode_stateid(xdr, &res->stateid);
4729 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4733 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4735 nfs_increment_open_seqid(status, res->seqid);
4737 status = decode_stateid(xdr, &res->stateid);
4741 static int decode_putfh(struct xdr_stream *xdr)
4743 return decode_op_hdr(xdr, OP_PUTFH);
4746 static int decode_putrootfh(struct xdr_stream *xdr)
4748 return decode_op_hdr(xdr, OP_PUTROOTFH);
4751 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4753 struct kvec *iov = req->rq_rcv_buf.head;
4755 uint32_t count, eof, recvd, hdrlen;
4758 status = decode_op_hdr(xdr, OP_READ);
4761 p = xdr_inline_decode(xdr, 8);
4764 eof = be32_to_cpup(p++);
4765 count = be32_to_cpup(p);
4766 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4767 recvd = req->rq_rcv_buf.len - hdrlen;
4768 if (count > recvd) {
4769 dprintk("NFS: server cheating in read reply: "
4770 "count %u > recvd %u\n", count, recvd);
4774 xdr_read_pages(xdr, count);
4779 print_overflow_msg(__func__, xdr);
4783 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4785 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4786 struct kvec *iov = rcvbuf->head;
4788 u32 recvd, pglen = rcvbuf->page_len;
4791 status = decode_op_hdr(xdr, OP_READDIR);
4793 status = decode_verifier(xdr, readdir->verifier.data);
4794 if (unlikely(status))
4796 dprintk("%s: verifier = %08x:%08x\n",
4798 ((u32 *)readdir->verifier.data)[0],
4799 ((u32 *)readdir->verifier.data)[1]);
4802 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4803 recvd = rcvbuf->len - hdrlen;
4806 xdr_read_pages(xdr, pglen);
4812 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4814 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4815 struct kvec *iov = rcvbuf->head;
4821 status = decode_op_hdr(xdr, OP_READLINK);
4825 /* Convert length of symlink */
4826 p = xdr_inline_decode(xdr, 4);
4829 len = be32_to_cpup(p);
4830 if (len >= rcvbuf->page_len || len <= 0) {
4831 dprintk("nfs: server returned giant symlink!\n");
4832 return -ENAMETOOLONG;
4834 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4835 recvd = req->rq_rcv_buf.len - hdrlen;
4837 dprintk("NFS: server cheating in readlink reply: "
4838 "count %u > recvd %u\n", len, recvd);
4841 xdr_read_pages(xdr, len);
4843 * The XDR encode routine has set things up so that
4844 * the link text will be copied directly into the
4845 * buffer. We just have to do overflow-checking,
4846 * and and null-terminate the text (the VFS expects
4847 * null-termination).
4849 xdr_terminate_string(rcvbuf, len);
4852 print_overflow_msg(__func__, xdr);
4856 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4860 status = decode_op_hdr(xdr, OP_REMOVE);
4863 status = decode_change_info(xdr, cinfo);
4868 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4869 struct nfs4_change_info *new_cinfo)
4873 status = decode_op_hdr(xdr, OP_RENAME);
4876 if ((status = decode_change_info(xdr, old_cinfo)))
4878 status = decode_change_info(xdr, new_cinfo);
4883 static int decode_renew(struct xdr_stream *xdr)
4885 return decode_op_hdr(xdr, OP_RENEW);
4889 decode_restorefh(struct xdr_stream *xdr)
4891 return decode_op_hdr(xdr, OP_RESTOREFH);
4894 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4900 struct kvec *iov = req->rq_rcv_buf.head;
4904 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4906 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4908 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4911 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4913 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4917 /* We ignore &savep and don't do consistency checks on
4918 * the attr length. Let userspace figure it out.... */
4919 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4920 recvd = req->rq_rcv_buf.len - hdrlen;
4921 if (attrlen > recvd) {
4922 dprintk("NFS: server cheating in getattr"
4923 " acl reply: attrlen %u > recvd %u\n",
4927 xdr_read_pages(xdr, attrlen);
4930 status = -EOPNOTSUPP;
4937 decode_savefh(struct xdr_stream *xdr)
4939 return decode_op_hdr(xdr, OP_SAVEFH);
4942 static int decode_setattr(struct xdr_stream *xdr)
4948 status = decode_op_hdr(xdr, OP_SETATTR);
4951 p = xdr_inline_decode(xdr, 4);
4954 bmlen = be32_to_cpup(p);
4955 p = xdr_inline_decode(xdr, bmlen << 2);
4959 print_overflow_msg(__func__, xdr);
4963 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
4969 p = xdr_inline_decode(xdr, 8);
4972 opnum = be32_to_cpup(p++);
4973 if (opnum != OP_SETCLIENTID) {
4974 dprintk("nfs: decode_setclientid: Server returned operation"
4978 nfserr = be32_to_cpup(p);
4979 if (nfserr == NFS_OK) {
4980 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4983 p = xdr_decode_hyper(p, &res->clientid);
4984 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
4985 } else if (nfserr == NFSERR_CLID_INUSE) {
4988 /* skip netid string */
4989 p = xdr_inline_decode(xdr, 4);
4992 len = be32_to_cpup(p);
4993 p = xdr_inline_decode(xdr, len);
4997 /* skip uaddr string */
4998 p = xdr_inline_decode(xdr, 4);
5001 len = be32_to_cpup(p);
5002 p = xdr_inline_decode(xdr, len);
5005 return -NFSERR_CLID_INUSE;
5007 return nfs4_stat_to_errno(nfserr);
5011 print_overflow_msg(__func__, xdr);
5015 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5017 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5020 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5025 status = decode_op_hdr(xdr, OP_WRITE);
5029 p = xdr_inline_decode(xdr, 16);
5032 res->count = be32_to_cpup(p++);
5033 res->verf->committed = be32_to_cpup(p++);
5034 memcpy(res->verf->verifier, p, 8);
5037 print_overflow_msg(__func__, xdr);
5041 static int decode_delegreturn(struct xdr_stream *xdr)
5043 return decode_op_hdr(xdr, OP_DELEGRETURN);
5046 static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5050 p = xdr_inline_decode(xdr, 4);
5053 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5054 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5057 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5060 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5062 p = xdr_inline_decode(xdr, 8);
5065 flavor->gss.qop4 = be32_to_cpup(p++);
5066 flavor->gss.service = be32_to_cpup(p);
5071 print_overflow_msg(__func__, xdr);
5077 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5079 struct nfs4_secinfo_flavor *sec_flavor;
5084 status = decode_op_hdr(xdr, OP_SECINFO);
5087 p = xdr_inline_decode(xdr, 4);
5091 res->flavors->num_flavors = 0;
5092 num_flavors = be32_to_cpup(p);
5094 for (i = 0; i < num_flavors; i++) {
5095 sec_flavor = &res->flavors->flavors[i];
5096 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5099 p = xdr_inline_decode(xdr, 4);
5102 sec_flavor->flavor = be32_to_cpup(p);
5104 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5105 status = decode_secinfo_gss(xdr, sec_flavor);
5109 res->flavors->num_flavors++;
5115 print_overflow_msg(__func__, xdr);
5119 #if defined(CONFIG_NFS_V4_1)
5120 static int decode_exchange_id(struct xdr_stream *xdr,
5121 struct nfs41_exchange_id_res *res)
5127 struct nfs_client *clp = res->client;
5129 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5133 p = xdr_inline_decode(xdr, 8);
5136 xdr_decode_hyper(p, &clp->cl_clientid);
5137 p = xdr_inline_decode(xdr, 12);
5140 clp->cl_seqid = be32_to_cpup(p++);
5141 clp->cl_exchange_flags = be32_to_cpup(p++);
5143 /* We ask for SP4_NONE */
5144 dummy = be32_to_cpup(p);
5145 if (dummy != SP4_NONE)
5148 /* Throw away minor_id */
5149 p = xdr_inline_decode(xdr, 8);
5153 /* Throw away Major id */
5154 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5155 if (unlikely(status))
5158 /* Save server_scope */
5159 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5160 if (unlikely(status))
5163 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5166 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5167 res->server_scope->server_scope_sz = dummy;
5169 /* Throw away Implementation id array */
5170 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5171 if (unlikely(status))
5176 print_overflow_msg(__func__, xdr);
5180 static int decode_chan_attrs(struct xdr_stream *xdr,
5181 struct nfs4_channel_attrs *attrs)
5186 p = xdr_inline_decode(xdr, 28);
5189 val = be32_to_cpup(p++); /* headerpadsz */
5191 return -EINVAL; /* no support for header padding yet */
5192 attrs->max_rqst_sz = be32_to_cpup(p++);
5193 attrs->max_resp_sz = be32_to_cpup(p++);
5194 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5195 attrs->max_ops = be32_to_cpup(p++);
5196 attrs->max_reqs = be32_to_cpup(p++);
5197 nr_attrs = be32_to_cpup(p);
5198 if (unlikely(nr_attrs > 1)) {
5199 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5200 __func__, nr_attrs);
5203 if (nr_attrs == 1) {
5204 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5210 print_overflow_msg(__func__, xdr);
5214 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5216 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5219 static int decode_create_session(struct xdr_stream *xdr,
5220 struct nfs41_create_session_res *res)
5224 struct nfs_client *clp = res->client;
5225 struct nfs4_session *session = clp->cl_session;
5227 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5229 status = decode_sessionid(xdr, &session->sess_id);
5230 if (unlikely(status))
5234 p = xdr_inline_decode(xdr, 8);
5237 clp->cl_seqid = be32_to_cpup(p++);
5238 session->flags = be32_to_cpup(p);
5240 /* Channel attributes */
5241 status = decode_chan_attrs(xdr, &session->fc_attrs);
5243 status = decode_chan_attrs(xdr, &session->bc_attrs);
5246 print_overflow_msg(__func__, xdr);
5250 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5252 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5255 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5257 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5259 #endif /* CONFIG_NFS_V4_1 */
5261 static int decode_sequence(struct xdr_stream *xdr,
5262 struct nfs4_sequence_res *res,
5263 struct rpc_rqst *rqstp)
5265 #if defined(CONFIG_NFS_V4_1)
5266 struct nfs4_sessionid id;
5271 if (!res->sr_session)
5274 status = decode_op_hdr(xdr, OP_SEQUENCE);
5276 status = decode_sessionid(xdr, &id);
5277 if (unlikely(status))
5281 * If the server returns different values for sessionID, slotID or
5282 * sequence number, the server is looney tunes.
5284 status = -EREMOTEIO;
5286 if (memcmp(id.data, res->sr_session->sess_id.data,
5287 NFS4_MAX_SESSIONID_LEN)) {
5288 dprintk("%s Invalid session id\n", __func__);
5292 p = xdr_inline_decode(xdr, 20);
5297 dummy = be32_to_cpup(p++);
5298 if (dummy != res->sr_slot->seq_nr) {
5299 dprintk("%s Invalid sequence number\n", __func__);
5303 dummy = be32_to_cpup(p++);
5304 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5305 dprintk("%s Invalid slot id\n", __func__);
5308 /* highest slot id - currently not processed */
5309 dummy = be32_to_cpup(p++);
5310 /* target highest slot id - currently not processed */
5311 dummy = be32_to_cpup(p++);
5313 res->sr_status_flags = be32_to_cpup(p);
5316 res->sr_status = status;
5319 print_overflow_msg(__func__, xdr);
5322 #else /* CONFIG_NFS_V4_1 */
5324 #endif /* CONFIG_NFS_V4_1 */
5327 #if defined(CONFIG_NFS_V4_1)
5329 * TODO: Need to handle case when EOF != true;
5331 static int decode_getdevicelist(struct xdr_stream *xdr,
5332 struct pnfs_devicelist *res)
5336 struct nfs_writeverf verftemp;
5338 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5342 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5346 /* TODO: Skip cookie for now */
5350 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5352 res->num_devs = be32_to_cpup(p);
5354 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5356 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5357 printk(KERN_ERR "%s too many result dev_num %u\n",
5358 __func__, res->num_devs);
5362 p = xdr_inline_decode(xdr,
5363 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5366 for (i = 0; i < res->num_devs; i++)
5367 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5368 NFS4_DEVICEID4_SIZE);
5369 res->eof = be32_to_cpup(p);
5372 print_overflow_msg(__func__, xdr);
5376 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5377 struct pnfs_device *pdev)
5383 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5385 if (status == -ETOOSMALL) {
5386 p = xdr_inline_decode(xdr, 4);
5389 pdev->mincount = be32_to_cpup(p);
5390 dprintk("%s: Min count too small. mincnt = %u\n",
5391 __func__, pdev->mincount);
5396 p = xdr_inline_decode(xdr, 8);
5399 type = be32_to_cpup(p++);
5400 if (type != pdev->layout_type) {
5401 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5402 __func__, pdev->layout_type, type);
5406 * Get the length of the opaque device_addr4. xdr_read_pages places
5407 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5408 * and places the remaining xdr data in xdr_buf->tail
5410 pdev->mincount = be32_to_cpup(p);
5411 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5413 /* Parse notification bitmap, verifying that it is zero. */
5414 p = xdr_inline_decode(xdr, 4);
5417 len = be32_to_cpup(p);
5421 p = xdr_inline_decode(xdr, 4 * len);
5424 for (i = 0; i < len; i++, p++) {
5425 if (be32_to_cpup(p)) {
5426 dprintk("%s: notifications not supported\n",
5434 print_overflow_msg(__func__, xdr);
5438 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5439 struct nfs4_layoutget_res *res)
5444 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5445 struct kvec *iov = rcvbuf->head;
5448 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5451 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5454 res->return_on_close = be32_to_cpup(p++);
5455 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5456 layout_count = be32_to_cpup(p);
5457 if (!layout_count) {
5458 dprintk("%s: server responded with empty layout array\n",
5463 p = xdr_inline_decode(xdr, 28);
5466 p = xdr_decode_hyper(p, &res->range.offset);
5467 p = xdr_decode_hyper(p, &res->range.length);
5468 res->range.iomode = be32_to_cpup(p++);
5469 res->type = be32_to_cpup(p++);
5470 res->layoutp->len = be32_to_cpup(p);
5472 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5474 (unsigned long)res->range.offset,
5475 (unsigned long)res->range.length,
5480 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5481 recvd = req->rq_rcv_buf.len - hdrlen;
5482 if (res->layoutp->len > recvd) {
5483 dprintk("NFS: server cheating in layoutget reply: "
5484 "layout len %u > recvd %u\n",
5485 res->layoutp->len, recvd);
5489 xdr_read_pages(xdr, res->layoutp->len);
5491 if (layout_count > 1) {
5492 /* We only handle a length one array at the moment. Any
5493 * further entries are just ignored. Note that this means
5494 * the client may see a response that is less than the
5495 * minimum it requested.
5497 dprintk("%s: server responded with %d layouts, dropping tail\n",
5498 __func__, layout_count);
5503 print_overflow_msg(__func__, xdr);
5507 static int decode_layoutreturn(struct xdr_stream *xdr,
5508 struct nfs4_layoutreturn_res *res)
5513 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5516 p = xdr_inline_decode(xdr, 4);
5519 res->lrs_present = be32_to_cpup(p);
5520 if (res->lrs_present)
5521 status = decode_stateid(xdr, &res->stateid);
5524 print_overflow_msg(__func__, xdr);
5528 static int decode_layoutcommit(struct xdr_stream *xdr,
5529 struct rpc_rqst *req,
5530 struct nfs4_layoutcommit_res *res)
5536 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5540 p = xdr_inline_decode(xdr, 4);
5543 sizechanged = be32_to_cpup(p);
5546 /* throw away new size */
5547 p = xdr_inline_decode(xdr, 8);
5553 print_overflow_msg(__func__, xdr);
5557 static int decode_test_stateid(struct xdr_stream *xdr,
5558 struct nfs41_test_stateid_res *res)
5564 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5568 p = xdr_inline_decode(xdr, 4);
5571 num_res = be32_to_cpup(p++);
5575 p = xdr_inline_decode(xdr, 4);
5578 res->status = be32_to_cpup(p++);
5581 print_overflow_msg(__func__, xdr);
5586 static int decode_free_stateid(struct xdr_stream *xdr,
5587 struct nfs41_free_stateid_res *res)
5592 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5596 p = xdr_inline_decode(xdr, 4);
5599 res->status = be32_to_cpup(p++);
5602 print_overflow_msg(__func__, xdr);
5605 #endif /* CONFIG_NFS_V4_1 */
5608 * END OF "GENERIC" DECODE ROUTINES.
5612 * Decode OPEN_DOWNGRADE response
5614 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5615 struct xdr_stream *xdr,
5616 struct nfs_closeres *res)
5618 struct compound_hdr hdr;
5621 status = decode_compound_hdr(xdr, &hdr);
5624 status = decode_sequence(xdr, &res->seq_res, rqstp);
5627 status = decode_putfh(xdr);
5630 status = decode_open_downgrade(xdr, res);
5633 decode_getfattr(xdr, res->fattr, res->server,
5634 !RPC_IS_ASYNC(rqstp->rq_task));
5640 * Decode ACCESS response
5642 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5643 struct nfs4_accessres *res)
5645 struct compound_hdr hdr;
5648 status = decode_compound_hdr(xdr, &hdr);
5651 status = decode_sequence(xdr, &res->seq_res, rqstp);
5654 status = decode_putfh(xdr);
5657 status = decode_access(xdr, res);
5660 decode_getfattr(xdr, res->fattr, res->server,
5661 !RPC_IS_ASYNC(rqstp->rq_task));
5667 * Decode LOOKUP response
5669 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5670 struct nfs4_lookup_res *res)
5672 struct compound_hdr hdr;
5675 status = decode_compound_hdr(xdr, &hdr);
5678 status = decode_sequence(xdr, &res->seq_res, rqstp);
5681 status = decode_putfh(xdr);
5684 status = decode_lookup(xdr);
5687 status = decode_getfh(xdr, res->fh);
5690 status = decode_getfattr(xdr, res->fattr, res->server
5691 ,!RPC_IS_ASYNC(rqstp->rq_task));
5697 * Decode LOOKUP_ROOT response
5699 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5700 struct xdr_stream *xdr,
5701 struct nfs4_lookup_res *res)
5703 struct compound_hdr hdr;
5706 status = decode_compound_hdr(xdr, &hdr);
5709 status = decode_sequence(xdr, &res->seq_res, rqstp);
5712 status = decode_putrootfh(xdr);
5715 status = decode_getfh(xdr, res->fh);
5717 status = decode_getfattr(xdr, res->fattr, res->server,
5718 !RPC_IS_ASYNC(rqstp->rq_task));
5724 * Decode REMOVE response
5726 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5727 struct nfs_removeres *res)
5729 struct compound_hdr hdr;
5732 status = decode_compound_hdr(xdr, &hdr);
5735 status = decode_sequence(xdr, &res->seq_res, rqstp);
5738 status = decode_putfh(xdr);
5741 status = decode_remove(xdr, &res->cinfo);
5744 decode_getfattr(xdr, res->dir_attr, res->server,
5745 !RPC_IS_ASYNC(rqstp->rq_task));
5751 * Decode RENAME response
5753 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5754 struct nfs_renameres *res)
5756 struct compound_hdr hdr;
5759 status = decode_compound_hdr(xdr, &hdr);
5762 status = decode_sequence(xdr, &res->seq_res, rqstp);
5765 status = decode_putfh(xdr);
5768 status = decode_savefh(xdr);
5771 status = decode_putfh(xdr);
5774 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5777 /* Current FH is target directory */
5778 if (decode_getfattr(xdr, res->new_fattr, res->server,
5779 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5781 status = decode_restorefh(xdr);
5784 decode_getfattr(xdr, res->old_fattr, res->server,
5785 !RPC_IS_ASYNC(rqstp->rq_task));
5791 * Decode LINK response
5793 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5794 struct nfs4_link_res *res)
5796 struct compound_hdr hdr;
5799 status = decode_compound_hdr(xdr, &hdr);
5802 status = decode_sequence(xdr, &res->seq_res, rqstp);
5805 status = decode_putfh(xdr);
5808 status = decode_savefh(xdr);
5811 status = decode_putfh(xdr);
5814 status = decode_link(xdr, &res->cinfo);
5818 * Note order: OP_LINK leaves the directory as the current
5821 if (decode_getfattr(xdr, res->dir_attr, res->server,
5822 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5824 status = decode_restorefh(xdr);
5827 decode_getfattr(xdr, res->fattr, res->server,
5828 !RPC_IS_ASYNC(rqstp->rq_task));
5834 * Decode CREATE response
5836 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5837 struct nfs4_create_res *res)
5839 struct compound_hdr hdr;
5842 status = decode_compound_hdr(xdr, &hdr);
5845 status = decode_sequence(xdr, &res->seq_res, rqstp);
5848 status = decode_putfh(xdr);
5851 status = decode_savefh(xdr);
5854 status = decode_create(xdr, &res->dir_cinfo);
5857 status = decode_getfh(xdr, res->fh);
5860 if (decode_getfattr(xdr, res->fattr, res->server,
5861 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5863 status = decode_restorefh(xdr);
5866 decode_getfattr(xdr, res->dir_fattr, res->server,
5867 !RPC_IS_ASYNC(rqstp->rq_task));
5873 * Decode SYMLINK response
5875 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5876 struct nfs4_create_res *res)
5878 return nfs4_xdr_dec_create(rqstp, xdr, res);
5882 * Decode GETATTR response
5884 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5885 struct nfs4_getattr_res *res)
5887 struct compound_hdr hdr;
5890 status = decode_compound_hdr(xdr, &hdr);
5893 status = decode_sequence(xdr, &res->seq_res, rqstp);
5896 status = decode_putfh(xdr);
5899 status = decode_getfattr(xdr, res->fattr, res->server,
5900 !RPC_IS_ASYNC(rqstp->rq_task));
5906 * Encode an SETACL request
5908 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5909 struct nfs_setaclargs *args)
5911 struct compound_hdr hdr = {
5912 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
5915 encode_compound_hdr(xdr, req, &hdr);
5916 encode_sequence(xdr, &args->seq_args, &hdr);
5917 encode_putfh(xdr, args->fh, &hdr);
5918 encode_setacl(xdr, args, &hdr);
5923 * Decode SETACL response
5926 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5927 struct nfs_setaclres *res)
5929 struct compound_hdr hdr;
5932 status = decode_compound_hdr(xdr, &hdr);
5935 status = decode_sequence(xdr, &res->seq_res, rqstp);
5938 status = decode_putfh(xdr);
5941 status = decode_setattr(xdr);
5947 * Decode GETACL response
5950 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5951 struct nfs_getaclres *res)
5953 struct compound_hdr hdr;
5956 status = decode_compound_hdr(xdr, &hdr);
5959 status = decode_sequence(xdr, &res->seq_res, rqstp);
5962 status = decode_putfh(xdr);
5965 status = decode_getacl(xdr, rqstp, &res->acl_len);
5972 * Decode CLOSE response
5974 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5975 struct nfs_closeres *res)
5977 struct compound_hdr hdr;
5980 status = decode_compound_hdr(xdr, &hdr);
5983 status = decode_sequence(xdr, &res->seq_res, rqstp);
5986 status = decode_putfh(xdr);
5989 status = decode_close(xdr, res);
5993 * Note: Server may do delete on close for this file
5994 * in which case the getattr call will fail with
5995 * an ESTALE error. Shouldn't be a problem,
5996 * though, since fattr->valid will remain unset.
5998 decode_getfattr(xdr, res->fattr, res->server,
5999 !RPC_IS_ASYNC(rqstp->rq_task));
6005 * Decode OPEN response
6007 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6008 struct nfs_openres *res)
6010 struct compound_hdr hdr;
6013 status = decode_compound_hdr(xdr, &hdr);
6016 status = decode_sequence(xdr, &res->seq_res, rqstp);
6019 status = decode_putfh(xdr);
6022 status = decode_savefh(xdr);
6025 status = decode_open(xdr, res);
6028 if (decode_getfh(xdr, &res->fh) != 0)
6030 if (decode_getfattr(xdr, res->f_attr, res->server,
6031 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
6033 if (decode_restorefh(xdr) != 0)
6035 decode_getfattr(xdr, res->dir_attr, res->server,
6036 !RPC_IS_ASYNC(rqstp->rq_task));
6042 * Decode OPEN_CONFIRM response
6044 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6045 struct xdr_stream *xdr,
6046 struct nfs_open_confirmres *res)
6048 struct compound_hdr hdr;
6051 status = decode_compound_hdr(xdr, &hdr);
6054 status = decode_putfh(xdr);
6057 status = decode_open_confirm(xdr, res);
6063 * Decode OPEN response
6065 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6066 struct xdr_stream *xdr,
6067 struct nfs_openres *res)
6069 struct compound_hdr hdr;
6072 status = decode_compound_hdr(xdr, &hdr);
6075 status = decode_sequence(xdr, &res->seq_res, rqstp);
6078 status = decode_putfh(xdr);
6081 status = decode_open(xdr, res);
6084 decode_getfattr(xdr, res->f_attr, res->server,
6085 !RPC_IS_ASYNC(rqstp->rq_task));
6091 * Decode SETATTR response
6093 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6094 struct xdr_stream *xdr,
6095 struct nfs_setattrres *res)
6097 struct compound_hdr hdr;
6100 status = decode_compound_hdr(xdr, &hdr);
6103 status = decode_sequence(xdr, &res->seq_res, rqstp);
6106 status = decode_putfh(xdr);
6109 status = decode_setattr(xdr);
6112 decode_getfattr(xdr, res->fattr, res->server,
6113 !RPC_IS_ASYNC(rqstp->rq_task));
6119 * Decode LOCK response
6121 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6122 struct nfs_lock_res *res)
6124 struct compound_hdr hdr;
6127 status = decode_compound_hdr(xdr, &hdr);
6130 status = decode_sequence(xdr, &res->seq_res, rqstp);
6133 status = decode_putfh(xdr);
6136 status = decode_lock(xdr, res);
6142 * Decode LOCKT response
6144 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6145 struct nfs_lockt_res *res)
6147 struct compound_hdr hdr;
6150 status = decode_compound_hdr(xdr, &hdr);
6153 status = decode_sequence(xdr, &res->seq_res, rqstp);
6156 status = decode_putfh(xdr);
6159 status = decode_lockt(xdr, res);
6165 * Decode LOCKU response
6167 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6168 struct nfs_locku_res *res)
6170 struct compound_hdr hdr;
6173 status = decode_compound_hdr(xdr, &hdr);
6176 status = decode_sequence(xdr, &res->seq_res, rqstp);
6179 status = decode_putfh(xdr);
6182 status = decode_locku(xdr, res);
6187 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6188 struct xdr_stream *xdr, void *dummy)
6190 struct compound_hdr hdr;
6193 status = decode_compound_hdr(xdr, &hdr);
6195 status = decode_release_lockowner(xdr);
6200 * Decode READLINK response
6202 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6203 struct xdr_stream *xdr,
6204 struct nfs4_readlink_res *res)
6206 struct compound_hdr hdr;
6209 status = decode_compound_hdr(xdr, &hdr);
6212 status = decode_sequence(xdr, &res->seq_res, rqstp);
6215 status = decode_putfh(xdr);
6218 status = decode_readlink(xdr, rqstp);
6224 * Decode READDIR response
6226 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6227 struct nfs4_readdir_res *res)
6229 struct compound_hdr hdr;
6232 status = decode_compound_hdr(xdr, &hdr);
6235 status = decode_sequence(xdr, &res->seq_res, rqstp);
6238 status = decode_putfh(xdr);
6241 status = decode_readdir(xdr, rqstp, res);
6247 * Decode Read response
6249 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6250 struct nfs_readres *res)
6252 struct compound_hdr hdr;
6255 status = decode_compound_hdr(xdr, &hdr);
6258 status = decode_sequence(xdr, &res->seq_res, rqstp);
6261 status = decode_putfh(xdr);
6264 status = decode_read(xdr, rqstp, res);
6266 status = res->count;
6272 * Decode WRITE response
6274 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6275 struct nfs_writeres *res)
6277 struct compound_hdr hdr;
6280 status = decode_compound_hdr(xdr, &hdr);
6283 status = decode_sequence(xdr, &res->seq_res, rqstp);
6286 status = decode_putfh(xdr);
6289 status = decode_write(xdr, res);
6293 decode_getfattr(xdr, res->fattr, res->server,
6294 !RPC_IS_ASYNC(rqstp->rq_task));
6296 status = res->count;
6302 * Decode COMMIT response
6304 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6305 struct nfs_writeres *res)
6307 struct compound_hdr hdr;
6310 status = decode_compound_hdr(xdr, &hdr);
6313 status = decode_sequence(xdr, &res->seq_res, rqstp);
6316 status = decode_putfh(xdr);
6319 status = decode_commit(xdr, res);
6323 decode_getfattr(xdr, res->fattr, res->server,
6324 !RPC_IS_ASYNC(rqstp->rq_task));
6330 * Decode FSINFO response
6332 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6333 struct nfs4_fsinfo_res *res)
6335 struct compound_hdr hdr;
6338 status = decode_compound_hdr(xdr, &hdr);
6340 status = decode_sequence(xdr, &res->seq_res, req);
6342 status = decode_putfh(xdr);
6344 status = decode_fsinfo(xdr, res->fsinfo);
6349 * Decode PATHCONF response
6351 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6352 struct nfs4_pathconf_res *res)
6354 struct compound_hdr hdr;
6357 status = decode_compound_hdr(xdr, &hdr);
6359 status = decode_sequence(xdr, &res->seq_res, req);
6361 status = decode_putfh(xdr);
6363 status = decode_pathconf(xdr, res->pathconf);
6368 * Decode STATFS response
6370 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6371 struct nfs4_statfs_res *res)
6373 struct compound_hdr hdr;
6376 status = decode_compound_hdr(xdr, &hdr);
6378 status = decode_sequence(xdr, &res->seq_res, req);
6380 status = decode_putfh(xdr);
6382 status = decode_statfs(xdr, res->fsstat);
6387 * Decode GETATTR_BITMAP response
6389 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6390 struct xdr_stream *xdr,
6391 struct nfs4_server_caps_res *res)
6393 struct compound_hdr hdr;
6396 status = decode_compound_hdr(xdr, &hdr);
6399 status = decode_sequence(xdr, &res->seq_res, req);
6402 status = decode_putfh(xdr);
6405 status = decode_server_caps(xdr, res);
6411 * Decode RENEW response
6413 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6416 struct compound_hdr hdr;
6419 status = decode_compound_hdr(xdr, &hdr);
6421 status = decode_renew(xdr);
6426 * Decode SETCLIENTID response
6428 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6429 struct xdr_stream *xdr,
6430 struct nfs4_setclientid_res *res)
6432 struct compound_hdr hdr;
6435 status = decode_compound_hdr(xdr, &hdr);
6437 status = decode_setclientid(xdr, res);
6442 * Decode SETCLIENTID_CONFIRM response
6444 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6445 struct xdr_stream *xdr,
6446 struct nfs_fsinfo *fsinfo)
6448 struct compound_hdr hdr;
6451 status = decode_compound_hdr(xdr, &hdr);
6453 status = decode_setclientid_confirm(xdr);
6455 status = decode_putrootfh(xdr);
6457 status = decode_fsinfo(xdr, fsinfo);
6462 * Decode DELEGRETURN response
6464 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6465 struct xdr_stream *xdr,
6466 struct nfs4_delegreturnres *res)
6468 struct compound_hdr hdr;
6471 status = decode_compound_hdr(xdr, &hdr);
6474 status = decode_sequence(xdr, &res->seq_res, rqstp);
6477 status = decode_putfh(xdr);
6480 status = decode_delegreturn(xdr);
6483 decode_getfattr(xdr, res->fattr, res->server,
6484 !RPC_IS_ASYNC(rqstp->rq_task));
6490 * Decode FS_LOCATIONS response
6492 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6493 struct xdr_stream *xdr,
6494 struct nfs4_fs_locations_res *res)
6496 struct compound_hdr hdr;
6499 status = decode_compound_hdr(xdr, &hdr);
6502 status = decode_sequence(xdr, &res->seq_res, req);
6505 status = decode_putfh(xdr);
6508 status = decode_lookup(xdr);
6511 xdr_enter_page(xdr, PAGE_SIZE);
6512 status = decode_getfattr(xdr, &res->fs_locations->fattr,
6513 res->fs_locations->server,
6514 !RPC_IS_ASYNC(req->rq_task));
6520 * Decode SECINFO response
6522 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6523 struct xdr_stream *xdr,
6524 struct nfs4_secinfo_res *res)
6526 struct compound_hdr hdr;
6529 status = decode_compound_hdr(xdr, &hdr);
6532 status = decode_sequence(xdr, &res->seq_res, rqstp);
6535 status = decode_putfh(xdr);
6538 status = decode_secinfo(xdr, res);
6545 #if defined(CONFIG_NFS_V4_1)
6547 * Decode EXCHANGE_ID response
6549 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6550 struct xdr_stream *xdr,
6553 struct compound_hdr hdr;
6556 status = decode_compound_hdr(xdr, &hdr);
6558 status = decode_exchange_id(xdr, res);
6563 * Decode CREATE_SESSION response
6565 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6566 struct xdr_stream *xdr,
6567 struct nfs41_create_session_res *res)
6569 struct compound_hdr hdr;
6572 status = decode_compound_hdr(xdr, &hdr);
6574 status = decode_create_session(xdr, res);
6579 * Decode DESTROY_SESSION response
6581 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6582 struct xdr_stream *xdr,
6585 struct compound_hdr hdr;
6588 status = decode_compound_hdr(xdr, &hdr);
6590 status = decode_destroy_session(xdr, res);
6595 * Decode SEQUENCE response
6597 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6598 struct xdr_stream *xdr,
6599 struct nfs4_sequence_res *res)
6601 struct compound_hdr hdr;
6604 status = decode_compound_hdr(xdr, &hdr);
6606 status = decode_sequence(xdr, res, rqstp);
6611 * Decode GET_LEASE_TIME response
6613 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6614 struct xdr_stream *xdr,
6615 struct nfs4_get_lease_time_res *res)
6617 struct compound_hdr hdr;
6620 status = decode_compound_hdr(xdr, &hdr);
6622 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6624 status = decode_putrootfh(xdr);
6626 status = decode_fsinfo(xdr, res->lr_fsinfo);
6631 * Decode RECLAIM_COMPLETE response
6633 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6634 struct xdr_stream *xdr,
6635 struct nfs41_reclaim_complete_res *res)
6637 struct compound_hdr hdr;
6640 status = decode_compound_hdr(xdr, &hdr);
6642 status = decode_sequence(xdr, &res->seq_res, rqstp);
6644 status = decode_reclaim_complete(xdr, (void *)NULL);
6649 * Decode GETDEVICELIST response
6651 static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6652 struct xdr_stream *xdr,
6653 struct nfs4_getdevicelist_res *res)
6655 struct compound_hdr hdr;
6658 dprintk("encoding getdevicelist!\n");
6660 status = decode_compound_hdr(xdr, &hdr);
6663 status = decode_sequence(xdr, &res->seq_res, rqstp);
6666 status = decode_putfh(xdr);
6669 status = decode_getdevicelist(xdr, res->devlist);
6675 * Decode GETDEVINFO response
6677 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6678 struct xdr_stream *xdr,
6679 struct nfs4_getdeviceinfo_res *res)
6681 struct compound_hdr hdr;
6684 status = decode_compound_hdr(xdr, &hdr);
6687 status = decode_sequence(xdr, &res->seq_res, rqstp);
6690 status = decode_getdeviceinfo(xdr, res->pdev);
6696 * Decode LAYOUTGET response
6698 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6699 struct xdr_stream *xdr,
6700 struct nfs4_layoutget_res *res)
6702 struct compound_hdr hdr;
6705 status = decode_compound_hdr(xdr, &hdr);
6708 status = decode_sequence(xdr, &res->seq_res, rqstp);
6711 status = decode_putfh(xdr);
6714 status = decode_layoutget(xdr, rqstp, res);
6720 * Decode LAYOUTRETURN response
6722 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6723 struct xdr_stream *xdr,
6724 struct nfs4_layoutreturn_res *res)
6726 struct compound_hdr hdr;
6729 status = decode_compound_hdr(xdr, &hdr);
6732 status = decode_sequence(xdr, &res->seq_res, rqstp);
6735 status = decode_putfh(xdr);
6738 status = decode_layoutreturn(xdr, res);
6744 * Decode LAYOUTCOMMIT response
6746 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6747 struct xdr_stream *xdr,
6748 struct nfs4_layoutcommit_res *res)
6750 struct compound_hdr hdr;
6753 status = decode_compound_hdr(xdr, &hdr);
6756 status = decode_sequence(xdr, &res->seq_res, rqstp);
6759 status = decode_putfh(xdr);
6762 status = decode_layoutcommit(xdr, rqstp, res);
6765 decode_getfattr(xdr, res->fattr, res->server,
6766 !RPC_IS_ASYNC(rqstp->rq_task));
6772 * Decode SECINFO_NO_NAME response
6774 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6775 struct xdr_stream *xdr,
6776 struct nfs4_secinfo_res *res)
6778 struct compound_hdr hdr;
6781 status = decode_compound_hdr(xdr, &hdr);
6784 status = decode_sequence(xdr, &res->seq_res, rqstp);
6787 status = decode_putrootfh(xdr);
6790 status = decode_secinfo(xdr, res);
6796 * Decode TEST_STATEID response
6798 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6799 struct xdr_stream *xdr,
6800 struct nfs41_test_stateid_res *res)
6802 struct compound_hdr hdr;
6805 status = decode_compound_hdr(xdr, &hdr);
6808 status = decode_sequence(xdr, &res->seq_res, rqstp);
6811 status = decode_test_stateid(xdr, res);
6817 * Decode FREE_STATEID response
6819 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6820 struct xdr_stream *xdr,
6821 struct nfs41_free_stateid_res *res)
6823 struct compound_hdr hdr;
6826 status = decode_compound_hdr(xdr, &hdr);
6829 status = decode_sequence(xdr, &res->seq_res, rqstp);
6832 status = decode_free_stateid(xdr, res);
6836 #endif /* CONFIG_NFS_V4_1 */
6839 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6840 * the local page cache.
6841 * @xdr: XDR stream where entry resides
6842 * @entry: buffer to fill in with entry data
6843 * @plus: boolean indicating whether this should be a readdirplus entry
6845 * Returns zero if successful, otherwise a negative errno value is
6848 * This function is not invoked during READDIR reply decoding, but
6849 * rather whenever an application invokes the getdents(2) system call
6850 * on a directory already in our cache.
6852 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6855 uint32_t bitmap[2] = {0};
6857 __be32 *p = xdr_inline_decode(xdr, 4);
6860 if (*p == xdr_zero) {
6861 p = xdr_inline_decode(xdr, 4);
6870 p = xdr_inline_decode(xdr, 12);
6873 entry->prev_cookie = entry->cookie;
6874 p = xdr_decode_hyper(p, &entry->cookie);
6875 entry->len = be32_to_cpup(p);
6877 p = xdr_inline_decode(xdr, entry->len);
6880 entry->name = (const char *) p;
6883 * In case the server doesn't return an inode number,
6884 * we fake one here. (We don't use inode number 0,
6885 * since glibc seems to choke on it...)
6888 entry->fattr->valid = 0;
6890 if (decode_attr_bitmap(xdr, bitmap) < 0)
6893 if (decode_attr_length(xdr, &len, &p) < 0)
6896 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6897 entry->server, 1) < 0)
6899 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6900 entry->ino = entry->fattr->mounted_on_fileid;
6901 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6902 entry->ino = entry->fattr->fileid;
6904 entry->d_type = DT_UNKNOWN;
6905 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6906 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6911 print_overflow_msg(__func__, xdr);
6916 * We need to translate between nfs status return values and
6917 * the local errno values which may not be the same.
6924 { NFS4ERR_PERM, -EPERM },
6925 { NFS4ERR_NOENT, -ENOENT },
6926 { NFS4ERR_IO, -errno_NFSERR_IO},
6927 { NFS4ERR_NXIO, -ENXIO },
6928 { NFS4ERR_ACCESS, -EACCES },
6929 { NFS4ERR_EXIST, -EEXIST },
6930 { NFS4ERR_XDEV, -EXDEV },
6931 { NFS4ERR_NOTDIR, -ENOTDIR },
6932 { NFS4ERR_ISDIR, -EISDIR },
6933 { NFS4ERR_INVAL, -EINVAL },
6934 { NFS4ERR_FBIG, -EFBIG },
6935 { NFS4ERR_NOSPC, -ENOSPC },
6936 { NFS4ERR_ROFS, -EROFS },
6937 { NFS4ERR_MLINK, -EMLINK },
6938 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6939 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6940 { NFS4ERR_DQUOT, -EDQUOT },
6941 { NFS4ERR_STALE, -ESTALE },
6942 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6943 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6944 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6945 { NFS4ERR_TOOSMALL, -ETOOSMALL },
6946 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
6947 { NFS4ERR_BADTYPE, -EBADTYPE },
6948 { NFS4ERR_LOCKED, -EAGAIN },
6949 { NFS4ERR_SYMLINK, -ELOOP },
6950 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6951 { NFS4ERR_DEADLOCK, -EDEADLK },
6956 * Convert an NFS error code to a local one.
6957 * This one is used jointly by NFSv2 and NFSv3.
6960 nfs4_stat_to_errno(int stat)
6963 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6964 if (nfs_errtbl[i].stat == stat)
6965 return nfs_errtbl[i].errno;
6967 if (stat <= 10000 || stat > 10100) {
6968 /* The server is looney tunes. */
6971 /* If we cannot translate the error, the recovery routines should
6973 * Note: remaining NFSv4 error codes have values > 10000, so should
6974 * not conflict with native Linux error codes.
6979 #define PROC(proc, argtype, restype) \
6980 [NFSPROC4_CLNT_##proc] = { \
6981 .p_proc = NFSPROC4_COMPOUND, \
6982 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6983 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6984 .p_arglen = NFS4_##argtype##_sz, \
6985 .p_replen = NFS4_##restype##_sz, \
6986 .p_statidx = NFSPROC4_CLNT_##proc, \
6990 struct rpc_procinfo nfs4_procedures[] = {
6991 PROC(READ, enc_read, dec_read),
6992 PROC(WRITE, enc_write, dec_write),
6993 PROC(COMMIT, enc_commit, dec_commit),
6994 PROC(OPEN, enc_open, dec_open),
6995 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6996 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6997 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6998 PROC(CLOSE, enc_close, dec_close),
6999 PROC(SETATTR, enc_setattr, dec_setattr),
7000 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7001 PROC(RENEW, enc_renew, dec_renew),
7002 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7003 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7004 PROC(LOCK, enc_lock, dec_lock),
7005 PROC(LOCKT, enc_lockt, dec_lockt),
7006 PROC(LOCKU, enc_locku, dec_locku),
7007 PROC(ACCESS, enc_access, dec_access),
7008 PROC(GETATTR, enc_getattr, dec_getattr),
7009 PROC(LOOKUP, enc_lookup, dec_lookup),
7010 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7011 PROC(REMOVE, enc_remove, dec_remove),
7012 PROC(RENAME, enc_rename, dec_rename),
7013 PROC(LINK, enc_link, dec_link),
7014 PROC(SYMLINK, enc_symlink, dec_symlink),
7015 PROC(CREATE, enc_create, dec_create),
7016 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7017 PROC(STATFS, enc_statfs, dec_statfs),
7018 PROC(READLINK, enc_readlink, dec_readlink),
7019 PROC(READDIR, enc_readdir, dec_readdir),
7020 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7021 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7022 PROC(GETACL, enc_getacl, dec_getacl),
7023 PROC(SETACL, enc_setacl, dec_setacl),
7024 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7025 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7026 PROC(SECINFO, enc_secinfo, dec_secinfo),
7027 #if defined(CONFIG_NFS_V4_1)
7028 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7029 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7030 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7031 PROC(SEQUENCE, enc_sequence, dec_sequence),
7032 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7033 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7034 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7035 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7036 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7037 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7038 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7039 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7040 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7041 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
7042 #endif /* CONFIG_NFS_V4_1 */
7045 struct rpc_version nfs_version4 = {
7047 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7048 .procs = nfs4_procedures