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/module.h>
48 #include <linux/utsname.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/sunrpc/msg_prot.h>
51 #include <linux/sunrpc/gss_api.h>
52 #include <linux/nfs.h>
53 #include <linux/nfs4.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/nfs_idmap.h>
62 #define NFSDBG_FACILITY NFSDBG_XDR
64 /* Mapping from NFS error code to "errno" error code. */
65 #define errno_NFSERR_IO EIO
67 static int nfs4_stat_to_errno(int);
69 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71 #define NFS4_MAXTAGLEN 20
73 #define NFS4_MAXTAGLEN 0
76 /* lock,open owner id:
77 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
79 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
80 #define lock_owner_id_maxsz (1 + 1 + 4)
81 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
82 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
83 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84 #define op_encode_hdr_maxsz (1)
85 #define op_decode_hdr_maxsz (2)
86 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
87 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
89 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
93 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
94 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
95 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
96 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
97 ((3+NFS4_FHSIZE) >> 2))
98 #define nfs4_fattr_bitmap_maxsz 4
99 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
100 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
101 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
102 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
103 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104 /* This is based on getfattr, which uses the most attributes: */
105 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
106 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
107 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
108 nfs4_fattr_value_maxsz)
109 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
110 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
115 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
116 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
117 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
118 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
119 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
120 /* The 5 accounts for the PNFS attributes, and assumes that at most three
121 * layout types will be returned.
123 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
124 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
125 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
126 #define decode_renew_maxsz (op_decode_hdr_maxsz)
127 #define encode_setclientid_maxsz \
128 (op_encode_hdr_maxsz + \
129 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
130 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
132 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
133 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
135 #define decode_setclientid_maxsz \
136 (op_decode_hdr_maxsz + \
138 1024) /* large value for CLID_INUSE */
139 #define encode_setclientid_confirm_maxsz \
140 (op_encode_hdr_maxsz + \
141 3 + (NFS4_VERIFIER_SIZE >> 2))
142 #define decode_setclientid_confirm_maxsz \
143 (op_decode_hdr_maxsz)
144 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
145 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
146 #define encode_share_access_maxsz \
148 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
149 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
150 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
151 #define encode_open_maxsz (op_encode_hdr_maxsz + \
152 2 + encode_share_access_maxsz + 2 + \
153 open_owner_id_maxsz + \
154 encode_opentype_maxsz + \
155 encode_claim_null_maxsz)
156 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
157 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
159 #define decode_change_info_maxsz (5)
160 #define decode_open_maxsz (op_decode_hdr_maxsz + \
161 decode_stateid_maxsz + \
162 decode_change_info_maxsz + 1 + \
163 nfs4_fattr_bitmap_maxsz + \
164 decode_delegation_maxsz)
165 #define encode_open_confirm_maxsz \
166 (op_encode_hdr_maxsz + \
167 encode_stateid_maxsz + 1)
168 #define decode_open_confirm_maxsz \
169 (op_decode_hdr_maxsz + \
170 decode_stateid_maxsz)
171 #define encode_open_downgrade_maxsz \
172 (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + 1 + \
174 encode_share_access_maxsz)
175 #define decode_open_downgrade_maxsz \
176 (op_decode_hdr_maxsz + \
177 decode_stateid_maxsz)
178 #define encode_close_maxsz (op_encode_hdr_maxsz + \
179 1 + encode_stateid_maxsz)
180 #define decode_close_maxsz (op_decode_hdr_maxsz + \
181 decode_stateid_maxsz)
182 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + \
185 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
186 nfs4_fattr_bitmap_maxsz)
187 #define encode_read_maxsz (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 3)
189 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
190 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
191 2 + encode_verifier_maxsz + 5)
192 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
193 decode_verifier_maxsz)
194 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
195 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
196 #define encode_write_maxsz (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + 4)
198 #define decode_write_maxsz (op_decode_hdr_maxsz + \
199 2 + decode_verifier_maxsz)
200 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
201 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
202 decode_verifier_maxsz)
203 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
205 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
206 decode_change_info_maxsz)
207 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
209 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
210 decode_change_info_maxsz + \
211 decode_change_info_maxsz)
212 #define encode_link_maxsz (op_encode_hdr_maxsz + \
214 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
215 #define encode_lockowner_maxsz (7)
216 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
218 1 + encode_stateid_maxsz + 1 + \
219 encode_lockowner_maxsz)
220 #define decode_lock_denied_maxsz \
221 (8 + decode_lockowner_maxsz)
222 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
223 decode_lock_denied_maxsz)
224 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
225 encode_lockowner_maxsz)
226 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
227 decode_lock_denied_maxsz)
228 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
229 encode_stateid_maxsz + \
231 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
232 decode_stateid_maxsz)
233 #define encode_release_lockowner_maxsz \
234 (op_encode_hdr_maxsz + \
235 encode_lockowner_maxsz)
236 #define decode_release_lockowner_maxsz \
237 (op_decode_hdr_maxsz)
238 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
239 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
240 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
241 1 + nfs4_name_maxsz + \
244 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
245 #define encode_create_maxsz (op_encode_hdr_maxsz + \
246 1 + 2 + nfs4_name_maxsz + \
248 #define decode_create_maxsz (op_decode_hdr_maxsz + \
249 decode_change_info_maxsz + \
250 nfs4_fattr_bitmap_maxsz)
251 #define encode_statfs_maxsz (encode_getattr_maxsz)
252 #define decode_statfs_maxsz (decode_getattr_maxsz)
253 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
254 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
255 #define encode_getacl_maxsz (encode_getattr_maxsz)
256 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
257 nfs4_fattr_bitmap_maxsz + 1)
258 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
259 encode_stateid_maxsz + 3)
260 #define decode_setacl_maxsz (decode_setattr_maxsz)
261 #define encode_fs_locations_maxsz \
262 (encode_getattr_maxsz)
263 #define decode_fs_locations_maxsz \
265 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
266 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
268 #if defined(CONFIG_NFS_V4_1)
269 #define NFS4_MAX_MACHINE_NAME_LEN (64)
271 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
272 encode_verifier_maxsz + \
273 1 /* co_ownerid.len */ + \
274 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
277 0 /* SP4_NONE (for now) */ + \
278 1 /* implementation id array of size 1 */ + \
279 1 /* nii_domain */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
282 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
284 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
285 2 /* eir_clientid */ + \
286 1 /* eir_sequenceid */ + \
287 1 /* eir_flags */ + \
289 0 /* SP4_NONE (for now) */ + \
290 2 /* eir_server_owner.so_minor_id */ + \
291 /* eir_server_owner.so_major_id<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 /* eir_server_scope<> */ \
294 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
295 1 /* eir_server_impl_id array length */ + \
296 1 /* nii_domain */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
299 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
302 #define decode_channel_attrs_maxsz (6 + \
303 1 /* ca_rdma_ird.len */ + \
305 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
306 2 /* csa_clientid */ + \
307 1 /* csa_sequence */ + \
308 1 /* csa_flags */ + \
309 encode_channel_attrs_maxsz + \
310 encode_channel_attrs_maxsz + \
311 1 /* csa_cb_program */ + \
312 1 /* csa_sec_parms.len (1) */ + \
313 1 /* cb_secflavor (AUTH_SYS) */ + \
315 1 /* machinename.len */ + \
316 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
319 1 /* gids.len (0) */)
320 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
321 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
322 1 /* csr_sequence */ + \
323 1 /* csr_flags */ + \
324 decode_channel_attrs_maxsz + \
325 decode_channel_attrs_maxsz)
326 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
327 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
328 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
330 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
331 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
332 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
333 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
334 #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
335 encode_verifier_maxsz)
336 #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
337 2 /* nfs_cookie4 gdlr_cookie */ + \
338 decode_verifier_maxsz \
339 /* verifier4 gdlr_verifier */ + \
340 1 /* gdlr_deviceid_list count */ + \
341 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
342 NFS4_DEVICEID4_SIZE) \
343 /* gdlr_deviceid_list */ + \
344 1 /* bool gdlr_eof */)
345 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
346 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
347 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
348 1 /* layout type */ + \
349 1 /* opaque devaddr4 length */ + \
350 /* devaddr4 payload is read into page */ \
351 1 /* notification bitmap length */ + \
352 1 /* notification bitmap */)
353 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
354 encode_stateid_maxsz)
355 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
356 decode_stateid_maxsz + \
357 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
358 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
362 encode_stateid_maxsz + \
363 1 /* new offset (true) */ + \
364 2 /* last byte written */ + \
365 1 /* nt_timechanged (false) */ + \
366 1 /* layoutupdate4 layout type */ + \
367 1 /* NULL filelayout layoutupdate4 payload */)
368 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
369 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
370 encode_stateid_maxsz + \
371 1 /* FIXME: opaque lrf_body always empty at the moment */)
372 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
373 1 + decode_stateid_maxsz)
374 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
375 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
376 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
377 XDR_QUADLEN(NFS4_STATEID_SIZE))
378 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
379 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
380 XDR_QUADLEN(NFS4_STATEID_SIZE))
381 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
382 #else /* CONFIG_NFS_V4_1 */
383 #define encode_sequence_maxsz 0
384 #define decode_sequence_maxsz 0
385 #endif /* CONFIG_NFS_V4_1 */
387 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
388 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
389 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
390 encode_sequence_maxsz + \
391 encode_putfh_maxsz + \
393 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
394 decode_sequence_maxsz + \
395 decode_putfh_maxsz + \
397 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
398 encode_sequence_maxsz + \
399 encode_putfh_maxsz + \
400 encode_readlink_maxsz)
401 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
402 decode_sequence_maxsz + \
403 decode_putfh_maxsz + \
404 decode_readlink_maxsz)
405 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
406 encode_sequence_maxsz + \
407 encode_putfh_maxsz + \
408 encode_readdir_maxsz)
409 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
410 decode_sequence_maxsz + \
411 decode_putfh_maxsz + \
412 decode_readdir_maxsz)
413 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
414 encode_sequence_maxsz + \
415 encode_putfh_maxsz + \
416 encode_write_maxsz + \
417 encode_getattr_maxsz)
418 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
419 decode_sequence_maxsz + \
420 decode_putfh_maxsz + \
421 decode_write_maxsz + \
422 decode_getattr_maxsz)
423 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
424 encode_sequence_maxsz + \
425 encode_putfh_maxsz + \
427 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
428 decode_sequence_maxsz + \
429 decode_putfh_maxsz + \
431 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
432 encode_sequence_maxsz + \
433 encode_putfh_maxsz + \
434 encode_open_maxsz + \
435 encode_getfh_maxsz + \
436 encode_getattr_maxsz)
437 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
438 decode_sequence_maxsz + \
439 decode_putfh_maxsz + \
440 decode_open_maxsz + \
441 decode_getfh_maxsz + \
442 decode_getattr_maxsz)
443 #define NFS4_enc_open_confirm_sz \
444 (compound_encode_hdr_maxsz + \
445 encode_putfh_maxsz + \
446 encode_open_confirm_maxsz)
447 #define NFS4_dec_open_confirm_sz \
448 (compound_decode_hdr_maxsz + \
449 decode_putfh_maxsz + \
450 decode_open_confirm_maxsz)
451 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
452 encode_sequence_maxsz + \
453 encode_putfh_maxsz + \
454 encode_open_maxsz + \
455 encode_getattr_maxsz)
456 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
457 decode_sequence_maxsz + \
458 decode_putfh_maxsz + \
459 decode_open_maxsz + \
460 decode_getattr_maxsz)
461 #define NFS4_enc_open_downgrade_sz \
462 (compound_encode_hdr_maxsz + \
463 encode_sequence_maxsz + \
464 encode_putfh_maxsz + \
465 encode_open_downgrade_maxsz + \
466 encode_getattr_maxsz)
467 #define NFS4_dec_open_downgrade_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_sequence_maxsz + \
470 decode_putfh_maxsz + \
471 decode_open_downgrade_maxsz + \
472 decode_getattr_maxsz)
473 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
474 encode_sequence_maxsz + \
475 encode_putfh_maxsz + \
476 encode_close_maxsz + \
477 encode_getattr_maxsz)
478 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
479 decode_sequence_maxsz + \
480 decode_putfh_maxsz + \
481 decode_close_maxsz + \
482 decode_getattr_maxsz)
483 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
484 encode_sequence_maxsz + \
485 encode_putfh_maxsz + \
486 encode_setattr_maxsz + \
487 encode_getattr_maxsz)
488 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
489 decode_sequence_maxsz + \
490 decode_putfh_maxsz + \
491 decode_setattr_maxsz + \
492 decode_getattr_maxsz)
493 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
494 encode_sequence_maxsz + \
495 encode_putfh_maxsz + \
497 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
498 decode_sequence_maxsz + \
499 decode_putfh_maxsz + \
501 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
503 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
505 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
506 encode_setclientid_maxsz)
507 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
508 decode_setclientid_maxsz)
509 #define NFS4_enc_setclientid_confirm_sz \
510 (compound_encode_hdr_maxsz + \
511 encode_setclientid_confirm_maxsz + \
512 encode_putrootfh_maxsz + \
514 #define NFS4_dec_setclientid_confirm_sz \
515 (compound_decode_hdr_maxsz + \
516 decode_setclientid_confirm_maxsz + \
517 decode_putrootfh_maxsz + \
519 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
520 encode_sequence_maxsz + \
521 encode_putfh_maxsz + \
523 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
524 decode_sequence_maxsz + \
525 decode_putfh_maxsz + \
527 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
528 encode_sequence_maxsz + \
529 encode_putfh_maxsz + \
531 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
532 decode_sequence_maxsz + \
533 decode_putfh_maxsz + \
535 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
536 encode_sequence_maxsz + \
537 encode_putfh_maxsz + \
539 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
540 decode_sequence_maxsz + \
541 decode_putfh_maxsz + \
543 #define NFS4_enc_release_lockowner_sz \
544 (compound_encode_hdr_maxsz + \
545 encode_lockowner_maxsz)
546 #define NFS4_dec_release_lockowner_sz \
547 (compound_decode_hdr_maxsz + \
548 decode_lockowner_maxsz)
549 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
550 encode_sequence_maxsz + \
551 encode_putfh_maxsz + \
552 encode_access_maxsz + \
553 encode_getattr_maxsz)
554 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
555 decode_sequence_maxsz + \
556 decode_putfh_maxsz + \
557 decode_access_maxsz + \
558 decode_getattr_maxsz)
559 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
560 encode_sequence_maxsz + \
561 encode_putfh_maxsz + \
562 encode_getattr_maxsz)
563 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
564 decode_sequence_maxsz + \
565 decode_putfh_maxsz + \
566 decode_getattr_maxsz)
567 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
568 encode_sequence_maxsz + \
569 encode_putfh_maxsz + \
570 encode_lookup_maxsz + \
571 encode_getattr_maxsz + \
573 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
574 decode_sequence_maxsz + \
575 decode_putfh_maxsz + \
576 decode_lookup_maxsz + \
577 decode_getattr_maxsz + \
579 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
580 encode_sequence_maxsz + \
581 encode_putrootfh_maxsz + \
582 encode_getattr_maxsz + \
584 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
585 decode_sequence_maxsz + \
586 decode_putrootfh_maxsz + \
587 decode_getattr_maxsz + \
589 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
590 encode_sequence_maxsz + \
591 encode_putfh_maxsz + \
593 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
594 decode_sequence_maxsz + \
595 decode_putfh_maxsz + \
597 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
598 encode_sequence_maxsz + \
599 encode_putfh_maxsz + \
600 encode_savefh_maxsz + \
601 encode_putfh_maxsz + \
603 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
604 decode_sequence_maxsz + \
605 decode_putfh_maxsz + \
606 decode_savefh_maxsz + \
607 decode_putfh_maxsz + \
609 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
610 encode_sequence_maxsz + \
611 encode_putfh_maxsz + \
612 encode_savefh_maxsz + \
613 encode_putfh_maxsz + \
614 encode_link_maxsz + \
615 encode_restorefh_maxsz + \
616 encode_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_restorefh_maxsz + \
624 decode_getattr_maxsz)
625 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
626 encode_sequence_maxsz + \
627 encode_putfh_maxsz + \
628 encode_symlink_maxsz + \
629 encode_getattr_maxsz + \
631 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
632 decode_sequence_maxsz + \
633 decode_putfh_maxsz + \
634 decode_symlink_maxsz + \
635 decode_getattr_maxsz + \
637 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
638 encode_sequence_maxsz + \
639 encode_putfh_maxsz + \
640 encode_create_maxsz + \
641 encode_getfh_maxsz + \
642 encode_getattr_maxsz)
643 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
644 decode_sequence_maxsz + \
645 decode_putfh_maxsz + \
646 decode_create_maxsz + \
647 decode_getfh_maxsz + \
648 decode_getattr_maxsz)
649 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
650 encode_sequence_maxsz + \
651 encode_putfh_maxsz + \
652 encode_getattr_maxsz)
653 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
654 decode_sequence_maxsz + \
655 decode_putfh_maxsz + \
656 decode_getattr_maxsz)
657 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
658 encode_sequence_maxsz + \
659 encode_putfh_maxsz + \
661 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
662 decode_sequence_maxsz + \
663 decode_putfh_maxsz + \
665 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
666 encode_sequence_maxsz + \
667 encode_putfh_maxsz + \
668 encode_getattr_maxsz)
669 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
670 decode_sequence_maxsz + \
671 decode_putfh_maxsz + \
672 decode_getattr_maxsz)
673 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
674 encode_sequence_maxsz + \
675 encode_putfh_maxsz + \
676 encode_delegreturn_maxsz + \
677 encode_getattr_maxsz)
678 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
679 decode_sequence_maxsz + \
680 decode_delegreturn_maxsz + \
681 decode_getattr_maxsz)
682 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
683 encode_sequence_maxsz + \
684 encode_putfh_maxsz + \
686 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
687 decode_sequence_maxsz + \
688 decode_putfh_maxsz + \
690 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
691 encode_sequence_maxsz + \
692 encode_putfh_maxsz + \
694 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
695 decode_sequence_maxsz + \
696 decode_putfh_maxsz + \
698 #define NFS4_enc_fs_locations_sz \
699 (compound_encode_hdr_maxsz + \
700 encode_sequence_maxsz + \
701 encode_putfh_maxsz + \
702 encode_lookup_maxsz + \
703 encode_fs_locations_maxsz)
704 #define NFS4_dec_fs_locations_sz \
705 (compound_decode_hdr_maxsz + \
706 decode_sequence_maxsz + \
707 decode_putfh_maxsz + \
708 decode_lookup_maxsz + \
709 decode_fs_locations_maxsz)
710 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_putfh_maxsz + \
713 encode_secinfo_maxsz)
714 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
715 decode_sequence_maxsz + \
716 decode_putfh_maxsz + \
717 decode_secinfo_maxsz)
718 #if defined(CONFIG_NFS_V4_1)
719 #define NFS4_enc_exchange_id_sz \
720 (compound_encode_hdr_maxsz + \
721 encode_exchange_id_maxsz)
722 #define NFS4_dec_exchange_id_sz \
723 (compound_decode_hdr_maxsz + \
724 decode_exchange_id_maxsz)
725 #define NFS4_enc_create_session_sz \
726 (compound_encode_hdr_maxsz + \
727 encode_create_session_maxsz)
728 #define NFS4_dec_create_session_sz \
729 (compound_decode_hdr_maxsz + \
730 decode_create_session_maxsz)
731 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
732 encode_destroy_session_maxsz)
733 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
734 decode_destroy_session_maxsz)
735 #define NFS4_enc_sequence_sz \
736 (compound_decode_hdr_maxsz + \
737 encode_sequence_maxsz)
738 #define NFS4_dec_sequence_sz \
739 (compound_decode_hdr_maxsz + \
740 decode_sequence_maxsz)
741 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
742 encode_sequence_maxsz + \
743 encode_putrootfh_maxsz + \
745 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
746 decode_sequence_maxsz + \
747 decode_putrootfh_maxsz + \
749 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
750 encode_sequence_maxsz + \
751 encode_reclaim_complete_maxsz)
752 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_reclaim_complete_maxsz)
755 #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_getdevicelist_maxsz)
759 #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_getdevicelist_maxsz)
763 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz +\
765 encode_getdeviceinfo_maxsz)
766 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
767 decode_sequence_maxsz + \
768 decode_getdeviceinfo_maxsz)
769 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
770 encode_sequence_maxsz + \
771 encode_putfh_maxsz + \
772 encode_layoutget_maxsz)
773 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_putfh_maxsz + \
776 decode_layoutget_maxsz)
777 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz +\
779 encode_putfh_maxsz + \
780 encode_layoutcommit_maxsz + \
781 encode_getattr_maxsz)
782 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
783 decode_sequence_maxsz + \
784 decode_putfh_maxsz + \
785 decode_layoutcommit_maxsz + \
786 decode_getattr_maxsz)
787 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_layoutreturn_maxsz)
791 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_layoutreturn_maxsz)
795 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz + \
797 encode_putrootfh_maxsz +\
798 encode_secinfo_no_name_maxsz)
799 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
800 decode_sequence_maxsz + \
801 decode_putrootfh_maxsz + \
802 decode_secinfo_no_name_maxsz)
803 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_test_stateid_maxsz)
806 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz + \
808 decode_test_stateid_maxsz)
809 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_free_stateid_maxsz)
812 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_free_stateid_maxsz)
816 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
817 compound_encode_hdr_maxsz +
818 encode_sequence_maxsz +
820 encode_getattr_maxsz) *
823 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
824 compound_decode_hdr_maxsz +
825 decode_sequence_maxsz +
826 decode_putfh_maxsz) *
828 #endif /* CONFIG_NFS_V4_1 */
830 static unsigned short send_implementation_id = 1;
832 module_param(send_implementation_id, ushort, 0644);
833 MODULE_PARM_DESC(send_implementation_id,
834 "Send implementation ID with NFSv4.1 exchange_id");
836 static const umode_t nfs_type2fmt[] = {
843 [NF4SOCK] = S_IFSOCK,
849 struct compound_hdr {
855 uint32_t replen; /* expected reply words */
859 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
861 __be32 *p = xdr_reserve_space(xdr, nbytes);
866 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
870 p = xdr_reserve_space(xdr, len);
871 xdr_encode_opaque_fixed(p, buf, len);
874 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
878 p = reserve_space(xdr, 4 + len);
879 xdr_encode_opaque(p, str, len);
882 static void encode_uint32(struct xdr_stream *xdr, u32 n)
886 p = reserve_space(xdr, 4);
890 static void encode_uint64(struct xdr_stream *xdr, u64 n)
894 p = reserve_space(xdr, 8);
895 xdr_encode_hyper(p, n);
898 static void encode_nfs4_seqid(struct xdr_stream *xdr,
899 const struct nfs_seqid *seqid)
901 encode_uint32(xdr, seqid->sequence->counter);
904 static void encode_compound_hdr(struct xdr_stream *xdr,
905 struct rpc_rqst *req,
906 struct compound_hdr *hdr)
909 struct rpc_auth *auth = req->rq_cred->cr_auth;
911 /* initialize running count of expected bytes in reply.
912 * NOTE: the replied tag SHOULD be the same is the one sent,
913 * but this is not required as a MUST for the server to do so. */
914 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
916 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
917 encode_string(xdr, hdr->taglen, hdr->tag);
918 p = reserve_space(xdr, 8);
919 *p++ = cpu_to_be32(hdr->minorversion);
921 *p = cpu_to_be32(hdr->nops);
924 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
926 struct compound_hdr *hdr)
928 encode_uint32(xdr, op);
930 hdr->replen += replen;
933 static void encode_nops(struct compound_hdr *hdr)
935 BUG_ON(hdr->nops > NFS4_MAX_OPS);
936 *hdr->nops_p = htonl(hdr->nops);
939 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
941 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
944 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
946 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
949 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
951 char owner_name[IDMAP_NAMESZ];
952 char owner_group[IDMAP_NAMESZ];
953 int owner_namelen = 0;
954 int owner_grouplen = 0;
962 * We reserve enough space to write the entire attribute buffer at once.
963 * In the worst-case, this would be
964 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
965 * = 36 bytes, plus any contribution from variable-length fields
966 * such as owner/group.
971 if (iap->ia_valid & ATTR_SIZE)
973 if (iap->ia_valid & ATTR_MODE)
975 if (iap->ia_valid & ATTR_UID) {
976 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
977 if (owner_namelen < 0) {
978 dprintk("nfs: couldn't resolve uid %d to string\n",
981 strcpy(owner_name, "nobody");
982 owner_namelen = sizeof("nobody") - 1;
985 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
987 if (iap->ia_valid & ATTR_GID) {
988 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
989 if (owner_grouplen < 0) {
990 dprintk("nfs: couldn't resolve gid %d to string\n",
992 strcpy(owner_group, "nobody");
993 owner_grouplen = sizeof("nobody") - 1;
996 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
998 if (iap->ia_valid & ATTR_ATIME_SET)
1000 else if (iap->ia_valid & ATTR_ATIME)
1002 if (iap->ia_valid & ATTR_MTIME_SET)
1004 else if (iap->ia_valid & ATTR_MTIME)
1006 p = reserve_space(xdr, len);
1009 * We write the bitmap length now, but leave the bitmap and the attribute
1010 * buffer length to be backfilled at the end of this routine.
1012 *p++ = cpu_to_be32(2);
1016 if (iap->ia_valid & ATTR_SIZE) {
1017 bmval0 |= FATTR4_WORD0_SIZE;
1018 p = xdr_encode_hyper(p, iap->ia_size);
1020 if (iap->ia_valid & ATTR_MODE) {
1021 bmval1 |= FATTR4_WORD1_MODE;
1022 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1024 if (iap->ia_valid & ATTR_UID) {
1025 bmval1 |= FATTR4_WORD1_OWNER;
1026 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1028 if (iap->ia_valid & ATTR_GID) {
1029 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
1030 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1032 if (iap->ia_valid & ATTR_ATIME_SET) {
1033 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1034 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1035 *p++ = cpu_to_be32(0);
1036 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1037 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1039 else if (iap->ia_valid & ATTR_ATIME) {
1040 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1041 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1043 if (iap->ia_valid & ATTR_MTIME_SET) {
1044 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1045 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1046 *p++ = cpu_to_be32(0);
1047 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1048 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1050 else if (iap->ia_valid & ATTR_MTIME) {
1051 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1052 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1056 * Now we backfill the bitmap and the attribute buffer length.
1058 if (len != ((char *)p - (char *)q) + 4) {
1059 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
1060 len, ((char *)p - (char *)q) + 4);
1063 len = (char *)p - (char *)q - 12;
1064 *q++ = htonl(bmval0);
1065 *q++ = htonl(bmval1);
1071 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1073 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1074 encode_uint32(xdr, access);
1077 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1079 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1080 encode_nfs4_seqid(xdr, arg->seqid);
1081 encode_nfs4_stateid(xdr, arg->stateid);
1084 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1088 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1089 p = reserve_space(xdr, 12);
1090 p = xdr_encode_hyper(p, args->offset);
1091 *p = cpu_to_be32(args->count);
1094 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1098 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1099 encode_uint32(xdr, create->ftype);
1101 switch (create->ftype) {
1103 p = reserve_space(xdr, 4);
1104 *p = cpu_to_be32(create->u.symlink.len);
1105 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1108 case NF4BLK: case NF4CHR:
1109 p = reserve_space(xdr, 8);
1110 *p++ = cpu_to_be32(create->u.device.specdata1);
1111 *p = cpu_to_be32(create->u.device.specdata2);
1118 encode_string(xdr, create->name->len, create->name->name);
1119 encode_attrs(xdr, create->attrs, create->server);
1122 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1126 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1127 p = reserve_space(xdr, 8);
1128 *p++ = cpu_to_be32(1);
1129 *p = cpu_to_be32(bitmap);
1132 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1136 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1137 p = reserve_space(xdr, 12);
1138 *p++ = cpu_to_be32(2);
1139 *p++ = cpu_to_be32(bm0);
1140 *p = cpu_to_be32(bm1);
1144 encode_getattr_three(struct xdr_stream *xdr,
1145 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1146 struct compound_hdr *hdr)
1150 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1152 p = reserve_space(xdr, 16);
1153 *p++ = cpu_to_be32(3);
1154 *p++ = cpu_to_be32(bm0);
1155 *p++ = cpu_to_be32(bm1);
1156 *p = cpu_to_be32(bm2);
1158 p = reserve_space(xdr, 12);
1159 *p++ = cpu_to_be32(2);
1160 *p++ = cpu_to_be32(bm0);
1161 *p = cpu_to_be32(bm1);
1163 p = reserve_space(xdr, 8);
1164 *p++ = cpu_to_be32(1);
1165 *p = cpu_to_be32(bm0);
1169 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1171 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1172 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1175 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1177 encode_getattr_three(xdr,
1178 bitmask[0] & nfs4_fsinfo_bitmap[0],
1179 bitmask[1] & nfs4_fsinfo_bitmap[1],
1180 bitmask[2] & nfs4_fsinfo_bitmap[2],
1184 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1186 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1187 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1190 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1192 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1195 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1197 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1198 encode_string(xdr, name->len, name->name);
1201 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1203 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1204 return block ? NFS4_READW_LT : NFS4_READ_LT;
1205 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1208 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1210 if (fl->fl_end == OFFSET_MAX)
1211 return ~(uint64_t)0;
1212 return fl->fl_end - fl->fl_start + 1;
1215 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1219 p = reserve_space(xdr, 32);
1220 p = xdr_encode_hyper(p, lowner->clientid);
1221 *p++ = cpu_to_be32(20);
1222 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1223 *p++ = cpu_to_be32(lowner->s_dev);
1224 xdr_encode_hyper(p, lowner->id);
1228 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1229 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1231 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1235 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1236 p = reserve_space(xdr, 28);
1237 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1238 *p++ = cpu_to_be32(args->reclaim);
1239 p = xdr_encode_hyper(p, args->fl->fl_start);
1240 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1241 *p = cpu_to_be32(args->new_lock_owner);
1242 if (args->new_lock_owner){
1243 encode_nfs4_seqid(xdr, args->open_seqid);
1244 encode_nfs4_stateid(xdr, args->open_stateid);
1245 encode_nfs4_seqid(xdr, args->lock_seqid);
1246 encode_lockowner(xdr, &args->lock_owner);
1249 encode_nfs4_stateid(xdr, args->lock_stateid);
1250 encode_nfs4_seqid(xdr, args->lock_seqid);
1254 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1258 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1259 p = reserve_space(xdr, 20);
1260 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1261 p = xdr_encode_hyper(p, args->fl->fl_start);
1262 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1263 encode_lockowner(xdr, &args->lock_owner);
1266 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1270 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1271 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1272 encode_nfs4_seqid(xdr, args->seqid);
1273 encode_nfs4_stateid(xdr, args->stateid);
1274 p = reserve_space(xdr, 16);
1275 p = xdr_encode_hyper(p, args->fl->fl_start);
1276 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1279 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1281 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1282 encode_lockowner(xdr, lowner);
1285 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1287 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1288 encode_string(xdr, name->len, name->name);
1291 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1295 p = reserve_space(xdr, 8);
1296 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1298 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1301 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1303 case FMODE_READ|FMODE_WRITE:
1304 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1307 *p++ = cpu_to_be32(0);
1309 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1312 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1316 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1319 encode_nfs4_seqid(xdr, arg->seqid);
1320 encode_share_access(xdr, arg->fmode);
1321 p = reserve_space(xdr, 36);
1322 p = xdr_encode_hyper(p, arg->clientid);
1323 *p++ = cpu_to_be32(24);
1324 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1325 *p++ = cpu_to_be32(arg->server->s_dev);
1326 *p++ = cpu_to_be32(arg->id.uniquifier);
1327 xdr_encode_hyper(p, arg->id.create_time);
1330 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1333 struct nfs_client *clp;
1335 p = reserve_space(xdr, 4);
1336 switch(arg->open_flags & O_EXCL) {
1338 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1339 encode_attrs(xdr, arg->u.attrs, arg->server);
1342 clp = arg->server->nfs_client;
1343 if (clp->cl_mvops->minor_version > 0) {
1344 if (nfs4_has_persistent_session(clp)) {
1345 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1346 encode_attrs(xdr, arg->u.attrs, arg->server);
1350 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1351 encode_nfs4_verifier(xdr, &arg->u.verifier);
1353 encode_attrs(xdr, &dummy, arg->server);
1356 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1357 encode_nfs4_verifier(xdr, &arg->u.verifier);
1362 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1366 p = reserve_space(xdr, 4);
1367 switch (arg->open_flags & O_CREAT) {
1369 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1372 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1373 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1374 encode_createmode(xdr, arg);
1378 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1382 p = reserve_space(xdr, 4);
1383 switch (delegation_type) {
1385 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1388 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1390 case FMODE_WRITE|FMODE_READ:
1391 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1398 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1402 p = reserve_space(xdr, 4);
1403 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1404 encode_string(xdr, name->len, name->name);
1407 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1411 p = reserve_space(xdr, 4);
1412 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1413 encode_delegation_type(xdr, type);
1416 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1420 p = reserve_space(xdr, 4);
1421 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1422 encode_nfs4_stateid(xdr, stateid);
1423 encode_string(xdr, name->len, name->name);
1426 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1428 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1429 encode_openhdr(xdr, arg);
1430 encode_opentype(xdr, arg);
1431 switch (arg->claim) {
1432 case NFS4_OPEN_CLAIM_NULL:
1433 encode_claim_null(xdr, arg->name);
1435 case NFS4_OPEN_CLAIM_PREVIOUS:
1436 encode_claim_previous(xdr, arg->u.delegation_type);
1438 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1439 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1446 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1448 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1449 encode_nfs4_stateid(xdr, arg->stateid);
1450 encode_nfs4_seqid(xdr, arg->seqid);
1453 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1455 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1456 encode_nfs4_stateid(xdr, arg->stateid);
1457 encode_nfs4_seqid(xdr, arg->seqid);
1458 encode_share_access(xdr, arg->fmode);
1462 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1464 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1465 encode_string(xdr, fh->size, fh->data);
1468 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1470 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1473 static void encode_open_stateid(struct xdr_stream *xdr,
1474 const struct nfs_open_context *ctx,
1475 const struct nfs_lock_context *l_ctx,
1479 nfs4_stateid stateid;
1481 if (ctx->state != NULL) {
1482 nfs4_select_rw_stateid(&stateid, ctx->state,
1483 fmode, l_ctx->lockowner, l_ctx->pid);
1486 encode_nfs4_stateid(xdr, &stateid);
1488 encode_nfs4_stateid(xdr, &zero_stateid);
1491 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1495 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1496 encode_open_stateid(xdr, args->context, args->lock_context,
1497 FMODE_READ, hdr->minorversion);
1499 p = reserve_space(xdr, 12);
1500 p = xdr_encode_hyper(p, args->offset);
1501 *p = cpu_to_be32(args->count);
1504 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1506 uint32_t attrs[2] = {
1507 FATTR4_WORD0_RDATTR_ERROR,
1508 FATTR4_WORD1_MOUNTED_ON_FILEID,
1510 uint32_t dircount = readdir->count >> 1;
1513 if (readdir->plus) {
1514 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1515 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1516 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1517 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1518 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1519 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1522 /* Use mounted_on_fileid only if the server supports it */
1523 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1524 attrs[0] |= FATTR4_WORD0_FILEID;
1526 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1527 encode_uint64(xdr, readdir->cookie);
1528 encode_nfs4_verifier(xdr, &readdir->verifier);
1529 p = reserve_space(xdr, 20);
1530 *p++ = cpu_to_be32(dircount);
1531 *p++ = cpu_to_be32(readdir->count);
1532 *p++ = cpu_to_be32(2);
1534 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1535 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1536 memcpy(verf, readdir->verifier.data, sizeof(verf));
1537 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1539 (unsigned long long)readdir->cookie,
1541 attrs[0] & readdir->bitmask[0],
1542 attrs[1] & readdir->bitmask[1]);
1545 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1547 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1550 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1552 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1553 encode_string(xdr, name->len, name->name);
1556 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1558 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1559 encode_string(xdr, oldname->len, oldname->name);
1560 encode_string(xdr, newname->len, newname->name);
1563 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1564 struct compound_hdr *hdr)
1566 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1567 encode_uint64(xdr, clid);
1571 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1573 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1577 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1581 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1582 encode_nfs4_stateid(xdr, &zero_stateid);
1583 p = reserve_space(xdr, 2*4);
1584 *p++ = cpu_to_be32(1);
1585 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1586 BUG_ON(arg->acl_len % 4);
1587 p = reserve_space(xdr, 4);
1588 *p = cpu_to_be32(arg->acl_len);
1589 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1593 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1595 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1598 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1600 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1601 encode_nfs4_stateid(xdr, &arg->stateid);
1602 encode_attrs(xdr, arg->iap, server);
1605 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1609 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1610 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1612 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1613 p = reserve_space(xdr, 4);
1614 *p = cpu_to_be32(setclientid->sc_prog);
1615 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1616 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1617 p = reserve_space(xdr, 4);
1618 *p = cpu_to_be32(setclientid->sc_cb_ident);
1621 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1623 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1624 decode_setclientid_confirm_maxsz, hdr);
1625 encode_uint64(xdr, arg->clientid);
1626 encode_nfs4_verifier(xdr, &arg->confirm);
1629 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1633 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1634 encode_open_stateid(xdr, args->context, args->lock_context,
1635 FMODE_WRITE, hdr->minorversion);
1637 p = reserve_space(xdr, 16);
1638 p = xdr_encode_hyper(p, args->offset);
1639 *p++ = cpu_to_be32(args->stable);
1640 *p = cpu_to_be32(args->count);
1642 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1645 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1647 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1648 encode_nfs4_stateid(xdr, stateid);
1651 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1653 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1654 encode_string(xdr, name->len, name->name);
1657 #if defined(CONFIG_NFS_V4_1)
1658 /* NFSv4.1 operations */
1659 static void encode_exchange_id(struct xdr_stream *xdr,
1660 struct nfs41_exchange_id_args *args,
1661 struct compound_hdr *hdr)
1664 char impl_name[NFS4_OPAQUE_LIMIT];
1667 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1668 encode_nfs4_verifier(xdr, args->verifier);
1670 encode_string(xdr, args->id_len, args->id);
1672 p = reserve_space(xdr, 12);
1673 *p++ = cpu_to_be32(args->flags);
1674 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1676 if (send_implementation_id &&
1677 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1678 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1679 <= NFS4_OPAQUE_LIMIT + 1)
1680 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1681 utsname()->sysname, utsname()->release,
1682 utsname()->version, utsname()->machine);
1685 *p = cpu_to_be32(1); /* implementation id array length=1 */
1688 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1689 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1690 encode_string(xdr, len, impl_name);
1691 /* just send zeros for nii_date - the date is in nii_name */
1692 p = reserve_space(xdr, 12);
1693 p = xdr_encode_hyper(p, 0);
1694 *p = cpu_to_be32(0);
1696 *p = cpu_to_be32(0); /* implementation id array length=0 */
1699 static void encode_create_session(struct xdr_stream *xdr,
1700 struct nfs41_create_session_args *args,
1701 struct compound_hdr *hdr)
1704 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1706 struct nfs_client *clp = args->client;
1707 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1708 u32 max_resp_sz_cached;
1711 * Assumes OPEN is the biggest non-idempotent compound.
1712 * 2 is the verifier.
1714 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1715 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1717 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1720 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1721 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1722 p = xdr_encode_hyper(p, clp->cl_clientid);
1723 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1724 *p++ = cpu_to_be32(args->flags); /*flags */
1727 *p++ = cpu_to_be32(0); /* header padding size */
1728 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1729 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1730 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1731 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1732 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1733 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1736 *p++ = cpu_to_be32(0); /* header padding size */
1737 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1738 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1739 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1740 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1741 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1742 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1744 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1745 *p++ = cpu_to_be32(1);
1746 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1748 /* authsys_parms rfc1831 */
1749 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
1750 p = xdr_encode_opaque(p, machine_name, len);
1751 *p++ = cpu_to_be32(0); /* UID */
1752 *p++ = cpu_to_be32(0); /* GID */
1753 *p = cpu_to_be32(0); /* No more gids */
1756 static void encode_destroy_session(struct xdr_stream *xdr,
1757 struct nfs4_session *session,
1758 struct compound_hdr *hdr)
1760 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1761 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1764 static void encode_reclaim_complete(struct xdr_stream *xdr,
1765 struct nfs41_reclaim_complete_args *args,
1766 struct compound_hdr *hdr)
1768 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1769 encode_uint32(xdr, args->one_fs);
1771 #endif /* CONFIG_NFS_V4_1 */
1773 static void encode_sequence(struct xdr_stream *xdr,
1774 const struct nfs4_sequence_args *args,
1775 struct compound_hdr *hdr)
1777 #if defined(CONFIG_NFS_V4_1)
1778 struct nfs4_session *session = args->sa_session;
1779 struct nfs4_slot_table *tp;
1780 struct nfs4_slot *slot;
1786 tp = &session->fc_slot_table;
1788 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1789 slot = tp->slots + args->sa_slotid;
1791 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1794 * Sessionid + seqid + slotid + max slotid + cache_this
1796 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1797 "max_slotid=%d cache_this=%d\n",
1799 ((u32 *)session->sess_id.data)[0],
1800 ((u32 *)session->sess_id.data)[1],
1801 ((u32 *)session->sess_id.data)[2],
1802 ((u32 *)session->sess_id.data)[3],
1803 slot->seq_nr, args->sa_slotid,
1804 tp->highest_used_slotid, args->sa_cache_this);
1805 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1806 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1807 *p++ = cpu_to_be32(slot->seq_nr);
1808 *p++ = cpu_to_be32(args->sa_slotid);
1809 *p++ = cpu_to_be32(tp->highest_used_slotid);
1810 *p = cpu_to_be32(args->sa_cache_this);
1811 #endif /* CONFIG_NFS_V4_1 */
1814 #ifdef CONFIG_NFS_V4_1
1816 encode_getdevicelist(struct xdr_stream *xdr,
1817 const struct nfs4_getdevicelist_args *args,
1818 struct compound_hdr *hdr)
1821 nfs4_verifier dummy = {
1825 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1826 p = reserve_space(xdr, 16);
1827 *p++ = cpu_to_be32(args->layoutclass);
1828 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1829 xdr_encode_hyper(p, 0ULL); /* cookie */
1830 encode_nfs4_verifier(xdr, &dummy);
1834 encode_getdeviceinfo(struct xdr_stream *xdr,
1835 const struct nfs4_getdeviceinfo_args *args,
1836 struct compound_hdr *hdr)
1840 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1841 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1842 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1843 NFS4_DEVICEID4_SIZE);
1844 *p++ = cpu_to_be32(args->pdev->layout_type);
1845 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1846 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1850 encode_layoutget(struct xdr_stream *xdr,
1851 const struct nfs4_layoutget_args *args,
1852 struct compound_hdr *hdr)
1856 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1857 p = reserve_space(xdr, 36);
1858 *p++ = cpu_to_be32(0); /* Signal layout available */
1859 *p++ = cpu_to_be32(args->type);
1860 *p++ = cpu_to_be32(args->range.iomode);
1861 p = xdr_encode_hyper(p, args->range.offset);
1862 p = xdr_encode_hyper(p, args->range.length);
1863 p = xdr_encode_hyper(p, args->minlength);
1864 encode_nfs4_stateid(xdr, &args->stateid);
1865 encode_uint32(xdr, args->maxcount);
1867 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1871 (unsigned long)args->range.offset,
1872 (unsigned long)args->range.length,
1877 encode_layoutcommit(struct xdr_stream *xdr,
1878 struct inode *inode,
1879 const struct nfs4_layoutcommit_args *args,
1880 struct compound_hdr *hdr)
1884 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1885 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1887 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1888 p = reserve_space(xdr, 20);
1889 /* Only whole file layouts */
1890 p = xdr_encode_hyper(p, 0); /* offset */
1891 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1892 *p = cpu_to_be32(0); /* reclaim */
1893 encode_nfs4_stateid(xdr, &args->stateid);
1894 p = reserve_space(xdr, 20);
1895 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1896 p = xdr_encode_hyper(p, args->lastbytewritten);
1897 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1898 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1900 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1901 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1902 NFS_I(inode)->layout, xdr, args);
1904 encode_uint32(xdr, 0); /* no layout-type payload */
1910 encode_layoutreturn(struct xdr_stream *xdr,
1911 const struct nfs4_layoutreturn_args *args,
1912 struct compound_hdr *hdr)
1916 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1917 p = reserve_space(xdr, 16);
1918 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1919 *p++ = cpu_to_be32(args->layout_type);
1920 *p++ = cpu_to_be32(IOMODE_ANY);
1921 *p = cpu_to_be32(RETURN_FILE);
1922 p = reserve_space(xdr, 16);
1923 p = xdr_encode_hyper(p, 0);
1924 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1925 spin_lock(&args->inode->i_lock);
1926 encode_nfs4_stateid(xdr, &args->stateid);
1927 spin_unlock(&args->inode->i_lock);
1928 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1929 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1930 NFS_I(args->inode)->layout, xdr, args);
1932 encode_uint32(xdr, 0);
1936 encode_secinfo_no_name(struct xdr_stream *xdr,
1937 const struct nfs41_secinfo_no_name_args *args,
1938 struct compound_hdr *hdr)
1940 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1941 encode_uint32(xdr, args->style);
1945 static void encode_test_stateid(struct xdr_stream *xdr,
1946 struct nfs41_test_stateid_args *args,
1947 struct compound_hdr *hdr)
1949 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1950 encode_uint32(xdr, 1);
1951 encode_nfs4_stateid(xdr, args->stateid);
1954 static void encode_free_stateid(struct xdr_stream *xdr,
1955 struct nfs41_free_stateid_args *args,
1956 struct compound_hdr *hdr)
1958 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
1959 encode_nfs4_stateid(xdr, args->stateid);
1961 #endif /* CONFIG_NFS_V4_1 */
1964 * END OF "GENERIC" ENCODE ROUTINES.
1967 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1969 #if defined(CONFIG_NFS_V4_1)
1970 if (args->sa_session)
1971 return args->sa_session->clp->cl_mvops->minor_version;
1972 #endif /* CONFIG_NFS_V4_1 */
1977 * Encode an ACCESS request
1979 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1980 const struct nfs4_accessargs *args)
1982 struct compound_hdr hdr = {
1983 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1986 encode_compound_hdr(xdr, req, &hdr);
1987 encode_sequence(xdr, &args->seq_args, &hdr);
1988 encode_putfh(xdr, args->fh, &hdr);
1989 encode_access(xdr, args->access, &hdr);
1990 encode_getfattr(xdr, args->bitmask, &hdr);
1995 * Encode LOOKUP request
1997 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1998 const struct nfs4_lookup_arg *args)
2000 struct compound_hdr hdr = {
2001 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2004 encode_compound_hdr(xdr, req, &hdr);
2005 encode_sequence(xdr, &args->seq_args, &hdr);
2006 encode_putfh(xdr, args->dir_fh, &hdr);
2007 encode_lookup(xdr, args->name, &hdr);
2008 encode_getfh(xdr, &hdr);
2009 encode_getfattr(xdr, args->bitmask, &hdr);
2014 * Encode LOOKUP_ROOT request
2016 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2017 struct xdr_stream *xdr,
2018 const struct nfs4_lookup_root_arg *args)
2020 struct compound_hdr hdr = {
2021 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2024 encode_compound_hdr(xdr, req, &hdr);
2025 encode_sequence(xdr, &args->seq_args, &hdr);
2026 encode_putrootfh(xdr, &hdr);
2027 encode_getfh(xdr, &hdr);
2028 encode_getfattr(xdr, args->bitmask, &hdr);
2033 * Encode REMOVE request
2035 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2036 const struct nfs_removeargs *args)
2038 struct compound_hdr hdr = {
2039 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2042 encode_compound_hdr(xdr, req, &hdr);
2043 encode_sequence(xdr, &args->seq_args, &hdr);
2044 encode_putfh(xdr, args->fh, &hdr);
2045 encode_remove(xdr, &args->name, &hdr);
2050 * Encode RENAME request
2052 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2053 const struct nfs_renameargs *args)
2055 struct compound_hdr hdr = {
2056 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2059 encode_compound_hdr(xdr, req, &hdr);
2060 encode_sequence(xdr, &args->seq_args, &hdr);
2061 encode_putfh(xdr, args->old_dir, &hdr);
2062 encode_savefh(xdr, &hdr);
2063 encode_putfh(xdr, args->new_dir, &hdr);
2064 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2069 * Encode LINK request
2071 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2072 const struct nfs4_link_arg *args)
2074 struct compound_hdr hdr = {
2075 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2078 encode_compound_hdr(xdr, req, &hdr);
2079 encode_sequence(xdr, &args->seq_args, &hdr);
2080 encode_putfh(xdr, args->fh, &hdr);
2081 encode_savefh(xdr, &hdr);
2082 encode_putfh(xdr, args->dir_fh, &hdr);
2083 encode_link(xdr, args->name, &hdr);
2084 encode_restorefh(xdr, &hdr);
2085 encode_getfattr(xdr, args->bitmask, &hdr);
2090 * Encode CREATE request
2092 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2093 const struct nfs4_create_arg *args)
2095 struct compound_hdr hdr = {
2096 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2099 encode_compound_hdr(xdr, req, &hdr);
2100 encode_sequence(xdr, &args->seq_args, &hdr);
2101 encode_putfh(xdr, args->dir_fh, &hdr);
2102 encode_create(xdr, args, &hdr);
2103 encode_getfh(xdr, &hdr);
2104 encode_getfattr(xdr, args->bitmask, &hdr);
2109 * Encode SYMLINK request
2111 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs4_create_arg *args)
2114 nfs4_xdr_enc_create(req, xdr, args);
2118 * Encode GETATTR request
2120 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2121 const struct nfs4_getattr_arg *args)
2123 struct compound_hdr hdr = {
2124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putfh(xdr, args->fh, &hdr);
2130 encode_getfattr(xdr, args->bitmask, &hdr);
2135 * Encode a CLOSE request
2137 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2138 struct nfs_closeargs *args)
2140 struct compound_hdr hdr = {
2141 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2144 encode_compound_hdr(xdr, req, &hdr);
2145 encode_sequence(xdr, &args->seq_args, &hdr);
2146 encode_putfh(xdr, args->fh, &hdr);
2147 encode_close(xdr, args, &hdr);
2148 encode_getfattr(xdr, args->bitmask, &hdr);
2153 * Encode an OPEN request
2155 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 struct nfs_openargs *args)
2158 struct compound_hdr hdr = {
2159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->fh, &hdr);
2165 encode_open(xdr, args, &hdr);
2166 encode_getfh(xdr, &hdr);
2167 encode_getfattr(xdr, args->bitmask, &hdr);
2172 * Encode an OPEN_CONFIRM request
2174 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2175 struct xdr_stream *xdr,
2176 struct nfs_open_confirmargs *args)
2178 struct compound_hdr hdr = {
2182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_putfh(xdr, args->fh, &hdr);
2184 encode_open_confirm(xdr, args, &hdr);
2189 * Encode an OPEN request with no attributes.
2191 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2192 struct xdr_stream *xdr,
2193 struct nfs_openargs *args)
2195 struct compound_hdr hdr = {
2196 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2199 encode_compound_hdr(xdr, req, &hdr);
2200 encode_sequence(xdr, &args->seq_args, &hdr);
2201 encode_putfh(xdr, args->fh, &hdr);
2202 encode_open(xdr, args, &hdr);
2203 encode_getfattr(xdr, args->bitmask, &hdr);
2208 * Encode an OPEN_DOWNGRADE request
2210 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2211 struct xdr_stream *xdr,
2212 struct nfs_closeargs *args)
2214 struct compound_hdr hdr = {
2215 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2218 encode_compound_hdr(xdr, req, &hdr);
2219 encode_sequence(xdr, &args->seq_args, &hdr);
2220 encode_putfh(xdr, args->fh, &hdr);
2221 encode_open_downgrade(xdr, args, &hdr);
2222 encode_getfattr(xdr, args->bitmask, &hdr);
2227 * Encode a LOCK request
2229 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2230 struct nfs_lock_args *args)
2232 struct compound_hdr hdr = {
2233 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2236 encode_compound_hdr(xdr, req, &hdr);
2237 encode_sequence(xdr, &args->seq_args, &hdr);
2238 encode_putfh(xdr, args->fh, &hdr);
2239 encode_lock(xdr, args, &hdr);
2244 * Encode a LOCKT request
2246 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2247 struct nfs_lockt_args *args)
2249 struct compound_hdr hdr = {
2250 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2253 encode_compound_hdr(xdr, req, &hdr);
2254 encode_sequence(xdr, &args->seq_args, &hdr);
2255 encode_putfh(xdr, args->fh, &hdr);
2256 encode_lockt(xdr, args, &hdr);
2261 * Encode a LOCKU request
2263 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2264 struct nfs_locku_args *args)
2266 struct compound_hdr hdr = {
2267 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2270 encode_compound_hdr(xdr, req, &hdr);
2271 encode_sequence(xdr, &args->seq_args, &hdr);
2272 encode_putfh(xdr, args->fh, &hdr);
2273 encode_locku(xdr, args, &hdr);
2277 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2278 struct xdr_stream *xdr,
2279 struct nfs_release_lockowner_args *args)
2281 struct compound_hdr hdr = {
2285 encode_compound_hdr(xdr, req, &hdr);
2286 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2291 * Encode a READLINK request
2293 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2294 const struct nfs4_readlink *args)
2296 struct compound_hdr hdr = {
2297 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_sequence(xdr, &args->seq_args, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_readlink(xdr, args, req, &hdr);
2305 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2306 args->pgbase, args->pglen);
2311 * Encode a READDIR request
2313 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2314 const struct nfs4_readdir_arg *args)
2316 struct compound_hdr hdr = {
2317 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2320 encode_compound_hdr(xdr, req, &hdr);
2321 encode_sequence(xdr, &args->seq_args, &hdr);
2322 encode_putfh(xdr, args->fh, &hdr);
2323 encode_readdir(xdr, args, req, &hdr);
2325 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2326 args->pgbase, args->count);
2327 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2328 __func__, hdr.replen << 2, args->pages,
2329 args->pgbase, args->count);
2334 * Encode a READ request
2336 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2337 struct nfs_readargs *args)
2339 struct compound_hdr hdr = {
2340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_read(xdr, args, &hdr);
2348 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2349 args->pages, args->pgbase, args->count);
2350 req->rq_rcv_buf.flags |= XDRBUF_READ;
2355 * Encode an SETATTR request
2357 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2358 struct nfs_setattrargs *args)
2360 struct compound_hdr hdr = {
2361 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2364 encode_compound_hdr(xdr, req, &hdr);
2365 encode_sequence(xdr, &args->seq_args, &hdr);
2366 encode_putfh(xdr, args->fh, &hdr);
2367 encode_setattr(xdr, args, args->server, &hdr);
2368 encode_getfattr(xdr, args->bitmask, &hdr);
2373 * Encode a GETACL request
2375 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2376 struct nfs_getaclargs *args)
2378 struct compound_hdr hdr = {
2379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_sequence(xdr, &args->seq_args, &hdr);
2385 encode_putfh(xdr, args->fh, &hdr);
2386 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2387 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2389 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2390 args->acl_pages, args->acl_pgbase, args->acl_len);
2396 * Encode a WRITE request
2398 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2399 struct nfs_writeargs *args)
2401 struct compound_hdr hdr = {
2402 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2405 encode_compound_hdr(xdr, req, &hdr);
2406 encode_sequence(xdr, &args->seq_args, &hdr);
2407 encode_putfh(xdr, args->fh, &hdr);
2408 encode_write(xdr, args, &hdr);
2409 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2411 encode_getfattr(xdr, args->bitmask, &hdr);
2418 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2419 struct nfs_commitargs *args)
2421 struct compound_hdr hdr = {
2422 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2425 encode_compound_hdr(xdr, req, &hdr);
2426 encode_sequence(xdr, &args->seq_args, &hdr);
2427 encode_putfh(xdr, args->fh, &hdr);
2428 encode_commit(xdr, args, &hdr);
2435 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2436 struct nfs4_fsinfo_arg *args)
2438 struct compound_hdr hdr = {
2439 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2442 encode_compound_hdr(xdr, req, &hdr);
2443 encode_sequence(xdr, &args->seq_args, &hdr);
2444 encode_putfh(xdr, args->fh, &hdr);
2445 encode_fsinfo(xdr, args->bitmask, &hdr);
2450 * a PATHCONF request
2452 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2453 const struct nfs4_pathconf_arg *args)
2455 struct compound_hdr hdr = {
2456 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2459 encode_compound_hdr(xdr, req, &hdr);
2460 encode_sequence(xdr, &args->seq_args, &hdr);
2461 encode_putfh(xdr, args->fh, &hdr);
2462 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2470 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2471 const struct nfs4_statfs_arg *args)
2473 struct compound_hdr hdr = {
2474 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2477 encode_compound_hdr(xdr, req, &hdr);
2478 encode_sequence(xdr, &args->seq_args, &hdr);
2479 encode_putfh(xdr, args->fh, &hdr);
2480 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2481 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2486 * GETATTR_BITMAP request
2488 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2489 struct xdr_stream *xdr,
2490 struct nfs4_server_caps_arg *args)
2492 struct compound_hdr hdr = {
2493 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_sequence(xdr, &args->seq_args, &hdr);
2498 encode_putfh(xdr, args->fhandle, &hdr);
2499 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2500 FATTR4_WORD0_FH_EXPIRE_TYPE|
2501 FATTR4_WORD0_LINK_SUPPORT|
2502 FATTR4_WORD0_SYMLINK_SUPPORT|
2503 FATTR4_WORD0_ACLSUPPORT, &hdr);
2510 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2511 struct nfs_client *clp)
2513 struct compound_hdr hdr = {
2517 encode_compound_hdr(xdr, req, &hdr);
2518 encode_renew(xdr, clp->cl_clientid, &hdr);
2523 * a SETCLIENTID request
2525 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2526 struct xdr_stream *xdr,
2527 struct nfs4_setclientid *sc)
2529 struct compound_hdr hdr = {
2533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_setclientid(xdr, sc, &hdr);
2539 * a SETCLIENTID_CONFIRM request
2541 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2542 struct xdr_stream *xdr,
2543 struct nfs4_setclientid_res *arg)
2545 struct compound_hdr hdr = {
2548 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2550 encode_compound_hdr(xdr, req, &hdr);
2551 encode_setclientid_confirm(xdr, arg, &hdr);
2552 encode_putrootfh(xdr, &hdr);
2553 encode_fsinfo(xdr, lease_bitmap, &hdr);
2558 * DELEGRETURN request
2560 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2561 struct xdr_stream *xdr,
2562 const struct nfs4_delegreturnargs *args)
2564 struct compound_hdr hdr = {
2565 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2568 encode_compound_hdr(xdr, req, &hdr);
2569 encode_sequence(xdr, &args->seq_args, &hdr);
2570 encode_putfh(xdr, args->fhandle, &hdr);
2571 encode_getfattr(xdr, args->bitmask, &hdr);
2572 encode_delegreturn(xdr, args->stateid, &hdr);
2577 * Encode FS_LOCATIONS request
2579 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2580 struct xdr_stream *xdr,
2581 struct nfs4_fs_locations_arg *args)
2583 struct compound_hdr hdr = {
2584 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_sequence(xdr, &args->seq_args, &hdr);
2590 encode_putfh(xdr, args->dir_fh, &hdr);
2591 encode_lookup(xdr, args->name, &hdr);
2592 replen = hdr.replen; /* get the attribute into args->page */
2593 encode_fs_locations(xdr, args->bitmask, &hdr);
2595 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2601 * Encode SECINFO request
2603 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2604 struct xdr_stream *xdr,
2605 struct nfs4_secinfo_arg *args)
2607 struct compound_hdr hdr = {
2608 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2611 encode_compound_hdr(xdr, req, &hdr);
2612 encode_sequence(xdr, &args->seq_args, &hdr);
2613 encode_putfh(xdr, args->dir_fh, &hdr);
2614 encode_secinfo(xdr, args->name, &hdr);
2618 #if defined(CONFIG_NFS_V4_1)
2620 * EXCHANGE_ID request
2622 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2623 struct xdr_stream *xdr,
2624 struct nfs41_exchange_id_args *args)
2626 struct compound_hdr hdr = {
2627 .minorversion = args->client->cl_mvops->minor_version,
2630 encode_compound_hdr(xdr, req, &hdr);
2631 encode_exchange_id(xdr, args, &hdr);
2636 * a CREATE_SESSION request
2638 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2639 struct xdr_stream *xdr,
2640 struct nfs41_create_session_args *args)
2642 struct compound_hdr hdr = {
2643 .minorversion = args->client->cl_mvops->minor_version,
2646 encode_compound_hdr(xdr, req, &hdr);
2647 encode_create_session(xdr, args, &hdr);
2652 * a DESTROY_SESSION request
2654 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2655 struct xdr_stream *xdr,
2656 struct nfs4_session *session)
2658 struct compound_hdr hdr = {
2659 .minorversion = session->clp->cl_mvops->minor_version,
2662 encode_compound_hdr(xdr, req, &hdr);
2663 encode_destroy_session(xdr, session, &hdr);
2668 * a SEQUENCE request
2670 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2671 struct nfs4_sequence_args *args)
2673 struct compound_hdr hdr = {
2674 .minorversion = nfs4_xdr_minorversion(args),
2677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, args, &hdr);
2683 * a GET_LEASE_TIME request
2685 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2686 struct xdr_stream *xdr,
2687 struct nfs4_get_lease_time_args *args)
2689 struct compound_hdr hdr = {
2690 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2692 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2694 encode_compound_hdr(xdr, req, &hdr);
2695 encode_sequence(xdr, &args->la_seq_args, &hdr);
2696 encode_putrootfh(xdr, &hdr);
2697 encode_fsinfo(xdr, lease_bitmap, &hdr);
2702 * a RECLAIM_COMPLETE request
2704 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2705 struct xdr_stream *xdr,
2706 struct nfs41_reclaim_complete_args *args)
2708 struct compound_hdr hdr = {
2709 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2712 encode_compound_hdr(xdr, req, &hdr);
2713 encode_sequence(xdr, &args->seq_args, &hdr);
2714 encode_reclaim_complete(xdr, args, &hdr);
2719 * Encode GETDEVICELIST request
2721 static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2722 struct xdr_stream *xdr,
2723 struct nfs4_getdevicelist_args *args)
2725 struct compound_hdr hdr = {
2726 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2729 encode_compound_hdr(xdr, req, &hdr);
2730 encode_sequence(xdr, &args->seq_args, &hdr);
2731 encode_putfh(xdr, args->fh, &hdr);
2732 encode_getdevicelist(xdr, args, &hdr);
2737 * Encode GETDEVICEINFO request
2739 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2740 struct xdr_stream *xdr,
2741 struct nfs4_getdeviceinfo_args *args)
2743 struct compound_hdr hdr = {
2744 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2747 encode_compound_hdr(xdr, req, &hdr);
2748 encode_sequence(xdr, &args->seq_args, &hdr);
2749 encode_getdeviceinfo(xdr, args, &hdr);
2751 /* set up reply kvec. Subtract notification bitmap max size (2)
2752 * so that notification bitmap is put in xdr_buf tail */
2753 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2754 args->pdev->pages, args->pdev->pgbase,
2761 * Encode LAYOUTGET request
2763 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2764 struct xdr_stream *xdr,
2765 struct nfs4_layoutget_args *args)
2767 struct compound_hdr hdr = {
2768 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2771 encode_compound_hdr(xdr, req, &hdr);
2772 encode_sequence(xdr, &args->seq_args, &hdr);
2773 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2774 encode_layoutget(xdr, args, &hdr);
2776 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2777 args->layout.pages, 0, args->layout.pglen);
2783 * Encode LAYOUTCOMMIT request
2785 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2786 struct xdr_stream *xdr,
2787 struct nfs4_layoutcommit_args *args)
2789 struct nfs4_layoutcommit_data *data =
2790 container_of(args, struct nfs4_layoutcommit_data, args);
2791 struct compound_hdr hdr = {
2792 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2795 encode_compound_hdr(xdr, req, &hdr);
2796 encode_sequence(xdr, &args->seq_args, &hdr);
2797 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2798 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2799 encode_getfattr(xdr, args->bitmask, &hdr);
2804 * Encode LAYOUTRETURN request
2806 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2807 struct xdr_stream *xdr,
2808 struct nfs4_layoutreturn_args *args)
2810 struct compound_hdr hdr = {
2811 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2814 encode_compound_hdr(xdr, req, &hdr);
2815 encode_sequence(xdr, &args->seq_args, &hdr);
2816 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2817 encode_layoutreturn(xdr, args, &hdr);
2822 * Encode SECINFO_NO_NAME request
2824 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2825 struct xdr_stream *xdr,
2826 struct nfs41_secinfo_no_name_args *args)
2828 struct compound_hdr hdr = {
2829 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2832 encode_compound_hdr(xdr, req, &hdr);
2833 encode_sequence(xdr, &args->seq_args, &hdr);
2834 encode_putrootfh(xdr, &hdr);
2835 encode_secinfo_no_name(xdr, args, &hdr);
2841 * Encode TEST_STATEID request
2843 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs41_test_stateid_args *args)
2847 struct compound_hdr hdr = {
2848 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2851 encode_compound_hdr(xdr, req, &hdr);
2852 encode_sequence(xdr, &args->seq_args, &hdr);
2853 encode_test_stateid(xdr, args, &hdr);
2858 * Encode FREE_STATEID request
2860 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2861 struct xdr_stream *xdr,
2862 struct nfs41_free_stateid_args *args)
2864 struct compound_hdr hdr = {
2865 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2868 encode_compound_hdr(xdr, req, &hdr);
2869 encode_sequence(xdr, &args->seq_args, &hdr);
2870 encode_free_stateid(xdr, args, &hdr);
2873 #endif /* CONFIG_NFS_V4_1 */
2875 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2877 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2878 "Remaining buffer length is %tu words.\n",
2879 func, xdr->end - xdr->p);
2882 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2886 p = xdr_inline_decode(xdr, 4);
2889 *len = be32_to_cpup(p);
2890 p = xdr_inline_decode(xdr, *len);
2893 *string = (char *)p;
2896 print_overflow_msg(__func__, xdr);
2900 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2904 p = xdr_inline_decode(xdr, 8);
2907 hdr->status = be32_to_cpup(p++);
2908 hdr->taglen = be32_to_cpup(p);
2910 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2913 hdr->tag = (char *)p;
2914 p += XDR_QUADLEN(hdr->taglen);
2915 hdr->nops = be32_to_cpup(p);
2916 if (unlikely(hdr->nops < 1))
2917 return nfs4_stat_to_errno(hdr->status);
2920 print_overflow_msg(__func__, xdr);
2924 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2930 p = xdr_inline_decode(xdr, 8);
2933 opnum = be32_to_cpup(p++);
2934 if (opnum != expected) {
2935 dprintk("nfs: Server returned operation"
2936 " %d but we issued a request for %d\n",
2940 nfserr = be32_to_cpup(p);
2941 if (nfserr != NFS_OK)
2942 return nfs4_stat_to_errno(nfserr);
2945 print_overflow_msg(__func__, xdr);
2950 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2953 unsigned int strlen;
2956 p = xdr_inline_decode(xdr, 12);
2958 return decode_opaque_inline(xdr, &strlen, &str);
2959 print_overflow_msg(__func__, xdr);
2963 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2968 p = xdr_inline_decode(xdr, 4);
2971 bmlen = be32_to_cpup(p);
2973 bitmap[0] = bitmap[1] = bitmap[2] = 0;
2974 p = xdr_inline_decode(xdr, (bmlen << 2));
2978 bitmap[0] = be32_to_cpup(p++);
2980 bitmap[1] = be32_to_cpup(p++);
2982 bitmap[2] = be32_to_cpup(p);
2987 print_overflow_msg(__func__, xdr);
2991 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2995 p = xdr_inline_decode(xdr, 4);
2998 *attrlen = be32_to_cpup(p);
3002 print_overflow_msg(__func__, xdr);
3006 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3008 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3010 ret = decode_attr_bitmap(xdr, bitmask);
3011 if (unlikely(ret < 0))
3013 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3015 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3016 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3017 bitmask[0], bitmask[1], bitmask[2]);
3021 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3027 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3029 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3030 p = xdr_inline_decode(xdr, 4);
3033 *type = be32_to_cpup(p);
3034 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3035 dprintk("%s: bad type %d\n", __func__, *type);
3038 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3039 ret = NFS_ATTR_FATTR_TYPE;
3041 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3044 print_overflow_msg(__func__, xdr);
3048 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3049 uint32_t *bitmap, uint32_t *type)
3054 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3056 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3057 p = xdr_inline_decode(xdr, 4);
3060 *type = be32_to_cpup(p);
3061 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3063 dprintk("%s: expire type=0x%x\n", __func__, *type);
3066 print_overflow_msg(__func__, xdr);
3070 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3076 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3078 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3079 p = xdr_inline_decode(xdr, 8);
3082 xdr_decode_hyper(p, change);
3083 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3084 ret = NFS_ATTR_FATTR_CHANGE;
3086 dprintk("%s: change attribute=%Lu\n", __func__,
3087 (unsigned long long)*change);
3090 print_overflow_msg(__func__, xdr);
3094 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3100 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3102 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3103 p = xdr_inline_decode(xdr, 8);
3106 xdr_decode_hyper(p, size);
3107 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3108 ret = NFS_ATTR_FATTR_SIZE;
3110 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3113 print_overflow_msg(__func__, xdr);
3117 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3122 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3124 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3125 p = xdr_inline_decode(xdr, 4);
3128 *res = be32_to_cpup(p);
3129 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3131 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3134 print_overflow_msg(__func__, xdr);
3138 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3143 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3145 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3146 p = xdr_inline_decode(xdr, 4);
3149 *res = be32_to_cpup(p);
3150 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3152 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3155 print_overflow_msg(__func__, xdr);
3159 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3166 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3168 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3169 p = xdr_inline_decode(xdr, 16);
3172 p = xdr_decode_hyper(p, &fsid->major);
3173 xdr_decode_hyper(p, &fsid->minor);
3174 bitmap[0] &= ~FATTR4_WORD0_FSID;
3175 ret = NFS_ATTR_FATTR_FSID;
3177 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3178 (unsigned long long)fsid->major,
3179 (unsigned long long)fsid->minor);
3182 print_overflow_msg(__func__, xdr);
3186 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3191 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3193 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3194 p = xdr_inline_decode(xdr, 4);
3197 *res = be32_to_cpup(p);
3198 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3200 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3203 print_overflow_msg(__func__, xdr);
3207 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3211 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3213 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3214 p = xdr_inline_decode(xdr, 4);
3217 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3218 *res = -be32_to_cpup(p);
3222 print_overflow_msg(__func__, xdr);
3226 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3232 memset(fh, 0, sizeof(*fh));
3234 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3236 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3237 p = xdr_inline_decode(xdr, 4);
3240 len = be32_to_cpup(p);
3241 if (len > NFS4_FHSIZE)
3243 p = xdr_inline_decode(xdr, len);
3247 memcpy(fh->data, p, len);
3250 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3254 print_overflow_msg(__func__, xdr);
3258 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3262 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3263 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3265 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3266 p = xdr_inline_decode(xdr, 4);
3269 *res = be32_to_cpup(p);
3270 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3272 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3275 print_overflow_msg(__func__, xdr);
3279 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3285 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3287 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3288 p = xdr_inline_decode(xdr, 8);
3291 xdr_decode_hyper(p, fileid);
3292 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3293 ret = NFS_ATTR_FATTR_FILEID;
3295 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3298 print_overflow_msg(__func__, xdr);
3302 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3308 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3310 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3311 p = xdr_inline_decode(xdr, 8);
3314 xdr_decode_hyper(p, fileid);
3315 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3316 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3318 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3321 print_overflow_msg(__func__, xdr);
3325 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3331 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3333 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3334 p = xdr_inline_decode(xdr, 8);
3337 xdr_decode_hyper(p, res);
3338 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3340 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3343 print_overflow_msg(__func__, xdr);
3347 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3353 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3355 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3356 p = xdr_inline_decode(xdr, 8);
3359 xdr_decode_hyper(p, res);
3360 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3362 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3365 print_overflow_msg(__func__, xdr);
3369 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3375 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3377 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3378 p = xdr_inline_decode(xdr, 8);
3381 xdr_decode_hyper(p, res);
3382 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3384 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3387 print_overflow_msg(__func__, xdr);
3391 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3397 p = xdr_inline_decode(xdr, 4);
3400 n = be32_to_cpup(p);
3403 dprintk("pathname4: ");
3404 path->ncomponents = 0;
3405 while (path->ncomponents < n) {
3406 struct nfs4_string *component = &path->components[path->ncomponents];
3407 status = decode_opaque_inline(xdr, &component->len, &component->data);
3408 if (unlikely(status != 0))
3412 (path->ncomponents != n ? "/ " : ""),
3413 component->len, component->data);
3414 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3415 path->ncomponents++;
3417 dprintk("cannot parse %d components in path\n", n);
3424 /* a root pathname is sent as a zero component4 */
3425 path->ncomponents = 1;
3426 path->components[0].len=0;
3427 path->components[0].data=NULL;
3428 dprintk("pathname4: /\n");
3431 dprintk(" status %d", status);
3435 print_overflow_msg(__func__, xdr);
3439 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3445 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3448 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3451 /* Ignore borken servers that return unrequested attrs */
3452 if (unlikely(res == NULL))
3454 dprintk("%s: fsroot:\n", __func__);
3455 status = decode_pathname(xdr, &res->fs_path);
3456 if (unlikely(status != 0))
3458 p = xdr_inline_decode(xdr, 4);
3461 n = be32_to_cpup(p);
3464 res->nlocations = 0;
3465 while (res->nlocations < n) {
3467 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3469 p = xdr_inline_decode(xdr, 4);
3472 m = be32_to_cpup(p);
3475 dprintk("%s: servers:\n", __func__);
3476 while (loc->nservers < m) {
3477 struct nfs4_string *server = &loc->servers[loc->nservers];
3478 status = decode_opaque_inline(xdr, &server->len, &server->data);
3479 if (unlikely(status != 0))
3481 dprintk("%s ", server->data);
3482 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3486 dprintk("%s: using first %u of %u servers "
3487 "returned for location %u\n",
3489 NFS4_FS_LOCATION_MAXSERVERS,
3490 m, res->nlocations);
3491 for (i = loc->nservers; i < m; i++) {
3494 status = decode_opaque_inline(xdr, &len, &data);
3495 if (unlikely(status != 0))
3500 status = decode_pathname(xdr, &loc->rootpath);
3501 if (unlikely(status != 0))
3503 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3506 if (res->nlocations != 0)
3507 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3509 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3512 print_overflow_msg(__func__, xdr);
3518 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3524 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3526 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3527 p = xdr_inline_decode(xdr, 8);
3530 xdr_decode_hyper(p, res);
3531 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3533 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3536 print_overflow_msg(__func__, xdr);
3540 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3546 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3548 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3549 p = xdr_inline_decode(xdr, 4);
3552 *maxlink = be32_to_cpup(p);
3553 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3555 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3558 print_overflow_msg(__func__, xdr);
3562 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3568 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3570 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3571 p = xdr_inline_decode(xdr, 4);
3574 *maxname = be32_to_cpup(p);
3575 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3577 dprintk("%s: maxname=%u\n", __func__, *maxname);
3580 print_overflow_msg(__func__, xdr);
3584 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3590 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3592 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3594 p = xdr_inline_decode(xdr, 8);
3597 xdr_decode_hyper(p, &maxread);
3598 if (maxread > 0x7FFFFFFF)
3599 maxread = 0x7FFFFFFF;
3600 *res = (uint32_t)maxread;
3601 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3603 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3606 print_overflow_msg(__func__, xdr);
3610 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3616 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3618 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3620 p = xdr_inline_decode(xdr, 8);
3623 xdr_decode_hyper(p, &maxwrite);
3624 if (maxwrite > 0x7FFFFFFF)
3625 maxwrite = 0x7FFFFFFF;
3626 *res = (uint32_t)maxwrite;
3627 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3629 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3632 print_overflow_msg(__func__, xdr);
3636 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3643 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3645 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3646 p = xdr_inline_decode(xdr, 4);
3649 tmp = be32_to_cpup(p);
3650 *mode = tmp & ~S_IFMT;
3651 bitmap[1] &= ~FATTR4_WORD1_MODE;
3652 ret = NFS_ATTR_FATTR_MODE;
3654 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3657 print_overflow_msg(__func__, xdr);
3661 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3667 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3669 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3670 p = xdr_inline_decode(xdr, 4);
3673 *nlink = be32_to_cpup(p);
3674 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3675 ret = NFS_ATTR_FATTR_NLINK;
3677 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3680 print_overflow_msg(__func__, xdr);
3684 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3685 const struct nfs_server *server, uint32_t *uid,
3686 struct nfs4_string *owner_name)
3693 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3695 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3696 p = xdr_inline_decode(xdr, 4);
3699 len = be32_to_cpup(p);
3700 p = xdr_inline_decode(xdr, len);
3703 if (owner_name != NULL) {
3704 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3705 if (owner_name->data != NULL) {
3706 owner_name->len = len;
3707 ret = NFS_ATTR_FATTR_OWNER_NAME;
3709 } else if (len < XDR_MAX_NETOBJ) {
3710 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3711 ret = NFS_ATTR_FATTR_OWNER;
3713 dprintk("%s: nfs_map_name_to_uid failed!\n",
3716 dprintk("%s: name too long (%u)!\n",
3718 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3720 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3723 print_overflow_msg(__func__, xdr);
3727 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3728 const struct nfs_server *server, uint32_t *gid,
3729 struct nfs4_string *group_name)
3736 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3738 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3739 p = xdr_inline_decode(xdr, 4);
3742 len = be32_to_cpup(p);
3743 p = xdr_inline_decode(xdr, len);
3746 if (group_name != NULL) {
3747 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3748 if (group_name->data != NULL) {
3749 group_name->len = len;
3750 ret = NFS_ATTR_FATTR_GROUP_NAME;
3752 } else if (len < XDR_MAX_NETOBJ) {
3753 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3754 ret = NFS_ATTR_FATTR_GROUP;
3756 dprintk("%s: nfs_map_group_to_gid failed!\n",
3759 dprintk("%s: name too long (%u)!\n",
3761 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3763 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3766 print_overflow_msg(__func__, xdr);
3770 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3772 uint32_t major = 0, minor = 0;
3777 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3779 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3782 p = xdr_inline_decode(xdr, 8);
3785 major = be32_to_cpup(p++);
3786 minor = be32_to_cpup(p);
3787 tmp = MKDEV(major, minor);
3788 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3790 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3791 ret = NFS_ATTR_FATTR_RDEV;
3793 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3796 print_overflow_msg(__func__, xdr);
3800 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3806 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3808 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3809 p = xdr_inline_decode(xdr, 8);
3812 xdr_decode_hyper(p, res);
3813 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3815 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3818 print_overflow_msg(__func__, xdr);
3822 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3828 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3830 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3831 p = xdr_inline_decode(xdr, 8);
3834 xdr_decode_hyper(p, res);
3835 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3837 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3840 print_overflow_msg(__func__, xdr);
3844 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3850 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3852 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3853 p = xdr_inline_decode(xdr, 8);
3856 xdr_decode_hyper(p, res);
3857 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3859 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3862 print_overflow_msg(__func__, xdr);
3866 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3872 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3874 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3875 p = xdr_inline_decode(xdr, 8);
3878 xdr_decode_hyper(p, used);
3879 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3880 ret = NFS_ATTR_FATTR_SPACE_USED;
3882 dprintk("%s: space used=%Lu\n", __func__,
3883 (unsigned long long)*used);
3886 print_overflow_msg(__func__, xdr);
3890 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3896 p = xdr_inline_decode(xdr, 12);
3899 p = xdr_decode_hyper(p, &sec);
3900 nsec = be32_to_cpup(p);
3901 time->tv_sec = (time_t)sec;
3902 time->tv_nsec = (long)nsec;
3905 print_overflow_msg(__func__, xdr);
3909 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3915 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3917 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3918 status = decode_attr_time(xdr, time);
3920 status = NFS_ATTR_FATTR_ATIME;
3921 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3923 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3927 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3933 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3935 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3936 status = decode_attr_time(xdr, time);
3938 status = NFS_ATTR_FATTR_CTIME;
3939 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3941 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3945 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3946 struct timespec *time)
3952 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3954 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3955 status = decode_attr_time(xdr, time);
3956 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3958 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3959 (long)time->tv_nsec);
3963 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3969 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3971 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3972 status = decode_attr_time(xdr, time);
3974 status = NFS_ATTR_FATTR_MTIME;
3975 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3977 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3981 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3983 unsigned int attrwords = XDR_QUADLEN(attrlen);
3984 unsigned int nwords = xdr->p - savep;
3986 if (unlikely(attrwords != nwords)) {
3987 dprintk("%s: server returned incorrect attribute length: "
3991 (attrwords < nwords) ? '<' : '>',
3998 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4002 p = xdr_inline_decode(xdr, 20);
4005 cinfo->atomic = be32_to_cpup(p++);
4006 p = xdr_decode_hyper(p, &cinfo->before);
4007 xdr_decode_hyper(p, &cinfo->after);
4010 print_overflow_msg(__func__, xdr);
4014 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4020 status = decode_op_hdr(xdr, OP_ACCESS);
4023 p = xdr_inline_decode(xdr, 8);
4026 supp = be32_to_cpup(p++);
4027 acc = be32_to_cpup(p);
4028 access->supported = supp;
4029 access->access = acc;
4032 print_overflow_msg(__func__, xdr);
4036 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4040 p = xdr_inline_decode(xdr, len);
4042 memcpy(buf, p, len);
4045 print_overflow_msg(__func__, xdr);
4049 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4051 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4054 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4058 status = decode_op_hdr(xdr, OP_CLOSE);
4060 nfs_increment_open_seqid(status, res->seqid);
4062 status = decode_stateid(xdr, &res->stateid);
4066 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4068 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4071 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4075 status = decode_op_hdr(xdr, OP_COMMIT);
4077 status = decode_verifier(xdr, res->verf->verifier);
4081 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4087 status = decode_op_hdr(xdr, OP_CREATE);
4090 if ((status = decode_change_info(xdr, cinfo)))
4092 p = xdr_inline_decode(xdr, 4);
4095 bmlen = be32_to_cpup(p);
4096 p = xdr_inline_decode(xdr, bmlen << 2);
4100 print_overflow_msg(__func__, xdr);
4104 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4107 uint32_t attrlen, bitmap[3] = {0};
4110 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4112 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4114 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4116 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4118 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4119 &res->fh_expire_type)) != 0)
4121 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4123 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4125 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4127 status = verify_attr_len(xdr, savep, attrlen);
4129 dprintk("%s: xdr returned %d!\n", __func__, -status);
4133 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4136 uint32_t attrlen, bitmap[3] = {0};
4139 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4141 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4143 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4146 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4148 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4150 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4152 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4154 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4156 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4159 status = verify_attr_len(xdr, savep, attrlen);
4161 dprintk("%s: xdr returned %d!\n", __func__, -status);
4165 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4168 uint32_t attrlen, bitmap[3] = {0};
4171 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4173 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4175 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4178 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4180 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4183 status = verify_attr_len(xdr, savep, attrlen);
4185 dprintk("%s: xdr returned %d!\n", __func__, -status);
4189 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4190 struct nfs_fattr *fattr, struct nfs_fh *fh,
4191 struct nfs4_fs_locations *fs_loc,
4192 const struct nfs_server *server)
4199 status = decode_attr_type(xdr, bitmap, &type);
4204 fattr->mode |= nfs_type2fmt[type];
4205 fattr->valid |= status;
4208 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4211 fattr->valid |= status;
4213 status = decode_attr_size(xdr, bitmap, &fattr->size);
4216 fattr->valid |= status;
4218 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4221 fattr->valid |= status;
4224 status = decode_attr_error(xdr, bitmap, &err);
4228 status = decode_attr_filehandle(xdr, bitmap, fh);
4232 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4235 fattr->valid |= status;
4237 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4240 fattr->valid |= status;
4242 status = decode_attr_mode(xdr, bitmap, &fmode);
4246 fattr->mode |= fmode;
4247 fattr->valid |= status;
4250 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4253 fattr->valid |= status;
4255 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4258 fattr->valid |= status;
4260 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4263 fattr->valid |= status;
4265 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4268 fattr->valid |= status;
4270 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4273 fattr->valid |= status;
4275 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4278 fattr->valid |= status;
4280 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4283 fattr->valid |= status;
4285 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4288 fattr->valid |= status;
4290 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4293 fattr->valid |= status;
4296 dprintk("%s: xdr returned %d\n", __func__, -status);
4300 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4301 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4302 const struct nfs_server *server)
4309 status = decode_op_hdr(xdr, OP_GETATTR);
4313 status = decode_attr_bitmap(xdr, bitmap);
4317 status = decode_attr_length(xdr, &attrlen, &savep);
4321 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4325 status = verify_attr_len(xdr, savep, attrlen);
4327 dprintk("%s: xdr returned %d\n", __func__, -status);
4331 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4332 const struct nfs_server *server)
4334 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4338 * Decode potentially multiple layout types. Currently we only support
4339 * one layout driver per file system.
4341 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4342 uint32_t *layouttype)
4347 p = xdr_inline_decode(xdr, 4);
4350 num = be32_to_cpup(p);
4352 /* pNFS is not supported by the underlying file system */
4358 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4359 "drivers per filesystem not supported\n", __func__);
4361 /* Decode and set first layout type, move xdr->p past unused types */
4362 p = xdr_inline_decode(xdr, num * 4);
4365 *layouttype = be32_to_cpup(p);
4368 print_overflow_msg(__func__, xdr);
4373 * The type of file system exported.
4374 * Note we must ensure that layouttype is set in any non-error case.
4376 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4377 uint32_t *layouttype)
4381 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4382 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4384 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4385 status = decode_first_pnfs_layout_type(xdr, layouttype);
4386 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4393 * The prefered block size for layout directed io
4395 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4400 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4402 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4403 p = xdr_inline_decode(xdr, 4);
4405 print_overflow_msg(__func__, xdr);
4408 *res = be32_to_cpup(p);
4409 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4414 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4417 uint32_t attrlen, bitmap[3];
4420 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4422 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4424 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4427 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4429 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4431 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4433 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4435 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4436 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4438 fsinfo->wtpref = fsinfo->wtmax;
4439 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4442 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4445 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4449 status = verify_attr_len(xdr, savep, attrlen);
4451 dprintk("%s: xdr returned %d!\n", __func__, -status);
4455 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4461 /* Zero handle first to allow comparisons */
4462 memset(fh, 0, sizeof(*fh));
4464 status = decode_op_hdr(xdr, OP_GETFH);
4468 p = xdr_inline_decode(xdr, 4);
4471 len = be32_to_cpup(p);
4472 if (len > NFS4_FHSIZE)
4475 p = xdr_inline_decode(xdr, len);
4478 memcpy(fh->data, p, len);
4481 print_overflow_msg(__func__, xdr);
4485 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4489 status = decode_op_hdr(xdr, OP_LINK);
4492 return decode_change_info(xdr, cinfo);
4496 * We create the owner, so we know a proper owner.id length is 4.
4498 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4500 uint64_t offset, length, clientid;
4502 uint32_t namelen, type;
4504 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4507 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4508 p = xdr_decode_hyper(p, &length);
4509 type = be32_to_cpup(p++); /* 4 byte read */
4510 if (fl != NULL) { /* manipulate file lock */
4511 fl->fl_start = (loff_t)offset;
4512 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4513 if (length == ~(uint64_t)0)
4514 fl->fl_end = OFFSET_MAX;
4515 fl->fl_type = F_WRLCK;
4517 fl->fl_type = F_RDLCK;
4520 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4521 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4522 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4524 return -NFS4ERR_DENIED;
4526 print_overflow_msg(__func__, xdr);
4530 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4534 status = decode_op_hdr(xdr, OP_LOCK);
4538 status = decode_stateid(xdr, &res->stateid);
4539 if (unlikely(status))
4541 } else if (status == -NFS4ERR_DENIED)
4542 status = decode_lock_denied(xdr, NULL);
4543 if (res->open_seqid != NULL)
4544 nfs_increment_open_seqid(status, res->open_seqid);
4545 nfs_increment_lock_seqid(status, res->lock_seqid);
4550 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4553 status = decode_op_hdr(xdr, OP_LOCKT);
4554 if (status == -NFS4ERR_DENIED)
4555 return decode_lock_denied(xdr, res->denied);
4559 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4563 status = decode_op_hdr(xdr, OP_LOCKU);
4565 nfs_increment_lock_seqid(status, res->seqid);
4567 status = decode_stateid(xdr, &res->stateid);
4571 static int decode_release_lockowner(struct xdr_stream *xdr)
4573 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4576 static int decode_lookup(struct xdr_stream *xdr)
4578 return decode_op_hdr(xdr, OP_LOOKUP);
4581 /* This is too sick! */
4582 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4585 uint32_t limit_type, nblocks, blocksize;
4587 p = xdr_inline_decode(xdr, 12);
4590 limit_type = be32_to_cpup(p++);
4591 switch (limit_type) {
4593 xdr_decode_hyper(p, maxsize);
4596 nblocks = be32_to_cpup(p++);
4597 blocksize = be32_to_cpup(p);
4598 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4602 print_overflow_msg(__func__, xdr);
4606 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4609 uint32_t delegation_type;
4612 p = xdr_inline_decode(xdr, 4);
4615 delegation_type = be32_to_cpup(p);
4616 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4617 res->delegation_type = 0;
4620 status = decode_stateid(xdr, &res->delegation);
4621 if (unlikely(status))
4623 p = xdr_inline_decode(xdr, 4);
4626 res->do_recall = be32_to_cpup(p);
4628 switch (delegation_type) {
4629 case NFS4_OPEN_DELEGATE_READ:
4630 res->delegation_type = FMODE_READ;
4632 case NFS4_OPEN_DELEGATE_WRITE:
4633 res->delegation_type = FMODE_WRITE|FMODE_READ;
4634 if (decode_space_limit(xdr, &res->maxsize) < 0)
4637 return decode_ace(xdr, NULL, res->server->nfs_client);
4639 print_overflow_msg(__func__, xdr);
4643 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4646 uint32_t savewords, bmlen, i;
4649 status = decode_op_hdr(xdr, OP_OPEN);
4651 nfs_increment_open_seqid(status, res->seqid);
4653 status = decode_stateid(xdr, &res->stateid);
4654 if (unlikely(status))
4657 decode_change_info(xdr, &res->cinfo);
4659 p = xdr_inline_decode(xdr, 8);
4662 res->rflags = be32_to_cpup(p++);
4663 bmlen = be32_to_cpup(p);
4667 p = xdr_inline_decode(xdr, bmlen << 2);
4670 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4671 for (i = 0; i < savewords; ++i)
4672 res->attrset[i] = be32_to_cpup(p++);
4673 for (; i < NFS4_BITMAP_SIZE; i++)
4674 res->attrset[i] = 0;
4676 return decode_delegation(xdr, res);
4678 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4681 print_overflow_msg(__func__, xdr);
4685 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4689 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4691 nfs_increment_open_seqid(status, res->seqid);
4693 status = decode_stateid(xdr, &res->stateid);
4697 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4701 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4703 nfs_increment_open_seqid(status, res->seqid);
4705 status = decode_stateid(xdr, &res->stateid);
4709 static int decode_putfh(struct xdr_stream *xdr)
4711 return decode_op_hdr(xdr, OP_PUTFH);
4714 static int decode_putrootfh(struct xdr_stream *xdr)
4716 return decode_op_hdr(xdr, OP_PUTROOTFH);
4719 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4721 struct kvec *iov = req->rq_rcv_buf.head;
4723 uint32_t count, eof, recvd, hdrlen;
4726 status = decode_op_hdr(xdr, OP_READ);
4729 p = xdr_inline_decode(xdr, 8);
4732 eof = be32_to_cpup(p++);
4733 count = be32_to_cpup(p);
4734 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4735 recvd = req->rq_rcv_buf.len - hdrlen;
4736 if (count > recvd) {
4737 dprintk("NFS: server cheating in read reply: "
4738 "count %u > recvd %u\n", count, recvd);
4742 xdr_read_pages(xdr, count);
4747 print_overflow_msg(__func__, xdr);
4751 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4753 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4754 struct kvec *iov = rcvbuf->head;
4756 u32 recvd, pglen = rcvbuf->page_len;
4760 status = decode_op_hdr(xdr, OP_READDIR);
4762 status = decode_verifier(xdr, readdir->verifier.data);
4763 if (unlikely(status))
4765 memcpy(verf, readdir->verifier.data, sizeof(verf));
4766 dprintk("%s: verifier = %08x:%08x\n",
4767 __func__, verf[0], verf[1]);
4769 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4770 recvd = rcvbuf->len - hdrlen;
4773 xdr_read_pages(xdr, pglen);
4779 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4781 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4782 struct kvec *iov = rcvbuf->head;
4788 status = decode_op_hdr(xdr, OP_READLINK);
4792 /* Convert length of symlink */
4793 p = xdr_inline_decode(xdr, 4);
4796 len = be32_to_cpup(p);
4797 if (len >= rcvbuf->page_len || len <= 0) {
4798 dprintk("nfs: server returned giant symlink!\n");
4799 return -ENAMETOOLONG;
4801 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4802 recvd = req->rq_rcv_buf.len - hdrlen;
4804 dprintk("NFS: server cheating in readlink reply: "
4805 "count %u > recvd %u\n", len, recvd);
4808 xdr_read_pages(xdr, len);
4810 * The XDR encode routine has set things up so that
4811 * the link text will be copied directly into the
4812 * buffer. We just have to do overflow-checking,
4813 * and and null-terminate the text (the VFS expects
4814 * null-termination).
4816 xdr_terminate_string(rcvbuf, len);
4819 print_overflow_msg(__func__, xdr);
4823 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4827 status = decode_op_hdr(xdr, OP_REMOVE);
4830 status = decode_change_info(xdr, cinfo);
4835 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4836 struct nfs4_change_info *new_cinfo)
4840 status = decode_op_hdr(xdr, OP_RENAME);
4843 if ((status = decode_change_info(xdr, old_cinfo)))
4845 status = decode_change_info(xdr, new_cinfo);
4850 static int decode_renew(struct xdr_stream *xdr)
4852 return decode_op_hdr(xdr, OP_RENEW);
4856 decode_restorefh(struct xdr_stream *xdr)
4858 return decode_op_hdr(xdr, OP_RESTOREFH);
4861 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4862 struct nfs_getaclres *res)
4864 __be32 *savep, *bm_p;
4867 struct kvec *iov = req->rq_rcv_buf.head;
4869 size_t page_len = xdr->buf->page_len;
4872 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4876 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4877 res->acl_data_offset <<= 2;
4878 /* Check if the acl data starts beyond the allocated buffer */
4879 if (res->acl_data_offset > page_len)
4882 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4884 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4887 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4889 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4892 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4893 * are stored with the acl data to handle the problem of
4894 * variable length bitmaps.*/
4897 /* We ignore &savep and don't do consistency checks on
4898 * the attr length. Let userspace figure it out.... */
4899 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4900 attrlen += res->acl_data_offset;
4901 if (attrlen > page_len) {
4902 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4903 /* getxattr interface called with a NULL buf */
4904 res->acl_len = attrlen;
4907 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
4911 xdr_read_pages(xdr, attrlen);
4912 res->acl_len = attrlen;
4914 status = -EOPNOTSUPP;
4921 decode_savefh(struct xdr_stream *xdr)
4923 return decode_op_hdr(xdr, OP_SAVEFH);
4926 static int decode_setattr(struct xdr_stream *xdr)
4932 status = decode_op_hdr(xdr, OP_SETATTR);
4935 p = xdr_inline_decode(xdr, 4);
4938 bmlen = be32_to_cpup(p);
4939 p = xdr_inline_decode(xdr, bmlen << 2);
4943 print_overflow_msg(__func__, xdr);
4947 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
4953 p = xdr_inline_decode(xdr, 8);
4956 opnum = be32_to_cpup(p++);
4957 if (opnum != OP_SETCLIENTID) {
4958 dprintk("nfs: decode_setclientid: Server returned operation"
4962 nfserr = be32_to_cpup(p);
4963 if (nfserr == NFS_OK) {
4964 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4967 p = xdr_decode_hyper(p, &res->clientid);
4968 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
4969 } else if (nfserr == NFSERR_CLID_INUSE) {
4972 /* skip netid string */
4973 p = xdr_inline_decode(xdr, 4);
4976 len = be32_to_cpup(p);
4977 p = xdr_inline_decode(xdr, len);
4981 /* skip uaddr string */
4982 p = xdr_inline_decode(xdr, 4);
4985 len = be32_to_cpup(p);
4986 p = xdr_inline_decode(xdr, len);
4989 return -NFSERR_CLID_INUSE;
4991 return nfs4_stat_to_errno(nfserr);
4995 print_overflow_msg(__func__, xdr);
4999 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5001 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5004 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5009 status = decode_op_hdr(xdr, OP_WRITE);
5013 p = xdr_inline_decode(xdr, 16);
5016 res->count = be32_to_cpup(p++);
5017 res->verf->committed = be32_to_cpup(p++);
5018 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
5021 print_overflow_msg(__func__, xdr);
5025 static int decode_delegreturn(struct xdr_stream *xdr)
5027 return decode_op_hdr(xdr, OP_DELEGRETURN);
5030 static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5034 p = xdr_inline_decode(xdr, 4);
5037 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5038 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5041 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5044 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5046 p = xdr_inline_decode(xdr, 8);
5049 flavor->gss.qop4 = be32_to_cpup(p++);
5050 flavor->gss.service = be32_to_cpup(p);
5055 print_overflow_msg(__func__, xdr);
5061 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5063 struct nfs4_secinfo_flavor *sec_flavor;
5068 p = xdr_inline_decode(xdr, 4);
5072 res->flavors->num_flavors = 0;
5073 num_flavors = be32_to_cpup(p);
5075 for (i = 0; i < num_flavors; i++) {
5076 sec_flavor = &res->flavors->flavors[i];
5077 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5080 p = xdr_inline_decode(xdr, 4);
5083 sec_flavor->flavor = be32_to_cpup(p);
5085 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5086 status = decode_secinfo_gss(xdr, sec_flavor);
5090 res->flavors->num_flavors++;
5097 print_overflow_msg(__func__, xdr);
5101 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5103 int status = decode_op_hdr(xdr, OP_SECINFO);
5106 return decode_secinfo_common(xdr, res);
5109 #if defined(CONFIG_NFS_V4_1)
5110 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5112 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5115 return decode_secinfo_common(xdr, res);
5118 static int decode_exchange_id(struct xdr_stream *xdr,
5119 struct nfs41_exchange_id_res *res)
5125 struct nfs_client *clp = res->client;
5126 uint32_t impl_id_count;
5128 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5132 p = xdr_inline_decode(xdr, 8);
5135 xdr_decode_hyper(p, &clp->cl_clientid);
5136 p = xdr_inline_decode(xdr, 12);
5139 clp->cl_seqid = be32_to_cpup(p++);
5140 clp->cl_exchange_flags = be32_to_cpup(p++);
5142 /* We ask for SP4_NONE */
5143 dummy = be32_to_cpup(p);
5144 if (dummy != SP4_NONE)
5147 /* Throw away minor_id */
5148 p = xdr_inline_decode(xdr, 8);
5152 /* Throw away Major id */
5153 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5154 if (unlikely(status))
5157 /* Save server_scope */
5158 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5159 if (unlikely(status))
5162 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5165 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5166 res->server_scope->server_scope_sz = dummy;
5168 /* Implementation Id */
5169 p = xdr_inline_decode(xdr, 4);
5172 impl_id_count = be32_to_cpup(p++);
5174 if (impl_id_count) {
5176 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5177 if (unlikely(status))
5179 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5181 memcpy(res->impl_id->domain, dummy_str, dummy);
5184 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5185 if (unlikely(status))
5187 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5189 memcpy(res->impl_id->name, dummy_str, dummy);
5192 p = xdr_inline_decode(xdr, 12);
5195 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5196 res->impl_id->date.nseconds = be32_to_cpup(p);
5198 /* if there's more than one entry, ignore the rest */
5202 print_overflow_msg(__func__, xdr);
5206 static int decode_chan_attrs(struct xdr_stream *xdr,
5207 struct nfs4_channel_attrs *attrs)
5212 p = xdr_inline_decode(xdr, 28);
5215 val = be32_to_cpup(p++); /* headerpadsz */
5217 return -EINVAL; /* no support for header padding yet */
5218 attrs->max_rqst_sz = be32_to_cpup(p++);
5219 attrs->max_resp_sz = be32_to_cpup(p++);
5220 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5221 attrs->max_ops = be32_to_cpup(p++);
5222 attrs->max_reqs = be32_to_cpup(p++);
5223 nr_attrs = be32_to_cpup(p);
5224 if (unlikely(nr_attrs > 1)) {
5225 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5226 "count %u\n", __func__, nr_attrs);
5229 if (nr_attrs == 1) {
5230 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5236 print_overflow_msg(__func__, xdr);
5240 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5242 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5245 static int decode_create_session(struct xdr_stream *xdr,
5246 struct nfs41_create_session_res *res)
5250 struct nfs_client *clp = res->client;
5251 struct nfs4_session *session = clp->cl_session;
5253 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5255 status = decode_sessionid(xdr, &session->sess_id);
5256 if (unlikely(status))
5260 p = xdr_inline_decode(xdr, 8);
5263 clp->cl_seqid = be32_to_cpup(p++);
5264 session->flags = be32_to_cpup(p);
5266 /* Channel attributes */
5267 status = decode_chan_attrs(xdr, &session->fc_attrs);
5269 status = decode_chan_attrs(xdr, &session->bc_attrs);
5272 print_overflow_msg(__func__, xdr);
5276 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5278 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5281 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5283 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5285 #endif /* CONFIG_NFS_V4_1 */
5287 static int decode_sequence(struct xdr_stream *xdr,
5288 struct nfs4_sequence_res *res,
5289 struct rpc_rqst *rqstp)
5291 #if defined(CONFIG_NFS_V4_1)
5292 struct nfs4_sessionid id;
5297 if (!res->sr_session)
5300 status = decode_op_hdr(xdr, OP_SEQUENCE);
5302 status = decode_sessionid(xdr, &id);
5303 if (unlikely(status))
5307 * If the server returns different values for sessionID, slotID or
5308 * sequence number, the server is looney tunes.
5310 status = -EREMOTEIO;
5312 if (memcmp(id.data, res->sr_session->sess_id.data,
5313 NFS4_MAX_SESSIONID_LEN)) {
5314 dprintk("%s Invalid session id\n", __func__);
5318 p = xdr_inline_decode(xdr, 20);
5323 dummy = be32_to_cpup(p++);
5324 if (dummy != res->sr_slot->seq_nr) {
5325 dprintk("%s Invalid sequence number\n", __func__);
5329 dummy = be32_to_cpup(p++);
5330 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5331 dprintk("%s Invalid slot id\n", __func__);
5334 /* highest slot id - currently not processed */
5335 dummy = be32_to_cpup(p++);
5336 /* target highest slot id - currently not processed */
5337 dummy = be32_to_cpup(p++);
5339 res->sr_status_flags = be32_to_cpup(p);
5342 res->sr_status = status;
5345 print_overflow_msg(__func__, xdr);
5348 #else /* CONFIG_NFS_V4_1 */
5350 #endif /* CONFIG_NFS_V4_1 */
5353 #if defined(CONFIG_NFS_V4_1)
5355 * TODO: Need to handle case when EOF != true;
5357 static int decode_getdevicelist(struct xdr_stream *xdr,
5358 struct pnfs_devicelist *res)
5362 struct nfs_writeverf verftemp;
5364 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5368 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5372 /* TODO: Skip cookie for now */
5376 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
5378 res->num_devs = be32_to_cpup(p);
5380 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5382 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5383 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
5384 __func__, res->num_devs);
5388 p = xdr_inline_decode(xdr,
5389 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5392 for (i = 0; i < res->num_devs; i++)
5393 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5394 NFS4_DEVICEID4_SIZE);
5395 res->eof = be32_to_cpup(p);
5398 print_overflow_msg(__func__, xdr);
5402 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5403 struct pnfs_device *pdev)
5409 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5411 if (status == -ETOOSMALL) {
5412 p = xdr_inline_decode(xdr, 4);
5415 pdev->mincount = be32_to_cpup(p);
5416 dprintk("%s: Min count too small. mincnt = %u\n",
5417 __func__, pdev->mincount);
5422 p = xdr_inline_decode(xdr, 8);
5425 type = be32_to_cpup(p++);
5426 if (type != pdev->layout_type) {
5427 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5428 __func__, pdev->layout_type, type);
5432 * Get the length of the opaque device_addr4. xdr_read_pages places
5433 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5434 * and places the remaining xdr data in xdr_buf->tail
5436 pdev->mincount = be32_to_cpup(p);
5437 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5439 /* Parse notification bitmap, verifying that it is zero. */
5440 p = xdr_inline_decode(xdr, 4);
5443 len = be32_to_cpup(p);
5447 p = xdr_inline_decode(xdr, 4 * len);
5450 for (i = 0; i < len; i++, p++) {
5451 if (be32_to_cpup(p)) {
5452 dprintk("%s: notifications not supported\n",
5460 print_overflow_msg(__func__, xdr);
5464 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5465 struct nfs4_layoutget_res *res)
5470 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5471 struct kvec *iov = rcvbuf->head;
5474 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5477 p = xdr_inline_decode(xdr, 4);
5480 res->return_on_close = be32_to_cpup(p);
5481 decode_stateid(xdr, &res->stateid);
5482 p = xdr_inline_decode(xdr, 4);
5485 layout_count = be32_to_cpup(p);
5486 if (!layout_count) {
5487 dprintk("%s: server responded with empty layout array\n",
5492 p = xdr_inline_decode(xdr, 28);
5495 p = xdr_decode_hyper(p, &res->range.offset);
5496 p = xdr_decode_hyper(p, &res->range.length);
5497 res->range.iomode = be32_to_cpup(p++);
5498 res->type = be32_to_cpup(p++);
5499 res->layoutp->len = be32_to_cpup(p);
5501 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5503 (unsigned long)res->range.offset,
5504 (unsigned long)res->range.length,
5509 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5510 recvd = req->rq_rcv_buf.len - hdrlen;
5511 if (res->layoutp->len > recvd) {
5512 dprintk("NFS: server cheating in layoutget reply: "
5513 "layout len %u > recvd %u\n",
5514 res->layoutp->len, recvd);
5518 xdr_read_pages(xdr, res->layoutp->len);
5520 if (layout_count > 1) {
5521 /* We only handle a length one array at the moment. Any
5522 * further entries are just ignored. Note that this means
5523 * the client may see a response that is less than the
5524 * minimum it requested.
5526 dprintk("%s: server responded with %d layouts, dropping tail\n",
5527 __func__, layout_count);
5532 print_overflow_msg(__func__, xdr);
5536 static int decode_layoutreturn(struct xdr_stream *xdr,
5537 struct nfs4_layoutreturn_res *res)
5542 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5545 p = xdr_inline_decode(xdr, 4);
5548 res->lrs_present = be32_to_cpup(p);
5549 if (res->lrs_present)
5550 status = decode_stateid(xdr, &res->stateid);
5553 print_overflow_msg(__func__, xdr);
5557 static int decode_layoutcommit(struct xdr_stream *xdr,
5558 struct rpc_rqst *req,
5559 struct nfs4_layoutcommit_res *res)
5565 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5566 res->status = status;
5570 p = xdr_inline_decode(xdr, 4);
5573 sizechanged = be32_to_cpup(p);
5576 /* throw away new size */
5577 p = xdr_inline_decode(xdr, 8);
5583 print_overflow_msg(__func__, xdr);
5587 static int decode_test_stateid(struct xdr_stream *xdr,
5588 struct nfs41_test_stateid_res *res)
5594 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5598 p = xdr_inline_decode(xdr, 4);
5601 num_res = be32_to_cpup(p++);
5605 p = xdr_inline_decode(xdr, 4);
5608 res->status = be32_to_cpup(p++);
5612 print_overflow_msg(__func__, xdr);
5617 static int decode_free_stateid(struct xdr_stream *xdr,
5618 struct nfs41_free_stateid_res *res)
5623 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5627 p = xdr_inline_decode(xdr, 4);
5630 res->status = be32_to_cpup(p++);
5633 print_overflow_msg(__func__, xdr);
5636 #endif /* CONFIG_NFS_V4_1 */
5639 * END OF "GENERIC" DECODE ROUTINES.
5643 * Decode OPEN_DOWNGRADE response
5645 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5646 struct xdr_stream *xdr,
5647 struct nfs_closeres *res)
5649 struct compound_hdr hdr;
5652 status = decode_compound_hdr(xdr, &hdr);
5655 status = decode_sequence(xdr, &res->seq_res, rqstp);
5658 status = decode_putfh(xdr);
5661 status = decode_open_downgrade(xdr, res);
5664 decode_getfattr(xdr, res->fattr, res->server);
5670 * Decode ACCESS response
5672 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5673 struct nfs4_accessres *res)
5675 struct compound_hdr hdr;
5678 status = decode_compound_hdr(xdr, &hdr);
5681 status = decode_sequence(xdr, &res->seq_res, rqstp);
5684 status = decode_putfh(xdr);
5687 status = decode_access(xdr, res);
5690 decode_getfattr(xdr, res->fattr, res->server);
5696 * Decode LOOKUP response
5698 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5699 struct nfs4_lookup_res *res)
5701 struct compound_hdr hdr;
5704 status = decode_compound_hdr(xdr, &hdr);
5707 status = decode_sequence(xdr, &res->seq_res, rqstp);
5710 status = decode_putfh(xdr);
5713 status = decode_lookup(xdr);
5716 status = decode_getfh(xdr, res->fh);
5719 status = decode_getfattr(xdr, res->fattr, res->server);
5725 * Decode LOOKUP_ROOT response
5727 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5728 struct xdr_stream *xdr,
5729 struct nfs4_lookup_res *res)
5731 struct compound_hdr hdr;
5734 status = decode_compound_hdr(xdr, &hdr);
5737 status = decode_sequence(xdr, &res->seq_res, rqstp);
5740 status = decode_putrootfh(xdr);
5743 status = decode_getfh(xdr, res->fh);
5745 status = decode_getfattr(xdr, res->fattr, res->server);
5751 * Decode REMOVE response
5753 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5754 struct nfs_removeres *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_remove(xdr, &res->cinfo);
5774 * Decode RENAME response
5776 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5777 struct nfs_renameres *res)
5779 struct compound_hdr hdr;
5782 status = decode_compound_hdr(xdr, &hdr);
5785 status = decode_sequence(xdr, &res->seq_res, rqstp);
5788 status = decode_putfh(xdr);
5791 status = decode_savefh(xdr);
5794 status = decode_putfh(xdr);
5797 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5803 * Decode LINK response
5805 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5806 struct nfs4_link_res *res)
5808 struct compound_hdr hdr;
5811 status = decode_compound_hdr(xdr, &hdr);
5814 status = decode_sequence(xdr, &res->seq_res, rqstp);
5817 status = decode_putfh(xdr);
5820 status = decode_savefh(xdr);
5823 status = decode_putfh(xdr);
5826 status = decode_link(xdr, &res->cinfo);
5830 * Note order: OP_LINK leaves the directory as the current
5833 status = decode_restorefh(xdr);
5836 decode_getfattr(xdr, res->fattr, res->server);
5842 * Decode CREATE response
5844 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5845 struct nfs4_create_res *res)
5847 struct compound_hdr hdr;
5850 status = decode_compound_hdr(xdr, &hdr);
5853 status = decode_sequence(xdr, &res->seq_res, rqstp);
5856 status = decode_putfh(xdr);
5859 status = decode_create(xdr, &res->dir_cinfo);
5862 status = decode_getfh(xdr, res->fh);
5865 decode_getfattr(xdr, res->fattr, res->server);
5871 * Decode SYMLINK response
5873 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5874 struct nfs4_create_res *res)
5876 return nfs4_xdr_dec_create(rqstp, xdr, res);
5880 * Decode GETATTR response
5882 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5883 struct nfs4_getattr_res *res)
5885 struct compound_hdr hdr;
5888 status = decode_compound_hdr(xdr, &hdr);
5891 status = decode_sequence(xdr, &res->seq_res, rqstp);
5894 status = decode_putfh(xdr);
5897 status = decode_getfattr(xdr, res->fattr, res->server);
5903 * Encode an SETACL request
5905 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5906 struct nfs_setaclargs *args)
5908 struct compound_hdr hdr = {
5909 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
5912 encode_compound_hdr(xdr, req, &hdr);
5913 encode_sequence(xdr, &args->seq_args, &hdr);
5914 encode_putfh(xdr, args->fh, &hdr);
5915 encode_setacl(xdr, args, &hdr);
5920 * Decode SETACL response
5923 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5924 struct nfs_setaclres *res)
5926 struct compound_hdr hdr;
5929 status = decode_compound_hdr(xdr, &hdr);
5932 status = decode_sequence(xdr, &res->seq_res, rqstp);
5935 status = decode_putfh(xdr);
5938 status = decode_setattr(xdr);
5944 * Decode GETACL response
5947 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5948 struct nfs_getaclres *res)
5950 struct compound_hdr hdr;
5953 if (res->acl_scratch != NULL) {
5954 void *p = page_address(res->acl_scratch);
5955 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5957 status = decode_compound_hdr(xdr, &hdr);
5960 status = decode_sequence(xdr, &res->seq_res, rqstp);
5963 status = decode_putfh(xdr);
5966 status = decode_getacl(xdr, rqstp, res);
5973 * Decode CLOSE response
5975 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5976 struct nfs_closeres *res)
5978 struct compound_hdr hdr;
5981 status = decode_compound_hdr(xdr, &hdr);
5984 status = decode_sequence(xdr, &res->seq_res, rqstp);
5987 status = decode_putfh(xdr);
5990 status = decode_close(xdr, res);
5994 * Note: Server may do delete on close for this file
5995 * in which case the getattr call will fail with
5996 * an ESTALE error. Shouldn't be a problem,
5997 * though, since fattr->valid will remain unset.
5999 decode_getfattr(xdr, res->fattr, res->server);
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_open(xdr, res);
6025 if (decode_getfh(xdr, &res->fh) != 0)
6027 decode_getfattr(xdr, res->f_attr, res->server);
6033 * Decode OPEN_CONFIRM response
6035 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6036 struct xdr_stream *xdr,
6037 struct nfs_open_confirmres *res)
6039 struct compound_hdr hdr;
6042 status = decode_compound_hdr(xdr, &hdr);
6045 status = decode_putfh(xdr);
6048 status = decode_open_confirm(xdr, res);
6054 * Decode OPEN response
6056 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6057 struct xdr_stream *xdr,
6058 struct nfs_openres *res)
6060 struct compound_hdr hdr;
6063 status = decode_compound_hdr(xdr, &hdr);
6066 status = decode_sequence(xdr, &res->seq_res, rqstp);
6069 status = decode_putfh(xdr);
6072 status = decode_open(xdr, res);
6075 decode_getfattr(xdr, res->f_attr, res->server);
6081 * Decode SETATTR response
6083 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6084 struct xdr_stream *xdr,
6085 struct nfs_setattrres *res)
6087 struct compound_hdr hdr;
6090 status = decode_compound_hdr(xdr, &hdr);
6093 status = decode_sequence(xdr, &res->seq_res, rqstp);
6096 status = decode_putfh(xdr);
6099 status = decode_setattr(xdr);
6102 decode_getfattr(xdr, res->fattr, res->server);
6108 * Decode LOCK response
6110 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6111 struct nfs_lock_res *res)
6113 struct compound_hdr hdr;
6116 status = decode_compound_hdr(xdr, &hdr);
6119 status = decode_sequence(xdr, &res->seq_res, rqstp);
6122 status = decode_putfh(xdr);
6125 status = decode_lock(xdr, res);
6131 * Decode LOCKT response
6133 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6134 struct nfs_lockt_res *res)
6136 struct compound_hdr hdr;
6139 status = decode_compound_hdr(xdr, &hdr);
6142 status = decode_sequence(xdr, &res->seq_res, rqstp);
6145 status = decode_putfh(xdr);
6148 status = decode_lockt(xdr, res);
6154 * Decode LOCKU response
6156 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6157 struct nfs_locku_res *res)
6159 struct compound_hdr hdr;
6162 status = decode_compound_hdr(xdr, &hdr);
6165 status = decode_sequence(xdr, &res->seq_res, rqstp);
6168 status = decode_putfh(xdr);
6171 status = decode_locku(xdr, res);
6176 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6177 struct xdr_stream *xdr, void *dummy)
6179 struct compound_hdr hdr;
6182 status = decode_compound_hdr(xdr, &hdr);
6184 status = decode_release_lockowner(xdr);
6189 * Decode READLINK response
6191 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6192 struct xdr_stream *xdr,
6193 struct nfs4_readlink_res *res)
6195 struct compound_hdr hdr;
6198 status = decode_compound_hdr(xdr, &hdr);
6201 status = decode_sequence(xdr, &res->seq_res, rqstp);
6204 status = decode_putfh(xdr);
6207 status = decode_readlink(xdr, rqstp);
6213 * Decode READDIR response
6215 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6216 struct nfs4_readdir_res *res)
6218 struct compound_hdr hdr;
6221 status = decode_compound_hdr(xdr, &hdr);
6224 status = decode_sequence(xdr, &res->seq_res, rqstp);
6227 status = decode_putfh(xdr);
6230 status = decode_readdir(xdr, rqstp, res);
6236 * Decode Read response
6238 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6239 struct nfs_readres *res)
6241 struct compound_hdr hdr;
6244 status = decode_compound_hdr(xdr, &hdr);
6247 status = decode_sequence(xdr, &res->seq_res, rqstp);
6250 status = decode_putfh(xdr);
6253 status = decode_read(xdr, rqstp, res);
6255 status = res->count;
6261 * Decode WRITE response
6263 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6264 struct nfs_writeres *res)
6266 struct compound_hdr hdr;
6269 status = decode_compound_hdr(xdr, &hdr);
6272 status = decode_sequence(xdr, &res->seq_res, rqstp);
6275 status = decode_putfh(xdr);
6278 status = decode_write(xdr, res);
6282 decode_getfattr(xdr, res->fattr, res->server);
6284 status = res->count;
6290 * Decode COMMIT response
6292 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6293 struct nfs_commitres *res)
6295 struct compound_hdr hdr;
6298 status = decode_compound_hdr(xdr, &hdr);
6301 status = decode_sequence(xdr, &res->seq_res, rqstp);
6304 status = decode_putfh(xdr);
6307 status = decode_commit(xdr, res);
6313 * Decode FSINFO response
6315 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6316 struct nfs4_fsinfo_res *res)
6318 struct compound_hdr hdr;
6321 status = decode_compound_hdr(xdr, &hdr);
6323 status = decode_sequence(xdr, &res->seq_res, req);
6325 status = decode_putfh(xdr);
6327 status = decode_fsinfo(xdr, res->fsinfo);
6332 * Decode PATHCONF response
6334 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6335 struct nfs4_pathconf_res *res)
6337 struct compound_hdr hdr;
6340 status = decode_compound_hdr(xdr, &hdr);
6342 status = decode_sequence(xdr, &res->seq_res, req);
6344 status = decode_putfh(xdr);
6346 status = decode_pathconf(xdr, res->pathconf);
6351 * Decode STATFS response
6353 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6354 struct nfs4_statfs_res *res)
6356 struct compound_hdr hdr;
6359 status = decode_compound_hdr(xdr, &hdr);
6361 status = decode_sequence(xdr, &res->seq_res, req);
6363 status = decode_putfh(xdr);
6365 status = decode_statfs(xdr, res->fsstat);
6370 * Decode GETATTR_BITMAP response
6372 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6373 struct xdr_stream *xdr,
6374 struct nfs4_server_caps_res *res)
6376 struct compound_hdr hdr;
6379 status = decode_compound_hdr(xdr, &hdr);
6382 status = decode_sequence(xdr, &res->seq_res, req);
6385 status = decode_putfh(xdr);
6388 status = decode_server_caps(xdr, res);
6394 * Decode RENEW response
6396 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6399 struct compound_hdr hdr;
6402 status = decode_compound_hdr(xdr, &hdr);
6404 status = decode_renew(xdr);
6409 * Decode SETCLIENTID response
6411 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6412 struct xdr_stream *xdr,
6413 struct nfs4_setclientid_res *res)
6415 struct compound_hdr hdr;
6418 status = decode_compound_hdr(xdr, &hdr);
6420 status = decode_setclientid(xdr, res);
6425 * Decode SETCLIENTID_CONFIRM response
6427 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6428 struct xdr_stream *xdr,
6429 struct nfs_fsinfo *fsinfo)
6431 struct compound_hdr hdr;
6434 status = decode_compound_hdr(xdr, &hdr);
6436 status = decode_setclientid_confirm(xdr);
6438 status = decode_putrootfh(xdr);
6440 status = decode_fsinfo(xdr, fsinfo);
6445 * Decode DELEGRETURN response
6447 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6448 struct xdr_stream *xdr,
6449 struct nfs4_delegreturnres *res)
6451 struct compound_hdr hdr;
6454 status = decode_compound_hdr(xdr, &hdr);
6457 status = decode_sequence(xdr, &res->seq_res, rqstp);
6460 status = decode_putfh(xdr);
6463 status = decode_getfattr(xdr, res->fattr, res->server);
6466 status = decode_delegreturn(xdr);
6472 * Decode FS_LOCATIONS response
6474 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6475 struct xdr_stream *xdr,
6476 struct nfs4_fs_locations_res *res)
6478 struct compound_hdr hdr;
6481 status = decode_compound_hdr(xdr, &hdr);
6484 status = decode_sequence(xdr, &res->seq_res, req);
6487 status = decode_putfh(xdr);
6490 status = decode_lookup(xdr);
6493 xdr_enter_page(xdr, PAGE_SIZE);
6494 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6495 NULL, res->fs_locations,
6496 res->fs_locations->server);
6502 * Decode SECINFO response
6504 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6505 struct xdr_stream *xdr,
6506 struct nfs4_secinfo_res *res)
6508 struct compound_hdr hdr;
6511 status = decode_compound_hdr(xdr, &hdr);
6514 status = decode_sequence(xdr, &res->seq_res, rqstp);
6517 status = decode_putfh(xdr);
6520 status = decode_secinfo(xdr, res);
6525 #if defined(CONFIG_NFS_V4_1)
6527 * Decode EXCHANGE_ID response
6529 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6530 struct xdr_stream *xdr,
6533 struct compound_hdr hdr;
6536 status = decode_compound_hdr(xdr, &hdr);
6538 status = decode_exchange_id(xdr, res);
6543 * Decode CREATE_SESSION response
6545 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6546 struct xdr_stream *xdr,
6547 struct nfs41_create_session_res *res)
6549 struct compound_hdr hdr;
6552 status = decode_compound_hdr(xdr, &hdr);
6554 status = decode_create_session(xdr, res);
6559 * Decode DESTROY_SESSION response
6561 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6562 struct xdr_stream *xdr,
6565 struct compound_hdr hdr;
6568 status = decode_compound_hdr(xdr, &hdr);
6570 status = decode_destroy_session(xdr, res);
6575 * Decode SEQUENCE response
6577 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6578 struct xdr_stream *xdr,
6579 struct nfs4_sequence_res *res)
6581 struct compound_hdr hdr;
6584 status = decode_compound_hdr(xdr, &hdr);
6586 status = decode_sequence(xdr, res, rqstp);
6591 * Decode GET_LEASE_TIME response
6593 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6594 struct xdr_stream *xdr,
6595 struct nfs4_get_lease_time_res *res)
6597 struct compound_hdr hdr;
6600 status = decode_compound_hdr(xdr, &hdr);
6602 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6604 status = decode_putrootfh(xdr);
6606 status = decode_fsinfo(xdr, res->lr_fsinfo);
6611 * Decode RECLAIM_COMPLETE response
6613 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6614 struct xdr_stream *xdr,
6615 struct nfs41_reclaim_complete_res *res)
6617 struct compound_hdr hdr;
6620 status = decode_compound_hdr(xdr, &hdr);
6622 status = decode_sequence(xdr, &res->seq_res, rqstp);
6624 status = decode_reclaim_complete(xdr, (void *)NULL);
6629 * Decode GETDEVICELIST response
6631 static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6632 struct xdr_stream *xdr,
6633 struct nfs4_getdevicelist_res *res)
6635 struct compound_hdr hdr;
6638 dprintk("encoding getdevicelist!\n");
6640 status = decode_compound_hdr(xdr, &hdr);
6643 status = decode_sequence(xdr, &res->seq_res, rqstp);
6646 status = decode_putfh(xdr);
6649 status = decode_getdevicelist(xdr, res->devlist);
6655 * Decode GETDEVINFO response
6657 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6658 struct xdr_stream *xdr,
6659 struct nfs4_getdeviceinfo_res *res)
6661 struct compound_hdr hdr;
6664 status = decode_compound_hdr(xdr, &hdr);
6667 status = decode_sequence(xdr, &res->seq_res, rqstp);
6670 status = decode_getdeviceinfo(xdr, res->pdev);
6676 * Decode LAYOUTGET response
6678 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6679 struct xdr_stream *xdr,
6680 struct nfs4_layoutget_res *res)
6682 struct compound_hdr hdr;
6685 status = decode_compound_hdr(xdr, &hdr);
6688 status = decode_sequence(xdr, &res->seq_res, rqstp);
6691 status = decode_putfh(xdr);
6694 status = decode_layoutget(xdr, rqstp, res);
6700 * Decode LAYOUTRETURN response
6702 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6703 struct xdr_stream *xdr,
6704 struct nfs4_layoutreturn_res *res)
6706 struct compound_hdr hdr;
6709 status = decode_compound_hdr(xdr, &hdr);
6712 status = decode_sequence(xdr, &res->seq_res, rqstp);
6715 status = decode_putfh(xdr);
6718 status = decode_layoutreturn(xdr, res);
6724 * Decode LAYOUTCOMMIT response
6726 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6727 struct xdr_stream *xdr,
6728 struct nfs4_layoutcommit_res *res)
6730 struct compound_hdr hdr;
6733 status = decode_compound_hdr(xdr, &hdr);
6736 status = decode_sequence(xdr, &res->seq_res, rqstp);
6739 status = decode_putfh(xdr);
6742 status = decode_layoutcommit(xdr, rqstp, res);
6745 decode_getfattr(xdr, res->fattr, res->server);
6751 * Decode SECINFO_NO_NAME response
6753 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6754 struct xdr_stream *xdr,
6755 struct nfs4_secinfo_res *res)
6757 struct compound_hdr hdr;
6760 status = decode_compound_hdr(xdr, &hdr);
6763 status = decode_sequence(xdr, &res->seq_res, rqstp);
6766 status = decode_putrootfh(xdr);
6769 status = decode_secinfo_no_name(xdr, res);
6775 * Decode TEST_STATEID response
6777 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6778 struct xdr_stream *xdr,
6779 struct nfs41_test_stateid_res *res)
6781 struct compound_hdr hdr;
6784 status = decode_compound_hdr(xdr, &hdr);
6787 status = decode_sequence(xdr, &res->seq_res, rqstp);
6790 status = decode_test_stateid(xdr, res);
6796 * Decode FREE_STATEID response
6798 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6799 struct xdr_stream *xdr,
6800 struct nfs41_free_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_free_stateid(xdr, res);
6815 #endif /* CONFIG_NFS_V4_1 */
6818 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6819 * the local page cache.
6820 * @xdr: XDR stream where entry resides
6821 * @entry: buffer to fill in with entry data
6822 * @plus: boolean indicating whether this should be a readdirplus entry
6824 * Returns zero if successful, otherwise a negative errno value is
6827 * This function is not invoked during READDIR reply decoding, but
6828 * rather whenever an application invokes the getdents(2) system call
6829 * on a directory already in our cache.
6831 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6834 uint32_t bitmap[3] = {0};
6836 __be32 *p = xdr_inline_decode(xdr, 4);
6839 if (*p == xdr_zero) {
6840 p = xdr_inline_decode(xdr, 4);
6849 p = xdr_inline_decode(xdr, 12);
6852 entry->prev_cookie = entry->cookie;
6853 p = xdr_decode_hyper(p, &entry->cookie);
6854 entry->len = be32_to_cpup(p);
6856 p = xdr_inline_decode(xdr, entry->len);
6859 entry->name = (const char *) p;
6862 * In case the server doesn't return an inode number,
6863 * we fake one here. (We don't use inode number 0,
6864 * since glibc seems to choke on it...)
6867 entry->fattr->valid = 0;
6869 if (decode_attr_bitmap(xdr, bitmap) < 0)
6872 if (decode_attr_length(xdr, &len, &p) < 0)
6875 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6876 NULL, entry->server) < 0)
6878 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6879 entry->ino = entry->fattr->mounted_on_fileid;
6880 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6881 entry->ino = entry->fattr->fileid;
6883 entry->d_type = DT_UNKNOWN;
6884 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6885 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6890 print_overflow_msg(__func__, xdr);
6895 * We need to translate between nfs status return values and
6896 * the local errno values which may not be the same.
6903 { NFS4ERR_PERM, -EPERM },
6904 { NFS4ERR_NOENT, -ENOENT },
6905 { NFS4ERR_IO, -errno_NFSERR_IO},
6906 { NFS4ERR_NXIO, -ENXIO },
6907 { NFS4ERR_ACCESS, -EACCES },
6908 { NFS4ERR_EXIST, -EEXIST },
6909 { NFS4ERR_XDEV, -EXDEV },
6910 { NFS4ERR_NOTDIR, -ENOTDIR },
6911 { NFS4ERR_ISDIR, -EISDIR },
6912 { NFS4ERR_INVAL, -EINVAL },
6913 { NFS4ERR_FBIG, -EFBIG },
6914 { NFS4ERR_NOSPC, -ENOSPC },
6915 { NFS4ERR_ROFS, -EROFS },
6916 { NFS4ERR_MLINK, -EMLINK },
6917 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6918 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6919 { NFS4ERR_DQUOT, -EDQUOT },
6920 { NFS4ERR_STALE, -ESTALE },
6921 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6922 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6923 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6924 { NFS4ERR_TOOSMALL, -ETOOSMALL },
6925 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
6926 { NFS4ERR_BADTYPE, -EBADTYPE },
6927 { NFS4ERR_LOCKED, -EAGAIN },
6928 { NFS4ERR_SYMLINK, -ELOOP },
6929 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6930 { NFS4ERR_DEADLOCK, -EDEADLK },
6935 * Convert an NFS error code to a local one.
6936 * This one is used jointly by NFSv2 and NFSv3.
6939 nfs4_stat_to_errno(int stat)
6942 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6943 if (nfs_errtbl[i].stat == stat)
6944 return nfs_errtbl[i].errno;
6946 if (stat <= 10000 || stat > 10100) {
6947 /* The server is looney tunes. */
6950 /* If we cannot translate the error, the recovery routines should
6952 * Note: remaining NFSv4 error codes have values > 10000, so should
6953 * not conflict with native Linux error codes.
6958 #define PROC(proc, argtype, restype) \
6959 [NFSPROC4_CLNT_##proc] = { \
6960 .p_proc = NFSPROC4_COMPOUND, \
6961 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6962 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6963 .p_arglen = NFS4_##argtype##_sz, \
6964 .p_replen = NFS4_##restype##_sz, \
6965 .p_statidx = NFSPROC4_CLNT_##proc, \
6969 struct rpc_procinfo nfs4_procedures[] = {
6970 PROC(READ, enc_read, dec_read),
6971 PROC(WRITE, enc_write, dec_write),
6972 PROC(COMMIT, enc_commit, dec_commit),
6973 PROC(OPEN, enc_open, dec_open),
6974 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6975 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6976 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6977 PROC(CLOSE, enc_close, dec_close),
6978 PROC(SETATTR, enc_setattr, dec_setattr),
6979 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6980 PROC(RENEW, enc_renew, dec_renew),
6981 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6982 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6983 PROC(LOCK, enc_lock, dec_lock),
6984 PROC(LOCKT, enc_lockt, dec_lockt),
6985 PROC(LOCKU, enc_locku, dec_locku),
6986 PROC(ACCESS, enc_access, dec_access),
6987 PROC(GETATTR, enc_getattr, dec_getattr),
6988 PROC(LOOKUP, enc_lookup, dec_lookup),
6989 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6990 PROC(REMOVE, enc_remove, dec_remove),
6991 PROC(RENAME, enc_rename, dec_rename),
6992 PROC(LINK, enc_link, dec_link),
6993 PROC(SYMLINK, enc_symlink, dec_symlink),
6994 PROC(CREATE, enc_create, dec_create),
6995 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6996 PROC(STATFS, enc_statfs, dec_statfs),
6997 PROC(READLINK, enc_readlink, dec_readlink),
6998 PROC(READDIR, enc_readdir, dec_readdir),
6999 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7000 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7001 PROC(GETACL, enc_getacl, dec_getacl),
7002 PROC(SETACL, enc_setacl, dec_setacl),
7003 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7004 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7005 PROC(SECINFO, enc_secinfo, dec_secinfo),
7006 #if defined(CONFIG_NFS_V4_1)
7007 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7008 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7009 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7010 PROC(SEQUENCE, enc_sequence, dec_sequence),
7011 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7012 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7013 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7014 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7015 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7016 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7017 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7018 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7019 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7020 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
7021 #endif /* CONFIG_NFS_V4_1 */
7024 const struct rpc_version nfs_version4 = {
7026 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7027 .procs = nfs4_procedures