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/fs_struct.h>
59 #include "nfs4idmap.h"
60 #include "nfs4session.h"
64 #define NFSDBG_FACILITY NFSDBG_XDR
66 /* Mapping from NFS error code to "errno" error code. */
67 #define errno_NFSERR_IO EIO
69 static int nfs4_stat_to_errno(int);
71 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
73 #define NFS4_MAXTAGLEN 20
75 #define NFS4_MAXTAGLEN 0
78 /* lock,open owner id:
79 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
81 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
82 #define lock_owner_id_maxsz (1 + 1 + 4)
83 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
84 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
86 #define op_encode_hdr_maxsz (1)
87 #define op_decode_hdr_maxsz (2)
88 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
90 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
92 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
94 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
95 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
96 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
97 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
98 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
99 ((3+NFS4_FHSIZE) >> 2))
100 #define nfs4_fattr_bitmap_maxsz 4
101 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
102 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
103 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
104 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
106 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
107 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108 #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
110 #define nfs4_label_maxsz 0
112 /* We support only one layout type per file system */
113 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
114 /* This is based on getfattr, which uses the most attributes: */
115 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
116 3 + 3 + 3 + nfs4_owner_maxsz + \
117 nfs4_group_maxsz + nfs4_label_maxsz + \
118 decode_mdsthreshold_maxsz))
119 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
120 nfs4_fattr_value_maxsz)
121 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
122 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
128 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
129 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
130 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
131 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
132 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
133 /* The 5 accounts for the PNFS attributes, and assumes that at most three
134 * layout types will be returned.
136 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
137 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
138 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
139 #define decode_renew_maxsz (op_decode_hdr_maxsz)
140 #define encode_setclientid_maxsz \
141 (op_encode_hdr_maxsz + \
142 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
144 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
147 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
149 #define decode_setclientid_maxsz \
150 (op_decode_hdr_maxsz + \
152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
154 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
155 #define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158 #define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
160 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
162 #define encode_share_access_maxsz \
164 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
165 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167 #define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
172 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
173 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
175 #define decode_change_info_maxsz (5)
176 #define decode_open_maxsz (op_decode_hdr_maxsz + \
177 decode_stateid_maxsz + \
178 decode_change_info_maxsz + 1 + \
179 nfs4_fattr_bitmap_maxsz + \
180 decode_delegation_maxsz)
181 #define encode_open_confirm_maxsz \
182 (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + 1)
184 #define decode_open_confirm_maxsz \
185 (op_decode_hdr_maxsz + \
186 decode_stateid_maxsz)
187 #define encode_open_downgrade_maxsz \
188 (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 1 + \
190 encode_share_access_maxsz)
191 #define decode_open_downgrade_maxsz \
192 (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194 #define encode_close_maxsz (op_encode_hdr_maxsz + \
195 1 + encode_stateid_maxsz)
196 #define decode_close_maxsz (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
199 encode_stateid_maxsz + \
201 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
202 nfs4_fattr_bitmap_maxsz)
203 #define encode_read_maxsz (op_encode_hdr_maxsz + \
204 encode_stateid_maxsz + 3)
205 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
206 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
207 2 + encode_verifier_maxsz + 5 + \
209 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
210 decode_verifier_maxsz)
211 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
212 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
213 #define encode_write_maxsz (op_encode_hdr_maxsz + \
214 encode_stateid_maxsz + 4)
215 #define decode_write_maxsz (op_decode_hdr_maxsz + \
216 2 + decode_verifier_maxsz)
217 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
218 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
219 decode_verifier_maxsz)
220 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
222 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
223 decode_change_info_maxsz)
224 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
226 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz + \
228 decode_change_info_maxsz)
229 #define encode_link_maxsz (op_encode_hdr_maxsz + \
231 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
232 #define encode_lockowner_maxsz (7)
233 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
235 1 + encode_stateid_maxsz + 1 + \
236 encode_lockowner_maxsz)
237 #define decode_lock_denied_maxsz \
238 (8 + decode_lockowner_maxsz)
239 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
240 decode_lock_denied_maxsz)
241 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
242 encode_lockowner_maxsz)
243 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
244 decode_lock_denied_maxsz)
245 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
246 encode_stateid_maxsz + \
248 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
249 decode_stateid_maxsz)
250 #define encode_release_lockowner_maxsz \
251 (op_encode_hdr_maxsz + \
252 encode_lockowner_maxsz)
253 #define decode_release_lockowner_maxsz \
254 (op_decode_hdr_maxsz)
255 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
256 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
257 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
258 1 + nfs4_name_maxsz + \
261 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
262 #define encode_create_maxsz (op_encode_hdr_maxsz + \
263 1 + 2 + nfs4_name_maxsz + \
265 #define decode_create_maxsz (op_decode_hdr_maxsz + \
266 decode_change_info_maxsz + \
267 nfs4_fattr_bitmap_maxsz)
268 #define encode_statfs_maxsz (encode_getattr_maxsz)
269 #define decode_statfs_maxsz (decode_getattr_maxsz)
270 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
271 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
272 #define encode_getacl_maxsz (encode_getattr_maxsz)
273 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
274 nfs4_fattr_bitmap_maxsz + 1)
275 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
276 encode_stateid_maxsz + 3)
277 #define decode_setacl_maxsz (decode_setattr_maxsz)
278 #define encode_fs_locations_maxsz \
279 (encode_getattr_maxsz)
280 #define decode_fs_locations_maxsz \
282 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
283 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
285 #if defined(CONFIG_NFS_V4_1)
286 #define NFS4_MAX_MACHINE_NAME_LEN (64)
287 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
288 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
290 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
291 encode_verifier_maxsz + \
292 1 /* co_ownerid.len */ + \
293 /* eia_clientowner */ \
294 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
297 /* max is SP4_MACH_CRED (for now) */ + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
299 1 + NFS4_OP_MAP_NUM_WORDS + \
300 1 /* implementation id array of size 1 */ + \
301 1 /* nii_domain */ + \
302 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
304 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
306 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
307 2 /* eir_clientid */ + \
308 1 /* eir_sequenceid */ + \
309 1 /* eir_flags */ + \
311 /* max is SP4_MACH_CRED (for now) */ + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
313 1 + NFS4_OP_MAP_NUM_WORDS + \
314 2 /* eir_server_owner.so_minor_id */ + \
315 /* eir_server_owner.so_major_id<> */ \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
317 /* eir_server_scope<> */ \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
319 1 /* eir_server_impl_id array length */ + \
320 1 /* nii_domain */ + \
321 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
323 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
325 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
326 #define decode_channel_attrs_maxsz (6 + \
327 1 /* ca_rdma_ird.len */ + \
329 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
330 2 /* csa_clientid */ + \
331 1 /* csa_sequence */ + \
332 1 /* csa_flags */ + \
333 encode_channel_attrs_maxsz + \
334 encode_channel_attrs_maxsz + \
335 1 /* csa_cb_program */ + \
336 1 /* csa_sec_parms.len (1) */ + \
337 1 /* cb_secflavor (AUTH_SYS) */ + \
339 1 /* machinename.len */ + \
340 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
343 1 /* gids.len (0) */)
344 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
345 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
346 1 /* csr_sequence */ + \
347 1 /* csr_flags */ + \
348 decode_channel_attrs_maxsz + \
349 decode_channel_attrs_maxsz)
350 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
352 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353 1 /* bctsa_dir */ + \
354 1 /* bctsa_use_conn_in_rdma_mode */)
355 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
357 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
358 1 /* bctsr_dir */ + \
359 1 /* bctsr_use_conn_in_rdma_mode */)
360 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
361 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
362 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
363 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
364 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
365 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
366 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
367 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
368 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
369 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
370 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
371 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
372 1 /* layout type */ + \
374 1 /* bitmap size */ + \
375 1 /* notification bitmap length */ + \
376 1 /* notification bitmap, word 0 */)
377 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
378 1 /* layout type */ + \
379 1 /* opaque devaddr4 length */ + \
380 /* devaddr4 payload is read into page */ \
381 1 /* notification bitmap length */ + \
382 1 /* notification bitmap, word 0 */)
383 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
384 encode_stateid_maxsz)
385 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
386 decode_stateid_maxsz + \
387 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
388 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
392 encode_stateid_maxsz + \
393 1 /* new offset (true) */ + \
394 2 /* last byte written */ + \
395 1 /* nt_timechanged (false) */ + \
396 1 /* layoutupdate4 layout type */ + \
397 1 /* layoutupdate4 opaqueue len */)
398 /* the actual content of layoutupdate4 should
399 be allocated by drivers and spliced in
400 using xdr_write_pages */
401 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
402 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
403 encode_stateid_maxsz + \
405 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
406 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
407 1 + decode_stateid_maxsz)
408 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
409 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
410 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
411 XDR_QUADLEN(NFS4_STATEID_SIZE))
412 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
413 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
414 XDR_QUADLEN(NFS4_STATEID_SIZE))
415 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
416 #else /* CONFIG_NFS_V4_1 */
417 #define encode_sequence_maxsz 0
418 #define decode_sequence_maxsz 0
419 #define encode_layoutreturn_maxsz 0
420 #define decode_layoutreturn_maxsz 0
421 #endif /* CONFIG_NFS_V4_1 */
423 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
424 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
425 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
426 encode_sequence_maxsz + \
427 encode_putfh_maxsz + \
429 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
430 decode_sequence_maxsz + \
431 decode_putfh_maxsz + \
433 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
434 encode_sequence_maxsz + \
435 encode_putfh_maxsz + \
436 encode_readlink_maxsz)
437 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
438 decode_sequence_maxsz + \
439 decode_putfh_maxsz + \
440 decode_readlink_maxsz)
441 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
442 encode_sequence_maxsz + \
443 encode_putfh_maxsz + \
444 encode_readdir_maxsz)
445 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
446 decode_sequence_maxsz + \
447 decode_putfh_maxsz + \
448 decode_readdir_maxsz)
449 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
450 encode_sequence_maxsz + \
451 encode_putfh_maxsz + \
452 encode_write_maxsz + \
453 encode_getattr_maxsz)
454 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
455 decode_sequence_maxsz + \
456 decode_putfh_maxsz + \
457 decode_write_maxsz + \
458 decode_getattr_maxsz)
459 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
460 encode_sequence_maxsz + \
461 encode_putfh_maxsz + \
463 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
464 decode_sequence_maxsz + \
465 decode_putfh_maxsz + \
467 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
468 encode_sequence_maxsz + \
469 encode_putfh_maxsz + \
470 encode_open_maxsz + \
471 encode_access_maxsz + \
472 encode_getfh_maxsz + \
473 encode_getattr_maxsz)
474 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
475 decode_sequence_maxsz + \
476 decode_putfh_maxsz + \
477 decode_open_maxsz + \
478 decode_access_maxsz + \
479 decode_getfh_maxsz + \
480 decode_getattr_maxsz)
481 #define NFS4_enc_open_confirm_sz \
482 (compound_encode_hdr_maxsz + \
483 encode_putfh_maxsz + \
484 encode_open_confirm_maxsz)
485 #define NFS4_dec_open_confirm_sz \
486 (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
488 decode_open_confirm_maxsz)
489 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
490 encode_sequence_maxsz + \
491 encode_putfh_maxsz + \
492 encode_open_maxsz + \
493 encode_access_maxsz + \
494 encode_getattr_maxsz)
495 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
496 decode_sequence_maxsz + \
497 decode_putfh_maxsz + \
498 decode_open_maxsz + \
499 decode_access_maxsz + \
500 decode_getattr_maxsz)
501 #define NFS4_enc_open_downgrade_sz \
502 (compound_encode_hdr_maxsz + \
503 encode_sequence_maxsz + \
504 encode_putfh_maxsz + \
505 encode_open_downgrade_maxsz)
506 #define NFS4_dec_open_downgrade_sz \
507 (compound_decode_hdr_maxsz + \
508 decode_sequence_maxsz + \
509 decode_putfh_maxsz + \
510 decode_open_downgrade_maxsz)
511 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
512 encode_sequence_maxsz + \
513 encode_putfh_maxsz + \
514 encode_layoutreturn_maxsz + \
515 encode_close_maxsz + \
516 encode_getattr_maxsz)
517 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
518 decode_sequence_maxsz + \
519 decode_putfh_maxsz + \
520 decode_layoutreturn_maxsz + \
521 decode_close_maxsz + \
522 decode_getattr_maxsz)
523 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
524 encode_sequence_maxsz + \
525 encode_putfh_maxsz + \
526 encode_setattr_maxsz + \
527 encode_getattr_maxsz)
528 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
529 decode_sequence_maxsz + \
530 decode_putfh_maxsz + \
531 decode_setattr_maxsz + \
532 decode_getattr_maxsz)
533 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
534 encode_sequence_maxsz + \
535 encode_putfh_maxsz + \
537 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
538 decode_sequence_maxsz + \
539 decode_putfh_maxsz + \
541 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
543 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
545 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
546 encode_setclientid_maxsz)
547 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
548 decode_setclientid_maxsz)
549 #define NFS4_enc_setclientid_confirm_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_setclientid_confirm_maxsz)
552 #define NFS4_dec_setclientid_confirm_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_setclientid_confirm_maxsz)
555 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
556 encode_sequence_maxsz + \
557 encode_putfh_maxsz + \
559 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
560 decode_sequence_maxsz + \
561 decode_putfh_maxsz + \
563 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
564 encode_sequence_maxsz + \
565 encode_putfh_maxsz + \
567 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
568 decode_sequence_maxsz + \
569 decode_putfh_maxsz + \
571 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
572 encode_sequence_maxsz + \
573 encode_putfh_maxsz + \
575 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
576 decode_sequence_maxsz + \
577 decode_putfh_maxsz + \
579 #define NFS4_enc_release_lockowner_sz \
580 (compound_encode_hdr_maxsz + \
581 encode_lockowner_maxsz)
582 #define NFS4_dec_release_lockowner_sz \
583 (compound_decode_hdr_maxsz + \
584 decode_lockowner_maxsz)
585 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
586 encode_sequence_maxsz + \
587 encode_putfh_maxsz + \
588 encode_access_maxsz + \
589 encode_getattr_maxsz)
590 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
591 decode_sequence_maxsz + \
592 decode_putfh_maxsz + \
593 decode_access_maxsz + \
594 decode_getattr_maxsz)
595 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
596 encode_sequence_maxsz + \
597 encode_putfh_maxsz + \
598 encode_getattr_maxsz + \
600 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
601 decode_sequence_maxsz + \
602 decode_putfh_maxsz + \
603 decode_getattr_maxsz + \
605 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
606 encode_sequence_maxsz + \
607 encode_putfh_maxsz + \
608 encode_lookup_maxsz + \
609 encode_getattr_maxsz + \
611 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
612 decode_sequence_maxsz + \
613 decode_putfh_maxsz + \
614 decode_lookup_maxsz + \
615 decode_getattr_maxsz + \
617 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
618 encode_sequence_maxsz + \
619 encode_putrootfh_maxsz + \
620 encode_getattr_maxsz + \
622 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
623 decode_sequence_maxsz + \
624 decode_putrootfh_maxsz + \
625 decode_getattr_maxsz + \
627 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
628 encode_sequence_maxsz + \
629 encode_putfh_maxsz + \
631 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
632 decode_sequence_maxsz + \
633 decode_putfh_maxsz + \
635 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
636 encode_sequence_maxsz + \
637 encode_putfh_maxsz + \
638 encode_savefh_maxsz + \
639 encode_putfh_maxsz + \
641 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
642 decode_sequence_maxsz + \
643 decode_putfh_maxsz + \
644 decode_savefh_maxsz + \
645 decode_putfh_maxsz + \
647 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
648 encode_sequence_maxsz + \
649 encode_putfh_maxsz + \
650 encode_savefh_maxsz + \
651 encode_putfh_maxsz + \
652 encode_link_maxsz + \
653 encode_restorefh_maxsz + \
654 encode_getattr_maxsz)
655 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
656 decode_sequence_maxsz + \
657 decode_putfh_maxsz + \
658 decode_savefh_maxsz + \
659 decode_putfh_maxsz + \
660 decode_link_maxsz + \
661 decode_restorefh_maxsz + \
662 decode_getattr_maxsz)
663 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
664 encode_sequence_maxsz + \
665 encode_putfh_maxsz + \
666 encode_symlink_maxsz + \
667 encode_getattr_maxsz + \
669 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
670 decode_sequence_maxsz + \
671 decode_putfh_maxsz + \
672 decode_symlink_maxsz + \
673 decode_getattr_maxsz + \
675 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
676 encode_sequence_maxsz + \
677 encode_putfh_maxsz + \
678 encode_create_maxsz + \
679 encode_getfh_maxsz + \
680 encode_getattr_maxsz)
681 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
682 decode_sequence_maxsz + \
683 decode_putfh_maxsz + \
684 decode_create_maxsz + \
685 decode_getfh_maxsz + \
686 decode_getattr_maxsz)
687 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
688 encode_sequence_maxsz + \
689 encode_putfh_maxsz + \
690 encode_getattr_maxsz)
691 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
692 decode_sequence_maxsz + \
693 decode_putfh_maxsz + \
694 decode_getattr_maxsz)
695 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
696 encode_sequence_maxsz + \
697 encode_putfh_maxsz + \
699 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_putfh_maxsz + \
703 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
704 encode_sequence_maxsz + \
705 encode_putfh_maxsz + \
706 encode_getattr_maxsz)
707 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
708 decode_sequence_maxsz + \
709 decode_putfh_maxsz + \
710 decode_getattr_maxsz)
711 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
712 encode_sequence_maxsz + \
713 encode_putfh_maxsz + \
714 encode_layoutreturn_maxsz + \
715 encode_delegreturn_maxsz + \
716 encode_getattr_maxsz)
717 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
718 decode_sequence_maxsz + \
719 decode_putfh_maxsz + \
720 decode_layoutreturn_maxsz + \
721 decode_delegreturn_maxsz + \
722 decode_getattr_maxsz)
723 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
724 encode_sequence_maxsz + \
725 encode_putfh_maxsz + \
727 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz + \
729 decode_putfh_maxsz + \
731 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
732 encode_sequence_maxsz + \
733 encode_putfh_maxsz + \
735 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
736 decode_sequence_maxsz + \
737 decode_putfh_maxsz + \
739 #define NFS4_enc_fs_locations_sz \
740 (compound_encode_hdr_maxsz + \
741 encode_sequence_maxsz + \
742 encode_putfh_maxsz + \
743 encode_lookup_maxsz + \
744 encode_fs_locations_maxsz + \
746 #define NFS4_dec_fs_locations_sz \
747 (compound_decode_hdr_maxsz + \
748 decode_sequence_maxsz + \
749 decode_putfh_maxsz + \
750 decode_lookup_maxsz + \
751 decode_fs_locations_maxsz + \
753 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
754 encode_sequence_maxsz + \
755 encode_putfh_maxsz + \
756 encode_secinfo_maxsz)
757 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
758 decode_sequence_maxsz + \
759 decode_putfh_maxsz + \
760 decode_secinfo_maxsz)
761 #define NFS4_enc_fsid_present_sz \
762 (compound_encode_hdr_maxsz + \
763 encode_sequence_maxsz + \
764 encode_putfh_maxsz + \
765 encode_getfh_maxsz + \
767 #define NFS4_dec_fsid_present_sz \
768 (compound_decode_hdr_maxsz + \
769 decode_sequence_maxsz + \
770 decode_putfh_maxsz + \
771 decode_getfh_maxsz + \
773 #if defined(CONFIG_NFS_V4_1)
774 #define NFS4_enc_bind_conn_to_session_sz \
775 (compound_encode_hdr_maxsz + \
776 encode_bind_conn_to_session_maxsz)
777 #define NFS4_dec_bind_conn_to_session_sz \
778 (compound_decode_hdr_maxsz + \
779 decode_bind_conn_to_session_maxsz)
780 #define NFS4_enc_exchange_id_sz \
781 (compound_encode_hdr_maxsz + \
782 encode_exchange_id_maxsz)
783 #define NFS4_dec_exchange_id_sz \
784 (compound_decode_hdr_maxsz + \
785 decode_exchange_id_maxsz)
786 #define NFS4_enc_create_session_sz \
787 (compound_encode_hdr_maxsz + \
788 encode_create_session_maxsz)
789 #define NFS4_dec_create_session_sz \
790 (compound_decode_hdr_maxsz + \
791 decode_create_session_maxsz)
792 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
793 encode_destroy_session_maxsz)
794 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
795 decode_destroy_session_maxsz)
796 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
797 encode_destroy_clientid_maxsz)
798 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
799 decode_destroy_clientid_maxsz)
800 #define NFS4_enc_sequence_sz \
801 (compound_decode_hdr_maxsz + \
802 encode_sequence_maxsz)
803 #define NFS4_dec_sequence_sz \
804 (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz)
806 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
807 encode_sequence_maxsz + \
808 encode_putrootfh_maxsz + \
810 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_putrootfh_maxsz + \
814 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
815 encode_sequence_maxsz + \
816 encode_reclaim_complete_maxsz)
817 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
818 decode_sequence_maxsz + \
819 decode_reclaim_complete_maxsz)
820 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
821 encode_sequence_maxsz +\
822 encode_getdeviceinfo_maxsz)
823 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_getdeviceinfo_maxsz)
826 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
827 encode_sequence_maxsz + \
828 encode_putfh_maxsz + \
829 encode_layoutget_maxsz)
830 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_putfh_maxsz + \
833 decode_layoutget_maxsz)
834 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
835 encode_sequence_maxsz +\
836 encode_putfh_maxsz + \
837 encode_layoutcommit_maxsz + \
838 encode_getattr_maxsz)
839 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
840 decode_sequence_maxsz + \
841 decode_putfh_maxsz + \
842 decode_layoutcommit_maxsz + \
843 decode_getattr_maxsz)
844 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
845 encode_sequence_maxsz + \
846 encode_putfh_maxsz + \
847 encode_layoutreturn_maxsz)
848 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_putfh_maxsz + \
851 decode_layoutreturn_maxsz)
852 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz + \
854 encode_putrootfh_maxsz +\
855 encode_secinfo_no_name_maxsz)
856 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
857 decode_sequence_maxsz + \
858 decode_putrootfh_maxsz + \
859 decode_secinfo_no_name_maxsz)
860 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
861 encode_sequence_maxsz + \
862 encode_test_stateid_maxsz)
863 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
864 decode_sequence_maxsz + \
865 decode_test_stateid_maxsz)
866 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
867 encode_sequence_maxsz + \
868 encode_free_stateid_maxsz)
869 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
870 decode_sequence_maxsz + \
871 decode_free_stateid_maxsz)
873 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
874 compound_encode_hdr_maxsz +
875 encode_sequence_maxsz +
877 encode_getattr_maxsz) *
880 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
881 compound_decode_hdr_maxsz +
882 decode_sequence_maxsz +
883 decode_putfh_maxsz) *
886 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
887 compound_decode_hdr_maxsz +
888 decode_sequence_maxsz) *
890 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
891 #endif /* CONFIG_NFS_V4_1 */
893 static const umode_t nfs_type2fmt[] = {
900 [NF4SOCK] = S_IFSOCK,
906 struct compound_hdr {
912 uint32_t replen; /* expected reply words */
916 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
918 __be32 *p = xdr_reserve_space(xdr, nbytes);
923 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
927 p = xdr_reserve_space(xdr, len);
928 xdr_encode_opaque_fixed(p, buf, len);
931 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
935 p = reserve_space(xdr, 4 + len);
936 xdr_encode_opaque(p, str, len);
939 static void encode_uint32(struct xdr_stream *xdr, u32 n)
943 p = reserve_space(xdr, 4);
947 static void encode_uint64(struct xdr_stream *xdr, u64 n)
951 p = reserve_space(xdr, 8);
952 xdr_encode_hyper(p, n);
955 static void encode_nfs4_seqid(struct xdr_stream *xdr,
956 const struct nfs_seqid *seqid)
959 encode_uint32(xdr, seqid->sequence->counter);
961 encode_uint32(xdr, 0);
964 static void encode_compound_hdr(struct xdr_stream *xdr,
965 struct rpc_rqst *req,
966 struct compound_hdr *hdr)
969 struct rpc_auth *auth = req->rq_cred->cr_auth;
971 /* initialize running count of expected bytes in reply.
972 * NOTE: the replied tag SHOULD be the same is the one sent,
973 * but this is not required as a MUST for the server to do so. */
974 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
976 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
977 encode_string(xdr, hdr->taglen, hdr->tag);
978 p = reserve_space(xdr, 8);
979 *p++ = cpu_to_be32(hdr->minorversion);
981 *p = cpu_to_be32(hdr->nops);
984 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
986 struct compound_hdr *hdr)
988 encode_uint32(xdr, op);
990 hdr->replen += replen;
993 static void encode_nops(struct compound_hdr *hdr)
995 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
996 *hdr->nops_p = htonl(hdr->nops);
999 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1001 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1004 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1006 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1009 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1010 const struct nfs4_label *label,
1011 const struct nfs_server *server,
1012 bool excl_check, const umode_t *umask)
1014 char owner_name[IDMAP_NAMESZ];
1015 char owner_group[IDMAP_NAMESZ];
1016 int owner_namelen = 0;
1017 int owner_grouplen = 0;
1022 uint32_t bmval[3] = { 0 };
1025 * We reserve enough space to write the entire attribute buffer at once.
1027 if (iap->ia_valid & ATTR_SIZE) {
1028 bmval[0] |= FATTR4_WORD0_SIZE;
1031 if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK))
1033 if (iap->ia_valid & ATTR_MODE) {
1035 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1038 bmval[1] |= FATTR4_WORD1_MODE;
1042 if (iap->ia_valid & ATTR_UID) {
1043 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1044 if (owner_namelen < 0) {
1045 dprintk("nfs: couldn't resolve uid %d to string\n",
1046 from_kuid(&init_user_ns, iap->ia_uid));
1048 strcpy(owner_name, "nobody");
1049 owner_namelen = sizeof("nobody") - 1;
1052 bmval[1] |= FATTR4_WORD1_OWNER;
1053 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1055 if (iap->ia_valid & ATTR_GID) {
1056 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1057 if (owner_grouplen < 0) {
1058 dprintk("nfs: couldn't resolve gid %d to string\n",
1059 from_kgid(&init_user_ns, iap->ia_gid));
1060 strcpy(owner_group, "nobody");
1061 owner_grouplen = sizeof("nobody") - 1;
1064 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1065 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1067 if (iap->ia_valid & ATTR_ATIME_SET) {
1068 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1070 } else if (iap->ia_valid & ATTR_ATIME) {
1071 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1074 if (iap->ia_valid & ATTR_MTIME_SET) {
1075 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1077 } else if (iap->ia_valid & ATTR_MTIME) {
1078 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1083 const u32 *excl_bmval = server->exclcreat_bitmask;
1084 bmval[0] &= excl_bmval[0];
1085 bmval[1] &= excl_bmval[1];
1086 bmval[2] &= excl_bmval[2];
1088 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1093 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1094 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1099 else if (bmval[1] != 0)
1104 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1106 *p++ = cpu_to_be32(bmval_len);
1107 for (i = 0; i < bmval_len; i++)
1108 *p++ = cpu_to_be32(bmval[i]);
1109 *p++ = cpu_to_be32(len);
1111 if (bmval[0] & FATTR4_WORD0_SIZE)
1112 p = xdr_encode_hyper(p, iap->ia_size);
1113 if (bmval[1] & FATTR4_WORD1_MODE)
1114 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1115 if (bmval[1] & FATTR4_WORD1_OWNER)
1116 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1117 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1118 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1119 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1120 if (iap->ia_valid & ATTR_ATIME_SET) {
1121 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1122 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1123 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1125 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1127 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1128 if (iap->ia_valid & ATTR_MTIME_SET) {
1129 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1130 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1131 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1133 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1135 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1136 *p++ = cpu_to_be32(label->lfs);
1137 *p++ = cpu_to_be32(label->pi);
1138 *p++ = cpu_to_be32(label->len);
1139 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1141 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1142 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1143 *p++ = cpu_to_be32(*umask);
1149 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1151 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1152 encode_uint32(xdr, access);
1155 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1157 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1158 encode_nfs4_seqid(xdr, arg->seqid);
1159 encode_nfs4_stateid(xdr, &arg->stateid);
1162 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1166 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1167 p = reserve_space(xdr, 12);
1168 p = xdr_encode_hyper(p, args->offset);
1169 *p = cpu_to_be32(args->count);
1172 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1176 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1177 encode_uint32(xdr, create->ftype);
1179 switch (create->ftype) {
1181 p = reserve_space(xdr, 4);
1182 *p = cpu_to_be32(create->u.symlink.len);
1183 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1184 create->u.symlink.len);
1185 xdr->buf->flags |= XDRBUF_WRITE;
1188 case NF4BLK: case NF4CHR:
1189 p = reserve_space(xdr, 8);
1190 *p++ = cpu_to_be32(create->u.device.specdata1);
1191 *p = cpu_to_be32(create->u.device.specdata2);
1198 encode_string(xdr, create->name->len, create->name->name);
1199 encode_attrs(xdr, create->attrs, create->label, create->server, false,
1203 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1207 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1208 p = reserve_space(xdr, 8);
1209 *p++ = cpu_to_be32(1);
1210 *p = cpu_to_be32(bitmap);
1213 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1217 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1218 p = reserve_space(xdr, 12);
1219 *p++ = cpu_to_be32(2);
1220 *p++ = cpu_to_be32(bm0);
1221 *p = cpu_to_be32(bm1);
1225 encode_getattr_three(struct xdr_stream *xdr,
1226 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1227 struct compound_hdr *hdr)
1231 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1233 p = reserve_space(xdr, 16);
1234 *p++ = cpu_to_be32(3);
1235 *p++ = cpu_to_be32(bm0);
1236 *p++ = cpu_to_be32(bm1);
1237 *p = cpu_to_be32(bm2);
1239 p = reserve_space(xdr, 12);
1240 *p++ = cpu_to_be32(2);
1241 *p++ = cpu_to_be32(bm0);
1242 *p = cpu_to_be32(bm1);
1244 p = reserve_space(xdr, 8);
1245 *p++ = cpu_to_be32(1);
1246 *p = cpu_to_be32(bm0);
1250 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1252 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1253 bitmask[1] & nfs4_fattr_bitmap[1],
1254 bitmask[2] & nfs4_fattr_bitmap[2],
1258 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1259 const u32 *open_bitmap,
1260 struct compound_hdr *hdr)
1262 encode_getattr_three(xdr,
1263 bitmask[0] & open_bitmap[0],
1264 bitmask[1] & open_bitmap[1],
1265 bitmask[2] & open_bitmap[2],
1269 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1271 encode_getattr_three(xdr,
1272 bitmask[0] & nfs4_fsinfo_bitmap[0],
1273 bitmask[1] & nfs4_fsinfo_bitmap[1],
1274 bitmask[2] & nfs4_fsinfo_bitmap[2],
1278 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1280 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1281 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1284 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1286 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1289 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1291 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1292 encode_string(xdr, name->len, name->name);
1295 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1297 if (fl->fl_type == F_RDLCK)
1298 return block ? NFS4_READW_LT : NFS4_READ_LT;
1299 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1302 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1304 if (fl->fl_end == OFFSET_MAX)
1305 return ~(uint64_t)0;
1306 return fl->fl_end - fl->fl_start + 1;
1309 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1313 p = reserve_space(xdr, 32);
1314 p = xdr_encode_hyper(p, lowner->clientid);
1315 *p++ = cpu_to_be32(20);
1316 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1317 *p++ = cpu_to_be32(lowner->s_dev);
1318 xdr_encode_hyper(p, lowner->id);
1322 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1323 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1325 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1329 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1330 p = reserve_space(xdr, 28);
1331 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1332 *p++ = cpu_to_be32(args->reclaim);
1333 p = xdr_encode_hyper(p, args->fl->fl_start);
1334 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1335 *p = cpu_to_be32(args->new_lock_owner);
1336 if (args->new_lock_owner){
1337 encode_nfs4_seqid(xdr, args->open_seqid);
1338 encode_nfs4_stateid(xdr, &args->open_stateid);
1339 encode_nfs4_seqid(xdr, args->lock_seqid);
1340 encode_lockowner(xdr, &args->lock_owner);
1343 encode_nfs4_stateid(xdr, &args->lock_stateid);
1344 encode_nfs4_seqid(xdr, args->lock_seqid);
1348 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1352 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1353 p = reserve_space(xdr, 20);
1354 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1355 p = xdr_encode_hyper(p, args->fl->fl_start);
1356 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1357 encode_lockowner(xdr, &args->lock_owner);
1360 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1364 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1365 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1366 encode_nfs4_seqid(xdr, args->seqid);
1367 encode_nfs4_stateid(xdr, &args->stateid);
1368 p = reserve_space(xdr, 16);
1369 p = xdr_encode_hyper(p, args->fl->fl_start);
1370 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1373 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1375 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1376 encode_lockowner(xdr, lowner);
1379 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1381 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1382 encode_string(xdr, name->len, name->name);
1385 static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
1389 p = reserve_space(xdr, 8);
1390 *p++ = cpu_to_be32(share_access);
1391 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1394 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1398 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1401 encode_nfs4_seqid(xdr, arg->seqid);
1402 encode_share_access(xdr, arg->share_access);
1403 p = reserve_space(xdr, 36);
1404 p = xdr_encode_hyper(p, arg->clientid);
1405 *p++ = cpu_to_be32(24);
1406 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1407 *p++ = cpu_to_be32(arg->server->s_dev);
1408 *p++ = cpu_to_be32(arg->id.uniquifier);
1409 xdr_encode_hyper(p, arg->id.create_time);
1412 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1416 p = reserve_space(xdr, 4);
1417 switch(arg->createmode) {
1418 case NFS4_CREATE_UNCHECKED:
1419 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1420 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1423 case NFS4_CREATE_GUARDED:
1424 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1425 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1428 case NFS4_CREATE_EXCLUSIVE:
1429 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1430 encode_nfs4_verifier(xdr, &arg->u.verifier);
1432 case NFS4_CREATE_EXCLUSIVE4_1:
1433 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1434 encode_nfs4_verifier(xdr, &arg->u.verifier);
1435 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true,
1440 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1444 p = reserve_space(xdr, 4);
1445 switch (arg->open_flags & O_CREAT) {
1447 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1450 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1451 encode_createmode(xdr, arg);
1455 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1459 p = reserve_space(xdr, 4);
1460 switch (delegation_type) {
1462 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1465 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1467 case FMODE_WRITE|FMODE_READ:
1468 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1475 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1479 p = reserve_space(xdr, 4);
1480 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1481 encode_string(xdr, name->len, name->name);
1484 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1488 p = reserve_space(xdr, 4);
1489 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1490 encode_delegation_type(xdr, type);
1493 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1497 p = reserve_space(xdr, 4);
1498 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1499 encode_nfs4_stateid(xdr, stateid);
1500 encode_string(xdr, name->len, name->name);
1503 static inline void encode_claim_fh(struct xdr_stream *xdr)
1507 p = reserve_space(xdr, 4);
1508 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1511 static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1515 p = reserve_space(xdr, 4);
1516 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1517 encode_nfs4_stateid(xdr, stateid);
1520 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1522 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1523 encode_openhdr(xdr, arg);
1524 encode_opentype(xdr, arg);
1525 switch (arg->claim) {
1526 case NFS4_OPEN_CLAIM_NULL:
1527 encode_claim_null(xdr, arg->name);
1529 case NFS4_OPEN_CLAIM_PREVIOUS:
1530 encode_claim_previous(xdr, arg->u.delegation_type);
1532 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1533 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1535 case NFS4_OPEN_CLAIM_FH:
1536 encode_claim_fh(xdr);
1538 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1539 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1546 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1548 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1549 encode_nfs4_stateid(xdr, arg->stateid);
1550 encode_nfs4_seqid(xdr, arg->seqid);
1553 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1555 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1556 encode_nfs4_stateid(xdr, &arg->stateid);
1557 encode_nfs4_seqid(xdr, arg->seqid);
1558 encode_share_access(xdr, arg->share_access);
1562 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1564 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1565 encode_string(xdr, fh->size, fh->data);
1568 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1570 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1573 static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1574 struct compound_hdr *hdr)
1578 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1579 encode_nfs4_stateid(xdr, &args->stateid);
1581 p = reserve_space(xdr, 12);
1582 p = xdr_encode_hyper(p, args->offset);
1583 *p = cpu_to_be32(args->count);
1586 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1588 uint32_t attrs[3] = {
1589 FATTR4_WORD0_RDATTR_ERROR,
1590 FATTR4_WORD1_MOUNTED_ON_FILEID,
1592 uint32_t dircount = readdir->count >> 1;
1594 uint32_t attrlen = 0;
1597 if (readdir->plus) {
1598 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1599 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1600 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1601 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1602 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1603 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1604 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1607 /* Use mounted_on_fileid only if the server supports it */
1608 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1609 attrs[0] |= FATTR4_WORD0_FILEID;
1610 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1611 attrs[i] &= readdir->bitmask[i];
1616 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1617 encode_uint64(xdr, readdir->cookie);
1618 encode_nfs4_verifier(xdr, &readdir->verifier);
1619 p = reserve_space(xdr, 12 + (attrlen << 2));
1620 *p++ = cpu_to_be32(dircount);
1621 *p++ = cpu_to_be32(readdir->count);
1622 *p++ = cpu_to_be32(attrlen);
1623 for (i = 0; i < attrlen; i++)
1624 *p++ = cpu_to_be32(attrs[i]);
1625 memcpy(verf, readdir->verifier.data, sizeof(verf));
1627 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1629 (unsigned long long)readdir->cookie,
1631 attrs[0] & readdir->bitmask[0],
1632 attrs[1] & readdir->bitmask[1],
1633 attrs[2] & readdir->bitmask[2]);
1636 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1638 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1641 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1643 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1644 encode_string(xdr, name->len, name->name);
1647 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1649 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1650 encode_string(xdr, oldname->len, oldname->name);
1651 encode_string(xdr, newname->len, newname->name);
1654 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1655 struct compound_hdr *hdr)
1657 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1658 encode_uint64(xdr, clid);
1662 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1664 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1668 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1672 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1673 encode_nfs4_stateid(xdr, &zero_stateid);
1674 p = reserve_space(xdr, 2*4);
1675 *p++ = cpu_to_be32(1);
1676 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1677 p = reserve_space(xdr, 4);
1678 *p = cpu_to_be32(arg->acl_len);
1679 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
1683 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1685 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1688 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1690 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1691 encode_nfs4_stateid(xdr, &arg->stateid);
1692 encode_attrs(xdr, arg->iap, arg->label, server, false, NULL);
1695 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1699 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1700 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1702 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1703 setclientid->sc_clnt->cl_owner_id);
1704 p = reserve_space(xdr, 4);
1705 *p = cpu_to_be32(setclientid->sc_prog);
1706 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1707 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1708 p = reserve_space(xdr, 4);
1709 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
1712 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1714 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1715 decode_setclientid_confirm_maxsz, hdr);
1716 encode_uint64(xdr, arg->clientid);
1717 encode_nfs4_verifier(xdr, &arg->confirm);
1720 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1721 struct compound_hdr *hdr)
1725 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1726 encode_nfs4_stateid(xdr, &args->stateid);
1728 p = reserve_space(xdr, 16);
1729 p = xdr_encode_hyper(p, args->offset);
1730 *p++ = cpu_to_be32(args->stable);
1731 *p = cpu_to_be32(args->count);
1733 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1736 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1738 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1739 encode_nfs4_stateid(xdr, stateid);
1742 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1744 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1745 encode_string(xdr, name->len, name->name);
1748 #if defined(CONFIG_NFS_V4_1)
1749 /* NFSv4.1 operations */
1750 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1751 struct nfs41_bind_conn_to_session_args *args,
1752 struct compound_hdr *hdr)
1756 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1757 decode_bind_conn_to_session_maxsz, hdr);
1758 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1759 p = xdr_reserve_space(xdr, 8);
1760 *p++ = cpu_to_be32(args->dir);
1761 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
1764 static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1767 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1768 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1769 encode_uint32(xdr, op_map->u.words[i]);
1772 static void encode_exchange_id(struct xdr_stream *xdr,
1773 struct nfs41_exchange_id_args *args,
1774 struct compound_hdr *hdr)
1777 char impl_name[IMPL_NAME_LIMIT];
1780 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1781 encode_nfs4_verifier(xdr, args->verifier);
1783 encode_string(xdr, strlen(args->client->cl_owner_id),
1784 args->client->cl_owner_id);
1786 encode_uint32(xdr, args->flags);
1787 encode_uint32(xdr, args->state_protect.how);
1789 switch (args->state_protect.how) {
1793 encode_op_map(xdr, &args->state_protect.enforce);
1794 encode_op_map(xdr, &args->state_protect.allow);
1801 if (send_implementation_id &&
1802 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1803 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1804 <= sizeof(impl_name) + 1)
1805 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1806 utsname()->sysname, utsname()->release,
1807 utsname()->version, utsname()->machine);
1810 encode_uint32(xdr, 1); /* implementation id array length=1 */
1813 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1814 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1815 encode_string(xdr, len, impl_name);
1816 /* just send zeros for nii_date - the date is in nii_name */
1817 p = reserve_space(xdr, 12);
1818 p = xdr_encode_hyper(p, 0);
1819 *p = cpu_to_be32(0);
1821 encode_uint32(xdr, 0); /* implementation id array length=0 */
1824 static void encode_create_session(struct xdr_stream *xdr,
1825 struct nfs41_create_session_args *args,
1826 struct compound_hdr *hdr)
1829 struct nfs_client *clp = args->client;
1830 struct rpc_clnt *clnt = clp->cl_rpcclient;
1831 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1832 u32 max_resp_sz_cached;
1835 * Assumes OPEN is the biggest non-idempotent compound.
1836 * 2 is the verifier.
1838 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1839 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1841 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1842 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
1843 p = xdr_encode_hyper(p, args->clientid);
1844 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
1845 *p++ = cpu_to_be32(args->flags); /*flags */
1848 *p++ = cpu_to_be32(0); /* header padding size */
1849 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1850 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1851 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1852 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1853 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1854 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1857 *p++ = cpu_to_be32(0); /* header padding size */
1858 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1859 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1860 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1861 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1862 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1863 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1865 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1866 *p++ = cpu_to_be32(1);
1867 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1869 /* authsys_parms rfc1831 */
1870 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
1871 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1872 *p++ = cpu_to_be32(0); /* UID */
1873 *p++ = cpu_to_be32(0); /* GID */
1874 *p = cpu_to_be32(0); /* No more gids */
1877 static void encode_destroy_session(struct xdr_stream *xdr,
1878 struct nfs4_session *session,
1879 struct compound_hdr *hdr)
1881 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1882 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1885 static void encode_destroy_clientid(struct xdr_stream *xdr,
1887 struct compound_hdr *hdr)
1889 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1890 encode_uint64(xdr, clientid);
1893 static void encode_reclaim_complete(struct xdr_stream *xdr,
1894 struct nfs41_reclaim_complete_args *args,
1895 struct compound_hdr *hdr)
1897 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1898 encode_uint32(xdr, args->one_fs);
1900 #endif /* CONFIG_NFS_V4_1 */
1902 static void encode_sequence(struct xdr_stream *xdr,
1903 const struct nfs4_sequence_args *args,
1904 struct compound_hdr *hdr)
1906 #if defined(CONFIG_NFS_V4_1)
1907 struct nfs4_session *session;
1908 struct nfs4_slot_table *tp;
1909 struct nfs4_slot *slot = args->sa_slot;
1913 session = tp->session;
1917 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1920 * Sessionid + seqid + slotid + max slotid + cache_this
1922 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1923 "max_slotid=%d cache_this=%d\n",
1925 ((u32 *)session->sess_id.data)[0],
1926 ((u32 *)session->sess_id.data)[1],
1927 ((u32 *)session->sess_id.data)[2],
1928 ((u32 *)session->sess_id.data)[3],
1929 slot->seq_nr, slot->slot_nr,
1930 tp->highest_used_slotid, args->sa_cache_this);
1931 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1932 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1933 *p++ = cpu_to_be32(slot->seq_nr);
1934 *p++ = cpu_to_be32(slot->slot_nr);
1935 *p++ = cpu_to_be32(tp->highest_used_slotid);
1936 *p = cpu_to_be32(args->sa_cache_this);
1937 #endif /* CONFIG_NFS_V4_1 */
1940 #ifdef CONFIG_NFS_V4_1
1942 encode_getdeviceinfo(struct xdr_stream *xdr,
1943 const struct nfs4_getdeviceinfo_args *args,
1944 struct compound_hdr *hdr)
1948 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1949 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1950 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1951 NFS4_DEVICEID4_SIZE);
1952 *p++ = cpu_to_be32(args->pdev->layout_type);
1953 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1955 p = reserve_space(xdr, 4 + 4);
1956 *p++ = cpu_to_be32(1); /* bitmap length */
1957 *p++ = cpu_to_be32(args->notify_types);
1961 encode_layoutget(struct xdr_stream *xdr,
1962 const struct nfs4_layoutget_args *args,
1963 struct compound_hdr *hdr)
1967 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1968 p = reserve_space(xdr, 36);
1969 *p++ = cpu_to_be32(0); /* Signal layout available */
1970 *p++ = cpu_to_be32(args->type);
1971 *p++ = cpu_to_be32(args->range.iomode);
1972 p = xdr_encode_hyper(p, args->range.offset);
1973 p = xdr_encode_hyper(p, args->range.length);
1974 p = xdr_encode_hyper(p, args->minlength);
1975 encode_nfs4_stateid(xdr, &args->stateid);
1976 encode_uint32(xdr, args->maxcount);
1978 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1982 (unsigned long)args->range.offset,
1983 (unsigned long)args->range.length,
1988 encode_layoutcommit(struct xdr_stream *xdr,
1989 struct inode *inode,
1990 struct nfs4_layoutcommit_args *args,
1991 struct compound_hdr *hdr)
1995 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1996 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1998 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1999 p = reserve_space(xdr, 20);
2000 /* Only whole file layouts */
2001 p = xdr_encode_hyper(p, 0); /* offset */
2002 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
2003 *p = cpu_to_be32(0); /* reclaim */
2004 encode_nfs4_stateid(xdr, &args->stateid);
2005 if (args->lastbytewritten != U64_MAX) {
2006 p = reserve_space(xdr, 20);
2007 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2008 p = xdr_encode_hyper(p, args->lastbytewritten);
2010 p = reserve_space(xdr, 12);
2011 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2013 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2014 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2016 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
2017 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2018 NFS_I(inode)->layout, xdr, args);
2020 encode_uint32(xdr, args->layoutupdate_len);
2021 if (args->layoutupdate_pages) {
2022 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2023 args->layoutupdate_len);
2031 encode_layoutreturn(struct xdr_stream *xdr,
2032 const struct nfs4_layoutreturn_args *args,
2033 struct compound_hdr *hdr)
2035 const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld;
2038 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2039 p = reserve_space(xdr, 16);
2040 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2041 *p++ = cpu_to_be32(args->layout_type);
2042 *p++ = cpu_to_be32(args->range.iomode);
2043 *p = cpu_to_be32(RETURN_FILE);
2044 p = reserve_space(xdr, 16);
2045 p = xdr_encode_hyper(p, args->range.offset);
2046 p = xdr_encode_hyper(p, args->range.length);
2047 spin_lock(&args->inode->i_lock);
2048 encode_nfs4_stateid(xdr, &args->stateid);
2049 spin_unlock(&args->inode->i_lock);
2050 if (args->ld_private->ops && args->ld_private->ops->encode)
2051 args->ld_private->ops->encode(xdr, args, args->ld_private);
2052 else if (lr_ops->encode_layoutreturn)
2053 lr_ops->encode_layoutreturn(xdr, args);
2055 encode_uint32(xdr, 0);
2059 encode_secinfo_no_name(struct xdr_stream *xdr,
2060 const struct nfs41_secinfo_no_name_args *args,
2061 struct compound_hdr *hdr)
2063 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2064 encode_uint32(xdr, args->style);
2068 static void encode_test_stateid(struct xdr_stream *xdr,
2069 struct nfs41_test_stateid_args *args,
2070 struct compound_hdr *hdr)
2072 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2073 encode_uint32(xdr, 1);
2074 encode_nfs4_stateid(xdr, args->stateid);
2077 static void encode_free_stateid(struct xdr_stream *xdr,
2078 struct nfs41_free_stateid_args *args,
2079 struct compound_hdr *hdr)
2081 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2082 encode_nfs4_stateid(xdr, &args->stateid);
2086 encode_layoutreturn(struct xdr_stream *xdr,
2087 const struct nfs4_layoutreturn_args *args,
2088 struct compound_hdr *hdr)
2091 #endif /* CONFIG_NFS_V4_1 */
2094 * END OF "GENERIC" ENCODE ROUTINES.
2097 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2099 #if defined(CONFIG_NFS_V4_1)
2100 struct nfs4_session *session = args->sa_slot->table->session;
2102 return session->clp->cl_mvops->minor_version;
2103 #endif /* CONFIG_NFS_V4_1 */
2108 * Encode an ACCESS request
2110 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2111 const struct nfs4_accessargs *args)
2113 struct compound_hdr hdr = {
2114 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2117 encode_compound_hdr(xdr, req, &hdr);
2118 encode_sequence(xdr, &args->seq_args, &hdr);
2119 encode_putfh(xdr, args->fh, &hdr);
2120 encode_access(xdr, args->access, &hdr);
2121 encode_getfattr(xdr, args->bitmask, &hdr);
2126 * Encode LOOKUP request
2128 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2129 const struct nfs4_lookup_arg *args)
2131 struct compound_hdr hdr = {
2132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2135 encode_compound_hdr(xdr, req, &hdr);
2136 encode_sequence(xdr, &args->seq_args, &hdr);
2137 encode_putfh(xdr, args->dir_fh, &hdr);
2138 encode_lookup(xdr, args->name, &hdr);
2139 encode_getfh(xdr, &hdr);
2140 encode_getfattr(xdr, args->bitmask, &hdr);
2145 * Encode LOOKUP_ROOT request
2147 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2148 struct xdr_stream *xdr,
2149 const struct nfs4_lookup_root_arg *args)
2151 struct compound_hdr hdr = {
2152 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2155 encode_compound_hdr(xdr, req, &hdr);
2156 encode_sequence(xdr, &args->seq_args, &hdr);
2157 encode_putrootfh(xdr, &hdr);
2158 encode_getfh(xdr, &hdr);
2159 encode_getfattr(xdr, args->bitmask, &hdr);
2164 * Encode REMOVE request
2166 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 const struct nfs_removeargs *args)
2169 struct compound_hdr hdr = {
2170 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_sequence(xdr, &args->seq_args, &hdr);
2175 encode_putfh(xdr, args->fh, &hdr);
2176 encode_remove(xdr, &args->name, &hdr);
2181 * Encode RENAME request
2183 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2184 const struct nfs_renameargs *args)
2186 struct compound_hdr hdr = {
2187 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2190 encode_compound_hdr(xdr, req, &hdr);
2191 encode_sequence(xdr, &args->seq_args, &hdr);
2192 encode_putfh(xdr, args->old_dir, &hdr);
2193 encode_savefh(xdr, &hdr);
2194 encode_putfh(xdr, args->new_dir, &hdr);
2195 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2200 * Encode LINK request
2202 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2203 const struct nfs4_link_arg *args)
2205 struct compound_hdr hdr = {
2206 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2209 encode_compound_hdr(xdr, req, &hdr);
2210 encode_sequence(xdr, &args->seq_args, &hdr);
2211 encode_putfh(xdr, args->fh, &hdr);
2212 encode_savefh(xdr, &hdr);
2213 encode_putfh(xdr, args->dir_fh, &hdr);
2214 encode_link(xdr, args->name, &hdr);
2215 encode_restorefh(xdr, &hdr);
2216 encode_getfattr(xdr, args->bitmask, &hdr);
2221 * Encode CREATE request
2223 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2224 const struct nfs4_create_arg *args)
2226 struct compound_hdr hdr = {
2227 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2230 encode_compound_hdr(xdr, req, &hdr);
2231 encode_sequence(xdr, &args->seq_args, &hdr);
2232 encode_putfh(xdr, args->dir_fh, &hdr);
2233 encode_create(xdr, args, &hdr);
2234 encode_getfh(xdr, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
2240 * Encode SYMLINK request
2242 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2243 const struct nfs4_create_arg *args)
2245 nfs4_xdr_enc_create(req, xdr, args);
2249 * Encode GETATTR request
2251 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 const struct nfs4_getattr_arg *args)
2254 struct compound_hdr hdr = {
2255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
2261 encode_getfattr(xdr, args->bitmask, &hdr);
2266 * Encode a CLOSE request
2268 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2269 struct nfs_closeargs *args)
2271 struct compound_hdr hdr = {
2272 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2275 encode_compound_hdr(xdr, req, &hdr);
2276 encode_sequence(xdr, &args->seq_args, &hdr);
2277 encode_putfh(xdr, args->fh, &hdr);
2279 encode_layoutreturn(xdr, args->lr_args, &hdr);
2280 encode_close(xdr, args, &hdr);
2281 if (args->bitmask != NULL)
2282 encode_getfattr(xdr, args->bitmask, &hdr);
2287 * Encode an OPEN request
2289 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2290 struct nfs_openargs *args)
2292 struct compound_hdr hdr = {
2293 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2296 encode_compound_hdr(xdr, req, &hdr);
2297 encode_sequence(xdr, &args->seq_args, &hdr);
2298 encode_putfh(xdr, args->fh, &hdr);
2299 encode_open(xdr, args, &hdr);
2300 encode_getfh(xdr, &hdr);
2302 encode_access(xdr, args->access, &hdr);
2303 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2308 * Encode an OPEN_CONFIRM request
2310 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2311 struct xdr_stream *xdr,
2312 struct nfs_open_confirmargs *args)
2314 struct compound_hdr hdr = {
2318 encode_compound_hdr(xdr, req, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_open_confirm(xdr, args, &hdr);
2325 * Encode an OPEN request with no attributes.
2327 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2328 struct xdr_stream *xdr,
2329 struct nfs_openargs *args)
2331 struct compound_hdr hdr = {
2332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
2338 encode_open(xdr, args, &hdr);
2340 encode_access(xdr, args->access, &hdr);
2341 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2346 * Encode an OPEN_DOWNGRADE request
2348 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2349 struct xdr_stream *xdr,
2350 struct nfs_closeargs *args)
2352 struct compound_hdr hdr = {
2353 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2356 encode_compound_hdr(xdr, req, &hdr);
2357 encode_sequence(xdr, &args->seq_args, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_open_downgrade(xdr, args, &hdr);
2364 * Encode a LOCK request
2366 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2367 struct nfs_lock_args *args)
2369 struct compound_hdr hdr = {
2370 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2373 encode_compound_hdr(xdr, req, &hdr);
2374 encode_sequence(xdr, &args->seq_args, &hdr);
2375 encode_putfh(xdr, args->fh, &hdr);
2376 encode_lock(xdr, args, &hdr);
2381 * Encode a LOCKT request
2383 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2384 struct nfs_lockt_args *args)
2386 struct compound_hdr hdr = {
2387 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2390 encode_compound_hdr(xdr, req, &hdr);
2391 encode_sequence(xdr, &args->seq_args, &hdr);
2392 encode_putfh(xdr, args->fh, &hdr);
2393 encode_lockt(xdr, args, &hdr);
2398 * Encode a LOCKU request
2400 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 struct nfs_locku_args *args)
2403 struct compound_hdr hdr = {
2404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_sequence(xdr, &args->seq_args, &hdr);
2409 encode_putfh(xdr, args->fh, &hdr);
2410 encode_locku(xdr, args, &hdr);
2414 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2415 struct xdr_stream *xdr,
2416 struct nfs_release_lockowner_args *args)
2418 struct compound_hdr hdr = {
2422 encode_compound_hdr(xdr, req, &hdr);
2423 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2428 * Encode a READLINK request
2430 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2431 const struct nfs4_readlink *args)
2433 struct compound_hdr hdr = {
2434 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2437 encode_compound_hdr(xdr, req, &hdr);
2438 encode_sequence(xdr, &args->seq_args, &hdr);
2439 encode_putfh(xdr, args->fh, &hdr);
2440 encode_readlink(xdr, args, req, &hdr);
2442 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2443 args->pgbase, args->pglen);
2448 * Encode a READDIR request
2450 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2451 const struct nfs4_readdir_arg *args)
2453 struct compound_hdr hdr = {
2454 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2457 encode_compound_hdr(xdr, req, &hdr);
2458 encode_sequence(xdr, &args->seq_args, &hdr);
2459 encode_putfh(xdr, args->fh, &hdr);
2460 encode_readdir(xdr, args, req, &hdr);
2462 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2463 args->pgbase, args->count);
2464 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2465 __func__, hdr.replen << 2, args->pages,
2466 args->pgbase, args->count);
2471 * Encode a READ request
2473 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2474 struct nfs_pgio_args *args)
2476 struct compound_hdr hdr = {
2477 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2480 encode_compound_hdr(xdr, req, &hdr);
2481 encode_sequence(xdr, &args->seq_args, &hdr);
2482 encode_putfh(xdr, args->fh, &hdr);
2483 encode_read(xdr, args, &hdr);
2485 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2486 args->pages, args->pgbase, args->count);
2487 req->rq_rcv_buf.flags |= XDRBUF_READ;
2492 * Encode an SETATTR request
2494 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2495 struct nfs_setattrargs *args)
2497 struct compound_hdr hdr = {
2498 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2501 encode_compound_hdr(xdr, req, &hdr);
2502 encode_sequence(xdr, &args->seq_args, &hdr);
2503 encode_putfh(xdr, args->fh, &hdr);
2504 encode_setattr(xdr, args, args->server, &hdr);
2505 encode_getfattr(xdr, args->bitmask, &hdr);
2510 * Encode a GETACL request
2512 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2513 struct nfs_getaclargs *args)
2515 struct compound_hdr hdr = {
2516 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2520 encode_compound_hdr(xdr, req, &hdr);
2521 encode_sequence(xdr, &args->seq_args, &hdr);
2522 encode_putfh(xdr, args->fh, &hdr);
2523 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2524 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2526 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2527 args->acl_pages, 0, args->acl_len);
2533 * Encode a WRITE request
2535 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2536 struct nfs_pgio_args *args)
2538 struct compound_hdr hdr = {
2539 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2542 encode_compound_hdr(xdr, req, &hdr);
2543 encode_sequence(xdr, &args->seq_args, &hdr);
2544 encode_putfh(xdr, args->fh, &hdr);
2545 encode_write(xdr, args, &hdr);
2546 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2548 encode_getfattr(xdr, args->bitmask, &hdr);
2555 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2556 struct nfs_commitargs *args)
2558 struct compound_hdr hdr = {
2559 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2562 encode_compound_hdr(xdr, req, &hdr);
2563 encode_sequence(xdr, &args->seq_args, &hdr);
2564 encode_putfh(xdr, args->fh, &hdr);
2565 encode_commit(xdr, args, &hdr);
2572 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2573 struct nfs4_fsinfo_arg *args)
2575 struct compound_hdr hdr = {
2576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2579 encode_compound_hdr(xdr, req, &hdr);
2580 encode_sequence(xdr, &args->seq_args, &hdr);
2581 encode_putfh(xdr, args->fh, &hdr);
2582 encode_fsinfo(xdr, args->bitmask, &hdr);
2587 * a PATHCONF request
2589 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2590 const struct nfs4_pathconf_arg *args)
2592 struct compound_hdr hdr = {
2593 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->seq_args, &hdr);
2598 encode_putfh(xdr, args->fh, &hdr);
2599 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2607 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2608 const struct nfs4_statfs_arg *args)
2610 struct compound_hdr hdr = {
2611 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2614 encode_compound_hdr(xdr, req, &hdr);
2615 encode_sequence(xdr, &args->seq_args, &hdr);
2616 encode_putfh(xdr, args->fh, &hdr);
2617 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2618 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2623 * GETATTR_BITMAP request
2625 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2626 struct xdr_stream *xdr,
2627 struct nfs4_server_caps_arg *args)
2629 const u32 *bitmask = args->bitmask;
2630 struct compound_hdr hdr = {
2631 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2634 encode_compound_hdr(xdr, req, &hdr);
2635 encode_sequence(xdr, &args->seq_args, &hdr);
2636 encode_putfh(xdr, args->fhandle, &hdr);
2637 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
2644 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2645 struct nfs_client *clp)
2647 struct compound_hdr hdr = {
2651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_renew(xdr, clp->cl_clientid, &hdr);
2657 * a SETCLIENTID request
2659 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2660 struct xdr_stream *xdr,
2661 struct nfs4_setclientid *sc)
2663 struct compound_hdr hdr = {
2667 encode_compound_hdr(xdr, req, &hdr);
2668 encode_setclientid(xdr, sc, &hdr);
2673 * a SETCLIENTID_CONFIRM request
2675 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2676 struct xdr_stream *xdr,
2677 struct nfs4_setclientid_res *arg)
2679 struct compound_hdr hdr = {
2683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_setclientid_confirm(xdr, arg, &hdr);
2689 * DELEGRETURN request
2691 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2692 struct xdr_stream *xdr,
2693 const struct nfs4_delegreturnargs *args)
2695 struct compound_hdr hdr = {
2696 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2699 encode_compound_hdr(xdr, req, &hdr);
2700 encode_sequence(xdr, &args->seq_args, &hdr);
2701 encode_putfh(xdr, args->fhandle, &hdr);
2703 encode_layoutreturn(xdr, args->lr_args, &hdr);
2704 encode_getfattr(xdr, args->bitmask, &hdr);
2705 encode_delegreturn(xdr, args->stateid, &hdr);
2710 * Encode FS_LOCATIONS request
2712 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2713 struct xdr_stream *xdr,
2714 struct nfs4_fs_locations_arg *args)
2716 struct compound_hdr hdr = {
2717 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2721 encode_compound_hdr(xdr, req, &hdr);
2722 encode_sequence(xdr, &args->seq_args, &hdr);
2723 if (args->migration) {
2724 encode_putfh(xdr, args->fh, &hdr);
2725 replen = hdr.replen;
2726 encode_fs_locations(xdr, args->bitmask, &hdr);
2728 encode_renew(xdr, args->clientid, &hdr);
2730 encode_putfh(xdr, args->dir_fh, &hdr);
2731 encode_lookup(xdr, args->name, &hdr);
2732 replen = hdr.replen;
2733 encode_fs_locations(xdr, args->bitmask, &hdr);
2736 /* Set up reply kvec to capture returned fs_locations array. */
2737 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2743 * Encode SECINFO request
2745 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2746 struct xdr_stream *xdr,
2747 struct nfs4_secinfo_arg *args)
2749 struct compound_hdr hdr = {
2750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->seq_args, &hdr);
2755 encode_putfh(xdr, args->dir_fh, &hdr);
2756 encode_secinfo(xdr, args->name, &hdr);
2761 * Encode FSID_PRESENT request
2763 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2764 struct xdr_stream *xdr,
2765 struct nfs4_fsid_present_arg *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, args->fh, &hdr);
2774 encode_getfh(xdr, &hdr);
2776 encode_renew(xdr, args->clientid, &hdr);
2780 #if defined(CONFIG_NFS_V4_1)
2782 * BIND_CONN_TO_SESSION request
2784 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2785 struct xdr_stream *xdr,
2786 struct nfs41_bind_conn_to_session_args *args)
2788 struct compound_hdr hdr = {
2789 .minorversion = args->client->cl_mvops->minor_version,
2792 encode_compound_hdr(xdr, req, &hdr);
2793 encode_bind_conn_to_session(xdr, args, &hdr);
2798 * EXCHANGE_ID request
2800 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2801 struct xdr_stream *xdr,
2802 struct nfs41_exchange_id_args *args)
2804 struct compound_hdr hdr = {
2805 .minorversion = args->client->cl_mvops->minor_version,
2808 encode_compound_hdr(xdr, req, &hdr);
2809 encode_exchange_id(xdr, args, &hdr);
2814 * a CREATE_SESSION request
2816 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2817 struct xdr_stream *xdr,
2818 struct nfs41_create_session_args *args)
2820 struct compound_hdr hdr = {
2821 .minorversion = args->client->cl_mvops->minor_version,
2824 encode_compound_hdr(xdr, req, &hdr);
2825 encode_create_session(xdr, args, &hdr);
2830 * a DESTROY_SESSION request
2832 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2833 struct xdr_stream *xdr,
2834 struct nfs4_session *session)
2836 struct compound_hdr hdr = {
2837 .minorversion = session->clp->cl_mvops->minor_version,
2840 encode_compound_hdr(xdr, req, &hdr);
2841 encode_destroy_session(xdr, session, &hdr);
2846 * a DESTROY_CLIENTID request
2848 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2849 struct xdr_stream *xdr,
2850 struct nfs_client *clp)
2852 struct compound_hdr hdr = {
2853 .minorversion = clp->cl_mvops->minor_version,
2856 encode_compound_hdr(xdr, req, &hdr);
2857 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2862 * a SEQUENCE request
2864 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2865 struct nfs4_sequence_args *args)
2867 struct compound_hdr hdr = {
2868 .minorversion = nfs4_xdr_minorversion(args),
2871 encode_compound_hdr(xdr, req, &hdr);
2872 encode_sequence(xdr, args, &hdr);
2877 * a GET_LEASE_TIME request
2879 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2880 struct xdr_stream *xdr,
2881 struct nfs4_get_lease_time_args *args)
2883 struct compound_hdr hdr = {
2884 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2886 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2888 encode_compound_hdr(xdr, req, &hdr);
2889 encode_sequence(xdr, &args->la_seq_args, &hdr);
2890 encode_putrootfh(xdr, &hdr);
2891 encode_fsinfo(xdr, lease_bitmap, &hdr);
2896 * a RECLAIM_COMPLETE request
2898 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2899 struct xdr_stream *xdr,
2900 struct nfs41_reclaim_complete_args *args)
2902 struct compound_hdr hdr = {
2903 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2906 encode_compound_hdr(xdr, req, &hdr);
2907 encode_sequence(xdr, &args->seq_args, &hdr);
2908 encode_reclaim_complete(xdr, args, &hdr);
2913 * Encode GETDEVICEINFO request
2915 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs4_getdeviceinfo_args *args)
2919 struct compound_hdr hdr = {
2920 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_sequence(xdr, &args->seq_args, &hdr);
2925 encode_getdeviceinfo(xdr, args, &hdr);
2927 /* set up reply kvec. Subtract notification bitmap max size (2)
2928 * so that notification bitmap is put in xdr_buf tail */
2929 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2930 args->pdev->pages, args->pdev->pgbase,
2937 * Encode LAYOUTGET request
2939 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2940 struct xdr_stream *xdr,
2941 struct nfs4_layoutget_args *args)
2943 struct compound_hdr hdr = {
2944 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2947 encode_compound_hdr(xdr, req, &hdr);
2948 encode_sequence(xdr, &args->seq_args, &hdr);
2949 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2950 encode_layoutget(xdr, args, &hdr);
2952 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2953 args->layout.pages, 0, args->layout.pglen);
2959 * Encode LAYOUTCOMMIT request
2961 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2962 struct xdr_stream *xdr,
2963 struct nfs4_layoutcommit_args *args)
2965 struct nfs4_layoutcommit_data *data =
2966 container_of(args, struct nfs4_layoutcommit_data, args);
2967 struct compound_hdr hdr = {
2968 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2971 encode_compound_hdr(xdr, req, &hdr);
2972 encode_sequence(xdr, &args->seq_args, &hdr);
2973 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2974 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2975 encode_getfattr(xdr, args->bitmask, &hdr);
2980 * Encode LAYOUTRETURN request
2982 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2983 struct xdr_stream *xdr,
2984 struct nfs4_layoutreturn_args *args)
2986 struct compound_hdr hdr = {
2987 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2990 encode_compound_hdr(xdr, req, &hdr);
2991 encode_sequence(xdr, &args->seq_args, &hdr);
2992 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2993 encode_layoutreturn(xdr, args, &hdr);
2998 * Encode SECINFO_NO_NAME request
3000 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3001 struct xdr_stream *xdr,
3002 struct nfs41_secinfo_no_name_args *args)
3004 struct compound_hdr hdr = {
3005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3008 encode_compound_hdr(xdr, req, &hdr);
3009 encode_sequence(xdr, &args->seq_args, &hdr);
3010 encode_putrootfh(xdr, &hdr);
3011 encode_secinfo_no_name(xdr, args, &hdr);
3017 * Encode TEST_STATEID request
3019 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3020 struct xdr_stream *xdr,
3021 struct nfs41_test_stateid_args *args)
3023 struct compound_hdr hdr = {
3024 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3027 encode_compound_hdr(xdr, req, &hdr);
3028 encode_sequence(xdr, &args->seq_args, &hdr);
3029 encode_test_stateid(xdr, args, &hdr);
3034 * Encode FREE_STATEID request
3036 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3037 struct xdr_stream *xdr,
3038 struct nfs41_free_stateid_args *args)
3040 struct compound_hdr hdr = {
3041 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3044 encode_compound_hdr(xdr, req, &hdr);
3045 encode_sequence(xdr, &args->seq_args, &hdr);
3046 encode_free_stateid(xdr, args, &hdr);
3049 #endif /* CONFIG_NFS_V4_1 */
3051 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3053 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3054 "Remaining buffer length is %tu words.\n",
3055 func, xdr->end - xdr->p);
3058 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3062 p = xdr_inline_decode(xdr, 4);
3065 *len = be32_to_cpup(p);
3066 p = xdr_inline_decode(xdr, *len);
3069 *string = (char *)p;
3072 print_overflow_msg(__func__, xdr);
3076 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3080 p = xdr_inline_decode(xdr, 8);
3083 hdr->status = be32_to_cpup(p++);
3084 hdr->taglen = be32_to_cpup(p);
3086 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3089 hdr->tag = (char *)p;
3090 p += XDR_QUADLEN(hdr->taglen);
3091 hdr->nops = be32_to_cpup(p);
3092 if (unlikely(hdr->nops < 1))
3093 return nfs4_stat_to_errno(hdr->status);
3096 print_overflow_msg(__func__, xdr);
3100 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3107 p = xdr_inline_decode(xdr, 8);
3110 opnum = be32_to_cpup(p++);
3111 if (unlikely(opnum != expected))
3112 goto out_bad_operation;
3113 nfserr = be32_to_cpup(p);
3114 if (nfserr == NFS_OK)
3117 *nfs_retval = nfs4_stat_to_errno(nfserr);
3120 dprintk("nfs: Server returned operation"
3121 " %d but we issued a request for %d\n",
3123 *nfs_retval = -EREMOTEIO;
3126 print_overflow_msg(__func__, xdr);
3131 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3135 __decode_op_hdr(xdr, expected, &retval);
3140 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3143 unsigned int strlen;
3146 p = xdr_inline_decode(xdr, 12);
3148 return decode_opaque_inline(xdr, &strlen, &str);
3149 print_overflow_msg(__func__, xdr);
3153 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3158 p = xdr_inline_decode(xdr, 4);
3161 bmlen = be32_to_cpup(p);
3163 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3164 p = xdr_inline_decode(xdr, (bmlen << 2));
3168 bitmap[0] = be32_to_cpup(p++);
3170 bitmap[1] = be32_to_cpup(p++);
3172 bitmap[2] = be32_to_cpup(p);
3177 print_overflow_msg(__func__, xdr);
3181 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3185 p = xdr_inline_decode(xdr, 4);
3188 *attrlen = be32_to_cpup(p);
3189 *savep = xdr_stream_pos(xdr);
3192 print_overflow_msg(__func__, xdr);
3196 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3198 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3200 ret = decode_attr_bitmap(xdr, bitmask);
3201 if (unlikely(ret < 0))
3203 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3205 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3206 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3207 bitmask[0], bitmask[1], bitmask[2]);
3211 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3217 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3219 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3220 p = xdr_inline_decode(xdr, 4);
3223 *type = be32_to_cpup(p);
3224 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3225 dprintk("%s: bad type %d\n", __func__, *type);
3228 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3229 ret = NFS_ATTR_FATTR_TYPE;
3231 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3234 print_overflow_msg(__func__, xdr);
3238 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3239 uint32_t *bitmap, uint32_t *type)
3244 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3246 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3247 p = xdr_inline_decode(xdr, 4);
3250 *type = be32_to_cpup(p);
3251 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3253 dprintk("%s: expire type=0x%x\n", __func__, *type);
3256 print_overflow_msg(__func__, xdr);
3260 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3266 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3268 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3269 p = xdr_inline_decode(xdr, 8);
3272 xdr_decode_hyper(p, change);
3273 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3274 ret = NFS_ATTR_FATTR_CHANGE;
3276 dprintk("%s: change attribute=%Lu\n", __func__,
3277 (unsigned long long)*change);
3280 print_overflow_msg(__func__, xdr);
3284 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3290 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3292 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3293 p = xdr_inline_decode(xdr, 8);
3296 xdr_decode_hyper(p, size);
3297 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3298 ret = NFS_ATTR_FATTR_SIZE;
3300 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3303 print_overflow_msg(__func__, xdr);
3307 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3312 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3314 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3315 p = xdr_inline_decode(xdr, 4);
3318 *res = be32_to_cpup(p);
3319 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3321 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3324 print_overflow_msg(__func__, xdr);
3328 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3333 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3335 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3336 p = xdr_inline_decode(xdr, 4);
3339 *res = be32_to_cpup(p);
3340 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3342 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3345 print_overflow_msg(__func__, xdr);
3349 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3356 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3358 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3359 p = xdr_inline_decode(xdr, 16);
3362 p = xdr_decode_hyper(p, &fsid->major);
3363 xdr_decode_hyper(p, &fsid->minor);
3364 bitmap[0] &= ~FATTR4_WORD0_FSID;
3365 ret = NFS_ATTR_FATTR_FSID;
3367 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3368 (unsigned long long)fsid->major,
3369 (unsigned long long)fsid->minor);
3372 print_overflow_msg(__func__, xdr);
3376 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3381 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3383 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3384 p = xdr_inline_decode(xdr, 4);
3387 *res = be32_to_cpup(p);
3388 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3390 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3393 print_overflow_msg(__func__, xdr);
3397 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3401 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3403 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3404 p = xdr_inline_decode(xdr, 4);
3407 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3408 *res = -be32_to_cpup(p);
3412 print_overflow_msg(__func__, xdr);
3416 static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3417 uint32_t *bitmap, uint32_t *bitmask)
3419 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3421 ret = decode_attr_bitmap(xdr, bitmask);
3422 if (unlikely(ret < 0))
3424 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3426 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3427 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3428 bitmask[0], bitmask[1], bitmask[2]);
3432 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3438 memset(fh, 0, sizeof(*fh));
3440 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3442 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3443 p = xdr_inline_decode(xdr, 4);
3446 len = be32_to_cpup(p);
3447 if (len > NFS4_FHSIZE)
3449 p = xdr_inline_decode(xdr, len);
3453 memcpy(fh->data, p, len);
3456 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3460 print_overflow_msg(__func__, xdr);
3464 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3469 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3471 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3472 p = xdr_inline_decode(xdr, 4);
3475 *res = be32_to_cpup(p);
3476 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3478 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3481 print_overflow_msg(__func__, xdr);
3485 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3491 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3493 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3494 p = xdr_inline_decode(xdr, 8);
3497 xdr_decode_hyper(p, fileid);
3498 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3499 ret = NFS_ATTR_FATTR_FILEID;
3501 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3504 print_overflow_msg(__func__, xdr);
3508 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3514 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3516 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3517 p = xdr_inline_decode(xdr, 8);
3520 xdr_decode_hyper(p, fileid);
3521 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3522 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3524 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3527 print_overflow_msg(__func__, xdr);
3531 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3537 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3539 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3540 p = xdr_inline_decode(xdr, 8);
3543 xdr_decode_hyper(p, res);
3544 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3546 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3549 print_overflow_msg(__func__, xdr);
3553 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3559 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3561 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3562 p = xdr_inline_decode(xdr, 8);
3565 xdr_decode_hyper(p, res);
3566 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3568 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3571 print_overflow_msg(__func__, xdr);
3575 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3581 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3583 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3584 p = xdr_inline_decode(xdr, 8);
3587 xdr_decode_hyper(p, res);
3588 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3590 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3593 print_overflow_msg(__func__, xdr);
3597 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3603 p = xdr_inline_decode(xdr, 4);
3606 n = be32_to_cpup(p);
3609 dprintk("pathname4: ");
3610 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3611 dprintk("cannot parse %d components in path\n", n);
3614 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3615 struct nfs4_string *component = &path->components[path->ncomponents];
3616 status = decode_opaque_inline(xdr, &component->len, &component->data);
3617 if (unlikely(status != 0))
3621 (path->ncomponents != n ? "/ " : ""),
3622 component->len, component->data);
3627 /* a root pathname is sent as a zero component4 */
3628 path->ncomponents = 1;
3629 path->components[0].len=0;
3630 path->components[0].data=NULL;
3631 dprintk("pathname4: /\n");
3634 dprintk(" status %d", status);
3638 print_overflow_msg(__func__, xdr);
3642 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3648 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3651 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3653 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
3655 /* Ignore borken servers that return unrequested attrs */
3656 if (unlikely(res == NULL))
3658 dprintk("%s: fsroot:\n", __func__);
3659 status = decode_pathname(xdr, &res->fs_path);
3660 if (unlikely(status != 0))
3662 p = xdr_inline_decode(xdr, 4);
3665 n = be32_to_cpup(p);
3668 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3670 struct nfs4_fs_location *loc;
3672 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3674 loc = &res->locations[res->nlocations];
3675 p = xdr_inline_decode(xdr, 4);
3678 m = be32_to_cpup(p);
3680 dprintk("%s: servers:\n", __func__);
3681 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3682 struct nfs4_string *server;
3684 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3686 dprintk("%s: using first %u of %u servers "
3687 "returned for location %u\n",
3689 NFS4_FS_LOCATION_MAXSERVERS,
3690 m, res->nlocations);
3691 for (i = loc->nservers; i < m; i++) {
3694 status = decode_opaque_inline(xdr, &len, &data);
3695 if (unlikely(status != 0))
3700 server = &loc->servers[loc->nservers];
3701 status = decode_opaque_inline(xdr, &server->len, &server->data);
3702 if (unlikely(status != 0))
3704 dprintk("%s ", server->data);
3706 status = decode_pathname(xdr, &loc->rootpath);
3707 if (unlikely(status != 0))
3710 if (res->nlocations != 0)
3711 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3713 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3716 print_overflow_msg(__func__, xdr);
3722 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3728 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3730 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3731 p = xdr_inline_decode(xdr, 8);
3734 xdr_decode_hyper(p, res);
3735 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3737 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3740 print_overflow_msg(__func__, xdr);
3744 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3750 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3752 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3753 p = xdr_inline_decode(xdr, 4);
3756 *maxlink = be32_to_cpup(p);
3757 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3759 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3762 print_overflow_msg(__func__, xdr);
3766 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3772 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3774 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3775 p = xdr_inline_decode(xdr, 4);
3778 *maxname = be32_to_cpup(p);
3779 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3781 dprintk("%s: maxname=%u\n", __func__, *maxname);
3784 print_overflow_msg(__func__, xdr);
3788 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3794 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3796 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3798 p = xdr_inline_decode(xdr, 8);
3801 xdr_decode_hyper(p, &maxread);
3802 if (maxread > 0x7FFFFFFF)
3803 maxread = 0x7FFFFFFF;
3804 *res = (uint32_t)maxread;
3805 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3807 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3810 print_overflow_msg(__func__, xdr);
3814 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3820 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3822 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3824 p = xdr_inline_decode(xdr, 8);
3827 xdr_decode_hyper(p, &maxwrite);
3828 if (maxwrite > 0x7FFFFFFF)
3829 maxwrite = 0x7FFFFFFF;
3830 *res = (uint32_t)maxwrite;
3831 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3833 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3836 print_overflow_msg(__func__, xdr);
3840 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3847 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3849 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3850 p = xdr_inline_decode(xdr, 4);
3853 tmp = be32_to_cpup(p);
3854 *mode = tmp & ~S_IFMT;
3855 bitmap[1] &= ~FATTR4_WORD1_MODE;
3856 ret = NFS_ATTR_FATTR_MODE;
3858 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3861 print_overflow_msg(__func__, xdr);
3865 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3871 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3873 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3874 p = xdr_inline_decode(xdr, 4);
3877 *nlink = be32_to_cpup(p);
3878 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3879 ret = NFS_ATTR_FATTR_NLINK;
3881 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3884 print_overflow_msg(__func__, xdr);
3888 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3889 const struct nfs_server *server, kuid_t *uid,
3890 struct nfs4_string *owner_name)
3896 *uid = make_kuid(&init_user_ns, -2);
3897 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3899 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3900 p = xdr_inline_decode(xdr, 4);
3903 len = be32_to_cpup(p);
3904 p = xdr_inline_decode(xdr, len);
3907 if (owner_name != NULL) {
3908 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3909 if (owner_name->data != NULL) {
3910 owner_name->len = len;
3911 ret = NFS_ATTR_FATTR_OWNER_NAME;
3913 } else if (len < XDR_MAX_NETOBJ) {
3914 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3915 ret = NFS_ATTR_FATTR_OWNER;
3917 dprintk("%s: nfs_map_name_to_uid failed!\n",
3920 dprintk("%s: name too long (%u)!\n",
3922 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3924 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3927 print_overflow_msg(__func__, xdr);
3931 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3932 const struct nfs_server *server, kgid_t *gid,
3933 struct nfs4_string *group_name)
3939 *gid = make_kgid(&init_user_ns, -2);
3940 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3942 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3943 p = xdr_inline_decode(xdr, 4);
3946 len = be32_to_cpup(p);
3947 p = xdr_inline_decode(xdr, len);
3950 if (group_name != NULL) {
3951 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3952 if (group_name->data != NULL) {
3953 group_name->len = len;
3954 ret = NFS_ATTR_FATTR_GROUP_NAME;
3956 } else if (len < XDR_MAX_NETOBJ) {
3957 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3958 ret = NFS_ATTR_FATTR_GROUP;
3960 dprintk("%s: nfs_map_group_to_gid failed!\n",
3963 dprintk("%s: name too long (%u)!\n",
3965 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3967 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3970 print_overflow_msg(__func__, xdr);
3974 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3976 uint32_t major = 0, minor = 0;
3981 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3983 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3986 p = xdr_inline_decode(xdr, 8);
3989 major = be32_to_cpup(p++);
3990 minor = be32_to_cpup(p);
3991 tmp = MKDEV(major, minor);
3992 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3994 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3995 ret = NFS_ATTR_FATTR_RDEV;
3997 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
4000 print_overflow_msg(__func__, xdr);
4004 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4010 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4012 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4013 p = xdr_inline_decode(xdr, 8);
4016 xdr_decode_hyper(p, res);
4017 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4019 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
4022 print_overflow_msg(__func__, xdr);
4026 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4032 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4034 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4035 p = xdr_inline_decode(xdr, 8);
4038 xdr_decode_hyper(p, res);
4039 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4041 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
4044 print_overflow_msg(__func__, xdr);
4048 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4054 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4056 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4057 p = xdr_inline_decode(xdr, 8);
4060 xdr_decode_hyper(p, res);
4061 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4063 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4066 print_overflow_msg(__func__, xdr);
4070 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4076 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4078 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4079 p = xdr_inline_decode(xdr, 8);
4082 xdr_decode_hyper(p, used);
4083 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4084 ret = NFS_ATTR_FATTR_SPACE_USED;
4086 dprintk("%s: space used=%Lu\n", __func__,
4087 (unsigned long long)*used);
4090 print_overflow_msg(__func__, xdr);
4094 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4100 p = xdr_inline_decode(xdr, 12);
4103 p = xdr_decode_hyper(p, &sec);
4104 nsec = be32_to_cpup(p);
4105 time->tv_sec = (time_t)sec;
4106 time->tv_nsec = (long)nsec;
4109 print_overflow_msg(__func__, xdr);
4113 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4119 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4121 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4122 status = decode_attr_time(xdr, time);
4124 status = NFS_ATTR_FATTR_ATIME;
4125 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4127 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4131 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4137 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4139 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4140 status = decode_attr_time(xdr, time);
4142 status = NFS_ATTR_FATTR_CTIME;
4143 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4145 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4149 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4150 struct timespec *time)
4156 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4158 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4159 status = decode_attr_time(xdr, time);
4160 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4162 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4163 (long)time->tv_nsec);
4167 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4168 struct nfs4_label *label)
4176 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4178 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4179 p = xdr_inline_decode(xdr, 4);
4182 lfs = be32_to_cpup(p++);
4183 p = xdr_inline_decode(xdr, 4);
4186 pi = be32_to_cpup(p++);
4187 p = xdr_inline_decode(xdr, 4);
4190 len = be32_to_cpup(p++);
4191 p = xdr_inline_decode(xdr, len);
4194 if (len < NFS4_MAXLABELLEN) {
4196 memcpy(label->label, p, len);
4200 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4202 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4204 printk(KERN_WARNING "%s: label too long (%u)!\n",
4207 if (label && label->label)
4208 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4209 (char *)label->label, label->len, label->pi, label->lfs);
4213 print_overflow_msg(__func__, xdr);
4217 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4223 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4225 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4226 status = decode_attr_time(xdr, time);
4228 status = NFS_ATTR_FATTR_MTIME;
4229 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4231 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4235 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4237 unsigned int attrwords = XDR_QUADLEN(attrlen);
4238 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4240 if (unlikely(attrwords != nwords)) {
4241 dprintk("%s: server returned incorrect attribute length: "
4245 (attrwords < nwords) ? '<' : '>',
4252 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4256 p = xdr_inline_decode(xdr, 20);
4259 cinfo->atomic = be32_to_cpup(p++);
4260 p = xdr_decode_hyper(p, &cinfo->before);
4261 xdr_decode_hyper(p, &cinfo->after);
4264 print_overflow_msg(__func__, xdr);
4268 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4274 status = decode_op_hdr(xdr, OP_ACCESS);
4277 p = xdr_inline_decode(xdr, 8);
4280 supp = be32_to_cpup(p++);
4281 acc = be32_to_cpup(p);
4286 print_overflow_msg(__func__, xdr);
4290 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4294 p = xdr_inline_decode(xdr, len);
4296 memcpy(buf, p, len);
4299 print_overflow_msg(__func__, xdr);
4303 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4305 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4308 static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4310 stateid->type = NFS4_OPEN_STATEID_TYPE;
4311 return decode_stateid(xdr, stateid);
4314 static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4316 stateid->type = NFS4_LOCK_STATEID_TYPE;
4317 return decode_stateid(xdr, stateid);
4320 static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4322 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4323 return decode_stateid(xdr, stateid);
4326 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4330 status = decode_op_hdr(xdr, OP_CLOSE);
4332 nfs_increment_open_seqid(status, res->seqid);
4334 status = decode_open_stateid(xdr, &res->stateid);
4338 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4340 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4343 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4345 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4348 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4352 status = decode_op_hdr(xdr, OP_COMMIT);
4354 status = decode_write_verifier(xdr, &res->verf->verifier);
4358 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4364 status = decode_op_hdr(xdr, OP_CREATE);
4367 if ((status = decode_change_info(xdr, cinfo)))
4369 p = xdr_inline_decode(xdr, 4);
4372 bmlen = be32_to_cpup(p);
4373 p = xdr_inline_decode(xdr, bmlen << 2);
4377 print_overflow_msg(__func__, xdr);
4381 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4384 uint32_t attrlen, bitmap[3] = {0};
4387 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4389 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4391 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4393 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4395 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4396 &res->fh_expire_type)) != 0)
4398 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4400 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4402 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4404 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4405 res->exclcreat_bitmask)) != 0)
4407 status = verify_attr_len(xdr, savep, attrlen);
4409 dprintk("%s: xdr returned %d!\n", __func__, -status);
4413 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4416 uint32_t attrlen, bitmap[3] = {0};
4419 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4421 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4423 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4426 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4428 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4430 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4434 if (unlikely(bitmap[0]))
4437 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4439 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4441 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4444 status = verify_attr_len(xdr, savep, attrlen);
4446 dprintk("%s: xdr returned %d!\n", __func__, -status);
4450 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4453 uint32_t attrlen, bitmap[3] = {0};
4456 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4458 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4460 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4463 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4465 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4468 status = verify_attr_len(xdr, savep, attrlen);
4470 dprintk("%s: xdr returned %d!\n", __func__, -status);
4474 static int decode_threshold_hint(struct xdr_stream *xdr,
4482 if (likely(bitmap[0] & hint_bit)) {
4483 p = xdr_inline_decode(xdr, 8);
4486 xdr_decode_hyper(p, res);
4490 print_overflow_msg(__func__, xdr);
4494 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4495 struct nfs4_threshold *res)
4499 uint32_t bitmap[3] = {0,}, attrlen;
4503 p = xdr_inline_decode(xdr, 4);
4505 print_overflow_msg(__func__, xdr);
4508 res->l_type = be32_to_cpup(p);
4510 /* thi_hintset bitmap */
4511 status = decode_attr_bitmap(xdr, bitmap);
4515 /* thi_hintlist length */
4516 status = decode_attr_length(xdr, &attrlen, &savep);
4520 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4523 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4526 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4530 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4535 status = verify_attr_len(xdr, savep, attrlen);
4536 res->bm = bitmap[0];
4538 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4539 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4542 dprintk("%s ret=%d!\n", __func__, status);
4547 * Thresholds on pNFS direct I/O vrs MDS I/O
4549 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4551 struct nfs4_threshold *res)
4557 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4559 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4560 /* Did the server return an unrequested attribute? */
4561 if (unlikely(res == NULL))
4563 p = xdr_inline_decode(xdr, 4);
4566 num = be32_to_cpup(p);
4570 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4571 "drivers per filesystem not supported\n",
4574 status = decode_first_threshold_item4(xdr, res);
4575 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4579 print_overflow_msg(__func__, xdr);
4583 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4584 struct nfs_fattr *fattr, struct nfs_fh *fh,
4585 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4586 const struct nfs_server *server)
4593 status = decode_attr_type(xdr, bitmap, &type);
4598 fattr->mode |= nfs_type2fmt[type];
4599 fattr->valid |= status;
4602 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4605 fattr->valid |= status;
4607 status = decode_attr_size(xdr, bitmap, &fattr->size);
4610 fattr->valid |= status;
4612 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4615 fattr->valid |= status;
4618 status = decode_attr_error(xdr, bitmap, &err);
4622 status = decode_attr_filehandle(xdr, bitmap, fh);
4626 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4629 fattr->valid |= status;
4631 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4634 fattr->valid |= status;
4637 if (unlikely(bitmap[0]))
4640 status = decode_attr_mode(xdr, bitmap, &fmode);
4644 fattr->mode |= fmode;
4645 fattr->valid |= status;
4648 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4651 fattr->valid |= status;
4653 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4656 fattr->valid |= status;
4658 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4661 fattr->valid |= status;
4663 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4666 fattr->valid |= status;
4668 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4671 fattr->valid |= status;
4673 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4676 fattr->valid |= status;
4678 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4681 fattr->valid |= status;
4683 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4686 fattr->valid |= status;
4688 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4691 fattr->valid |= status;
4694 if (unlikely(bitmap[1]))
4697 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4702 status = decode_attr_security_label(xdr, bitmap, label);
4705 fattr->valid |= status;
4709 dprintk("%s: xdr returned %d\n", __func__, -status);
4713 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4714 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4715 struct nfs4_label *label, const struct nfs_server *server)
4722 status = decode_op_hdr(xdr, OP_GETATTR);
4726 status = decode_attr_bitmap(xdr, bitmap);
4730 status = decode_attr_length(xdr, &attrlen, &savep);
4734 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4739 status = verify_attr_len(xdr, savep, attrlen);
4741 dprintk("%s: xdr returned %d\n", __func__, -status);
4745 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4746 struct nfs4_label *label, const struct nfs_server *server)
4748 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4751 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4752 const struct nfs_server *server)
4754 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4758 * Decode potentially multiple layout types.
4760 static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4761 struct nfs_fsinfo *fsinfo)
4766 p = xdr_inline_decode(xdr, 4);
4769 fsinfo->nlayouttypes = be32_to_cpup(p);
4771 /* pNFS is not supported by the underlying file system */
4772 if (fsinfo->nlayouttypes == 0)
4775 /* Decode and set first layout type, move xdr->p past unused types */
4776 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4780 /* If we get too many, then just cap it at the max */
4781 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4782 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4783 __func__, fsinfo->nlayouttypes);
4784 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4787 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4788 fsinfo->layouttype[i] = be32_to_cpup(p++);
4791 print_overflow_msg(__func__, xdr);
4796 * The type of file system exported.
4797 * Note we must ensure that layouttype is set in any non-error case.
4799 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4800 struct nfs_fsinfo *fsinfo)
4804 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4805 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4807 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4808 status = decode_pnfs_layout_types(xdr, fsinfo);
4809 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4815 * The prefered block size for layout directed io
4817 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4822 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4824 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4825 p = xdr_inline_decode(xdr, 4);
4827 print_overflow_msg(__func__, xdr);
4830 *res = be32_to_cpup(p);
4831 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4837 * The granularity of a CLONE operation.
4839 static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4844 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4846 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4847 p = xdr_inline_decode(xdr, 4);
4849 print_overflow_msg(__func__, xdr);
4852 *res = be32_to_cpup(p);
4853 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4858 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4861 uint32_t attrlen, bitmap[3];
4864 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4866 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4868 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4871 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4873 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4875 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4877 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4879 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4880 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4882 fsinfo->wtpref = fsinfo->wtmax;
4885 if (unlikely(bitmap[0]))
4888 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4891 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4896 if (unlikely(bitmap[1]))
4899 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4902 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4906 status = verify_attr_len(xdr, savep, attrlen);
4908 dprintk("%s: xdr returned %d!\n", __func__, -status);
4912 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4918 /* Zero handle first to allow comparisons */
4919 memset(fh, 0, sizeof(*fh));
4921 status = decode_op_hdr(xdr, OP_GETFH);
4925 p = xdr_inline_decode(xdr, 4);
4928 len = be32_to_cpup(p);
4929 if (len > NFS4_FHSIZE)
4932 p = xdr_inline_decode(xdr, len);
4935 memcpy(fh->data, p, len);
4938 print_overflow_msg(__func__, xdr);
4942 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4946 status = decode_op_hdr(xdr, OP_LINK);
4949 return decode_change_info(xdr, cinfo);
4953 * We create the owner, so we know a proper owner.id length is 4.
4955 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4957 uint64_t offset, length, clientid;
4959 uint32_t namelen, type;
4961 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4964 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4965 p = xdr_decode_hyper(p, &length);
4966 type = be32_to_cpup(p++); /* 4 byte read */
4967 if (fl != NULL) { /* manipulate file lock */
4968 fl->fl_start = (loff_t)offset;
4969 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4970 if (length == ~(uint64_t)0)
4971 fl->fl_end = OFFSET_MAX;
4972 fl->fl_type = F_WRLCK;
4974 fl->fl_type = F_RDLCK;
4977 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4978 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4979 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4981 return -NFS4ERR_DENIED;
4983 print_overflow_msg(__func__, xdr);
4987 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4991 status = decode_op_hdr(xdr, OP_LOCK);
4995 status = decode_lock_stateid(xdr, &res->stateid);
4996 if (unlikely(status))
4998 } else if (status == -NFS4ERR_DENIED)
4999 status = decode_lock_denied(xdr, NULL);
5000 if (res->open_seqid != NULL)
5001 nfs_increment_open_seqid(status, res->open_seqid);
5002 nfs_increment_lock_seqid(status, res->lock_seqid);
5007 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
5010 status = decode_op_hdr(xdr, OP_LOCKT);
5011 if (status == -NFS4ERR_DENIED)
5012 return decode_lock_denied(xdr, res->denied);
5016 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
5020 status = decode_op_hdr(xdr, OP_LOCKU);
5022 nfs_increment_lock_seqid(status, res->seqid);
5024 status = decode_lock_stateid(xdr, &res->stateid);
5028 static int decode_release_lockowner(struct xdr_stream *xdr)
5030 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5033 static int decode_lookup(struct xdr_stream *xdr)
5035 return decode_op_hdr(xdr, OP_LOOKUP);
5038 /* This is too sick! */
5039 static int decode_space_limit(struct xdr_stream *xdr,
5040 unsigned long *pagemod_limit)
5043 uint32_t limit_type, nblocks, blocksize;
5046 p = xdr_inline_decode(xdr, 12);
5049 limit_type = be32_to_cpup(p++);
5050 switch (limit_type) {
5051 case NFS4_LIMIT_SIZE:
5052 xdr_decode_hyper(p, &maxsize);
5054 case NFS4_LIMIT_BLOCKS:
5055 nblocks = be32_to_cpup(p++);
5056 blocksize = be32_to_cpup(p);
5057 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
5059 maxsize >>= PAGE_SHIFT;
5060 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
5063 print_overflow_msg(__func__, xdr);
5067 static int decode_rw_delegation(struct xdr_stream *xdr,
5068 uint32_t delegation_type,
5069 struct nfs_openres *res)
5074 status = decode_delegation_stateid(xdr, &res->delegation);
5075 if (unlikely(status))
5077 p = xdr_inline_decode(xdr, 4);
5080 res->do_recall = be32_to_cpup(p);
5082 switch (delegation_type) {
5083 case NFS4_OPEN_DELEGATE_READ:
5084 res->delegation_type = FMODE_READ;
5086 case NFS4_OPEN_DELEGATE_WRITE:
5087 res->delegation_type = FMODE_WRITE|FMODE_READ;
5088 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
5091 return decode_ace(xdr, NULL, res->server->nfs_client);
5093 print_overflow_msg(__func__, xdr);
5097 static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5100 uint32_t why_no_delegation;
5102 p = xdr_inline_decode(xdr, 4);
5105 why_no_delegation = be32_to_cpup(p);
5106 switch (why_no_delegation) {
5107 case WND4_CONTENTION:
5109 xdr_inline_decode(xdr, 4);
5110 /* Ignore for now */
5114 print_overflow_msg(__func__, xdr);
5118 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5121 uint32_t delegation_type;
5123 p = xdr_inline_decode(xdr, 4);
5126 delegation_type = be32_to_cpup(p);
5127 res->delegation_type = 0;
5128 switch (delegation_type) {
5129 case NFS4_OPEN_DELEGATE_NONE:
5131 case NFS4_OPEN_DELEGATE_READ:
5132 case NFS4_OPEN_DELEGATE_WRITE:
5133 return decode_rw_delegation(xdr, delegation_type, res);
5134 case NFS4_OPEN_DELEGATE_NONE_EXT:
5135 return decode_no_delegation(xdr, res);
5139 print_overflow_msg(__func__, xdr);
5143 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5146 uint32_t savewords, bmlen, i;
5149 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5151 nfs_increment_open_seqid(status, res->seqid);
5154 status = decode_open_stateid(xdr, &res->stateid);
5155 if (unlikely(status))
5158 decode_change_info(xdr, &res->cinfo);
5160 p = xdr_inline_decode(xdr, 8);
5163 res->rflags = be32_to_cpup(p++);
5164 bmlen = be32_to_cpup(p);
5168 p = xdr_inline_decode(xdr, bmlen << 2);
5171 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5172 for (i = 0; i < savewords; ++i)
5173 res->attrset[i] = be32_to_cpup(p++);
5174 for (; i < NFS4_BITMAP_SIZE; i++)
5175 res->attrset[i] = 0;
5177 return decode_delegation(xdr, res);
5179 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5182 print_overflow_msg(__func__, xdr);
5186 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5190 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5192 nfs_increment_open_seqid(status, res->seqid);
5194 status = decode_open_stateid(xdr, &res->stateid);
5198 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5202 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5204 nfs_increment_open_seqid(status, res->seqid);
5206 status = decode_open_stateid(xdr, &res->stateid);
5210 static int decode_putfh(struct xdr_stream *xdr)
5212 return decode_op_hdr(xdr, OP_PUTFH);
5215 static int decode_putrootfh(struct xdr_stream *xdr)
5217 return decode_op_hdr(xdr, OP_PUTROOTFH);
5220 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5221 struct nfs_pgio_res *res)
5224 uint32_t count, eof, recvd;
5227 status = decode_op_hdr(xdr, OP_READ);
5230 p = xdr_inline_decode(xdr, 8);
5233 eof = be32_to_cpup(p++);
5234 count = be32_to_cpup(p);
5235 recvd = xdr_read_pages(xdr, count);
5236 if (count > recvd) {
5237 dprintk("NFS: server cheating in read reply: "
5238 "count %u > recvd %u\n", count, recvd);
5246 print_overflow_msg(__func__, xdr);
5250 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5255 status = decode_op_hdr(xdr, OP_READDIR);
5257 status = decode_verifier(xdr, readdir->verifier.data);
5258 if (unlikely(status))
5260 memcpy(verf, readdir->verifier.data, sizeof(verf));
5261 dprintk("%s: verifier = %08x:%08x\n",
5262 __func__, verf[0], verf[1]);
5263 return xdr_read_pages(xdr, xdr->buf->page_len);
5266 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5268 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5273 status = decode_op_hdr(xdr, OP_READLINK);
5277 /* Convert length of symlink */
5278 p = xdr_inline_decode(xdr, 4);
5281 len = be32_to_cpup(p);
5282 if (len >= rcvbuf->page_len || len <= 0) {
5283 dprintk("nfs: server returned giant symlink!\n");
5284 return -ENAMETOOLONG;
5286 recvd = xdr_read_pages(xdr, len);
5288 dprintk("NFS: server cheating in readlink reply: "
5289 "count %u > recvd %u\n", len, recvd);
5293 * The XDR encode routine has set things up so that
5294 * the link text will be copied directly into the
5295 * buffer. We just have to do overflow-checking,
5296 * and and null-terminate the text (the VFS expects
5297 * null-termination).
5299 xdr_terminate_string(rcvbuf, len);
5302 print_overflow_msg(__func__, xdr);
5306 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5310 status = decode_op_hdr(xdr, OP_REMOVE);
5313 status = decode_change_info(xdr, cinfo);
5318 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5319 struct nfs4_change_info *new_cinfo)
5323 status = decode_op_hdr(xdr, OP_RENAME);
5326 if ((status = decode_change_info(xdr, old_cinfo)))
5328 status = decode_change_info(xdr, new_cinfo);
5333 static int decode_renew(struct xdr_stream *xdr)
5335 return decode_op_hdr(xdr, OP_RENEW);
5339 decode_restorefh(struct xdr_stream *xdr)
5341 return decode_op_hdr(xdr, OP_RESTOREFH);
5344 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5345 struct nfs_getaclres *res)
5351 unsigned int pg_offset;
5354 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5357 xdr_enter_page(xdr, xdr->buf->page_len);
5359 /* Calculate the offset of the page data */
5360 pg_offset = xdr->buf->head[0].iov_len;
5362 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5364 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5367 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5369 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5371 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5372 * are stored with the acl data to handle the problem of
5373 * variable length bitmaps.*/
5374 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5375 res->acl_len = attrlen;
5377 /* Check for receive buffer overflow */
5378 if (res->acl_len > (xdr->nwords << 2) ||
5379 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5380 res->acl_flags |= NFS4_ACL_TRUNC;
5381 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5382 attrlen, xdr->nwords << 2);
5385 status = -EOPNOTSUPP;
5392 decode_savefh(struct xdr_stream *xdr)
5394 return decode_op_hdr(xdr, OP_SAVEFH);
5397 static int decode_setattr(struct xdr_stream *xdr)
5403 status = decode_op_hdr(xdr, OP_SETATTR);
5406 p = xdr_inline_decode(xdr, 4);
5409 bmlen = be32_to_cpup(p);
5410 p = xdr_inline_decode(xdr, bmlen << 2);
5414 print_overflow_msg(__func__, xdr);
5418 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5424 p = xdr_inline_decode(xdr, 8);
5427 opnum = be32_to_cpup(p++);
5428 if (opnum != OP_SETCLIENTID) {
5429 dprintk("nfs: decode_setclientid: Server returned operation"
5433 nfserr = be32_to_cpup(p);
5434 if (nfserr == NFS_OK) {
5435 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5438 p = xdr_decode_hyper(p, &res->clientid);
5439 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5440 } else if (nfserr == NFSERR_CLID_INUSE) {
5443 /* skip netid string */
5444 p = xdr_inline_decode(xdr, 4);
5447 len = be32_to_cpup(p);
5448 p = xdr_inline_decode(xdr, len);
5452 /* skip uaddr string */
5453 p = xdr_inline_decode(xdr, 4);
5456 len = be32_to_cpup(p);
5457 p = xdr_inline_decode(xdr, len);
5460 return -NFSERR_CLID_INUSE;
5462 return nfs4_stat_to_errno(nfserr);
5466 print_overflow_msg(__func__, xdr);
5470 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5472 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5475 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5480 status = decode_op_hdr(xdr, OP_WRITE);
5484 p = xdr_inline_decode(xdr, 8);
5487 res->count = be32_to_cpup(p++);
5488 res->verf->committed = be32_to_cpup(p++);
5489 return decode_write_verifier(xdr, &res->verf->verifier);
5491 print_overflow_msg(__func__, xdr);
5495 static int decode_delegreturn(struct xdr_stream *xdr)
5497 return decode_op_hdr(xdr, OP_DELEGRETURN);
5500 static int decode_secinfo_gss(struct xdr_stream *xdr,
5501 struct nfs4_secinfo4 *flavor)
5506 p = xdr_inline_decode(xdr, 4);
5509 oid_len = be32_to_cpup(p);
5510 if (oid_len > GSS_OID_MAX_LEN)
5513 p = xdr_inline_decode(xdr, oid_len);
5516 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5517 flavor->flavor_info.oid.len = oid_len;
5519 p = xdr_inline_decode(xdr, 8);
5522 flavor->flavor_info.qop = be32_to_cpup(p++);
5523 flavor->flavor_info.service = be32_to_cpup(p);
5528 print_overflow_msg(__func__, xdr);
5534 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5536 struct nfs4_secinfo4 *sec_flavor;
5537 unsigned int i, num_flavors;
5541 p = xdr_inline_decode(xdr, 4);
5545 res->flavors->num_flavors = 0;
5546 num_flavors = be32_to_cpup(p);
5548 for (i = 0; i < num_flavors; i++) {
5549 sec_flavor = &res->flavors->flavors[i];
5550 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5553 p = xdr_inline_decode(xdr, 4);
5556 sec_flavor->flavor = be32_to_cpup(p);
5558 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5559 status = decode_secinfo_gss(xdr, sec_flavor);
5563 res->flavors->num_flavors++;
5570 print_overflow_msg(__func__, xdr);
5574 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5576 int status = decode_op_hdr(xdr, OP_SECINFO);
5579 return decode_secinfo_common(xdr, res);
5582 #if defined(CONFIG_NFS_V4_1)
5583 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5585 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5588 return decode_secinfo_common(xdr, res);
5591 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5594 uint32_t bitmap_words;
5597 p = xdr_inline_decode(xdr, 4);
5598 bitmap_words = be32_to_cpup(p++);
5599 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5601 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5602 for (i = 0; i < bitmap_words; i++)
5603 op_map->u.words[i] = be32_to_cpup(p++);
5608 static int decode_exchange_id(struct xdr_stream *xdr,
5609 struct nfs41_exchange_id_res *res)
5615 uint32_t impl_id_count;
5617 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5621 p = xdr_inline_decode(xdr, 8);
5624 xdr_decode_hyper(p, &res->clientid);
5625 p = xdr_inline_decode(xdr, 12);
5628 res->seqid = be32_to_cpup(p++);
5629 res->flags = be32_to_cpup(p++);
5631 res->state_protect.how = be32_to_cpup(p);
5632 switch (res->state_protect.how) {
5636 status = decode_op_map(xdr, &res->state_protect.enforce);
5639 status = decode_op_map(xdr, &res->state_protect.allow);
5648 /* server_owner4.so_minor_id */
5649 p = xdr_inline_decode(xdr, 8);
5652 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5654 /* server_owner4.so_major_id */
5655 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5656 if (unlikely(status))
5658 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5660 memcpy(res->server_owner->major_id, dummy_str, dummy);
5661 res->server_owner->major_id_sz = dummy;
5664 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5665 if (unlikely(status))
5667 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5669 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5670 res->server_scope->server_scope_sz = dummy;
5672 /* Implementation Id */
5673 p = xdr_inline_decode(xdr, 4);
5676 impl_id_count = be32_to_cpup(p++);
5678 if (impl_id_count) {
5680 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5681 if (unlikely(status))
5683 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5685 memcpy(res->impl_id->domain, dummy_str, dummy);
5688 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5689 if (unlikely(status))
5691 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5693 memcpy(res->impl_id->name, dummy_str, dummy);
5696 p = xdr_inline_decode(xdr, 12);
5699 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5700 res->impl_id->date.nseconds = be32_to_cpup(p);
5702 /* if there's more than one entry, ignore the rest */
5706 print_overflow_msg(__func__, xdr);
5710 static int decode_chan_attrs(struct xdr_stream *xdr,
5711 struct nfs4_channel_attrs *attrs)
5716 p = xdr_inline_decode(xdr, 28);
5719 val = be32_to_cpup(p++); /* headerpadsz */
5721 return -EINVAL; /* no support for header padding yet */
5722 attrs->max_rqst_sz = be32_to_cpup(p++);
5723 attrs->max_resp_sz = be32_to_cpup(p++);
5724 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5725 attrs->max_ops = be32_to_cpup(p++);
5726 attrs->max_reqs = be32_to_cpup(p++);
5727 nr_attrs = be32_to_cpup(p);
5728 if (unlikely(nr_attrs > 1)) {
5729 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5730 "count %u\n", __func__, nr_attrs);
5733 if (nr_attrs == 1) {
5734 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5740 print_overflow_msg(__func__, xdr);
5744 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5746 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5749 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5750 struct nfs41_bind_conn_to_session_res *res)
5755 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5757 status = decode_sessionid(xdr, &res->sessionid);
5758 if (unlikely(status))
5761 /* dir flags, rdma mode bool */
5762 p = xdr_inline_decode(xdr, 8);
5766 res->dir = be32_to_cpup(p++);
5767 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5769 if (be32_to_cpup(p) == 0)
5770 res->use_conn_in_rdma_mode = false;
5772 res->use_conn_in_rdma_mode = true;
5776 print_overflow_msg(__func__, xdr);
5780 static int decode_create_session(struct xdr_stream *xdr,
5781 struct nfs41_create_session_res *res)
5786 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5788 status = decode_sessionid(xdr, &res->sessionid);
5789 if (unlikely(status))
5793 p = xdr_inline_decode(xdr, 8);
5796 res->seqid = be32_to_cpup(p++);
5797 res->flags = be32_to_cpup(p);
5799 /* Channel attributes */
5800 status = decode_chan_attrs(xdr, &res->fc_attrs);
5802 status = decode_chan_attrs(xdr, &res->bc_attrs);
5805 print_overflow_msg(__func__, xdr);
5809 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5811 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5814 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5816 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5819 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5821 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5823 #endif /* CONFIG_NFS_V4_1 */
5825 static int decode_sequence(struct xdr_stream *xdr,
5826 struct nfs4_sequence_res *res,
5827 struct rpc_rqst *rqstp)
5829 #if defined(CONFIG_NFS_V4_1)
5830 struct nfs4_session *session;
5831 struct nfs4_sessionid id;
5836 if (res->sr_slot == NULL)
5838 if (!res->sr_slot->table->session)
5841 status = decode_op_hdr(xdr, OP_SEQUENCE);
5843 status = decode_sessionid(xdr, &id);
5844 if (unlikely(status))
5848 * If the server returns different values for sessionID, slotID or
5849 * sequence number, the server is looney tunes.
5851 status = -EREMOTEIO;
5852 session = res->sr_slot->table->session;
5854 if (memcmp(id.data, session->sess_id.data,
5855 NFS4_MAX_SESSIONID_LEN)) {
5856 dprintk("%s Invalid session id\n", __func__);
5860 p = xdr_inline_decode(xdr, 20);
5865 dummy = be32_to_cpup(p++);
5866 if (dummy != res->sr_slot->seq_nr) {
5867 dprintk("%s Invalid sequence number\n", __func__);
5871 dummy = be32_to_cpup(p++);
5872 if (dummy != res->sr_slot->slot_nr) {
5873 dprintk("%s Invalid slot id\n", __func__);
5876 /* highest slot id */
5877 res->sr_highest_slotid = be32_to_cpup(p++);
5878 /* target highest slot id */
5879 res->sr_target_highest_slotid = be32_to_cpup(p++);
5881 res->sr_status_flags = be32_to_cpup(p);
5884 res->sr_status = status;
5887 print_overflow_msg(__func__, xdr);
5890 #else /* CONFIG_NFS_V4_1 */
5892 #endif /* CONFIG_NFS_V4_1 */
5895 #if defined(CONFIG_NFS_V4_1)
5896 static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5898 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5899 return decode_stateid(xdr, stateid);
5902 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5903 struct nfs4_getdeviceinfo_res *res)
5905 struct pnfs_device *pdev = res->pdev;
5910 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5912 if (status == -ETOOSMALL) {
5913 p = xdr_inline_decode(xdr, 4);
5916 pdev->mincount = be32_to_cpup(p);
5917 dprintk("%s: Min count too small. mincnt = %u\n",
5918 __func__, pdev->mincount);
5923 p = xdr_inline_decode(xdr, 8);
5926 type = be32_to_cpup(p++);
5927 if (type != pdev->layout_type) {
5928 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5929 __func__, pdev->layout_type, type);
5933 * Get the length of the opaque device_addr4. xdr_read_pages places
5934 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5935 * and places the remaining xdr data in xdr_buf->tail
5937 pdev->mincount = be32_to_cpup(p);
5938 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5941 /* Parse notification bitmap, verifying that it is zero. */
5942 p = xdr_inline_decode(xdr, 4);
5945 len = be32_to_cpup(p);
5949 p = xdr_inline_decode(xdr, 4 * len);
5953 res->notification = be32_to_cpup(p++);
5954 for (i = 1; i < len; i++) {
5955 if (be32_to_cpup(p++)) {
5956 dprintk("%s: unsupported notification\n",
5964 print_overflow_msg(__func__, xdr);
5968 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5969 struct nfs4_layoutget_res *res)
5976 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5979 p = xdr_inline_decode(xdr, 4);
5982 res->return_on_close = be32_to_cpup(p);
5983 decode_layout_stateid(xdr, &res->stateid);
5984 p = xdr_inline_decode(xdr, 4);
5987 layout_count = be32_to_cpup(p);
5988 if (!layout_count) {
5989 dprintk("%s: server responded with empty layout array\n",
5994 p = xdr_inline_decode(xdr, 28);
5997 p = xdr_decode_hyper(p, &res->range.offset);
5998 p = xdr_decode_hyper(p, &res->range.length);
5999 res->range.iomode = be32_to_cpup(p++);
6000 res->type = be32_to_cpup(p++);
6001 res->layoutp->len = be32_to_cpup(p);
6003 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6005 (unsigned long)res->range.offset,
6006 (unsigned long)res->range.length,
6011 recvd = xdr_read_pages(xdr, res->layoutp->len);
6012 if (res->layoutp->len > recvd) {
6013 dprintk("NFS: server cheating in layoutget reply: "
6014 "layout len %u > recvd %u\n",
6015 res->layoutp->len, recvd);
6019 if (layout_count > 1) {
6020 /* We only handle a length one array at the moment. Any
6021 * further entries are just ignored. Note that this means
6022 * the client may see a response that is less than the
6023 * minimum it requested.
6025 dprintk("%s: server responded with %d layouts, dropping tail\n",
6026 __func__, layout_count);
6031 print_overflow_msg(__func__, xdr);
6035 static int decode_layoutreturn(struct xdr_stream *xdr,
6036 struct nfs4_layoutreturn_res *res)
6041 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6044 p = xdr_inline_decode(xdr, 4);
6047 res->lrs_present = be32_to_cpup(p);
6048 if (res->lrs_present)
6049 status = decode_layout_stateid(xdr, &res->stateid);
6052 print_overflow_msg(__func__, xdr);
6056 static int decode_layoutcommit(struct xdr_stream *xdr,
6057 struct rpc_rqst *req,
6058 struct nfs4_layoutcommit_res *res)
6064 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
6065 res->status = status;
6069 p = xdr_inline_decode(xdr, 4);
6072 sizechanged = be32_to_cpup(p);
6075 /* throw away new size */
6076 p = xdr_inline_decode(xdr, 8);
6082 print_overflow_msg(__func__, xdr);
6086 static int decode_test_stateid(struct xdr_stream *xdr,
6087 struct nfs41_test_stateid_res *res)
6093 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6097 p = xdr_inline_decode(xdr, 4);
6100 num_res = be32_to_cpup(p++);
6104 p = xdr_inline_decode(xdr, 4);
6107 res->status = be32_to_cpup(p++);
6111 print_overflow_msg(__func__, xdr);
6116 static int decode_free_stateid(struct xdr_stream *xdr,
6117 struct nfs41_free_stateid_res *res)
6119 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
6124 int decode_layoutreturn(struct xdr_stream *xdr,
6125 struct nfs4_layoutreturn_res *res)
6129 #endif /* CONFIG_NFS_V4_1 */
6132 * END OF "GENERIC" DECODE ROUTINES.
6136 * Decode OPEN_DOWNGRADE response
6138 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6139 struct xdr_stream *xdr,
6140 struct nfs_closeres *res)
6142 struct compound_hdr hdr;
6145 status = decode_compound_hdr(xdr, &hdr);
6148 status = decode_sequence(xdr, &res->seq_res, rqstp);
6151 status = decode_putfh(xdr);
6154 status = decode_open_downgrade(xdr, res);
6160 * Decode ACCESS response
6162 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6163 struct nfs4_accessres *res)
6165 struct compound_hdr hdr;
6168 status = decode_compound_hdr(xdr, &hdr);
6171 status = decode_sequence(xdr, &res->seq_res, rqstp);
6174 status = decode_putfh(xdr);
6177 status = decode_access(xdr, &res->supported, &res->access);
6180 decode_getfattr(xdr, res->fattr, res->server);
6186 * Decode LOOKUP response
6188 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6189 struct nfs4_lookup_res *res)
6191 struct compound_hdr hdr;
6194 status = decode_compound_hdr(xdr, &hdr);
6197 status = decode_sequence(xdr, &res->seq_res, rqstp);
6200 status = decode_putfh(xdr);
6203 status = decode_lookup(xdr);
6206 status = decode_getfh(xdr, res->fh);
6209 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6215 * Decode LOOKUP_ROOT response
6217 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6218 struct xdr_stream *xdr,
6219 struct nfs4_lookup_res *res)
6221 struct compound_hdr hdr;
6224 status = decode_compound_hdr(xdr, &hdr);
6227 status = decode_sequence(xdr, &res->seq_res, rqstp);
6230 status = decode_putrootfh(xdr);
6233 status = decode_getfh(xdr, res->fh);
6235 status = decode_getfattr_label(xdr, res->fattr,
6236 res->label, res->server);
6242 * Decode REMOVE response
6244 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6245 struct nfs_removeres *res)
6247 struct compound_hdr hdr;
6250 status = decode_compound_hdr(xdr, &hdr);
6253 status = decode_sequence(xdr, &res->seq_res, rqstp);
6256 status = decode_putfh(xdr);
6259 status = decode_remove(xdr, &res->cinfo);
6265 * Decode RENAME response
6267 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6268 struct nfs_renameres *res)
6270 struct compound_hdr hdr;
6273 status = decode_compound_hdr(xdr, &hdr);
6276 status = decode_sequence(xdr, &res->seq_res, rqstp);
6279 status = decode_putfh(xdr);
6282 status = decode_savefh(xdr);
6285 status = decode_putfh(xdr);
6288 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6294 * Decode LINK response
6296 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6297 struct nfs4_link_res *res)
6299 struct compound_hdr hdr;
6302 status = decode_compound_hdr(xdr, &hdr);
6305 status = decode_sequence(xdr, &res->seq_res, rqstp);
6308 status = decode_putfh(xdr);
6311 status = decode_savefh(xdr);
6314 status = decode_putfh(xdr);
6317 status = decode_link(xdr, &res->cinfo);
6321 * Note order: OP_LINK leaves the directory as the current
6324 status = decode_restorefh(xdr);
6327 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6333 * Decode CREATE response
6335 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6336 struct nfs4_create_res *res)
6338 struct compound_hdr hdr;
6341 status = decode_compound_hdr(xdr, &hdr);
6344 status = decode_sequence(xdr, &res->seq_res, rqstp);
6347 status = decode_putfh(xdr);
6350 status = decode_create(xdr, &res->dir_cinfo);
6353 status = decode_getfh(xdr, res->fh);
6356 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6362 * Decode SYMLINK response
6364 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6365 struct nfs4_create_res *res)
6367 return nfs4_xdr_dec_create(rqstp, xdr, res);
6371 * Decode GETATTR response
6373 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6374 struct nfs4_getattr_res *res)
6376 struct compound_hdr hdr;
6379 status = decode_compound_hdr(xdr, &hdr);
6382 status = decode_sequence(xdr, &res->seq_res, rqstp);
6385 status = decode_putfh(xdr);
6388 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6394 * Encode an SETACL request
6396 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6397 struct nfs_setaclargs *args)
6399 struct compound_hdr hdr = {
6400 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6403 encode_compound_hdr(xdr, req, &hdr);
6404 encode_sequence(xdr, &args->seq_args, &hdr);
6405 encode_putfh(xdr, args->fh, &hdr);
6406 encode_setacl(xdr, args, &hdr);
6411 * Decode SETACL response
6414 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6415 struct nfs_setaclres *res)
6417 struct compound_hdr hdr;
6420 status = decode_compound_hdr(xdr, &hdr);
6423 status = decode_sequence(xdr, &res->seq_res, rqstp);
6426 status = decode_putfh(xdr);
6429 status = decode_setattr(xdr);
6435 * Decode GETACL response
6438 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6439 struct nfs_getaclres *res)
6441 struct compound_hdr hdr;
6444 if (res->acl_scratch != NULL) {
6445 void *p = page_address(res->acl_scratch);
6446 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6448 status = decode_compound_hdr(xdr, &hdr);
6451 status = decode_sequence(xdr, &res->seq_res, rqstp);
6454 status = decode_putfh(xdr);
6457 status = decode_getacl(xdr, rqstp, res);
6464 * Decode CLOSE response
6466 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6467 struct nfs_closeres *res)
6469 struct compound_hdr hdr;
6472 status = decode_compound_hdr(xdr, &hdr);
6475 status = decode_sequence(xdr, &res->seq_res, rqstp);
6478 status = decode_putfh(xdr);
6482 status = decode_layoutreturn(xdr, res->lr_res);
6483 res->lr_ret = status;
6487 status = decode_close(xdr, res);
6491 * Note: Server may do delete on close for this file
6492 * in which case the getattr call will fail with
6493 * an ESTALE error. Shouldn't be a problem,
6494 * though, since fattr->valid will remain unset.
6496 decode_getfattr(xdr, res->fattr, res->server);
6502 * Decode OPEN response
6504 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6505 struct nfs_openres *res)
6507 struct compound_hdr hdr;
6510 status = decode_compound_hdr(xdr, &hdr);
6513 status = decode_sequence(xdr, &res->seq_res, rqstp);
6516 status = decode_putfh(xdr);
6519 status = decode_open(xdr, res);
6522 status = decode_getfh(xdr, &res->fh);
6525 if (res->access_request)
6526 decode_access(xdr, &res->access_supported, &res->access_result);
6527 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6533 * Decode OPEN_CONFIRM response
6535 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6536 struct xdr_stream *xdr,
6537 struct nfs_open_confirmres *res)
6539 struct compound_hdr hdr;
6542 status = decode_compound_hdr(xdr, &hdr);
6545 status = decode_putfh(xdr);
6548 status = decode_open_confirm(xdr, res);
6554 * Decode OPEN response
6556 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6557 struct xdr_stream *xdr,
6558 struct nfs_openres *res)
6560 struct compound_hdr hdr;
6563 status = decode_compound_hdr(xdr, &hdr);
6566 status = decode_sequence(xdr, &res->seq_res, rqstp);
6569 status = decode_putfh(xdr);
6572 status = decode_open(xdr, res);
6575 if (res->access_request)
6576 decode_access(xdr, &res->access_supported, &res->access_result);
6577 decode_getfattr(xdr, res->f_attr, res->server);
6583 * Decode SETATTR response
6585 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6586 struct xdr_stream *xdr,
6587 struct nfs_setattrres *res)
6589 struct compound_hdr hdr;
6592 status = decode_compound_hdr(xdr, &hdr);
6595 status = decode_sequence(xdr, &res->seq_res, rqstp);
6598 status = decode_putfh(xdr);
6601 status = decode_setattr(xdr);
6604 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6610 * Decode LOCK response
6612 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6613 struct nfs_lock_res *res)
6615 struct compound_hdr hdr;
6618 status = decode_compound_hdr(xdr, &hdr);
6621 status = decode_sequence(xdr, &res->seq_res, rqstp);
6624 status = decode_putfh(xdr);
6627 status = decode_lock(xdr, res);
6633 * Decode LOCKT response
6635 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6636 struct nfs_lockt_res *res)
6638 struct compound_hdr hdr;
6641 status = decode_compound_hdr(xdr, &hdr);
6644 status = decode_sequence(xdr, &res->seq_res, rqstp);
6647 status = decode_putfh(xdr);
6650 status = decode_lockt(xdr, res);
6656 * Decode LOCKU response
6658 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6659 struct nfs_locku_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_putfh(xdr);
6673 status = decode_locku(xdr, res);
6678 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6679 struct xdr_stream *xdr, void *dummy)
6681 struct compound_hdr hdr;
6684 status = decode_compound_hdr(xdr, &hdr);
6686 status = decode_release_lockowner(xdr);
6691 * Decode READLINK response
6693 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6694 struct xdr_stream *xdr,
6695 struct nfs4_readlink_res *res)
6697 struct compound_hdr hdr;
6700 status = decode_compound_hdr(xdr, &hdr);
6703 status = decode_sequence(xdr, &res->seq_res, rqstp);
6706 status = decode_putfh(xdr);
6709 status = decode_readlink(xdr, rqstp);
6715 * Decode READDIR response
6717 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6718 struct nfs4_readdir_res *res)
6720 struct compound_hdr hdr;
6723 status = decode_compound_hdr(xdr, &hdr);
6726 status = decode_sequence(xdr, &res->seq_res, rqstp);
6729 status = decode_putfh(xdr);
6732 status = decode_readdir(xdr, rqstp, res);
6738 * Decode Read response
6740 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6741 struct nfs_pgio_res *res)
6743 struct compound_hdr hdr;
6746 status = decode_compound_hdr(xdr, &hdr);
6747 res->op_status = hdr.status;
6750 status = decode_sequence(xdr, &res->seq_res, rqstp);
6753 status = decode_putfh(xdr);
6756 status = decode_read(xdr, rqstp, res);
6758 status = res->count;
6764 * Decode WRITE response
6766 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6767 struct nfs_pgio_res *res)
6769 struct compound_hdr hdr;
6772 status = decode_compound_hdr(xdr, &hdr);
6773 res->op_status = hdr.status;
6776 status = decode_sequence(xdr, &res->seq_res, rqstp);
6779 status = decode_putfh(xdr);
6782 status = decode_write(xdr, res);
6786 decode_getfattr(xdr, res->fattr, res->server);
6788 status = res->count;
6794 * Decode COMMIT response
6796 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6797 struct nfs_commitres *res)
6799 struct compound_hdr hdr;
6802 status = decode_compound_hdr(xdr, &hdr);
6803 res->op_status = hdr.status;
6806 status = decode_sequence(xdr, &res->seq_res, rqstp);
6809 status = decode_putfh(xdr);
6812 status = decode_commit(xdr, res);
6818 * Decode FSINFO response
6820 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6821 struct nfs4_fsinfo_res *res)
6823 struct compound_hdr hdr;
6826 status = decode_compound_hdr(xdr, &hdr);
6828 status = decode_sequence(xdr, &res->seq_res, req);
6830 status = decode_putfh(xdr);
6832 status = decode_fsinfo(xdr, res->fsinfo);
6837 * Decode PATHCONF response
6839 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6840 struct nfs4_pathconf_res *res)
6842 struct compound_hdr hdr;
6845 status = decode_compound_hdr(xdr, &hdr);
6847 status = decode_sequence(xdr, &res->seq_res, req);
6849 status = decode_putfh(xdr);
6851 status = decode_pathconf(xdr, res->pathconf);
6856 * Decode STATFS response
6858 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6859 struct nfs4_statfs_res *res)
6861 struct compound_hdr hdr;
6864 status = decode_compound_hdr(xdr, &hdr);
6866 status = decode_sequence(xdr, &res->seq_res, req);
6868 status = decode_putfh(xdr);
6870 status = decode_statfs(xdr, res->fsstat);
6875 * Decode GETATTR_BITMAP response
6877 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6878 struct xdr_stream *xdr,
6879 struct nfs4_server_caps_res *res)
6881 struct compound_hdr hdr;
6884 status = decode_compound_hdr(xdr, &hdr);
6887 status = decode_sequence(xdr, &res->seq_res, req);
6890 status = decode_putfh(xdr);
6893 status = decode_server_caps(xdr, res);
6899 * Decode RENEW response
6901 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6904 struct compound_hdr hdr;
6907 status = decode_compound_hdr(xdr, &hdr);
6909 status = decode_renew(xdr);
6914 * Decode SETCLIENTID response
6916 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6917 struct xdr_stream *xdr,
6918 struct nfs4_setclientid_res *res)
6920 struct compound_hdr hdr;
6923 status = decode_compound_hdr(xdr, &hdr);
6925 status = decode_setclientid(xdr, res);
6930 * Decode SETCLIENTID_CONFIRM response
6932 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6933 struct xdr_stream *xdr)
6935 struct compound_hdr hdr;
6938 status = decode_compound_hdr(xdr, &hdr);
6940 status = decode_setclientid_confirm(xdr);
6945 * Decode DELEGRETURN response
6947 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6948 struct xdr_stream *xdr,
6949 struct nfs4_delegreturnres *res)
6951 struct compound_hdr hdr;
6954 status = decode_compound_hdr(xdr, &hdr);
6957 status = decode_sequence(xdr, &res->seq_res, rqstp);
6960 status = decode_putfh(xdr);
6964 status = decode_layoutreturn(xdr, res->lr_res);
6965 res->lr_ret = status;
6969 status = decode_getfattr(xdr, res->fattr, res->server);
6972 status = decode_delegreturn(xdr);
6978 * Decode FS_LOCATIONS response
6980 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6981 struct xdr_stream *xdr,
6982 struct nfs4_fs_locations_res *res)
6984 struct compound_hdr hdr;
6987 status = decode_compound_hdr(xdr, &hdr);
6990 status = decode_sequence(xdr, &res->seq_res, req);
6993 status = decode_putfh(xdr);
6996 if (res->migration) {
6997 xdr_enter_page(xdr, PAGE_SIZE);
6998 status = decode_getfattr_generic(xdr,
6999 &res->fs_locations->fattr,
7000 NULL, res->fs_locations,
7001 NULL, res->fs_locations->server);
7005 status = decode_renew(xdr);
7007 status = decode_lookup(xdr);
7010 xdr_enter_page(xdr, PAGE_SIZE);
7011 status = decode_getfattr_generic(xdr,
7012 &res->fs_locations->fattr,
7013 NULL, res->fs_locations,
7014 NULL, res->fs_locations->server);
7021 * Decode SECINFO response
7023 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7024 struct xdr_stream *xdr,
7025 struct nfs4_secinfo_res *res)
7027 struct compound_hdr hdr;
7030 status = decode_compound_hdr(xdr, &hdr);
7033 status = decode_sequence(xdr, &res->seq_res, rqstp);
7036 status = decode_putfh(xdr);
7039 status = decode_secinfo(xdr, res);
7045 * Decode FSID_PRESENT response
7047 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7048 struct xdr_stream *xdr,
7049 struct nfs4_fsid_present_res *res)
7051 struct compound_hdr hdr;
7054 status = decode_compound_hdr(xdr, &hdr);
7057 status = decode_sequence(xdr, &res->seq_res, rqstp);
7060 status = decode_putfh(xdr);
7063 status = decode_getfh(xdr, res->fh);
7067 status = decode_renew(xdr);
7072 #if defined(CONFIG_NFS_V4_1)
7074 * Decode BIND_CONN_TO_SESSION response
7076 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7077 struct xdr_stream *xdr,
7080 struct compound_hdr hdr;
7083 status = decode_compound_hdr(xdr, &hdr);
7085 status = decode_bind_conn_to_session(xdr, res);
7090 * Decode EXCHANGE_ID response
7092 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7093 struct xdr_stream *xdr,
7096 struct compound_hdr hdr;
7099 status = decode_compound_hdr(xdr, &hdr);
7101 status = decode_exchange_id(xdr, res);
7106 * Decode CREATE_SESSION response
7108 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7109 struct xdr_stream *xdr,
7110 struct nfs41_create_session_res *res)
7112 struct compound_hdr hdr;
7115 status = decode_compound_hdr(xdr, &hdr);
7117 status = decode_create_session(xdr, res);
7122 * Decode DESTROY_SESSION response
7124 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7125 struct xdr_stream *xdr,
7128 struct compound_hdr hdr;
7131 status = decode_compound_hdr(xdr, &hdr);
7133 status = decode_destroy_session(xdr, res);
7138 * Decode DESTROY_CLIENTID response
7140 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7141 struct xdr_stream *xdr,
7144 struct compound_hdr hdr;
7147 status = decode_compound_hdr(xdr, &hdr);
7149 status = decode_destroy_clientid(xdr, res);
7154 * Decode SEQUENCE response
7156 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7157 struct xdr_stream *xdr,
7158 struct nfs4_sequence_res *res)
7160 struct compound_hdr hdr;
7163 status = decode_compound_hdr(xdr, &hdr);
7165 status = decode_sequence(xdr, res, rqstp);
7170 * Decode GET_LEASE_TIME response
7172 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7173 struct xdr_stream *xdr,
7174 struct nfs4_get_lease_time_res *res)
7176 struct compound_hdr hdr;
7179 status = decode_compound_hdr(xdr, &hdr);
7181 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
7183 status = decode_putrootfh(xdr);
7185 status = decode_fsinfo(xdr, res->lr_fsinfo);
7190 * Decode RECLAIM_COMPLETE response
7192 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7193 struct xdr_stream *xdr,
7194 struct nfs41_reclaim_complete_res *res)
7196 struct compound_hdr hdr;
7199 status = decode_compound_hdr(xdr, &hdr);
7201 status = decode_sequence(xdr, &res->seq_res, rqstp);
7203 status = decode_reclaim_complete(xdr, NULL);
7208 * Decode GETDEVINFO response
7210 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7211 struct xdr_stream *xdr,
7212 struct nfs4_getdeviceinfo_res *res)
7214 struct compound_hdr hdr;
7217 status = decode_compound_hdr(xdr, &hdr);
7220 status = decode_sequence(xdr, &res->seq_res, rqstp);
7223 status = decode_getdeviceinfo(xdr, res);
7229 * Decode LAYOUTGET response
7231 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7232 struct xdr_stream *xdr,
7233 struct nfs4_layoutget_res *res)
7235 struct compound_hdr hdr;
7238 status = decode_compound_hdr(xdr, &hdr);
7241 status = decode_sequence(xdr, &res->seq_res, rqstp);
7244 status = decode_putfh(xdr);
7247 status = decode_layoutget(xdr, rqstp, res);
7253 * Decode LAYOUTRETURN response
7255 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7256 struct xdr_stream *xdr,
7257 struct nfs4_layoutreturn_res *res)
7259 struct compound_hdr hdr;
7262 status = decode_compound_hdr(xdr, &hdr);
7265 status = decode_sequence(xdr, &res->seq_res, rqstp);
7268 status = decode_putfh(xdr);
7271 status = decode_layoutreturn(xdr, res);
7277 * Decode LAYOUTCOMMIT response
7279 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7280 struct xdr_stream *xdr,
7281 struct nfs4_layoutcommit_res *res)
7283 struct compound_hdr hdr;
7286 status = decode_compound_hdr(xdr, &hdr);
7289 status = decode_sequence(xdr, &res->seq_res, rqstp);
7292 status = decode_putfh(xdr);
7295 status = decode_layoutcommit(xdr, rqstp, res);
7298 decode_getfattr(xdr, res->fattr, res->server);
7304 * Decode SECINFO_NO_NAME response
7306 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7307 struct xdr_stream *xdr,
7308 struct nfs4_secinfo_res *res)
7310 struct compound_hdr hdr;
7313 status = decode_compound_hdr(xdr, &hdr);
7316 status = decode_sequence(xdr, &res->seq_res, rqstp);
7319 status = decode_putrootfh(xdr);
7322 status = decode_secinfo_no_name(xdr, res);
7328 * Decode TEST_STATEID response
7330 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7331 struct xdr_stream *xdr,
7332 struct nfs41_test_stateid_res *res)
7334 struct compound_hdr hdr;
7337 status = decode_compound_hdr(xdr, &hdr);
7340 status = decode_sequence(xdr, &res->seq_res, rqstp);
7343 status = decode_test_stateid(xdr, res);
7349 * Decode FREE_STATEID response
7351 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7352 struct xdr_stream *xdr,
7353 struct nfs41_free_stateid_res *res)
7355 struct compound_hdr hdr;
7358 status = decode_compound_hdr(xdr, &hdr);
7361 status = decode_sequence(xdr, &res->seq_res, rqstp);
7364 status = decode_free_stateid(xdr, res);
7368 #endif /* CONFIG_NFS_V4_1 */
7371 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7372 * the local page cache.
7373 * @xdr: XDR stream where entry resides
7374 * @entry: buffer to fill in with entry data
7375 * @plus: boolean indicating whether this should be a readdirplus entry
7377 * Returns zero if successful, otherwise a negative errno value is
7380 * This function is not invoked during READDIR reply decoding, but
7381 * rather whenever an application invokes the getdents(2) system call
7382 * on a directory already in our cache.
7384 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7388 uint32_t bitmap[3] = {0};
7390 __be32 *p = xdr_inline_decode(xdr, 4);
7393 if (*p == xdr_zero) {
7394 p = xdr_inline_decode(xdr, 4);
7403 p = xdr_inline_decode(xdr, 12);
7406 entry->prev_cookie = entry->cookie;
7407 p = xdr_decode_hyper(p, &entry->cookie);
7408 entry->len = be32_to_cpup(p);
7410 p = xdr_inline_decode(xdr, entry->len);
7413 entry->name = (const char *) p;
7416 * In case the server doesn't return an inode number,
7417 * we fake one here. (We don't use inode number 0,
7418 * since glibc seems to choke on it...)
7421 entry->fattr->valid = 0;
7423 if (decode_attr_bitmap(xdr, bitmap) < 0)
7426 if (decode_attr_length(xdr, &len, &savep) < 0)
7429 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7430 NULL, entry->label, entry->server) < 0)
7432 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7433 entry->ino = entry->fattr->mounted_on_fileid;
7434 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7435 entry->ino = entry->fattr->fileid;
7437 entry->d_type = DT_UNKNOWN;
7438 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7439 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7444 print_overflow_msg(__func__, xdr);
7449 * We need to translate between nfs status return values and
7450 * the local errno values which may not be the same.
7457 { NFS4ERR_PERM, -EPERM },
7458 { NFS4ERR_NOENT, -ENOENT },
7459 { NFS4ERR_IO, -errno_NFSERR_IO},
7460 { NFS4ERR_NXIO, -ENXIO },
7461 { NFS4ERR_ACCESS, -EACCES },
7462 { NFS4ERR_EXIST, -EEXIST },
7463 { NFS4ERR_XDEV, -EXDEV },
7464 { NFS4ERR_NOTDIR, -ENOTDIR },
7465 { NFS4ERR_ISDIR, -EISDIR },
7466 { NFS4ERR_INVAL, -EINVAL },
7467 { NFS4ERR_FBIG, -EFBIG },
7468 { NFS4ERR_NOSPC, -ENOSPC },
7469 { NFS4ERR_ROFS, -EROFS },
7470 { NFS4ERR_MLINK, -EMLINK },
7471 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7472 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7473 { NFS4ERR_DQUOT, -EDQUOT },
7474 { NFS4ERR_STALE, -ESTALE },
7475 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7476 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7477 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7478 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7479 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7480 { NFS4ERR_BADTYPE, -EBADTYPE },
7481 { NFS4ERR_LOCKED, -EAGAIN },
7482 { NFS4ERR_SYMLINK, -ELOOP },
7483 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7484 { NFS4ERR_DEADLOCK, -EDEADLK },
7489 * Convert an NFS error code to a local one.
7490 * This one is used jointly by NFSv2 and NFSv3.
7493 nfs4_stat_to_errno(int stat)
7496 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7497 if (nfs_errtbl[i].stat == stat)
7498 return nfs_errtbl[i].errno;
7500 if (stat <= 10000 || stat > 10100) {
7501 /* The server is looney tunes. */
7504 /* If we cannot translate the error, the recovery routines should
7506 * Note: remaining NFSv4 error codes have values > 10000, so should
7507 * not conflict with native Linux error codes.
7512 #ifdef CONFIG_NFS_V4_2
7513 #include "nfs42xdr.c"
7514 #endif /* CONFIG_NFS_V4_2 */
7516 #define PROC(proc, argtype, restype) \
7517 [NFSPROC4_CLNT_##proc] = { \
7518 .p_proc = NFSPROC4_COMPOUND, \
7519 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7520 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7521 .p_arglen = NFS4_##argtype##_sz, \
7522 .p_replen = NFS4_##restype##_sz, \
7523 .p_statidx = NFSPROC4_CLNT_##proc, \
7527 #define STUB(proc) \
7528 [NFSPROC4_CLNT_##proc] = { \
7532 struct rpc_procinfo nfs4_procedures[] = {
7533 PROC(READ, enc_read, dec_read),
7534 PROC(WRITE, enc_write, dec_write),
7535 PROC(COMMIT, enc_commit, dec_commit),
7536 PROC(OPEN, enc_open, dec_open),
7537 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7538 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7539 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7540 PROC(CLOSE, enc_close, dec_close),
7541 PROC(SETATTR, enc_setattr, dec_setattr),
7542 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7543 PROC(RENEW, enc_renew, dec_renew),
7544 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7545 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7546 PROC(LOCK, enc_lock, dec_lock),
7547 PROC(LOCKT, enc_lockt, dec_lockt),
7548 PROC(LOCKU, enc_locku, dec_locku),
7549 PROC(ACCESS, enc_access, dec_access),
7550 PROC(GETATTR, enc_getattr, dec_getattr),
7551 PROC(LOOKUP, enc_lookup, dec_lookup),
7552 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7553 PROC(REMOVE, enc_remove, dec_remove),
7554 PROC(RENAME, enc_rename, dec_rename),
7555 PROC(LINK, enc_link, dec_link),
7556 PROC(SYMLINK, enc_symlink, dec_symlink),
7557 PROC(CREATE, enc_create, dec_create),
7558 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7559 PROC(STATFS, enc_statfs, dec_statfs),
7560 PROC(READLINK, enc_readlink, dec_readlink),
7561 PROC(READDIR, enc_readdir, dec_readdir),
7562 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7563 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7564 PROC(GETACL, enc_getacl, dec_getacl),
7565 PROC(SETACL, enc_setacl, dec_setacl),
7566 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7567 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7568 PROC(SECINFO, enc_secinfo, dec_secinfo),
7569 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7570 #if defined(CONFIG_NFS_V4_1)
7571 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7572 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7573 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7574 PROC(SEQUENCE, enc_sequence, dec_sequence),
7575 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7576 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7577 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7578 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7579 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7580 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7581 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7582 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7583 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7584 STUB(GETDEVICELIST),
7585 PROC(BIND_CONN_TO_SESSION,
7586 enc_bind_conn_to_session, dec_bind_conn_to_session),
7587 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7588 #endif /* CONFIG_NFS_V4_1 */
7589 #ifdef CONFIG_NFS_V4_2
7590 PROC(SEEK, enc_seek, dec_seek),
7591 PROC(ALLOCATE, enc_allocate, dec_allocate),
7592 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
7593 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7594 PROC(CLONE, enc_clone, dec_clone),
7595 PROC(COPY, enc_copy, dec_copy),
7596 #endif /* CONFIG_NFS_V4_2 */
7599 const struct rpc_version nfs_version4 = {
7601 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7602 .procs = nfs4_procedures