4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
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>
57 #include "nfs4trace.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
70 static int nfs4_stat_to_errno(int);
71 static void encode_layoutget(struct xdr_stream *xdr,
72 const struct nfs4_layoutget_args *args,
73 struct compound_hdr *hdr);
74 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
75 struct nfs4_layoutget_res *res);
77 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
79 #define NFS4_MAXTAGLEN 20
81 #define NFS4_MAXTAGLEN 0
84 /* lock,open owner id:
85 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
87 #define pagepad_maxsz (1)
88 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
89 #define lock_owner_id_maxsz (1 + 1 + 4)
90 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
91 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
92 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
93 #define op_encode_hdr_maxsz (1)
94 #define op_decode_hdr_maxsz (2)
95 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
96 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
97 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
98 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
99 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
101 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
102 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
103 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
104 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
105 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
106 ((3+NFS4_FHSIZE) >> 2))
107 #define nfs4_fattr_bitmap_maxsz 4
108 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
109 #define nfstime4_maxsz (3)
110 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
111 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
112 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
113 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
114 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
115 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
116 #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
118 #define nfs4_label_maxsz 0
120 /* We support only one layout type per file system */
121 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
122 /* This is based on getfattr, which uses the most attributes: */
123 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
126 nfs4_group_maxsz + nfs4_label_maxsz + \
127 decode_mdsthreshold_maxsz))
128 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
129 nfs4_fattr_value_maxsz)
130 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
131 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
136 1 + nfstime4_maxsz + \
138 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
139 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
140 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
141 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
142 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
143 /* The 5 accounts for the PNFS attributes, and assumes that at most three
144 * layout types will be returned.
146 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
147 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
148 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
149 #define decode_renew_maxsz (op_decode_hdr_maxsz)
150 #define encode_setclientid_maxsz \
151 (op_encode_hdr_maxsz + \
152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
154 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
156 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
157 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
159 #define decode_setclientid_maxsz \
160 (op_decode_hdr_maxsz + \
162 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
163 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
164 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
165 #define encode_setclientid_confirm_maxsz \
166 (op_encode_hdr_maxsz + \
167 3 + (NFS4_VERIFIER_SIZE >> 2))
168 #define decode_setclientid_confirm_maxsz \
169 (op_decode_hdr_maxsz)
170 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
171 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
172 #define encode_lookupp_maxsz (op_encode_hdr_maxsz)
173 #define decode_lookupp_maxsz (op_decode_hdr_maxsz)
174 #define encode_share_access_maxsz \
176 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
177 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
178 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
179 #define encode_open_maxsz (op_encode_hdr_maxsz + \
180 2 + encode_share_access_maxsz + 2 + \
181 open_owner_id_maxsz + \
182 encode_opentype_maxsz + \
183 encode_claim_null_maxsz)
184 #define decode_space_limit_maxsz (3)
185 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
186 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
187 decode_space_limit_maxsz + \
189 #define decode_change_info_maxsz (5)
190 #define decode_open_maxsz (op_decode_hdr_maxsz + \
191 decode_stateid_maxsz + \
192 decode_change_info_maxsz + 1 + \
193 nfs4_fattr_bitmap_maxsz + \
194 decode_delegation_maxsz)
195 #define encode_open_confirm_maxsz \
196 (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + 1)
198 #define decode_open_confirm_maxsz \
199 (op_decode_hdr_maxsz + \
200 decode_stateid_maxsz)
201 #define encode_open_downgrade_maxsz \
202 (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + 1 + \
204 encode_share_access_maxsz)
205 #define decode_open_downgrade_maxsz \
206 (op_decode_hdr_maxsz + \
207 decode_stateid_maxsz)
208 #define encode_close_maxsz (op_encode_hdr_maxsz + \
209 1 + encode_stateid_maxsz)
210 #define decode_close_maxsz (op_decode_hdr_maxsz + \
211 decode_stateid_maxsz)
212 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + \
215 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
216 nfs4_fattr_bitmap_maxsz)
217 #define encode_read_maxsz (op_encode_hdr_maxsz + \
218 encode_stateid_maxsz + 3)
219 #define decode_read_maxsz (op_decode_hdr_maxsz + 2 + pagepad_maxsz)
220 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
221 2 + encode_verifier_maxsz + 5 + \
223 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
224 decode_verifier_maxsz + pagepad_maxsz)
225 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
226 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + pagepad_maxsz)
227 #define encode_write_maxsz (op_encode_hdr_maxsz + \
228 encode_stateid_maxsz + 4)
229 #define decode_write_maxsz (op_decode_hdr_maxsz + \
230 2 + decode_verifier_maxsz)
231 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
232 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
233 decode_verifier_maxsz)
234 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
236 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
237 decode_change_info_maxsz)
238 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
240 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 decode_change_info_maxsz)
243 #define encode_link_maxsz (op_encode_hdr_maxsz + \
245 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
246 #define encode_lockowner_maxsz (7)
247 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
249 1 + encode_stateid_maxsz + 1 + \
250 encode_lockowner_maxsz)
251 #define decode_lock_denied_maxsz \
252 (8 + decode_lockowner_maxsz)
253 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
254 decode_lock_denied_maxsz)
255 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
256 encode_lockowner_maxsz)
257 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
258 decode_lock_denied_maxsz)
259 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
260 encode_stateid_maxsz + \
262 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
263 decode_stateid_maxsz)
264 #define encode_release_lockowner_maxsz \
265 (op_encode_hdr_maxsz + \
266 encode_lockowner_maxsz)
267 #define decode_release_lockowner_maxsz \
268 (op_decode_hdr_maxsz)
269 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
270 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
271 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
272 1 + nfs4_name_maxsz + \
275 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
276 #define encode_create_maxsz (op_encode_hdr_maxsz + \
277 1 + 2 + nfs4_name_maxsz + \
279 #define decode_create_maxsz (op_decode_hdr_maxsz + \
280 decode_change_info_maxsz + \
281 nfs4_fattr_bitmap_maxsz)
282 #define encode_statfs_maxsz (encode_getattr_maxsz)
283 #define decode_statfs_maxsz (decode_getattr_maxsz)
284 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
285 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
286 #define encode_getacl_maxsz (encode_getattr_maxsz)
287 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
288 nfs4_fattr_bitmap_maxsz + 1 + pagepad_maxsz)
289 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
290 encode_stateid_maxsz + 3)
291 #define decode_setacl_maxsz (decode_setattr_maxsz)
292 #define encode_fs_locations_maxsz \
293 (encode_getattr_maxsz)
294 #define decode_fs_locations_maxsz \
296 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
297 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
299 #if defined(CONFIG_NFS_V4_1)
300 #define NFS4_MAX_MACHINE_NAME_LEN (64)
301 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
302 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
304 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
305 encode_verifier_maxsz + \
306 1 /* co_ownerid.len */ + \
307 /* eia_clientowner */ \
308 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
311 /* max is SP4_MACH_CRED (for now) */ + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
313 1 + NFS4_OP_MAP_NUM_WORDS + \
314 1 /* implementation id array of size 1 */ + \
315 1 /* nii_domain */ + \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
318 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
320 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
321 2 /* eir_clientid */ + \
322 1 /* eir_sequenceid */ + \
323 1 /* eir_flags */ + \
325 /* max is SP4_MACH_CRED (for now) */ + \
326 1 + NFS4_OP_MAP_NUM_WORDS + \
327 1 + NFS4_OP_MAP_NUM_WORDS + \
328 2 /* eir_server_owner.so_minor_id */ + \
329 /* eir_server_owner.so_major_id<> */ \
330 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
331 /* eir_server_scope<> */ \
332 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
333 1 /* eir_server_impl_id array length */ + \
334 1 /* nii_domain */ + \
335 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
337 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
339 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
340 #define decode_channel_attrs_maxsz (6 + \
341 1 /* ca_rdma_ird.len */ + \
343 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
344 2 /* csa_clientid */ + \
345 1 /* csa_sequence */ + \
346 1 /* csa_flags */ + \
347 encode_channel_attrs_maxsz + \
348 encode_channel_attrs_maxsz + \
349 1 /* csa_cb_program */ + \
350 1 /* csa_sec_parms.len (1) */ + \
351 1 /* cb_secflavor (AUTH_SYS) */ + \
353 1 /* machinename.len */ + \
354 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
357 1 /* gids.len (0) */)
358 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
359 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
360 1 /* csr_sequence */ + \
361 1 /* csr_flags */ + \
362 decode_channel_attrs_maxsz + \
363 decode_channel_attrs_maxsz)
364 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
366 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
367 1 /* bctsa_dir */ + \
368 1 /* bctsa_use_conn_in_rdma_mode */)
369 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
371 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
372 1 /* bctsr_dir */ + \
373 1 /* bctsr_use_conn_in_rdma_mode */)
374 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
375 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
376 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
377 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
378 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
379 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
380 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
381 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
382 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
383 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
384 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
385 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
386 1 /* layout type */ + \
388 1 /* bitmap size */ + \
389 1 /* notification bitmap length */ + \
390 1 /* notification bitmap, word 0 */)
391 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
392 1 /* layout type */ + \
393 1 /* opaque devaddr4 length */ + \
394 /* devaddr4 payload is read into page */ \
395 1 /* notification bitmap length */ + \
396 1 /* notification bitmap, word 0 */ + \
397 pagepad_maxsz /* possible XDR padding */)
398 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
399 encode_stateid_maxsz)
400 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
401 decode_stateid_maxsz + \
402 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + \
404 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
408 encode_stateid_maxsz + \
409 1 /* new offset (true) */ + \
410 2 /* last byte written */ + \
411 1 /* nt_timechanged (false) */ + \
412 1 /* layoutupdate4 layout type */ + \
413 1 /* layoutupdate4 opaqueue len */)
414 /* the actual content of layoutupdate4 should
415 be allocated by drivers and spliced in
416 using xdr_write_pages */
417 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
418 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
419 encode_stateid_maxsz + \
421 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
422 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
423 1 + decode_stateid_maxsz)
424 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
425 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
426 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
427 XDR_QUADLEN(NFS4_STATEID_SIZE))
428 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
429 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
430 XDR_QUADLEN(NFS4_STATEID_SIZE))
431 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
432 #else /* CONFIG_NFS_V4_1 */
433 #define encode_sequence_maxsz 0
434 #define decode_sequence_maxsz 0
435 #define encode_layoutreturn_maxsz 0
436 #define decode_layoutreturn_maxsz 0
437 #define encode_layoutget_maxsz 0
438 #define decode_layoutget_maxsz 0
439 #endif /* CONFIG_NFS_V4_1 */
441 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
442 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
443 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
444 encode_sequence_maxsz + \
445 encode_putfh_maxsz + \
447 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
448 decode_sequence_maxsz + \
449 decode_putfh_maxsz + \
451 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
452 encode_sequence_maxsz + \
453 encode_putfh_maxsz + \
454 encode_readlink_maxsz)
455 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
456 decode_sequence_maxsz + \
457 decode_putfh_maxsz + \
458 decode_readlink_maxsz)
459 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
460 encode_sequence_maxsz + \
461 encode_putfh_maxsz + \
462 encode_readdir_maxsz)
463 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
464 decode_sequence_maxsz + \
465 decode_putfh_maxsz + \
466 decode_readdir_maxsz)
467 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
468 encode_sequence_maxsz + \
469 encode_putfh_maxsz + \
470 encode_write_maxsz + \
471 encode_getattr_maxsz)
472 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
473 decode_sequence_maxsz + \
474 decode_putfh_maxsz + \
475 decode_write_maxsz + \
476 decode_getattr_maxsz)
477 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
478 encode_sequence_maxsz + \
479 encode_putfh_maxsz + \
481 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
482 decode_sequence_maxsz + \
483 decode_putfh_maxsz + \
485 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
486 encode_sequence_maxsz + \
487 encode_putfh_maxsz + \
488 encode_open_maxsz + \
489 encode_access_maxsz + \
490 encode_getfh_maxsz + \
491 encode_getattr_maxsz + \
492 encode_layoutget_maxsz)
493 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
494 decode_sequence_maxsz + \
495 decode_putfh_maxsz + \
496 decode_open_maxsz + \
497 decode_access_maxsz + \
498 decode_getfh_maxsz + \
499 decode_getattr_maxsz + \
500 decode_layoutget_maxsz)
501 #define NFS4_enc_open_confirm_sz \
502 (compound_encode_hdr_maxsz + \
503 encode_putfh_maxsz + \
504 encode_open_confirm_maxsz)
505 #define NFS4_dec_open_confirm_sz \
506 (compound_decode_hdr_maxsz + \
507 decode_putfh_maxsz + \
508 decode_open_confirm_maxsz)
509 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
510 encode_sequence_maxsz + \
511 encode_putfh_maxsz + \
512 encode_open_maxsz + \
513 encode_access_maxsz + \
514 encode_getattr_maxsz + \
515 encode_layoutget_maxsz)
516 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
517 decode_sequence_maxsz + \
518 decode_putfh_maxsz + \
519 decode_open_maxsz + \
520 decode_access_maxsz + \
521 decode_getattr_maxsz + \
522 decode_layoutget_maxsz)
523 #define NFS4_enc_open_downgrade_sz \
524 (compound_encode_hdr_maxsz + \
525 encode_sequence_maxsz + \
526 encode_putfh_maxsz + \
527 encode_layoutreturn_maxsz + \
528 encode_open_downgrade_maxsz)
529 #define NFS4_dec_open_downgrade_sz \
530 (compound_decode_hdr_maxsz + \
531 decode_sequence_maxsz + \
532 decode_putfh_maxsz + \
533 decode_layoutreturn_maxsz + \
534 decode_open_downgrade_maxsz)
535 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
536 encode_sequence_maxsz + \
537 encode_putfh_maxsz + \
538 encode_layoutreturn_maxsz + \
539 encode_close_maxsz + \
540 encode_getattr_maxsz)
541 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
542 decode_sequence_maxsz + \
543 decode_putfh_maxsz + \
544 decode_layoutreturn_maxsz + \
545 decode_close_maxsz + \
546 decode_getattr_maxsz)
547 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
548 encode_sequence_maxsz + \
549 encode_putfh_maxsz + \
550 encode_setattr_maxsz + \
551 encode_getattr_maxsz)
552 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
553 decode_sequence_maxsz + \
554 decode_putfh_maxsz + \
555 decode_setattr_maxsz + \
556 decode_getattr_maxsz)
557 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
558 encode_sequence_maxsz + \
559 encode_putfh_maxsz + \
561 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
562 decode_sequence_maxsz + \
563 decode_putfh_maxsz + \
565 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
567 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
569 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
570 encode_setclientid_maxsz)
571 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
572 decode_setclientid_maxsz)
573 #define NFS4_enc_setclientid_confirm_sz \
574 (compound_encode_hdr_maxsz + \
575 encode_setclientid_confirm_maxsz)
576 #define NFS4_dec_setclientid_confirm_sz \
577 (compound_decode_hdr_maxsz + \
578 decode_setclientid_confirm_maxsz)
579 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
580 encode_sequence_maxsz + \
581 encode_putfh_maxsz + \
583 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
584 decode_sequence_maxsz + \
585 decode_putfh_maxsz + \
587 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
588 encode_sequence_maxsz + \
589 encode_putfh_maxsz + \
591 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
592 decode_sequence_maxsz + \
593 decode_putfh_maxsz + \
595 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
596 encode_sequence_maxsz + \
597 encode_putfh_maxsz + \
599 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
600 decode_sequence_maxsz + \
601 decode_putfh_maxsz + \
603 #define NFS4_enc_release_lockowner_sz \
604 (compound_encode_hdr_maxsz + \
605 encode_lockowner_maxsz)
606 #define NFS4_dec_release_lockowner_sz \
607 (compound_decode_hdr_maxsz + \
608 decode_lockowner_maxsz)
609 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
610 encode_sequence_maxsz + \
611 encode_putfh_maxsz + \
612 encode_access_maxsz + \
613 encode_getattr_maxsz)
614 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
615 decode_sequence_maxsz + \
616 decode_putfh_maxsz + \
617 decode_access_maxsz + \
618 decode_getattr_maxsz)
619 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
620 encode_sequence_maxsz + \
621 encode_putfh_maxsz + \
622 encode_getattr_maxsz + \
624 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
625 decode_sequence_maxsz + \
626 decode_putfh_maxsz + \
627 decode_getattr_maxsz + \
629 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
630 encode_sequence_maxsz + \
631 encode_putfh_maxsz + \
632 encode_lookup_maxsz + \
633 encode_getattr_maxsz + \
635 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
636 decode_sequence_maxsz + \
637 decode_putfh_maxsz + \
638 decode_lookup_maxsz + \
639 decode_getattr_maxsz + \
641 #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
642 encode_sequence_maxsz + \
643 encode_putfh_maxsz + \
644 encode_lookupp_maxsz + \
645 encode_getattr_maxsz + \
647 #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
648 decode_sequence_maxsz + \
649 decode_putfh_maxsz + \
650 decode_lookupp_maxsz + \
651 decode_getattr_maxsz + \
653 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
654 encode_sequence_maxsz + \
655 encode_putrootfh_maxsz + \
656 encode_getattr_maxsz + \
658 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
659 decode_sequence_maxsz + \
660 decode_putrootfh_maxsz + \
661 decode_getattr_maxsz + \
663 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
664 encode_sequence_maxsz + \
665 encode_putfh_maxsz + \
667 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
668 decode_sequence_maxsz + \
669 decode_putfh_maxsz + \
671 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
672 encode_sequence_maxsz + \
673 encode_putfh_maxsz + \
674 encode_savefh_maxsz + \
675 encode_putfh_maxsz + \
677 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
678 decode_sequence_maxsz + \
679 decode_putfh_maxsz + \
680 decode_savefh_maxsz + \
681 decode_putfh_maxsz + \
683 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
684 encode_sequence_maxsz + \
685 encode_putfh_maxsz + \
686 encode_savefh_maxsz + \
687 encode_putfh_maxsz + \
688 encode_link_maxsz + \
689 encode_restorefh_maxsz + \
690 encode_getattr_maxsz)
691 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
692 decode_sequence_maxsz + \
693 decode_putfh_maxsz + \
694 decode_savefh_maxsz + \
695 decode_putfh_maxsz + \
696 decode_link_maxsz + \
697 decode_restorefh_maxsz + \
698 decode_getattr_maxsz)
699 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
700 encode_sequence_maxsz + \
701 encode_putfh_maxsz + \
702 encode_symlink_maxsz + \
703 encode_getattr_maxsz + \
705 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
706 decode_sequence_maxsz + \
707 decode_putfh_maxsz + \
708 decode_symlink_maxsz + \
709 decode_getattr_maxsz + \
711 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
712 encode_sequence_maxsz + \
713 encode_putfh_maxsz + \
714 encode_create_maxsz + \
715 encode_getfh_maxsz + \
716 encode_getattr_maxsz)
717 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
718 decode_sequence_maxsz + \
719 decode_putfh_maxsz + \
720 decode_create_maxsz + \
721 decode_getfh_maxsz + \
722 decode_getattr_maxsz)
723 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
724 encode_sequence_maxsz + \
725 encode_putfh_maxsz + \
726 encode_getattr_maxsz)
727 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz + \
729 decode_putfh_maxsz + \
730 decode_getattr_maxsz)
731 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
732 encode_sequence_maxsz + \
733 encode_putfh_maxsz + \
735 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
736 decode_sequence_maxsz + \
737 decode_putfh_maxsz + \
739 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
740 encode_sequence_maxsz + \
741 encode_putfh_maxsz + \
742 encode_getattr_maxsz)
743 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
744 decode_sequence_maxsz + \
745 decode_putfh_maxsz + \
746 decode_getattr_maxsz)
747 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
748 encode_sequence_maxsz + \
749 encode_putfh_maxsz + \
750 encode_layoutreturn_maxsz + \
751 encode_delegreturn_maxsz + \
752 encode_getattr_maxsz)
753 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
754 decode_sequence_maxsz + \
755 decode_putfh_maxsz + \
756 decode_layoutreturn_maxsz + \
757 decode_delegreturn_maxsz + \
758 decode_getattr_maxsz)
759 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
760 encode_sequence_maxsz + \
761 encode_putfh_maxsz + \
763 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
764 decode_sequence_maxsz + \
765 decode_putfh_maxsz + \
767 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
768 encode_sequence_maxsz + \
769 encode_putfh_maxsz + \
771 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz + \
773 decode_putfh_maxsz + \
775 #define NFS4_enc_fs_locations_sz \
776 (compound_encode_hdr_maxsz + \
777 encode_sequence_maxsz + \
778 encode_putfh_maxsz + \
779 encode_lookup_maxsz + \
780 encode_fs_locations_maxsz + \
782 #define NFS4_dec_fs_locations_sz \
783 (compound_decode_hdr_maxsz + \
784 decode_sequence_maxsz + \
785 decode_putfh_maxsz + \
786 decode_lookup_maxsz + \
787 decode_fs_locations_maxsz + \
789 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
790 encode_sequence_maxsz + \
791 encode_putfh_maxsz + \
792 encode_secinfo_maxsz)
793 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
794 decode_sequence_maxsz + \
795 decode_putfh_maxsz + \
796 decode_secinfo_maxsz)
797 #define NFS4_enc_fsid_present_sz \
798 (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_putfh_maxsz + \
801 encode_getfh_maxsz + \
803 #define NFS4_dec_fsid_present_sz \
804 (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_getfh_maxsz + \
809 #if defined(CONFIG_NFS_V4_1)
810 #define NFS4_enc_bind_conn_to_session_sz \
811 (compound_encode_hdr_maxsz + \
812 encode_bind_conn_to_session_maxsz)
813 #define NFS4_dec_bind_conn_to_session_sz \
814 (compound_decode_hdr_maxsz + \
815 decode_bind_conn_to_session_maxsz)
816 #define NFS4_enc_exchange_id_sz \
817 (compound_encode_hdr_maxsz + \
818 encode_exchange_id_maxsz)
819 #define NFS4_dec_exchange_id_sz \
820 (compound_decode_hdr_maxsz + \
821 decode_exchange_id_maxsz)
822 #define NFS4_enc_create_session_sz \
823 (compound_encode_hdr_maxsz + \
824 encode_create_session_maxsz)
825 #define NFS4_dec_create_session_sz \
826 (compound_decode_hdr_maxsz + \
827 decode_create_session_maxsz)
828 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
829 encode_destroy_session_maxsz)
830 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
831 decode_destroy_session_maxsz)
832 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
833 encode_destroy_clientid_maxsz)
834 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
835 decode_destroy_clientid_maxsz)
836 #define NFS4_enc_sequence_sz \
837 (compound_decode_hdr_maxsz + \
838 encode_sequence_maxsz)
839 #define NFS4_dec_sequence_sz \
840 (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz)
843 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putrootfh_maxsz + \
847 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putrootfh_maxsz + \
851 #if defined(CONFIG_NFS_V4_1)
852 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz + \
854 encode_reclaim_complete_maxsz)
855 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
856 decode_sequence_maxsz + \
857 decode_reclaim_complete_maxsz)
858 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
859 encode_sequence_maxsz +\
860 encode_getdeviceinfo_maxsz)
861 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
862 decode_sequence_maxsz + \
863 decode_getdeviceinfo_maxsz)
864 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
865 encode_sequence_maxsz + \
866 encode_putfh_maxsz + \
867 encode_layoutget_maxsz)
868 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
869 decode_sequence_maxsz + \
870 decode_putfh_maxsz + \
871 decode_layoutget_maxsz)
872 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
873 encode_sequence_maxsz +\
874 encode_putfh_maxsz + \
875 encode_layoutcommit_maxsz + \
876 encode_getattr_maxsz)
877 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
878 decode_sequence_maxsz + \
879 decode_putfh_maxsz + \
880 decode_layoutcommit_maxsz + \
881 decode_getattr_maxsz)
882 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
883 encode_sequence_maxsz + \
884 encode_putfh_maxsz + \
885 encode_layoutreturn_maxsz)
886 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
887 decode_sequence_maxsz + \
888 decode_putfh_maxsz + \
889 decode_layoutreturn_maxsz)
890 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
891 encode_sequence_maxsz + \
892 encode_putrootfh_maxsz +\
893 encode_secinfo_no_name_maxsz)
894 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
895 decode_sequence_maxsz + \
896 decode_putrootfh_maxsz + \
897 decode_secinfo_no_name_maxsz)
898 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
899 encode_sequence_maxsz + \
900 encode_test_stateid_maxsz)
901 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
902 decode_sequence_maxsz + \
903 decode_test_stateid_maxsz)
904 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
905 encode_sequence_maxsz + \
906 encode_free_stateid_maxsz)
907 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
908 decode_sequence_maxsz + \
909 decode_free_stateid_maxsz)
911 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
912 compound_encode_hdr_maxsz +
913 encode_sequence_maxsz +
915 encode_getattr_maxsz) *
918 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
919 compound_decode_hdr_maxsz +
920 decode_sequence_maxsz +
921 decode_putfh_maxsz) *
924 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
925 compound_decode_hdr_maxsz +
926 decode_sequence_maxsz) *
928 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
929 #endif /* CONFIG_NFS_V4_1 */
931 static const umode_t nfs_type2fmt[] = {
938 [NF4SOCK] = S_IFSOCK,
944 struct compound_hdr {
950 uint32_t replen; /* expected reply words */
954 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
956 __be32 *p = xdr_reserve_space(xdr, nbytes);
961 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
963 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
966 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
968 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
971 static void encode_uint32(struct xdr_stream *xdr, u32 n)
973 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
976 static void encode_uint64(struct xdr_stream *xdr, u64 n)
978 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
981 static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
982 const __u32 *bitmap, size_t len)
986 /* Trim empty words */
987 while (len > 0 && bitmap[len-1] == 0)
989 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
990 if (WARN_ON_ONCE(ret < 0))
995 static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
996 __u32 *res, size_t len)
1001 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
1003 for (i = len; i-- > 0;) {
1004 tmp = bitmap[i] & mask[i];
1010 static void encode_nfs4_seqid(struct xdr_stream *xdr,
1011 const struct nfs_seqid *seqid)
1014 encode_uint32(xdr, seqid->sequence->counter);
1016 encode_uint32(xdr, 0);
1019 static void encode_compound_hdr(struct xdr_stream *xdr,
1020 struct rpc_rqst *req,
1021 struct compound_hdr *hdr)
1025 /* initialize running count of expected bytes in reply.
1026 * NOTE: the replied tag SHOULD be the same is the one sent,
1027 * but this is not required as a MUST for the server to do so. */
1028 hdr->replen = 3 + hdr->taglen;
1030 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
1031 encode_string(xdr, hdr->taglen, hdr->tag);
1032 p = reserve_space(xdr, 8);
1033 *p++ = cpu_to_be32(hdr->minorversion);
1035 *p = cpu_to_be32(hdr->nops);
1038 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1040 struct compound_hdr *hdr)
1042 encode_uint32(xdr, op);
1044 hdr->replen += replen;
1047 static void encode_nops(struct compound_hdr *hdr)
1049 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
1050 *hdr->nops_p = htonl(hdr->nops);
1053 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1055 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1058 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1060 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1064 xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
1066 p = xdr_encode_hyper(p, t->tv_sec);
1067 *p++ = cpu_to_be32(t->tv_nsec);
1071 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1072 const struct nfs4_label *label,
1073 const umode_t *umask,
1074 const struct nfs_server *server,
1075 const uint32_t attrmask[])
1077 char owner_name[IDMAP_NAMESZ];
1078 char owner_group[IDMAP_NAMESZ];
1079 int owner_namelen = 0;
1080 int owner_grouplen = 0;
1083 uint32_t bmval[3] = { 0 };
1086 * We reserve enough space to write the entire attribute buffer at once.
1088 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
1089 bmval[0] |= FATTR4_WORD0_SIZE;
1092 if (iap->ia_valid & ATTR_MODE) {
1093 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
1094 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1096 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
1097 bmval[1] |= FATTR4_WORD1_MODE;
1101 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
1102 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1103 if (owner_namelen < 0) {
1104 dprintk("nfs: couldn't resolve uid %d to string\n",
1105 from_kuid(&init_user_ns, iap->ia_uid));
1107 strcpy(owner_name, "nobody");
1108 owner_namelen = sizeof("nobody") - 1;
1111 bmval[1] |= FATTR4_WORD1_OWNER;
1112 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1114 if ((iap->ia_valid & ATTR_GID) &&
1115 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
1116 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1117 if (owner_grouplen < 0) {
1118 dprintk("nfs: couldn't resolve gid %d to string\n",
1119 from_kgid(&init_user_ns, iap->ia_gid));
1120 strcpy(owner_group, "nobody");
1121 owner_grouplen = sizeof("nobody") - 1;
1124 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1125 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1127 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1128 if (iap->ia_valid & ATTR_ATIME_SET) {
1129 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1130 len += 4 + (nfstime4_maxsz << 2);
1131 } else if (iap->ia_valid & ATTR_ATIME) {
1132 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1136 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1137 if (iap->ia_valid & ATTR_MTIME_SET) {
1138 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1139 len += 4 + (nfstime4_maxsz << 2);
1140 } else if (iap->ia_valid & ATTR_MTIME) {
1141 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1146 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1147 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1148 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1151 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1152 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
1154 if (bmval[0] & FATTR4_WORD0_SIZE)
1155 p = xdr_encode_hyper(p, iap->ia_size);
1156 if (bmval[1] & FATTR4_WORD1_MODE)
1157 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1158 if (bmval[1] & FATTR4_WORD1_OWNER)
1159 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1160 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1161 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1162 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1163 if (iap->ia_valid & ATTR_ATIME_SET) {
1164 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1165 p = xdr_encode_nfstime4(p, &iap->ia_atime);
1167 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1169 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1170 if (iap->ia_valid & ATTR_MTIME_SET) {
1171 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1172 p = xdr_encode_nfstime4(p, &iap->ia_mtime);
1174 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1176 if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1177 *p++ = cpu_to_be32(label->lfs);
1178 *p++ = cpu_to_be32(label->pi);
1179 *p++ = cpu_to_be32(label->len);
1180 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1182 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1183 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1184 *p++ = cpu_to_be32(*umask);
1190 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1192 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1193 encode_uint32(xdr, access);
1196 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1198 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1199 encode_nfs4_seqid(xdr, arg->seqid);
1200 encode_nfs4_stateid(xdr, &arg->stateid);
1203 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1207 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1208 p = reserve_space(xdr, 12);
1209 p = xdr_encode_hyper(p, args->offset);
1210 *p = cpu_to_be32(args->count);
1213 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1217 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1218 encode_uint32(xdr, create->ftype);
1220 switch (create->ftype) {
1222 p = reserve_space(xdr, 4);
1223 *p = cpu_to_be32(create->u.symlink.len);
1224 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1225 create->u.symlink.len);
1226 xdr->buf->flags |= XDRBUF_WRITE;
1229 case NF4BLK: case NF4CHR:
1230 p = reserve_space(xdr, 8);
1231 *p++ = cpu_to_be32(create->u.device.specdata1);
1232 *p = cpu_to_be32(create->u.device.specdata2);
1239 encode_string(xdr, create->name->len, create->name->name);
1240 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1241 create->server, create->server->attr_bitmask);
1244 static void encode_getattr(struct xdr_stream *xdr,
1245 const __u32 *bitmap, const __u32 *mask, size_t len,
1246 struct compound_hdr *hdr)
1248 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
1250 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1252 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1253 len = ARRAY_SIZE(masked_bitmap);
1254 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1255 bitmap = masked_bitmap;
1257 xdr_encode_bitmap4(xdr, bitmap, len);
1260 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1262 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1263 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
1266 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1267 const u32 *open_bitmap,
1268 struct compound_hdr *hdr)
1270 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
1273 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1275 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1276 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
1279 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1281 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1282 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
1285 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1287 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1290 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1292 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1293 encode_string(xdr, name->len, name->name);
1296 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1298 if (fl->fl_type == F_RDLCK)
1299 return block ? NFS4_READW_LT : NFS4_READ_LT;
1300 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1303 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1305 if (fl->fl_end == OFFSET_MAX)
1306 return ~(uint64_t)0;
1307 return fl->fl_end - fl->fl_start + 1;
1310 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1314 p = reserve_space(xdr, 32);
1315 p = xdr_encode_hyper(p, lowner->clientid);
1316 *p++ = cpu_to_be32(20);
1317 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1318 *p++ = cpu_to_be32(lowner->s_dev);
1319 xdr_encode_hyper(p, lowner->id);
1323 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1324 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1326 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1330 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1331 p = reserve_space(xdr, 28);
1332 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1333 *p++ = cpu_to_be32(args->reclaim);
1334 p = xdr_encode_hyper(p, args->fl->fl_start);
1335 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1336 *p = cpu_to_be32(args->new_lock_owner);
1337 if (args->new_lock_owner){
1338 encode_nfs4_seqid(xdr, args->open_seqid);
1339 encode_nfs4_stateid(xdr, &args->open_stateid);
1340 encode_nfs4_seqid(xdr, args->lock_seqid);
1341 encode_lockowner(xdr, &args->lock_owner);
1344 encode_nfs4_stateid(xdr, &args->lock_stateid);
1345 encode_nfs4_seqid(xdr, args->lock_seqid);
1349 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1353 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1354 p = reserve_space(xdr, 20);
1355 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1356 p = xdr_encode_hyper(p, args->fl->fl_start);
1357 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1358 encode_lockowner(xdr, &args->lock_owner);
1361 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1365 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1366 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1367 encode_nfs4_seqid(xdr, args->seqid);
1368 encode_nfs4_stateid(xdr, &args->stateid);
1369 p = reserve_space(xdr, 16);
1370 p = xdr_encode_hyper(p, args->fl->fl_start);
1371 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1374 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1376 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1377 encode_lockowner(xdr, lowner);
1380 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1382 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1383 encode_string(xdr, name->len, name->name);
1386 static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1388 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1391 static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
1395 p = reserve_space(xdr, 8);
1396 *p++ = cpu_to_be32(share_access);
1397 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1400 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1404 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1407 encode_nfs4_seqid(xdr, arg->seqid);
1408 encode_share_access(xdr, arg->share_access);
1409 p = reserve_space(xdr, 36);
1410 p = xdr_encode_hyper(p, arg->clientid);
1411 *p++ = cpu_to_be32(24);
1412 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1413 *p++ = cpu_to_be32(arg->server->s_dev);
1414 *p++ = cpu_to_be32(arg->id.uniquifier);
1415 xdr_encode_hyper(p, arg->id.create_time);
1418 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1422 p = reserve_space(xdr, 4);
1423 switch(arg->createmode) {
1424 case NFS4_CREATE_UNCHECKED:
1425 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1426 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1427 arg->server, arg->server->attr_bitmask);
1429 case NFS4_CREATE_GUARDED:
1430 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1431 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1432 arg->server, arg->server->attr_bitmask);
1434 case NFS4_CREATE_EXCLUSIVE:
1435 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1436 encode_nfs4_verifier(xdr, &arg->u.verifier);
1438 case NFS4_CREATE_EXCLUSIVE4_1:
1439 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1440 encode_nfs4_verifier(xdr, &arg->u.verifier);
1441 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1442 arg->server, arg->server->exclcreat_bitmask);
1446 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1450 p = reserve_space(xdr, 4);
1451 switch (arg->open_flags & O_CREAT) {
1453 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1456 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1457 encode_createmode(xdr, arg);
1461 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1465 p = reserve_space(xdr, 4);
1466 switch (delegation_type) {
1468 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1471 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1473 case FMODE_WRITE|FMODE_READ:
1474 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1481 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1485 p = reserve_space(xdr, 4);
1486 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1487 encode_string(xdr, name->len, name->name);
1490 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1494 p = reserve_space(xdr, 4);
1495 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1496 encode_delegation_type(xdr, type);
1499 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1503 p = reserve_space(xdr, 4);
1504 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1505 encode_nfs4_stateid(xdr, stateid);
1506 encode_string(xdr, name->len, name->name);
1509 static inline void encode_claim_fh(struct xdr_stream *xdr)
1513 p = reserve_space(xdr, 4);
1514 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1517 static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1521 p = reserve_space(xdr, 4);
1522 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1523 encode_nfs4_stateid(xdr, stateid);
1526 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1528 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1529 encode_openhdr(xdr, arg);
1530 encode_opentype(xdr, arg);
1531 switch (arg->claim) {
1532 case NFS4_OPEN_CLAIM_NULL:
1533 encode_claim_null(xdr, arg->name);
1535 case NFS4_OPEN_CLAIM_PREVIOUS:
1536 encode_claim_previous(xdr, arg->u.delegation_type);
1538 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1539 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1541 case NFS4_OPEN_CLAIM_FH:
1542 encode_claim_fh(xdr);
1544 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1545 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1552 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1554 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1555 encode_nfs4_stateid(xdr, arg->stateid);
1556 encode_nfs4_seqid(xdr, arg->seqid);
1559 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1561 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1562 encode_nfs4_stateid(xdr, &arg->stateid);
1563 encode_nfs4_seqid(xdr, arg->seqid);
1564 encode_share_access(xdr, arg->share_access);
1568 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1570 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1571 encode_string(xdr, fh->size, fh->data);
1574 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1576 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1579 static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1580 struct compound_hdr *hdr)
1584 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1585 encode_nfs4_stateid(xdr, &args->stateid);
1587 p = reserve_space(xdr, 12);
1588 p = xdr_encode_hyper(p, args->offset);
1589 *p = cpu_to_be32(args->count);
1592 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1594 uint32_t attrs[3] = {
1595 FATTR4_WORD0_RDATTR_ERROR,
1596 FATTR4_WORD1_MOUNTED_ON_FILEID,
1598 uint32_t dircount = readdir->count >> 1;
1600 uint32_t attrlen = 0;
1603 if (readdir->plus) {
1604 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1605 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1606 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1607 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1608 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1609 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1610 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1613 /* Use mounted_on_fileid only if the server supports it */
1614 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1615 attrs[0] |= FATTR4_WORD0_FILEID;
1616 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1617 attrs[i] &= readdir->bitmask[i];
1622 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1623 encode_uint64(xdr, readdir->cookie);
1624 encode_nfs4_verifier(xdr, &readdir->verifier);
1625 p = reserve_space(xdr, 12 + (attrlen << 2));
1626 *p++ = cpu_to_be32(dircount);
1627 *p++ = cpu_to_be32(readdir->count);
1628 *p++ = cpu_to_be32(attrlen);
1629 for (i = 0; i < attrlen; i++)
1630 *p++ = cpu_to_be32(attrs[i]);
1631 memcpy(verf, readdir->verifier.data, sizeof(verf));
1633 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1635 (unsigned long long)readdir->cookie,
1637 attrs[0] & readdir->bitmask[0],
1638 attrs[1] & readdir->bitmask[1],
1639 attrs[2] & readdir->bitmask[2]);
1642 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1644 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1647 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1649 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1650 encode_string(xdr, name->len, name->name);
1653 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1655 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1656 encode_string(xdr, oldname->len, oldname->name);
1657 encode_string(xdr, newname->len, newname->name);
1660 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1661 struct compound_hdr *hdr)
1663 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1664 encode_uint64(xdr, clid);
1668 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1670 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1674 encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1675 struct compound_hdr *hdr)
1679 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1680 encode_nfs4_stateid(xdr, &zero_stateid);
1681 p = reserve_space(xdr, 2*4);
1682 *p++ = cpu_to_be32(1);
1683 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1684 p = reserve_space(xdr, 4);
1685 *p = cpu_to_be32(arg->acl_len);
1686 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
1690 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1692 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1695 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1697 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1698 encode_nfs4_stateid(xdr, &arg->stateid);
1699 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1700 server->attr_bitmask);
1703 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1707 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1708 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1710 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1711 setclientid->sc_clnt->cl_owner_id);
1712 p = reserve_space(xdr, 4);
1713 *p = cpu_to_be32(setclientid->sc_prog);
1714 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1715 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1716 p = reserve_space(xdr, 4);
1717 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
1720 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1722 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1723 decode_setclientid_confirm_maxsz, hdr);
1724 encode_uint64(xdr, arg->clientid);
1725 encode_nfs4_verifier(xdr, &arg->confirm);
1728 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1729 struct compound_hdr *hdr)
1733 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1734 encode_nfs4_stateid(xdr, &args->stateid);
1736 p = reserve_space(xdr, 16);
1737 p = xdr_encode_hyper(p, args->offset);
1738 *p++ = cpu_to_be32(args->stable);
1739 *p = cpu_to_be32(args->count);
1741 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1744 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1746 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1747 encode_nfs4_stateid(xdr, stateid);
1750 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1752 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1753 encode_string(xdr, name->len, name->name);
1756 #if defined(CONFIG_NFS_V4_1)
1757 /* NFSv4.1 operations */
1758 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1759 const struct nfs41_bind_conn_to_session_args *args,
1760 struct compound_hdr *hdr)
1764 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1765 decode_bind_conn_to_session_maxsz, hdr);
1766 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1767 p = xdr_reserve_space(xdr, 8);
1768 *p++ = cpu_to_be32(args->dir);
1769 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
1772 static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
1775 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1776 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1777 encode_uint32(xdr, op_map->u.words[i]);
1780 static void encode_exchange_id(struct xdr_stream *xdr,
1781 const struct nfs41_exchange_id_args *args,
1782 struct compound_hdr *hdr)
1785 char impl_name[IMPL_NAME_LIMIT];
1788 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1789 encode_nfs4_verifier(xdr, &args->verifier);
1791 encode_string(xdr, strlen(args->client->cl_owner_id),
1792 args->client->cl_owner_id);
1794 encode_uint32(xdr, args->flags);
1795 encode_uint32(xdr, args->state_protect.how);
1797 switch (args->state_protect.how) {
1801 encode_op_map(xdr, &args->state_protect.enforce);
1802 encode_op_map(xdr, &args->state_protect.allow);
1809 if (send_implementation_id &&
1810 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1811 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1812 <= sizeof(impl_name) + 1)
1813 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1814 utsname()->sysname, utsname()->release,
1815 utsname()->version, utsname()->machine);
1818 encode_uint32(xdr, 1); /* implementation id array length=1 */
1821 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1822 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1823 encode_string(xdr, len, impl_name);
1824 /* just send zeros for nii_date - the date is in nii_name */
1825 p = reserve_space(xdr, 12);
1826 p = xdr_encode_hyper(p, 0);
1827 *p = cpu_to_be32(0);
1829 encode_uint32(xdr, 0); /* implementation id array length=0 */
1832 static void encode_create_session(struct xdr_stream *xdr,
1833 const struct nfs41_create_session_args *args,
1834 struct compound_hdr *hdr)
1837 struct nfs_client *clp = args->client;
1838 struct rpc_clnt *clnt = clp->cl_rpcclient;
1839 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1840 u32 max_resp_sz_cached;
1843 * Assumes OPEN is the biggest non-idempotent compound.
1844 * 2 is the verifier.
1846 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1847 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
1849 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1850 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
1851 p = xdr_encode_hyper(p, args->clientid);
1852 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
1853 *p++ = cpu_to_be32(args->flags); /*flags */
1856 *p++ = cpu_to_be32(0); /* header padding size */
1857 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1858 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1859 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1860 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1861 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1862 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1865 *p++ = cpu_to_be32(0); /* header padding size */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1869 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1870 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1871 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1873 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1874 *p++ = cpu_to_be32(1);
1875 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1877 /* authsys_parms rfc1831 */
1878 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
1879 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1880 *p++ = cpu_to_be32(0); /* UID */
1881 *p++ = cpu_to_be32(0); /* GID */
1882 *p = cpu_to_be32(0); /* No more gids */
1885 static void encode_destroy_session(struct xdr_stream *xdr,
1886 const struct nfs4_session *session,
1887 struct compound_hdr *hdr)
1889 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1890 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1893 static void encode_destroy_clientid(struct xdr_stream *xdr,
1895 struct compound_hdr *hdr)
1897 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1898 encode_uint64(xdr, clientid);
1901 static void encode_reclaim_complete(struct xdr_stream *xdr,
1902 const struct nfs41_reclaim_complete_args *args,
1903 struct compound_hdr *hdr)
1905 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1906 encode_uint32(xdr, args->one_fs);
1908 #endif /* CONFIG_NFS_V4_1 */
1910 static void encode_sequence(struct xdr_stream *xdr,
1911 const struct nfs4_sequence_args *args,
1912 struct compound_hdr *hdr)
1914 #if defined(CONFIG_NFS_V4_1)
1915 struct nfs4_session *session;
1916 struct nfs4_slot_table *tp;
1917 struct nfs4_slot *slot = args->sa_slot;
1921 session = tp->session;
1925 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1928 * Sessionid + seqid + slotid + max slotid + cache_this
1930 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1931 "max_slotid=%d cache_this=%d\n",
1933 ((u32 *)session->sess_id.data)[0],
1934 ((u32 *)session->sess_id.data)[1],
1935 ((u32 *)session->sess_id.data)[2],
1936 ((u32 *)session->sess_id.data)[3],
1937 slot->seq_nr, slot->slot_nr,
1938 tp->highest_used_slotid, args->sa_cache_this);
1939 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1940 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1941 *p++ = cpu_to_be32(slot->seq_nr);
1942 *p++ = cpu_to_be32(slot->slot_nr);
1943 *p++ = cpu_to_be32(tp->highest_used_slotid);
1944 *p = cpu_to_be32(args->sa_cache_this);
1945 #endif /* CONFIG_NFS_V4_1 */
1948 #ifdef CONFIG_NFS_V4_1
1950 encode_getdeviceinfo(struct xdr_stream *xdr,
1951 const struct nfs4_getdeviceinfo_args *args,
1952 struct compound_hdr *hdr)
1956 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1957 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1958 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1959 NFS4_DEVICEID4_SIZE);
1960 *p++ = cpu_to_be32(args->pdev->layout_type);
1961 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1963 p = reserve_space(xdr, 4 + 4);
1964 *p++ = cpu_to_be32(1); /* bitmap length */
1965 *p++ = cpu_to_be32(args->notify_types);
1969 encode_layoutget(struct xdr_stream *xdr,
1970 const struct nfs4_layoutget_args *args,
1971 struct compound_hdr *hdr)
1975 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1976 p = reserve_space(xdr, 36);
1977 *p++ = cpu_to_be32(0); /* Signal layout available */
1978 *p++ = cpu_to_be32(args->type);
1979 *p++ = cpu_to_be32(args->range.iomode);
1980 p = xdr_encode_hyper(p, args->range.offset);
1981 p = xdr_encode_hyper(p, args->range.length);
1982 p = xdr_encode_hyper(p, args->minlength);
1983 encode_nfs4_stateid(xdr, &args->stateid);
1984 encode_uint32(xdr, args->maxcount);
1986 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1990 (unsigned long)args->range.offset,
1991 (unsigned long)args->range.length,
1996 encode_layoutcommit(struct xdr_stream *xdr,
1997 struct inode *inode,
1998 const struct nfs4_layoutcommit_args *args,
1999 struct compound_hdr *hdr)
2003 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2004 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2006 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2007 p = reserve_space(xdr, 20);
2008 /* Only whole file layouts */
2009 p = xdr_encode_hyper(p, 0); /* offset */
2010 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
2011 *p = cpu_to_be32(0); /* reclaim */
2012 encode_nfs4_stateid(xdr, &args->stateid);
2013 if (args->lastbytewritten != U64_MAX) {
2014 p = reserve_space(xdr, 20);
2015 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2016 p = xdr_encode_hyper(p, args->lastbytewritten);
2018 p = reserve_space(xdr, 12);
2019 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2021 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2022 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2024 encode_uint32(xdr, args->layoutupdate_len);
2025 if (args->layoutupdate_pages)
2026 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2027 args->layoutupdate_len);
2033 encode_layoutreturn(struct xdr_stream *xdr,
2034 const struct nfs4_layoutreturn_args *args,
2035 struct compound_hdr *hdr)
2039 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2040 p = reserve_space(xdr, 16);
2041 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2042 *p++ = cpu_to_be32(args->layout_type);
2043 *p++ = cpu_to_be32(args->range.iomode);
2044 *p = cpu_to_be32(RETURN_FILE);
2045 p = reserve_space(xdr, 16);
2046 p = xdr_encode_hyper(p, args->range.offset);
2047 p = xdr_encode_hyper(p, args->range.length);
2048 spin_lock(&args->inode->i_lock);
2049 encode_nfs4_stateid(xdr, &args->stateid);
2050 spin_unlock(&args->inode->i_lock);
2051 if (args->ld_private->ops && args->ld_private->ops->encode)
2052 args->ld_private->ops->encode(xdr, args, args->ld_private);
2054 encode_uint32(xdr, 0);
2058 encode_secinfo_no_name(struct xdr_stream *xdr,
2059 const struct nfs41_secinfo_no_name_args *args,
2060 struct compound_hdr *hdr)
2062 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2063 encode_uint32(xdr, args->style);
2067 static void encode_test_stateid(struct xdr_stream *xdr,
2068 const struct nfs41_test_stateid_args *args,
2069 struct compound_hdr *hdr)
2071 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2072 encode_uint32(xdr, 1);
2073 encode_nfs4_stateid(xdr, args->stateid);
2076 static void encode_free_stateid(struct xdr_stream *xdr,
2077 const struct nfs41_free_stateid_args *args,
2078 struct compound_hdr *hdr)
2080 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2081 encode_nfs4_stateid(xdr, &args->stateid);
2085 encode_layoutreturn(struct xdr_stream *xdr,
2086 const struct nfs4_layoutreturn_args *args,
2087 struct compound_hdr *hdr)
2092 encode_layoutget(struct xdr_stream *xdr,
2093 const struct nfs4_layoutget_args *args,
2094 struct compound_hdr *hdr)
2097 #endif /* CONFIG_NFS_V4_1 */
2100 * END OF "GENERIC" ENCODE ROUTINES.
2103 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2105 #if defined(CONFIG_NFS_V4_1)
2106 struct nfs4_session *session = args->sa_slot->table->session;
2108 return session->clp->cl_mvops->minor_version;
2109 #endif /* CONFIG_NFS_V4_1 */
2114 * Encode an ACCESS request
2116 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2119 const struct nfs4_accessargs *args = data;
2120 struct compound_hdr hdr = {
2121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2124 encode_compound_hdr(xdr, req, &hdr);
2125 encode_sequence(xdr, &args->seq_args, &hdr);
2126 encode_putfh(xdr, args->fh, &hdr);
2127 encode_access(xdr, args->access, &hdr);
2129 encode_getfattr(xdr, args->bitmask, &hdr);
2134 * Encode LOOKUP request
2136 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2139 const struct nfs4_lookup_arg *args = data;
2140 struct compound_hdr hdr = {
2141 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2144 encode_compound_hdr(xdr, req, &hdr);
2145 encode_sequence(xdr, &args->seq_args, &hdr);
2146 encode_putfh(xdr, args->dir_fh, &hdr);
2147 encode_lookup(xdr, args->name, &hdr);
2148 encode_getfh(xdr, &hdr);
2149 encode_getfattr(xdr, args->bitmask, &hdr);
2154 * Encode LOOKUPP request
2156 static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs4_lookupp_arg *args = data;
2160 struct compound_hdr hdr = {
2161 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2164 encode_compound_hdr(xdr, req, &hdr);
2165 encode_sequence(xdr, &args->seq_args, &hdr);
2166 encode_putfh(xdr, args->fh, &hdr);
2167 encode_lookupp(xdr, &hdr);
2168 encode_getfh(xdr, &hdr);
2169 encode_getfattr(xdr, args->bitmask, &hdr);
2174 * Encode LOOKUP_ROOT request
2176 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2177 struct xdr_stream *xdr,
2180 const struct nfs4_lookup_root_arg *args = data;
2181 struct compound_hdr hdr = {
2182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putrootfh(xdr, &hdr);
2188 encode_getfh(xdr, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
2194 * Encode REMOVE request
2196 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2199 const struct nfs_removeargs *args = data;
2200 struct compound_hdr hdr = {
2201 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2204 encode_compound_hdr(xdr, req, &hdr);
2205 encode_sequence(xdr, &args->seq_args, &hdr);
2206 encode_putfh(xdr, args->fh, &hdr);
2207 encode_remove(xdr, &args->name, &hdr);
2212 * Encode RENAME request
2214 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2217 const struct nfs_renameargs *args = data;
2218 struct compound_hdr hdr = {
2219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->old_dir, &hdr);
2225 encode_savefh(xdr, &hdr);
2226 encode_putfh(xdr, args->new_dir, &hdr);
2227 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2232 * Encode LINK request
2234 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2237 const struct nfs4_link_arg *args = data;
2238 struct compound_hdr hdr = {
2239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2242 encode_compound_hdr(xdr, req, &hdr);
2243 encode_sequence(xdr, &args->seq_args, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_savefh(xdr, &hdr);
2246 encode_putfh(xdr, args->dir_fh, &hdr);
2247 encode_link(xdr, args->name, &hdr);
2248 encode_restorefh(xdr, &hdr);
2249 encode_getfattr(xdr, args->bitmask, &hdr);
2254 * Encode CREATE request
2256 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2259 const struct nfs4_create_arg *args = data;
2260 struct compound_hdr hdr = {
2261 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2264 encode_compound_hdr(xdr, req, &hdr);
2265 encode_sequence(xdr, &args->seq_args, &hdr);
2266 encode_putfh(xdr, args->dir_fh, &hdr);
2267 encode_create(xdr, args, &hdr);
2268 encode_getfh(xdr, &hdr);
2269 encode_getfattr(xdr, args->bitmask, &hdr);
2274 * Encode SYMLINK request
2276 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2279 const struct nfs4_create_arg *args = data;
2281 nfs4_xdr_enc_create(req, xdr, args);
2285 * Encode GETATTR request
2287 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2290 const struct nfs4_getattr_arg *args = data;
2291 struct compound_hdr hdr = {
2292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_getfattr(xdr, args->bitmask, &hdr);
2303 * Encode a CLOSE request
2305 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2308 const struct nfs_closeargs *args = data;
2309 struct compound_hdr hdr = {
2310 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2313 encode_compound_hdr(xdr, req, &hdr);
2314 encode_sequence(xdr, &args->seq_args, &hdr);
2315 encode_putfh(xdr, args->fh, &hdr);
2317 encode_layoutreturn(xdr, args->lr_args, &hdr);
2318 if (args->bitmask != NULL)
2319 encode_getfattr(xdr, args->bitmask, &hdr);
2320 encode_close(xdr, args, &hdr);
2325 * Encode an OPEN request
2327 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2330 const struct nfs_openargs *args = data;
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);
2339 encode_getfh(xdr, &hdr);
2341 encode_access(xdr, args->access, &hdr);
2342 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2343 if (args->lg_args) {
2344 encode_layoutget(xdr, args->lg_args, &hdr);
2345 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2346 args->lg_args->layout.pglen,
2347 hdr.replen - pagepad_maxsz);
2353 * Encode an OPEN_CONFIRM request
2355 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2356 struct xdr_stream *xdr,
2359 const struct nfs_open_confirmargs *args = data;
2360 struct compound_hdr hdr = {
2364 encode_compound_hdr(xdr, req, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_open_confirm(xdr, args, &hdr);
2371 * Encode an OPEN request with no attributes.
2373 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2374 struct xdr_stream *xdr,
2377 const struct nfs_openargs *args = data;
2378 struct compound_hdr hdr = {
2379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2382 encode_compound_hdr(xdr, req, &hdr);
2383 encode_sequence(xdr, &args->seq_args, &hdr);
2384 encode_putfh(xdr, args->fh, &hdr);
2385 encode_open(xdr, args, &hdr);
2387 encode_access(xdr, args->access, &hdr);
2388 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2389 if (args->lg_args) {
2390 encode_layoutget(xdr, args->lg_args, &hdr);
2391 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2392 args->lg_args->layout.pglen,
2393 hdr.replen - pagepad_maxsz);
2399 * Encode an OPEN_DOWNGRADE request
2401 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2402 struct xdr_stream *xdr,
2405 const struct nfs_closeargs *args = data;
2406 struct compound_hdr hdr = {
2407 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2410 encode_compound_hdr(xdr, req, &hdr);
2411 encode_sequence(xdr, &args->seq_args, &hdr);
2412 encode_putfh(xdr, args->fh, &hdr);
2414 encode_layoutreturn(xdr, args->lr_args, &hdr);
2415 encode_open_downgrade(xdr, args, &hdr);
2420 * Encode a LOCK request
2422 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2425 const struct nfs_lock_args *args = data;
2426 struct compound_hdr hdr = {
2427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2430 encode_compound_hdr(xdr, req, &hdr);
2431 encode_sequence(xdr, &args->seq_args, &hdr);
2432 encode_putfh(xdr, args->fh, &hdr);
2433 encode_lock(xdr, args, &hdr);
2438 * Encode a LOCKT request
2440 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2443 const struct nfs_lockt_args *args = data;
2444 struct compound_hdr hdr = {
2445 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2448 encode_compound_hdr(xdr, req, &hdr);
2449 encode_sequence(xdr, &args->seq_args, &hdr);
2450 encode_putfh(xdr, args->fh, &hdr);
2451 encode_lockt(xdr, args, &hdr);
2456 * Encode a LOCKU request
2458 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2461 const struct nfs_locku_args *args = data;
2462 struct compound_hdr hdr = {
2463 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2466 encode_compound_hdr(xdr, req, &hdr);
2467 encode_sequence(xdr, &args->seq_args, &hdr);
2468 encode_putfh(xdr, args->fh, &hdr);
2469 encode_locku(xdr, args, &hdr);
2473 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2474 struct xdr_stream *xdr,
2477 const struct nfs_release_lockowner_args *args = data;
2478 struct compound_hdr hdr = {
2482 encode_compound_hdr(xdr, req, &hdr);
2483 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2488 * Encode a READLINK request
2490 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2493 const struct nfs4_readlink *args = data;
2494 struct compound_hdr hdr = {
2495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_readlink(xdr, args, req, &hdr);
2503 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2504 args->pglen, hdr.replen - pagepad_maxsz);
2509 * Encode a READDIR request
2511 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2514 const struct nfs4_readdir_arg *args = data;
2515 struct compound_hdr hdr = {
2516 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2519 encode_compound_hdr(xdr, req, &hdr);
2520 encode_sequence(xdr, &args->seq_args, &hdr);
2521 encode_putfh(xdr, args->fh, &hdr);
2522 encode_readdir(xdr, args, req, &hdr);
2524 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2525 args->count, hdr.replen - pagepad_maxsz);
2530 * Encode a READ request
2532 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2535 const struct nfs_pgio_args *args = data;
2536 struct compound_hdr hdr = {
2537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_read(xdr, args, &hdr);
2545 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2546 args->count, hdr.replen - pagepad_maxsz);
2547 req->rq_rcv_buf.flags |= XDRBUF_READ;
2552 * Encode an SETATTR request
2554 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2557 const struct nfs_setattrargs *args = data;
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_setattr(xdr, args, args->server, &hdr);
2566 encode_getfattr(xdr, args->bitmask, &hdr);
2571 * Encode a GETACL request
2573 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2576 const struct nfs_getaclargs *args = data;
2577 struct compound_hdr hdr = {
2578 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2580 const __u32 nfs4_acl_bitmap[1] = {
2581 [0] = FATTR4_WORD0_ACL,
2585 encode_compound_hdr(xdr, req, &hdr);
2586 encode_sequence(xdr, &args->seq_args, &hdr);
2587 encode_putfh(xdr, args->fh, &hdr);
2588 replen = hdr.replen + op_decode_hdr_maxsz;
2589 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2590 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
2592 rpc_prepare_reply_pages(req, args->acl_pages, 0,
2593 args->acl_len, replen);
2598 * Encode a WRITE request
2600 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2603 const struct nfs_pgio_args *args = data;
2604 struct compound_hdr hdr = {
2605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->fh, &hdr);
2611 encode_write(xdr, args, &hdr);
2612 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2614 encode_getfattr(xdr, args->bitmask, &hdr);
2621 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2624 const struct nfs_commitargs *args = data;
2625 struct compound_hdr hdr = {
2626 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2629 encode_compound_hdr(xdr, req, &hdr);
2630 encode_sequence(xdr, &args->seq_args, &hdr);
2631 encode_putfh(xdr, args->fh, &hdr);
2632 encode_commit(xdr, args, &hdr);
2639 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2642 const struct nfs4_fsinfo_arg *args = data;
2643 struct compound_hdr hdr = {
2644 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2647 encode_compound_hdr(xdr, req, &hdr);
2648 encode_sequence(xdr, &args->seq_args, &hdr);
2649 encode_putfh(xdr, args->fh, &hdr);
2650 encode_fsinfo(xdr, args->bitmask, &hdr);
2655 * a PATHCONF request
2657 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2660 const struct nfs4_pathconf_arg *args = data;
2661 struct compound_hdr hdr = {
2662 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2665 encode_compound_hdr(xdr, req, &hdr);
2666 encode_sequence(xdr, &args->seq_args, &hdr);
2667 encode_putfh(xdr, args->fh, &hdr);
2668 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2669 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
2676 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2679 const struct nfs4_statfs_arg *args = data;
2680 struct compound_hdr hdr = {
2681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_sequence(xdr, &args->seq_args, &hdr);
2686 encode_putfh(xdr, args->fh, &hdr);
2687 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2688 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
2693 * GETATTR_BITMAP request
2695 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2696 struct xdr_stream *xdr,
2699 const struct nfs4_server_caps_arg *args = data;
2700 const u32 *bitmask = args->bitmask;
2701 struct compound_hdr hdr = {
2702 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2705 encode_compound_hdr(xdr, req, &hdr);
2706 encode_sequence(xdr, &args->seq_args, &hdr);
2707 encode_putfh(xdr, args->fhandle, &hdr);
2708 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
2715 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2719 const struct nfs_client *clp = data;
2720 struct compound_hdr hdr = {
2724 encode_compound_hdr(xdr, req, &hdr);
2725 encode_renew(xdr, clp->cl_clientid, &hdr);
2730 * a SETCLIENTID request
2732 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2733 struct xdr_stream *xdr,
2736 const struct nfs4_setclientid *sc = data;
2737 struct compound_hdr hdr = {
2741 encode_compound_hdr(xdr, req, &hdr);
2742 encode_setclientid(xdr, sc, &hdr);
2747 * a SETCLIENTID_CONFIRM request
2749 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2753 const struct nfs4_setclientid_res *arg = data;
2754 struct compound_hdr hdr = {
2758 encode_compound_hdr(xdr, req, &hdr);
2759 encode_setclientid_confirm(xdr, arg, &hdr);
2764 * DELEGRETURN request
2766 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2767 struct xdr_stream *xdr,
2770 const struct nfs4_delegreturnargs *args = data;
2771 struct compound_hdr hdr = {
2772 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2775 encode_compound_hdr(xdr, req, &hdr);
2776 encode_sequence(xdr, &args->seq_args, &hdr);
2777 encode_putfh(xdr, args->fhandle, &hdr);
2779 encode_layoutreturn(xdr, args->lr_args, &hdr);
2781 encode_getfattr(xdr, args->bitmask, &hdr);
2782 encode_delegreturn(xdr, args->stateid, &hdr);
2787 * Encode FS_LOCATIONS request
2789 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2790 struct xdr_stream *xdr,
2793 const struct nfs4_fs_locations_arg *args = data;
2794 struct compound_hdr hdr = {
2795 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2799 encode_compound_hdr(xdr, req, &hdr);
2800 encode_sequence(xdr, &args->seq_args, &hdr);
2801 if (args->migration) {
2802 encode_putfh(xdr, args->fh, &hdr);
2803 replen = hdr.replen;
2804 encode_fs_locations(xdr, args->bitmask, &hdr);
2806 encode_renew(xdr, args->clientid, &hdr);
2808 encode_putfh(xdr, args->dir_fh, &hdr);
2809 encode_lookup(xdr, args->name, &hdr);
2810 replen = hdr.replen;
2811 encode_fs_locations(xdr, args->bitmask, &hdr);
2814 rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
2820 * Encode SECINFO request
2822 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2823 struct xdr_stream *xdr,
2826 const struct nfs4_secinfo_arg *args = data;
2827 struct compound_hdr hdr = {
2828 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2831 encode_compound_hdr(xdr, req, &hdr);
2832 encode_sequence(xdr, &args->seq_args, &hdr);
2833 encode_putfh(xdr, args->dir_fh, &hdr);
2834 encode_secinfo(xdr, args->name, &hdr);
2839 * Encode FSID_PRESENT request
2841 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
2845 const struct nfs4_fsid_present_arg *args = data;
2846 struct compound_hdr hdr = {
2847 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2850 encode_compound_hdr(xdr, req, &hdr);
2851 encode_sequence(xdr, &args->seq_args, &hdr);
2852 encode_putfh(xdr, args->fh, &hdr);
2853 encode_getfh(xdr, &hdr);
2855 encode_renew(xdr, args->clientid, &hdr);
2859 #if defined(CONFIG_NFS_V4_1)
2861 * BIND_CONN_TO_SESSION request
2863 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2864 struct xdr_stream *xdr,
2867 const struct nfs41_bind_conn_to_session_args *args = data;
2868 struct compound_hdr hdr = {
2869 .minorversion = args->client->cl_mvops->minor_version,
2872 encode_compound_hdr(xdr, req, &hdr);
2873 encode_bind_conn_to_session(xdr, args, &hdr);
2878 * EXCHANGE_ID request
2880 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2881 struct xdr_stream *xdr,
2884 const struct nfs41_exchange_id_args *args = data;
2885 struct compound_hdr hdr = {
2886 .minorversion = args->client->cl_mvops->minor_version,
2889 encode_compound_hdr(xdr, req, &hdr);
2890 encode_exchange_id(xdr, args, &hdr);
2895 * a CREATE_SESSION request
2897 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2898 struct xdr_stream *xdr,
2901 const struct nfs41_create_session_args *args = data;
2902 struct compound_hdr hdr = {
2903 .minorversion = args->client->cl_mvops->minor_version,
2906 encode_compound_hdr(xdr, req, &hdr);
2907 encode_create_session(xdr, args, &hdr);
2912 * a DESTROY_SESSION request
2914 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2915 struct xdr_stream *xdr,
2918 const struct nfs4_session *session = data;
2919 struct compound_hdr hdr = {
2920 .minorversion = session->clp->cl_mvops->minor_version,
2923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_destroy_session(xdr, session, &hdr);
2929 * a DESTROY_CLIENTID request
2931 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2932 struct xdr_stream *xdr,
2935 const struct nfs_client *clp = data;
2936 struct compound_hdr hdr = {
2937 .minorversion = clp->cl_mvops->minor_version,
2940 encode_compound_hdr(xdr, req, &hdr);
2941 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2946 * a SEQUENCE request
2948 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2951 const struct nfs4_sequence_args *args = data;
2952 struct compound_hdr hdr = {
2953 .minorversion = nfs4_xdr_minorversion(args),
2956 encode_compound_hdr(xdr, req, &hdr);
2957 encode_sequence(xdr, args, &hdr);
2964 * a GET_LEASE_TIME request
2966 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2967 struct xdr_stream *xdr,
2970 const struct nfs4_get_lease_time_args *args = data;
2971 struct compound_hdr hdr = {
2972 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2974 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2976 encode_compound_hdr(xdr, req, &hdr);
2977 encode_sequence(xdr, &args->la_seq_args, &hdr);
2978 encode_putrootfh(xdr, &hdr);
2979 encode_fsinfo(xdr, lease_bitmap, &hdr);
2983 #ifdef CONFIG_NFS_V4_1
2986 * a RECLAIM_COMPLETE request
2988 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2989 struct xdr_stream *xdr,
2992 const struct nfs41_reclaim_complete_args *args = data;
2993 struct compound_hdr hdr = {
2994 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2997 encode_compound_hdr(xdr, req, &hdr);
2998 encode_sequence(xdr, &args->seq_args, &hdr);
2999 encode_reclaim_complete(xdr, args, &hdr);
3004 * Encode GETDEVICEINFO request
3006 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3007 struct xdr_stream *xdr,
3010 const struct nfs4_getdeviceinfo_args *args = data;
3011 struct compound_hdr hdr = {
3012 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3016 encode_compound_hdr(xdr, req, &hdr);
3017 encode_sequence(xdr, &args->seq_args, &hdr);
3019 replen = hdr.replen + op_decode_hdr_maxsz + 2;
3021 encode_getdeviceinfo(xdr, args, &hdr);
3023 /* set up reply kvec. device_addr4 opaque data is read into the
3025 rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
3026 args->pdev->pglen, replen);
3031 * Encode LAYOUTGET request
3033 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3034 struct xdr_stream *xdr,
3037 const struct nfs4_layoutget_args *args = data;
3038 struct compound_hdr hdr = {
3039 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3042 encode_compound_hdr(xdr, req, &hdr);
3043 encode_sequence(xdr, &args->seq_args, &hdr);
3044 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3045 encode_layoutget(xdr, args, &hdr);
3047 rpc_prepare_reply_pages(req, args->layout.pages, 0,
3048 args->layout.pglen, hdr.replen - pagepad_maxsz);
3053 * Encode LAYOUTCOMMIT request
3055 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3056 struct xdr_stream *xdr,
3059 const struct nfs4_layoutcommit_args *args = priv;
3060 struct nfs4_layoutcommit_data *data =
3061 container_of(args, struct nfs4_layoutcommit_data, args);
3062 struct compound_hdr hdr = {
3063 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3066 encode_compound_hdr(xdr, req, &hdr);
3067 encode_sequence(xdr, &args->seq_args, &hdr);
3068 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3069 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
3070 encode_getfattr(xdr, args->bitmask, &hdr);
3075 * Encode LAYOUTRETURN request
3077 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3078 struct xdr_stream *xdr,
3081 const struct nfs4_layoutreturn_args *args = data;
3082 struct compound_hdr hdr = {
3083 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3086 encode_compound_hdr(xdr, req, &hdr);
3087 encode_sequence(xdr, &args->seq_args, &hdr);
3088 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3089 encode_layoutreturn(xdr, args, &hdr);
3094 * Encode SECINFO_NO_NAME request
3096 static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3097 struct xdr_stream *xdr,
3100 const struct nfs41_secinfo_no_name_args *args = data;
3101 struct compound_hdr hdr = {
3102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3105 encode_compound_hdr(xdr, req, &hdr);
3106 encode_sequence(xdr, &args->seq_args, &hdr);
3107 encode_putrootfh(xdr, &hdr);
3108 encode_secinfo_no_name(xdr, args, &hdr);
3113 * Encode TEST_STATEID request
3115 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3116 struct xdr_stream *xdr,
3119 const struct nfs41_test_stateid_args *args = data;
3120 struct compound_hdr hdr = {
3121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3124 encode_compound_hdr(xdr, req, &hdr);
3125 encode_sequence(xdr, &args->seq_args, &hdr);
3126 encode_test_stateid(xdr, args, &hdr);
3131 * Encode FREE_STATEID request
3133 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3134 struct xdr_stream *xdr,
3137 const struct nfs41_free_stateid_args *args = data;
3138 struct compound_hdr hdr = {
3139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3142 encode_compound_hdr(xdr, req, &hdr);
3143 encode_sequence(xdr, &args->seq_args, &hdr);
3144 encode_free_stateid(xdr, args, &hdr);
3147 #endif /* CONFIG_NFS_V4_1 */
3149 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3151 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3153 if (unlikely(ret < 0))
3159 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3163 p = xdr_inline_decode(xdr, 8);
3166 hdr->status = be32_to_cpup(p++);
3167 hdr->taglen = be32_to_cpup(p);
3169 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3172 hdr->tag = (char *)p;
3173 p += XDR_QUADLEN(hdr->taglen);
3174 hdr->nops = be32_to_cpup(p);
3175 if (unlikely(hdr->nops < 1))
3176 return nfs4_stat_to_errno(hdr->status);
3180 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3187 p = xdr_inline_decode(xdr, 8);
3190 opnum = be32_to_cpup(p++);
3191 if (unlikely(opnum != expected))
3192 goto out_bad_operation;
3193 if (unlikely(*p != cpu_to_be32(NFS_OK)))
3198 nfserr = be32_to_cpup(p);
3199 trace_nfs4_xdr_status(xdr, opnum, nfserr);
3200 *nfs_retval = nfs4_stat_to_errno(nfserr);
3203 dprintk("nfs: Server returned operation"
3204 " %d but we issued a request for %d\n",
3206 *nfs_retval = -EREMOTEIO;
3213 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3217 __decode_op_hdr(xdr, expected, &retval);
3222 static int decode_ace(struct xdr_stream *xdr, void *ace)
3225 unsigned int strlen;
3228 p = xdr_inline_decode(xdr, 12);
3231 return decode_opaque_inline(xdr, &strlen, &str);
3235 decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
3239 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3240 if (likely(ret >= 0))
3242 if (ret != -EMSGSIZE)
3247 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3250 ret = decode_bitmap4(xdr, bitmap, 3);
3251 return ret < 0 ? ret : 0;
3254 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3258 p = xdr_inline_decode(xdr, 4);
3261 *attrlen = be32_to_cpup(p);
3262 *savep = xdr_stream_pos(xdr);
3266 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3268 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3270 ret = decode_attr_bitmap(xdr, bitmask);
3271 if (unlikely(ret < 0))
3273 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3275 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3276 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3277 bitmask[0], bitmask[1], bitmask[2]);
3281 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3287 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3289 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3290 p = xdr_inline_decode(xdr, 4);
3293 *type = be32_to_cpup(p);
3294 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3295 dprintk("%s: bad type %d\n", __func__, *type);
3298 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3299 ret = NFS_ATTR_FATTR_TYPE;
3301 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3305 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3306 uint32_t *bitmap, uint32_t *type)
3311 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3313 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3314 p = xdr_inline_decode(xdr, 4);
3317 *type = be32_to_cpup(p);
3318 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3320 dprintk("%s: expire type=0x%x\n", __func__, *type);
3324 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3330 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3332 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3333 p = xdr_inline_decode(xdr, 8);
3336 xdr_decode_hyper(p, change);
3337 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3338 ret = NFS_ATTR_FATTR_CHANGE;
3340 dprintk("%s: change attribute=%Lu\n", __func__,
3341 (unsigned long long)*change);
3345 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3351 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3353 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3354 p = xdr_inline_decode(xdr, 8);
3357 xdr_decode_hyper(p, size);
3358 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3359 ret = NFS_ATTR_FATTR_SIZE;
3361 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3365 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3370 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3372 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3373 p = xdr_inline_decode(xdr, 4);
3376 *res = be32_to_cpup(p);
3377 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3379 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3383 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3388 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3390 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3391 p = xdr_inline_decode(xdr, 4);
3394 *res = be32_to_cpup(p);
3395 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3397 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3401 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3408 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3410 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3411 p = xdr_inline_decode(xdr, 16);
3414 p = xdr_decode_hyper(p, &fsid->major);
3415 xdr_decode_hyper(p, &fsid->minor);
3416 bitmap[0] &= ~FATTR4_WORD0_FSID;
3417 ret = NFS_ATTR_FATTR_FSID;
3419 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3420 (unsigned long long)fsid->major,
3421 (unsigned long long)fsid->minor);
3425 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3430 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3432 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3433 p = xdr_inline_decode(xdr, 4);
3436 *res = be32_to_cpup(p);
3437 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3439 dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
3443 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3447 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3449 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3450 p = xdr_inline_decode(xdr, 4);
3453 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3454 *res = -be32_to_cpup(p);
3459 static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3460 uint32_t *bitmap, uint32_t *bitmask)
3462 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3464 ret = decode_attr_bitmap(xdr, bitmask);
3465 if (unlikely(ret < 0))
3467 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3469 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3470 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3471 bitmask[0], bitmask[1], bitmask[2]);
3475 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3481 memset(fh, 0, sizeof(*fh));
3483 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3485 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3486 p = xdr_inline_decode(xdr, 4);
3489 len = be32_to_cpup(p);
3490 if (len > NFS4_FHSIZE)
3492 p = xdr_inline_decode(xdr, len);
3496 memcpy(fh->data, p, len);
3499 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3504 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3509 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3511 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3512 p = xdr_inline_decode(xdr, 4);
3515 *res = be32_to_cpup(p);
3516 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3518 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3522 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3528 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3530 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3531 p = xdr_inline_decode(xdr, 8);
3534 xdr_decode_hyper(p, fileid);
3535 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3536 ret = NFS_ATTR_FATTR_FILEID;
3538 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3542 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3548 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3550 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3551 p = xdr_inline_decode(xdr, 8);
3554 xdr_decode_hyper(p, fileid);
3555 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3556 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3558 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3562 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3568 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3570 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3571 p = xdr_inline_decode(xdr, 8);
3574 xdr_decode_hyper(p, res);
3575 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3577 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3581 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3587 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3589 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3590 p = xdr_inline_decode(xdr, 8);
3593 xdr_decode_hyper(p, res);
3594 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3596 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3600 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3606 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3608 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3609 p = xdr_inline_decode(xdr, 8);
3612 xdr_decode_hyper(p, res);
3613 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3615 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3619 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3625 p = xdr_inline_decode(xdr, 4);
3628 n = be32_to_cpup(p);
3631 dprintk("pathname4: ");
3632 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3633 dprintk("cannot parse %d components in path\n", n);
3636 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3637 struct nfs4_string *component = &path->components[path->ncomponents];
3638 status = decode_opaque_inline(xdr, &component->len, &component->data);
3639 if (unlikely(status != 0))
3643 (path->ncomponents != n ? "/ " : ""),
3644 component->len, component->data);
3649 /* a root pathname is sent as a zero component4 */
3650 path->ncomponents = 1;
3651 path->components[0].len=0;
3652 path->components[0].data=NULL;
3653 dprintk("pathname4: /\n");
3656 dprintk(" status %d", status);
3661 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3667 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3670 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3672 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
3674 /* Ignore borken servers that return unrequested attrs */
3675 if (unlikely(res == NULL))
3677 dprintk("%s: fsroot:\n", __func__);
3678 status = decode_pathname(xdr, &res->fs_path);
3679 if (unlikely(status != 0))
3681 p = xdr_inline_decode(xdr, 4);
3684 n = be32_to_cpup(p);
3687 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3689 struct nfs4_fs_location *loc;
3691 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3693 loc = &res->locations[res->nlocations];
3694 p = xdr_inline_decode(xdr, 4);
3697 m = be32_to_cpup(p);
3699 dprintk("%s: servers:\n", __func__);
3700 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3701 struct nfs4_string *server;
3703 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3705 dprintk("%s: using first %u of %u servers "
3706 "returned for location %u\n",
3708 NFS4_FS_LOCATION_MAXSERVERS,
3709 m, res->nlocations);
3710 for (i = loc->nservers; i < m; i++) {
3713 status = decode_opaque_inline(xdr, &len, &data);
3714 if (unlikely(status != 0))
3719 server = &loc->servers[loc->nservers];
3720 status = decode_opaque_inline(xdr, &server->len, &server->data);
3721 if (unlikely(status != 0))
3723 dprintk("%s ", server->data);
3725 status = decode_pathname(xdr, &loc->rootpath);
3726 if (unlikely(status != 0))
3729 if (res->nlocations != 0)
3730 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3732 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3739 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3745 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3747 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3748 p = xdr_inline_decode(xdr, 8);
3751 xdr_decode_hyper(p, res);
3752 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3754 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3758 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3764 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3766 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3767 p = xdr_inline_decode(xdr, 4);
3770 *maxlink = be32_to_cpup(p);
3771 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3773 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3777 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3783 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3785 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3786 p = xdr_inline_decode(xdr, 4);
3789 *maxname = be32_to_cpup(p);
3790 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3792 dprintk("%s: maxname=%u\n", __func__, *maxname);
3796 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3802 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3804 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3806 p = xdr_inline_decode(xdr, 8);
3809 xdr_decode_hyper(p, &maxread);
3810 if (maxread > 0x7FFFFFFF)
3811 maxread = 0x7FFFFFFF;
3812 *res = (uint32_t)maxread;
3813 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3815 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3819 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3825 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3827 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3829 p = xdr_inline_decode(xdr, 8);
3832 xdr_decode_hyper(p, &maxwrite);
3833 if (maxwrite > 0x7FFFFFFF)
3834 maxwrite = 0x7FFFFFFF;
3835 *res = (uint32_t)maxwrite;
3836 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3838 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3842 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3849 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3851 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3852 p = xdr_inline_decode(xdr, 4);
3855 tmp = be32_to_cpup(p);
3856 *mode = tmp & ~S_IFMT;
3857 bitmap[1] &= ~FATTR4_WORD1_MODE;
3858 ret = NFS_ATTR_FATTR_MODE;
3860 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3864 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3870 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3872 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3873 p = xdr_inline_decode(xdr, 4);
3876 *nlink = be32_to_cpup(p);
3877 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3878 ret = NFS_ATTR_FATTR_NLINK;
3880 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3884 static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3885 struct nfs4_string *name, gfp_t gfp_flags)
3889 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3890 XDR_MAX_NETOBJ, gfp_flags);
3897 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3898 const struct nfs_server *server, kuid_t *uid,
3899 struct nfs4_string *owner_name)
3904 *uid = make_kuid(&init_user_ns, -2);
3905 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3907 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3909 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3911 if (owner_name != NULL) {
3912 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
3915 dprintk("%s: name=%s\n", __func__, owner_name->data);
3916 return NFS_ATTR_FATTR_OWNER_NAME;
3918 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3920 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3922 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3923 return NFS_ATTR_FATTR_OWNER;
3926 if (len == -EBADMSG)
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)
3938 *gid = make_kgid(&init_user_ns, -2);
3939 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3941 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3943 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3945 if (group_name != NULL) {
3946 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
3949 dprintk("%s: name=%s\n", __func__, group_name->data);
3950 return NFS_ATTR_FATTR_GROUP_NAME;
3952 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3954 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3956 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3957 return NFS_ATTR_FATTR_GROUP;
3960 if (len == -EBADMSG)
3965 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3967 uint32_t major = 0, minor = 0;
3972 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3974 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3977 p = xdr_inline_decode(xdr, 8);
3980 major = be32_to_cpup(p++);
3981 minor = be32_to_cpup(p);
3982 tmp = MKDEV(major, minor);
3983 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3985 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3986 ret = NFS_ATTR_FATTR_RDEV;
3988 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3992 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3998 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4000 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4001 p = xdr_inline_decode(xdr, 8);
4004 xdr_decode_hyper(p, res);
4005 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4007 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
4011 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4017 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4019 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4020 p = xdr_inline_decode(xdr, 8);
4023 xdr_decode_hyper(p, res);
4024 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4026 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
4030 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4036 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4038 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4039 p = xdr_inline_decode(xdr, 8);
4042 xdr_decode_hyper(p, res);
4043 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4045 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4049 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4055 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4057 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4058 p = xdr_inline_decode(xdr, 8);
4061 xdr_decode_hyper(p, used);
4062 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4063 ret = NFS_ATTR_FATTR_SPACE_USED;
4065 dprintk("%s: space used=%Lu\n", __func__,
4066 (unsigned long long)*used);
4071 xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
4075 p = xdr_decode_hyper(p, &sec);
4077 t->tv_nsec = be32_to_cpup(p++);
4081 static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
4085 p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
4088 xdr_decode_nfstime4(p, time);
4092 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4098 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4100 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4101 status = decode_attr_time(xdr, time);
4103 status = NFS_ATTR_FATTR_ATIME;
4104 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4106 dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
4110 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4116 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4118 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4119 status = decode_attr_time(xdr, time);
4121 status = NFS_ATTR_FATTR_CTIME;
4122 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4124 dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
4128 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4129 struct timespec64 *time)
4135 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4137 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4138 status = decode_attr_time(xdr, time);
4139 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4141 dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4146 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4147 struct nfs4_label *label)
4155 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4157 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4158 p = xdr_inline_decode(xdr, 4);
4161 lfs = be32_to_cpup(p++);
4162 p = xdr_inline_decode(xdr, 4);
4165 pi = be32_to_cpup(p++);
4166 p = xdr_inline_decode(xdr, 4);
4169 len = be32_to_cpup(p++);
4170 p = xdr_inline_decode(xdr, len);
4173 if (len < NFS4_MAXLABELLEN) {
4176 if (label->len < len)
4178 memcpy(label->label, p, len);
4183 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4185 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4187 printk(KERN_WARNING "%s: label too long (%u)!\n",
4190 if (label && label->label)
4191 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4192 (char *)label->label, label->len, label->pi, label->lfs);
4196 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4202 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4204 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4205 status = decode_attr_time(xdr, time);
4207 status = NFS_ATTR_FATTR_MTIME;
4208 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4210 dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
4214 static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
4220 if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
4222 if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
4223 p = xdr_inline_decode(xdr, 4);
4226 *res = be32_to_cpup(p);
4227 bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
4229 dprintk("%s: XATTR support=%s\n", __func__,
4230 *res == 0 ? "false" : "true");
4234 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4236 unsigned int attrwords = XDR_QUADLEN(attrlen);
4237 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4239 if (unlikely(attrwords != nwords)) {
4240 dprintk("%s: server returned incorrect attribute length: "
4244 (attrwords < nwords) ? '<' : '>',
4251 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4255 p = xdr_inline_decode(xdr, 20);
4258 cinfo->atomic = be32_to_cpup(p++);
4259 p = xdr_decode_hyper(p, &cinfo->before);
4260 xdr_decode_hyper(p, &cinfo->after);
4264 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4270 status = decode_op_hdr(xdr, OP_ACCESS);
4273 p = xdr_inline_decode(xdr, 8);
4276 supp = be32_to_cpup(p++);
4277 acc = be32_to_cpup(p);
4283 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4285 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4286 if (unlikely(ret < 0))
4291 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4293 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4296 static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4298 stateid->type = NFS4_OPEN_STATEID_TYPE;
4299 return decode_stateid(xdr, stateid);
4302 static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4304 stateid->type = NFS4_LOCK_STATEID_TYPE;
4305 return decode_stateid(xdr, stateid);
4308 static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4310 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4311 return decode_stateid(xdr, stateid);
4314 static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4318 nfs4_stateid_copy(stateid, &invalid_stateid);
4319 return decode_stateid(xdr, &dummy);
4322 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4326 status = decode_op_hdr(xdr, OP_CLOSE);
4328 nfs_increment_open_seqid(status, res->seqid);
4330 status = decode_invalid_stateid(xdr, &res->stateid);
4334 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4336 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4339 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4341 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4344 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4346 struct nfs_writeverf *verf = res->verf;
4349 status = decode_op_hdr(xdr, OP_COMMIT);
4351 status = decode_write_verifier(xdr, &verf->verifier);
4353 verf->committed = NFS_FILE_SYNC;
4357 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4363 status = decode_op_hdr(xdr, OP_CREATE);
4366 if ((status = decode_change_info(xdr, cinfo)))
4368 p = xdr_inline_decode(xdr, 4);
4371 bmlen = be32_to_cpup(p);
4372 p = xdr_inline_decode(xdr, bmlen << 2);
4378 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4381 uint32_t attrlen, bitmap[3] = {0};
4384 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4386 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4388 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4390 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4392 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4393 &res->fh_expire_type)) != 0)
4395 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4397 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4399 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4401 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4402 res->exclcreat_bitmask)) != 0)
4404 status = verify_attr_len(xdr, savep, attrlen);
4406 dprintk("%s: xdr returned %d!\n", __func__, -status);
4410 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4413 uint32_t attrlen, bitmap[3] = {0};
4416 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4418 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4420 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4423 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4425 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4427 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4431 if (unlikely(bitmap[0]))
4434 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4436 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4438 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4441 status = verify_attr_len(xdr, savep, attrlen);
4443 dprintk("%s: xdr returned %d!\n", __func__, -status);
4447 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4450 uint32_t attrlen, bitmap[3] = {0};
4453 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4455 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4457 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4460 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4462 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4465 status = verify_attr_len(xdr, savep, attrlen);
4467 dprintk("%s: xdr returned %d!\n", __func__, -status);
4471 static int decode_threshold_hint(struct xdr_stream *xdr,
4479 if (likely(bitmap[0] & hint_bit)) {
4480 p = xdr_inline_decode(xdr, 8);
4483 xdr_decode_hyper(p, res);
4488 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4489 struct nfs4_threshold *res)
4493 uint32_t bitmap[3] = {0,}, attrlen;
4497 p = xdr_inline_decode(xdr, 4);
4500 res->l_type = be32_to_cpup(p);
4502 /* thi_hintset bitmap */
4503 status = decode_attr_bitmap(xdr, bitmap);
4507 /* thi_hintlist length */
4508 status = decode_attr_length(xdr, &attrlen, &savep);
4512 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4515 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4518 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4522 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4527 status = verify_attr_len(xdr, savep, attrlen);
4528 res->bm = bitmap[0];
4530 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4531 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4534 dprintk("%s ret=%d!\n", __func__, status);
4539 * Thresholds on pNFS direct I/O vrs MDS I/O
4541 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4543 struct nfs4_threshold *res)
4549 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4551 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4552 /* Did the server return an unrequested attribute? */
4553 if (unlikely(res == NULL))
4555 p = xdr_inline_decode(xdr, 4);
4558 num = be32_to_cpup(p);
4562 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4563 "drivers per filesystem not supported\n",
4566 status = decode_first_threshold_item4(xdr, res);
4567 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4572 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4573 struct nfs_fattr *fattr, struct nfs_fh *fh,
4574 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4575 const struct nfs_server *server)
4582 status = decode_attr_type(xdr, bitmap, &type);
4587 fattr->mode |= nfs_type2fmt[type];
4588 fattr->valid |= status;
4591 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4594 fattr->valid |= status;
4596 status = decode_attr_size(xdr, bitmap, &fattr->size);
4599 fattr->valid |= status;
4601 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4604 fattr->valid |= status;
4607 status = decode_attr_error(xdr, bitmap, &err);
4611 status = decode_attr_filehandle(xdr, bitmap, fh);
4615 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4618 fattr->valid |= status;
4620 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4623 fattr->valid |= status;
4626 if (unlikely(bitmap[0]))
4629 status = decode_attr_mode(xdr, bitmap, &fmode);
4633 fattr->mode |= fmode;
4634 fattr->valid |= status;
4637 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4640 fattr->valid |= status;
4642 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4645 fattr->valid |= status;
4647 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4650 fattr->valid |= status;
4652 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4655 fattr->valid |= status;
4657 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4660 fattr->valid |= status;
4662 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4665 fattr->valid |= status;
4667 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4670 fattr->valid |= status;
4672 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4675 fattr->valid |= status;
4677 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4680 fattr->valid |= status;
4683 if (unlikely(bitmap[1]))
4686 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4691 status = decode_attr_security_label(xdr, bitmap, label);
4694 fattr->valid |= status;
4698 dprintk("%s: xdr returned %d\n", __func__, -status);
4702 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4703 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4704 struct nfs4_label *label, const struct nfs_server *server)
4711 status = decode_op_hdr(xdr, OP_GETATTR);
4715 status = decode_attr_bitmap(xdr, bitmap);
4719 status = decode_attr_length(xdr, &attrlen, &savep);
4723 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4728 status = verify_attr_len(xdr, savep, attrlen);
4730 dprintk("%s: xdr returned %d\n", __func__, -status);
4734 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4735 struct nfs4_label *label, const struct nfs_server *server)
4737 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4740 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4741 const struct nfs_server *server)
4743 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4747 * Decode potentially multiple layout types.
4749 static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4750 struct nfs_fsinfo *fsinfo)
4755 p = xdr_inline_decode(xdr, 4);
4758 fsinfo->nlayouttypes = be32_to_cpup(p);
4760 /* pNFS is not supported by the underlying file system */
4761 if (fsinfo->nlayouttypes == 0)
4764 /* Decode and set first layout type, move xdr->p past unused types */
4765 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4769 /* If we get too many, then just cap it at the max */
4770 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4771 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4772 __func__, fsinfo->nlayouttypes);
4773 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4776 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4777 fsinfo->layouttype[i] = be32_to_cpup(p++);
4782 * The type of file system exported.
4783 * Note we must ensure that layouttype is set in any non-error case.
4785 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4786 struct nfs_fsinfo *fsinfo)
4790 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4791 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4793 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4794 status = decode_pnfs_layout_types(xdr, fsinfo);
4795 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4801 * The prefered block size for layout directed io
4803 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4808 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4810 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4811 p = xdr_inline_decode(xdr, 4);
4814 *res = be32_to_cpup(p);
4815 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4821 * The granularity of a CLONE operation.
4823 static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4828 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4830 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4831 p = xdr_inline_decode(xdr, 4);
4834 *res = be32_to_cpup(p);
4835 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4840 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4843 uint32_t attrlen, bitmap[3];
4846 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4848 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4850 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4853 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4855 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4857 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4859 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4861 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4862 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4864 fsinfo->wtpref = fsinfo->wtmax;
4867 if (unlikely(bitmap[0]))
4870 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4873 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4878 if (unlikely(bitmap[1]))
4881 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4884 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4888 status = decode_attr_xattrsupport(xdr, bitmap,
4889 &fsinfo->xattr_support);
4893 status = verify_attr_len(xdr, savep, attrlen);
4895 dprintk("%s: xdr returned %d!\n", __func__, -status);
4899 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4905 /* Zero handle first to allow comparisons */
4906 memset(fh, 0, sizeof(*fh));
4908 status = decode_op_hdr(xdr, OP_GETFH);
4912 p = xdr_inline_decode(xdr, 4);
4915 len = be32_to_cpup(p);
4916 if (len > NFS4_FHSIZE)
4919 p = xdr_inline_decode(xdr, len);
4922 memcpy(fh->data, p, len);
4926 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4930 status = decode_op_hdr(xdr, OP_LINK);
4933 return decode_change_info(xdr, cinfo);
4937 * We create the owner, so we know a proper owner.id length is 4.
4939 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4941 uint64_t offset, length, clientid;
4943 uint32_t namelen, type;
4945 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4948 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4949 p = xdr_decode_hyper(p, &length);
4950 type = be32_to_cpup(p++); /* 4 byte read */
4951 if (fl != NULL) { /* manipulate file lock */
4952 fl->fl_start = (loff_t)offset;
4953 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4954 if (length == ~(uint64_t)0)
4955 fl->fl_end = OFFSET_MAX;
4956 fl->fl_type = F_WRLCK;
4958 fl->fl_type = F_RDLCK;
4961 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4962 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4963 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4966 return -NFS4ERR_DENIED;
4969 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4973 status = decode_op_hdr(xdr, OP_LOCK);
4977 status = decode_lock_stateid(xdr, &res->stateid);
4978 if (unlikely(status))
4980 } else if (status == -NFS4ERR_DENIED)
4981 status = decode_lock_denied(xdr, NULL);
4982 if (res->open_seqid != NULL)
4983 nfs_increment_open_seqid(status, res->open_seqid);
4984 nfs_increment_lock_seqid(status, res->lock_seqid);
4989 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4992 status = decode_op_hdr(xdr, OP_LOCKT);
4993 if (status == -NFS4ERR_DENIED)
4994 return decode_lock_denied(xdr, res->denied);
4998 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
5002 status = decode_op_hdr(xdr, OP_LOCKU);
5004 nfs_increment_lock_seqid(status, res->seqid);
5006 status = decode_lock_stateid(xdr, &res->stateid);
5010 static int decode_release_lockowner(struct xdr_stream *xdr)
5012 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5015 static int decode_lookup(struct xdr_stream *xdr)
5017 return decode_op_hdr(xdr, OP_LOOKUP);
5020 static int decode_lookupp(struct xdr_stream *xdr)
5022 return decode_op_hdr(xdr, OP_LOOKUPP);
5025 /* This is too sick! */
5026 static int decode_space_limit(struct xdr_stream *xdr,
5027 unsigned long *pagemod_limit)
5030 uint32_t limit_type, nblocks, blocksize;
5033 p = xdr_inline_decode(xdr, 12);
5036 limit_type = be32_to_cpup(p++);
5037 switch (limit_type) {
5038 case NFS4_LIMIT_SIZE:
5039 xdr_decode_hyper(p, &maxsize);
5041 case NFS4_LIMIT_BLOCKS:
5042 nblocks = be32_to_cpup(p++);
5043 blocksize = be32_to_cpup(p);
5044 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
5046 maxsize >>= PAGE_SHIFT;
5047 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
5051 static int decode_rw_delegation(struct xdr_stream *xdr,
5052 uint32_t delegation_type,
5053 struct nfs_openres *res)
5058 status = decode_delegation_stateid(xdr, &res->delegation);
5059 if (unlikely(status))
5061 p = xdr_inline_decode(xdr, 4);
5064 res->do_recall = be32_to_cpup(p);
5066 switch (delegation_type) {
5067 case NFS4_OPEN_DELEGATE_READ:
5068 res->delegation_type = FMODE_READ;
5070 case NFS4_OPEN_DELEGATE_WRITE:
5071 res->delegation_type = FMODE_WRITE|FMODE_READ;
5072 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
5075 return decode_ace(xdr, NULL);
5078 static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5081 uint32_t why_no_delegation;
5083 p = xdr_inline_decode(xdr, 4);
5086 why_no_delegation = be32_to_cpup(p);
5087 switch (why_no_delegation) {
5088 case WND4_CONTENTION:
5090 xdr_inline_decode(xdr, 4);
5091 /* Ignore for now */
5096 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5099 uint32_t delegation_type;
5101 p = xdr_inline_decode(xdr, 4);
5104 delegation_type = be32_to_cpup(p);
5105 res->delegation_type = 0;
5106 switch (delegation_type) {
5107 case NFS4_OPEN_DELEGATE_NONE:
5109 case NFS4_OPEN_DELEGATE_READ:
5110 case NFS4_OPEN_DELEGATE_WRITE:
5111 return decode_rw_delegation(xdr, delegation_type, res);
5112 case NFS4_OPEN_DELEGATE_NONE_EXT:
5113 return decode_no_delegation(xdr, res);
5118 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5121 uint32_t savewords, bmlen, i;
5124 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5126 nfs_increment_open_seqid(status, res->seqid);
5129 status = decode_open_stateid(xdr, &res->stateid);
5130 if (unlikely(status))
5133 decode_change_info(xdr, &res->cinfo);
5135 p = xdr_inline_decode(xdr, 8);
5138 res->rflags = be32_to_cpup(p++);
5139 bmlen = be32_to_cpup(p);
5143 p = xdr_inline_decode(xdr, bmlen << 2);
5146 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5147 for (i = 0; i < savewords; ++i)
5148 res->attrset[i] = be32_to_cpup(p++);
5149 for (; i < NFS4_BITMAP_SIZE; i++)
5150 res->attrset[i] = 0;
5152 return decode_delegation(xdr, res);
5154 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5158 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5162 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5164 nfs_increment_open_seqid(status, res->seqid);
5166 status = decode_open_stateid(xdr, &res->stateid);
5170 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5174 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5176 nfs_increment_open_seqid(status, res->seqid);
5178 status = decode_open_stateid(xdr, &res->stateid);
5182 static int decode_putfh(struct xdr_stream *xdr)
5184 return decode_op_hdr(xdr, OP_PUTFH);
5187 static int decode_putrootfh(struct xdr_stream *xdr)
5189 return decode_op_hdr(xdr, OP_PUTROOTFH);
5192 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5193 struct nfs_pgio_res *res)
5196 uint32_t count, eof, recvd;
5199 status = decode_op_hdr(xdr, OP_READ);
5202 p = xdr_inline_decode(xdr, 8);
5205 eof = be32_to_cpup(p++);
5206 count = be32_to_cpup(p);
5207 recvd = xdr_read_pages(xdr, count);
5208 if (count > recvd) {
5209 dprintk("NFS: server cheating in read reply: "
5210 "count %u > recvd %u\n", count, recvd);
5219 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5224 status = decode_op_hdr(xdr, OP_READDIR);
5226 status = decode_verifier(xdr, readdir->verifier.data);
5227 if (unlikely(status))
5229 memcpy(verf, readdir->verifier.data, sizeof(verf));
5230 dprintk("%s: verifier = %08x:%08x\n",
5231 __func__, verf[0], verf[1]);
5232 return xdr_read_pages(xdr, xdr->buf->page_len);
5235 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5237 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5242 status = decode_op_hdr(xdr, OP_READLINK);
5246 /* Convert length of symlink */
5247 p = xdr_inline_decode(xdr, 4);
5250 len = be32_to_cpup(p);
5251 if (len >= rcvbuf->page_len || len <= 0) {
5252 dprintk("nfs: server returned giant symlink!\n");
5253 return -ENAMETOOLONG;
5255 recvd = xdr_read_pages(xdr, len);
5257 dprintk("NFS: server cheating in readlink reply: "
5258 "count %u > recvd %u\n", len, recvd);
5262 * The XDR encode routine has set things up so that
5263 * the link text will be copied directly into the
5264 * buffer. We just have to do overflow-checking,
5265 * and null-terminate the text (the VFS expects
5266 * null-termination).
5268 xdr_terminate_string(rcvbuf, len);
5272 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5276 status = decode_op_hdr(xdr, OP_REMOVE);
5279 status = decode_change_info(xdr, cinfo);
5284 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5285 struct nfs4_change_info *new_cinfo)
5289 status = decode_op_hdr(xdr, OP_RENAME);
5292 if ((status = decode_change_info(xdr, old_cinfo)))
5294 status = decode_change_info(xdr, new_cinfo);
5299 static int decode_renew(struct xdr_stream *xdr)
5301 return decode_op_hdr(xdr, OP_RENEW);
5305 decode_restorefh(struct xdr_stream *xdr)
5307 return decode_op_hdr(xdr, OP_RESTOREFH);
5310 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5311 struct nfs_getaclres *res)
5319 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5322 xdr_enter_page(xdr, xdr->buf->page_len);
5324 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5326 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5329 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5331 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5333 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5334 * are stored with the acl data to handle the problem of
5335 * variable length bitmaps.*/
5336 res->acl_data_offset = xdr_page_pos(xdr);
5337 res->acl_len = attrlen;
5339 /* Check for receive buffer overflow */
5340 if (res->acl_len > xdr_stream_remaining(xdr) ||
5341 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5342 res->acl_flags |= NFS4_ACL_TRUNC;
5343 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
5344 attrlen, xdr_stream_remaining(xdr));
5347 status = -EOPNOTSUPP;
5354 decode_savefh(struct xdr_stream *xdr)
5356 return decode_op_hdr(xdr, OP_SAVEFH);
5359 static int decode_setattr(struct xdr_stream *xdr)
5363 status = decode_op_hdr(xdr, OP_SETATTR);
5366 if (decode_bitmap4(xdr, NULL, 0) >= 0)
5371 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5377 p = xdr_inline_decode(xdr, 8);
5380 opnum = be32_to_cpup(p++);
5381 if (opnum != OP_SETCLIENTID) {
5382 dprintk("nfs: decode_setclientid: Server returned operation"
5386 nfserr = be32_to_cpup(p);
5387 if (nfserr == NFS_OK) {
5388 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5391 p = xdr_decode_hyper(p, &res->clientid);
5392 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5393 } else if (nfserr == NFSERR_CLID_INUSE) {
5396 /* skip netid string */
5397 p = xdr_inline_decode(xdr, 4);
5400 len = be32_to_cpup(p);
5401 p = xdr_inline_decode(xdr, len);
5405 /* skip uaddr string */
5406 p = xdr_inline_decode(xdr, 4);
5409 len = be32_to_cpup(p);
5410 p = xdr_inline_decode(xdr, len);
5413 return -NFSERR_CLID_INUSE;
5415 return nfs4_stat_to_errno(nfserr);
5420 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5422 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5425 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5430 status = decode_op_hdr(xdr, OP_WRITE);
5434 p = xdr_inline_decode(xdr, 8);
5437 res->count = be32_to_cpup(p++);
5438 res->verf->committed = be32_to_cpup(p++);
5439 return decode_write_verifier(xdr, &res->verf->verifier);
5442 static int decode_delegreturn(struct xdr_stream *xdr)
5444 return decode_op_hdr(xdr, OP_DELEGRETURN);
5447 static int decode_secinfo_gss(struct xdr_stream *xdr,
5448 struct nfs4_secinfo4 *flavor)
5453 p = xdr_inline_decode(xdr, 4);
5456 oid_len = be32_to_cpup(p);
5457 if (oid_len > GSS_OID_MAX_LEN)
5460 p = xdr_inline_decode(xdr, oid_len);
5463 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5464 flavor->flavor_info.oid.len = oid_len;
5466 p = xdr_inline_decode(xdr, 8);
5469 flavor->flavor_info.qop = be32_to_cpup(p++);
5470 flavor->flavor_info.service = be32_to_cpup(p);
5475 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5477 struct nfs4_secinfo4 *sec_flavor;
5478 unsigned int i, num_flavors;
5482 p = xdr_inline_decode(xdr, 4);
5486 res->flavors->num_flavors = 0;
5487 num_flavors = be32_to_cpup(p);
5489 for (i = 0; i < num_flavors; i++) {
5490 sec_flavor = &res->flavors->flavors[i];
5491 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5494 p = xdr_inline_decode(xdr, 4);
5497 sec_flavor->flavor = be32_to_cpup(p);
5499 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5500 status = decode_secinfo_gss(xdr, sec_flavor);
5504 res->flavors->num_flavors++;
5512 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5514 int status = decode_op_hdr(xdr, OP_SECINFO);
5517 return decode_secinfo_common(xdr, res);
5520 #if defined(CONFIG_NFS_V4_1)
5521 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5523 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5526 return decode_secinfo_common(xdr, res);
5529 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5532 uint32_t bitmap_words;
5535 p = xdr_inline_decode(xdr, 4);
5538 bitmap_words = be32_to_cpup(p++);
5539 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5541 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5542 for (i = 0; i < bitmap_words; i++)
5543 op_map->u.words[i] = be32_to_cpup(p++);
5548 static int decode_exchange_id(struct xdr_stream *xdr,
5549 struct nfs41_exchange_id_res *res)
5555 uint32_t impl_id_count;
5557 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5561 p = xdr_inline_decode(xdr, 8);
5564 xdr_decode_hyper(p, &res->clientid);
5565 p = xdr_inline_decode(xdr, 12);
5568 res->seqid = be32_to_cpup(p++);
5569 res->flags = be32_to_cpup(p++);
5571 res->state_protect.how = be32_to_cpup(p);
5572 switch (res->state_protect.how) {
5576 status = decode_op_map(xdr, &res->state_protect.enforce);
5579 status = decode_op_map(xdr, &res->state_protect.allow);
5588 /* server_owner4.so_minor_id */
5589 p = xdr_inline_decode(xdr, 8);
5592 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5594 /* server_owner4.so_major_id */
5595 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5596 if (unlikely(status))
5598 memcpy(res->server_owner->major_id, dummy_str, dummy);
5599 res->server_owner->major_id_sz = dummy;
5602 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5603 if (unlikely(status))
5605 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5606 res->server_scope->server_scope_sz = dummy;
5608 /* Implementation Id */
5609 p = xdr_inline_decode(xdr, 4);
5612 impl_id_count = be32_to_cpup(p++);
5614 if (impl_id_count) {
5616 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5617 if (unlikely(status))
5619 memcpy(res->impl_id->domain, dummy_str, dummy);
5622 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5623 if (unlikely(status))
5625 memcpy(res->impl_id->name, dummy_str, dummy);
5628 p = xdr_inline_decode(xdr, 12);
5631 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5632 res->impl_id->date.nseconds = be32_to_cpup(p);
5634 /* if there's more than one entry, ignore the rest */
5639 static int decode_chan_attrs(struct xdr_stream *xdr,
5640 struct nfs4_channel_attrs *attrs)
5645 p = xdr_inline_decode(xdr, 28);
5648 val = be32_to_cpup(p++); /* headerpadsz */
5650 return -EINVAL; /* no support for header padding yet */
5651 attrs->max_rqst_sz = be32_to_cpup(p++);
5652 attrs->max_resp_sz = be32_to_cpup(p++);
5653 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5654 attrs->max_ops = be32_to_cpup(p++);
5655 attrs->max_reqs = be32_to_cpup(p++);
5656 nr_attrs = be32_to_cpup(p);
5657 if (unlikely(nr_attrs > 1)) {
5658 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5659 "count %u\n", __func__, nr_attrs);
5662 if (nr_attrs == 1) {
5663 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5670 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5672 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5675 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5676 struct nfs41_bind_conn_to_session_res *res)
5681 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5683 status = decode_sessionid(xdr, &res->sessionid);
5684 if (unlikely(status))
5687 /* dir flags, rdma mode bool */
5688 p = xdr_inline_decode(xdr, 8);
5692 res->dir = be32_to_cpup(p++);
5693 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5695 if (be32_to_cpup(p) == 0)
5696 res->use_conn_in_rdma_mode = false;
5698 res->use_conn_in_rdma_mode = true;
5703 static int decode_create_session(struct xdr_stream *xdr,
5704 struct nfs41_create_session_res *res)
5709 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5711 status = decode_sessionid(xdr, &res->sessionid);
5712 if (unlikely(status))
5716 p = xdr_inline_decode(xdr, 8);
5719 res->seqid = be32_to_cpup(p++);
5720 res->flags = be32_to_cpup(p);
5722 /* Channel attributes */
5723 status = decode_chan_attrs(xdr, &res->fc_attrs);
5725 status = decode_chan_attrs(xdr, &res->bc_attrs);
5729 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5731 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5734 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5736 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5739 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5741 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5743 #endif /* CONFIG_NFS_V4_1 */
5745 static int decode_sequence(struct xdr_stream *xdr,
5746 struct nfs4_sequence_res *res,
5747 struct rpc_rqst *rqstp)
5749 #if defined(CONFIG_NFS_V4_1)
5750 struct nfs4_session *session;
5751 struct nfs4_sessionid id;
5756 if (res->sr_slot == NULL)
5758 if (!res->sr_slot->table->session)
5761 status = decode_op_hdr(xdr, OP_SEQUENCE);
5763 status = decode_sessionid(xdr, &id);
5764 if (unlikely(status))
5768 * If the server returns different values for sessionID, slotID or
5769 * sequence number, the server is looney tunes.
5771 status = -EREMOTEIO;
5772 session = res->sr_slot->table->session;
5774 if (memcmp(id.data, session->sess_id.data,
5775 NFS4_MAX_SESSIONID_LEN)) {
5776 dprintk("%s Invalid session id\n", __func__);
5780 p = xdr_inline_decode(xdr, 20);
5785 dummy = be32_to_cpup(p++);
5786 if (dummy != res->sr_slot->seq_nr) {
5787 dprintk("%s Invalid sequence number\n", __func__);
5791 dummy = be32_to_cpup(p++);
5792 if (dummy != res->sr_slot->slot_nr) {
5793 dprintk("%s Invalid slot id\n", __func__);
5796 /* highest slot id */
5797 res->sr_highest_slotid = be32_to_cpup(p++);
5798 /* target highest slot id */
5799 res->sr_target_highest_slotid = be32_to_cpup(p++);
5801 res->sr_status_flags = be32_to_cpup(p);
5804 res->sr_status = status;
5809 #else /* CONFIG_NFS_V4_1 */
5811 #endif /* CONFIG_NFS_V4_1 */
5814 #if defined(CONFIG_NFS_V4_1)
5815 static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5817 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5818 return decode_stateid(xdr, stateid);
5821 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5822 struct nfs4_getdeviceinfo_res *res)
5824 struct pnfs_device *pdev = res->pdev;
5829 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5831 if (status == -ETOOSMALL) {
5832 p = xdr_inline_decode(xdr, 4);
5835 pdev->mincount = be32_to_cpup(p);
5836 dprintk("%s: Min count too small. mincnt = %u\n",
5837 __func__, pdev->mincount);
5842 p = xdr_inline_decode(xdr, 8);
5845 type = be32_to_cpup(p++);
5846 if (type != pdev->layout_type) {
5847 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5848 __func__, pdev->layout_type, type);
5852 * Get the length of the opaque device_addr4. xdr_read_pages places
5853 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5854 * and places the remaining xdr data in xdr_buf->tail
5856 pdev->mincount = be32_to_cpup(p);
5857 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5860 /* Parse notification bitmap, verifying that it is zero. */
5861 p = xdr_inline_decode(xdr, 4);
5864 len = be32_to_cpup(p);
5868 p = xdr_inline_decode(xdr, 4 * len);
5872 res->notification = be32_to_cpup(p++);
5873 for (i = 1; i < len; i++) {
5874 if (be32_to_cpup(p++)) {
5875 dprintk("%s: unsupported notification\n",
5884 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5885 struct nfs4_layoutget_res *res)
5892 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5895 p = xdr_inline_decode(xdr, 4);
5898 res->return_on_close = be32_to_cpup(p);
5899 decode_layout_stateid(xdr, &res->stateid);
5900 p = xdr_inline_decode(xdr, 4);
5903 layout_count = be32_to_cpup(p);
5904 if (!layout_count) {
5905 dprintk("%s: server responded with empty layout array\n",
5911 p = xdr_inline_decode(xdr, 28);
5914 p = xdr_decode_hyper(p, &res->range.offset);
5915 p = xdr_decode_hyper(p, &res->range.length);
5916 res->range.iomode = be32_to_cpup(p++);
5917 res->type = be32_to_cpup(p++);
5918 res->layoutp->len = be32_to_cpup(p);
5920 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5922 (unsigned long)res->range.offset,
5923 (unsigned long)res->range.length,
5928 recvd = xdr_read_pages(xdr, res->layoutp->len);
5929 if (res->layoutp->len > recvd) {
5930 dprintk("NFS: server cheating in layoutget reply: "
5931 "layout len %u > recvd %u\n",
5932 res->layoutp->len, recvd);
5937 if (layout_count > 1) {
5938 /* We only handle a length one array at the moment. Any
5939 * further entries are just ignored. Note that this means
5940 * the client may see a response that is less than the
5941 * minimum it requested.
5943 dprintk("%s: server responded with %d layouts, dropping tail\n",
5944 __func__, layout_count);
5948 res->status = status;
5955 static int decode_layoutreturn(struct xdr_stream *xdr,
5956 struct nfs4_layoutreturn_res *res)
5961 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5964 p = xdr_inline_decode(xdr, 4);
5967 res->lrs_present = be32_to_cpup(p);
5968 if (res->lrs_present)
5969 status = decode_layout_stateid(xdr, &res->stateid);
5971 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
5975 static int decode_layoutcommit(struct xdr_stream *xdr,
5976 struct rpc_rqst *req,
5977 struct nfs4_layoutcommit_res *res)
5983 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5984 res->status = status;
5988 p = xdr_inline_decode(xdr, 4);
5991 sizechanged = be32_to_cpup(p);
5994 /* throw away new size */
5995 p = xdr_inline_decode(xdr, 8);
6002 static int decode_test_stateid(struct xdr_stream *xdr,
6003 struct nfs41_test_stateid_res *res)
6009 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6013 p = xdr_inline_decode(xdr, 4);
6016 num_res = be32_to_cpup(p++);
6020 p = xdr_inline_decode(xdr, 4);
6023 res->status = be32_to_cpup(p++);
6028 static int decode_free_stateid(struct xdr_stream *xdr,
6029 struct nfs41_free_stateid_res *res)
6031 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
6036 int decode_layoutreturn(struct xdr_stream *xdr,
6037 struct nfs4_layoutreturn_res *res)
6042 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6043 struct nfs4_layoutget_res *res)
6048 #endif /* CONFIG_NFS_V4_1 */
6051 * END OF "GENERIC" DECODE ROUTINES.
6055 * Decode OPEN_DOWNGRADE response
6057 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6058 struct xdr_stream *xdr,
6061 struct nfs_closeres *res = data;
6062 struct compound_hdr hdr;
6065 status = decode_compound_hdr(xdr, &hdr);
6068 status = decode_sequence(xdr, &res->seq_res, rqstp);
6071 status = decode_putfh(xdr);
6075 status = decode_layoutreturn(xdr, res->lr_res);
6076 res->lr_ret = status;
6080 status = decode_open_downgrade(xdr, res);
6086 * Decode ACCESS response
6088 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6091 struct nfs4_accessres *res = data;
6092 struct compound_hdr hdr;
6095 status = decode_compound_hdr(xdr, &hdr);
6098 status = decode_sequence(xdr, &res->seq_res, rqstp);
6101 status = decode_putfh(xdr);
6104 status = decode_access(xdr, &res->supported, &res->access);
6108 decode_getfattr(xdr, res->fattr, res->server);
6114 * Decode LOOKUP response
6116 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6119 struct nfs4_lookup_res *res = data;
6120 struct compound_hdr hdr;
6123 status = decode_compound_hdr(xdr, &hdr);
6126 status = decode_sequence(xdr, &res->seq_res, rqstp);
6129 status = decode_putfh(xdr);
6132 status = decode_lookup(xdr);
6135 status = decode_getfh(xdr, res->fh);
6138 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6144 * Decode LOOKUPP response
6146 static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6149 struct nfs4_lookupp_res *res = data;
6150 struct compound_hdr hdr;
6153 status = decode_compound_hdr(xdr, &hdr);
6156 status = decode_sequence(xdr, &res->seq_res, rqstp);
6159 status = decode_putfh(xdr);
6162 status = decode_lookupp(xdr);
6165 status = decode_getfh(xdr, res->fh);
6168 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6174 * Decode LOOKUP_ROOT response
6176 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6177 struct xdr_stream *xdr,
6180 struct nfs4_lookup_res *res = data;
6181 struct compound_hdr hdr;
6184 status = decode_compound_hdr(xdr, &hdr);
6187 status = decode_sequence(xdr, &res->seq_res, rqstp);
6190 status = decode_putrootfh(xdr);
6193 status = decode_getfh(xdr, res->fh);
6195 status = decode_getfattr_label(xdr, res->fattr,
6196 res->label, res->server);
6202 * Decode REMOVE response
6204 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6207 struct nfs_removeres *res = data;
6208 struct compound_hdr hdr;
6211 status = decode_compound_hdr(xdr, &hdr);
6214 status = decode_sequence(xdr, &res->seq_res, rqstp);
6217 status = decode_putfh(xdr);
6220 status = decode_remove(xdr, &res->cinfo);
6226 * Decode RENAME response
6228 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6231 struct nfs_renameres *res = data;
6232 struct compound_hdr hdr;
6235 status = decode_compound_hdr(xdr, &hdr);
6238 status = decode_sequence(xdr, &res->seq_res, rqstp);
6241 status = decode_putfh(xdr);
6244 status = decode_savefh(xdr);
6247 status = decode_putfh(xdr);
6250 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6256 * Decode LINK response
6258 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6261 struct nfs4_link_res *res = data;
6262 struct compound_hdr hdr;
6265 status = decode_compound_hdr(xdr, &hdr);
6268 status = decode_sequence(xdr, &res->seq_res, rqstp);
6271 status = decode_putfh(xdr);
6274 status = decode_savefh(xdr);
6277 status = decode_putfh(xdr);
6280 status = decode_link(xdr, &res->cinfo);
6284 * Note order: OP_LINK leaves the directory as the current
6287 status = decode_restorefh(xdr);
6290 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6296 * Decode CREATE response
6298 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6301 struct nfs4_create_res *res = data;
6302 struct compound_hdr hdr;
6305 status = decode_compound_hdr(xdr, &hdr);
6308 status = decode_sequence(xdr, &res->seq_res, rqstp);
6311 status = decode_putfh(xdr);
6314 status = decode_create(xdr, &res->dir_cinfo);
6317 status = decode_getfh(xdr, res->fh);
6320 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6326 * Decode SYMLINK response
6328 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6331 return nfs4_xdr_dec_create(rqstp, xdr, res);
6335 * Decode GETATTR response
6337 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6340 struct nfs4_getattr_res *res = data;
6341 struct compound_hdr hdr;
6344 status = decode_compound_hdr(xdr, &hdr);
6347 status = decode_sequence(xdr, &res->seq_res, rqstp);
6350 status = decode_putfh(xdr);
6353 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6359 * Encode an SETACL request
6361 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6364 const struct nfs_setaclargs *args = data;
6365 struct compound_hdr hdr = {
6366 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6369 encode_compound_hdr(xdr, req, &hdr);
6370 encode_sequence(xdr, &args->seq_args, &hdr);
6371 encode_putfh(xdr, args->fh, &hdr);
6372 encode_setacl(xdr, args, &hdr);
6377 * Decode SETACL response
6380 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6383 struct nfs_setaclres *res = data;
6384 struct compound_hdr hdr;
6387 status = decode_compound_hdr(xdr, &hdr);
6390 status = decode_sequence(xdr, &res->seq_res, rqstp);
6393 status = decode_putfh(xdr);
6396 status = decode_setattr(xdr);
6402 * Decode GETACL response
6405 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6408 struct nfs_getaclres *res = data;
6409 struct compound_hdr hdr;
6412 if (res->acl_scratch != NULL)
6413 xdr_set_scratch_page(xdr, res->acl_scratch);
6414 status = decode_compound_hdr(xdr, &hdr);
6417 status = decode_sequence(xdr, &res->seq_res, rqstp);
6420 status = decode_putfh(xdr);
6423 status = decode_getacl(xdr, rqstp, res);
6430 * Decode CLOSE response
6432 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6435 struct nfs_closeres *res = data;
6436 struct compound_hdr hdr;
6439 status = decode_compound_hdr(xdr, &hdr);
6442 status = decode_sequence(xdr, &res->seq_res, rqstp);
6445 status = decode_putfh(xdr);
6449 status = decode_layoutreturn(xdr, res->lr_res);
6450 res->lr_ret = status;
6454 if (res->fattr != NULL) {
6455 status = decode_getfattr(xdr, res->fattr, res->server);
6459 status = decode_close(xdr, res);
6465 * Decode OPEN response
6467 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6470 struct nfs_openres *res = data;
6471 struct compound_hdr hdr;
6474 status = decode_compound_hdr(xdr, &hdr);
6477 status = decode_sequence(xdr, &res->seq_res, rqstp);
6480 status = decode_putfh(xdr);
6483 status = decode_open(xdr, res);
6486 status = decode_getfh(xdr, &res->fh);
6489 if (res->access_request)
6490 decode_access(xdr, &res->access_supported, &res->access_result);
6491 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6493 decode_layoutget(xdr, rqstp, res->lg_res);
6499 * Decode OPEN_CONFIRM response
6501 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6502 struct xdr_stream *xdr,
6505 struct nfs_open_confirmres *res = data;
6506 struct compound_hdr hdr;
6509 status = decode_compound_hdr(xdr, &hdr);
6512 status = decode_putfh(xdr);
6515 status = decode_open_confirm(xdr, res);
6521 * Decode OPEN response
6523 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6524 struct xdr_stream *xdr,
6527 struct nfs_openres *res = data;
6528 struct compound_hdr hdr;
6531 status = decode_compound_hdr(xdr, &hdr);
6534 status = decode_sequence(xdr, &res->seq_res, rqstp);
6537 status = decode_putfh(xdr);
6540 status = decode_open(xdr, res);
6543 if (res->access_request)
6544 decode_access(xdr, &res->access_supported, &res->access_result);
6545 decode_getfattr(xdr, res->f_attr, res->server);
6547 decode_layoutget(xdr, rqstp, res->lg_res);
6553 * Decode SETATTR response
6555 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6556 struct xdr_stream *xdr,
6559 struct nfs_setattrres *res = data;
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_setattr(xdr);
6575 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6581 * Decode LOCK response
6583 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6586 struct nfs_lock_res *res = data;
6587 struct compound_hdr hdr;
6590 status = decode_compound_hdr(xdr, &hdr);
6593 status = decode_sequence(xdr, &res->seq_res, rqstp);
6596 status = decode_putfh(xdr);
6599 status = decode_lock(xdr, res);
6605 * Decode LOCKT response
6607 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6610 struct nfs_lockt_res *res = data;
6611 struct compound_hdr hdr;
6614 status = decode_compound_hdr(xdr, &hdr);
6617 status = decode_sequence(xdr, &res->seq_res, rqstp);
6620 status = decode_putfh(xdr);
6623 status = decode_lockt(xdr, res);
6629 * Decode LOCKU response
6631 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6634 struct nfs_locku_res *res = data;
6635 struct compound_hdr hdr;
6638 status = decode_compound_hdr(xdr, &hdr);
6641 status = decode_sequence(xdr, &res->seq_res, rqstp);
6644 status = decode_putfh(xdr);
6647 status = decode_locku(xdr, res);
6652 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6653 struct xdr_stream *xdr, void *dummy)
6655 struct compound_hdr hdr;
6658 status = decode_compound_hdr(xdr, &hdr);
6660 status = decode_release_lockowner(xdr);
6665 * Decode READLINK response
6667 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6668 struct xdr_stream *xdr,
6671 struct nfs4_readlink_res *res = data;
6672 struct compound_hdr hdr;
6675 status = decode_compound_hdr(xdr, &hdr);
6678 status = decode_sequence(xdr, &res->seq_res, rqstp);
6681 status = decode_putfh(xdr);
6684 status = decode_readlink(xdr, rqstp);
6690 * Decode READDIR response
6692 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6695 struct nfs4_readdir_res *res = data;
6696 struct compound_hdr hdr;
6699 status = decode_compound_hdr(xdr, &hdr);
6702 status = decode_sequence(xdr, &res->seq_res, rqstp);
6705 status = decode_putfh(xdr);
6708 status = decode_readdir(xdr, rqstp, res);
6714 * Decode Read response
6716 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6719 struct nfs_pgio_res *res = data;
6720 struct compound_hdr hdr;
6723 status = decode_compound_hdr(xdr, &hdr);
6724 res->op_status = hdr.status;
6727 status = decode_sequence(xdr, &res->seq_res, rqstp);
6730 status = decode_putfh(xdr);
6733 status = decode_read(xdr, rqstp, res);
6735 status = res->count;
6741 * Decode WRITE response
6743 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6746 struct nfs_pgio_res *res = data;
6747 struct compound_hdr hdr;
6750 status = decode_compound_hdr(xdr, &hdr);
6751 res->op_status = hdr.status;
6754 status = decode_sequence(xdr, &res->seq_res, rqstp);
6757 status = decode_putfh(xdr);
6760 status = decode_write(xdr, res);
6764 decode_getfattr(xdr, res->fattr, res->server);
6766 status = res->count;
6772 * Decode COMMIT response
6774 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6777 struct nfs_commitres *res = data;
6778 struct compound_hdr hdr;
6781 status = decode_compound_hdr(xdr, &hdr);
6782 res->op_status = hdr.status;
6785 status = decode_sequence(xdr, &res->seq_res, rqstp);
6788 status = decode_putfh(xdr);
6791 status = decode_commit(xdr, res);
6797 * Decode FSINFO response
6799 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6802 struct nfs4_fsinfo_res *res = data;
6803 struct compound_hdr hdr;
6806 status = decode_compound_hdr(xdr, &hdr);
6808 status = decode_sequence(xdr, &res->seq_res, req);
6810 status = decode_putfh(xdr);
6812 status = decode_fsinfo(xdr, res->fsinfo);
6817 * Decode PATHCONF response
6819 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6822 struct nfs4_pathconf_res *res = data;
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_pathconf(xdr, res->pathconf);
6837 * Decode STATFS response
6839 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6842 struct nfs4_statfs_res *res = data;
6843 struct compound_hdr hdr;
6846 status = decode_compound_hdr(xdr, &hdr);
6848 status = decode_sequence(xdr, &res->seq_res, req);
6850 status = decode_putfh(xdr);
6852 status = decode_statfs(xdr, res->fsstat);
6857 * Decode GETATTR_BITMAP response
6859 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6860 struct xdr_stream *xdr,
6863 struct nfs4_server_caps_res *res = data;
6864 struct compound_hdr hdr;
6867 status = decode_compound_hdr(xdr, &hdr);
6870 status = decode_sequence(xdr, &res->seq_res, req);
6873 status = decode_putfh(xdr);
6876 status = decode_server_caps(xdr, res);
6882 * Decode RENEW response
6884 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6887 struct compound_hdr hdr;
6890 status = decode_compound_hdr(xdr, &hdr);
6892 status = decode_renew(xdr);
6897 * Decode SETCLIENTID response
6899 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6900 struct xdr_stream *xdr,
6903 struct nfs4_setclientid_res *res = data;
6904 struct compound_hdr hdr;
6907 status = decode_compound_hdr(xdr, &hdr);
6909 status = decode_setclientid(xdr, res);
6914 * Decode SETCLIENTID_CONFIRM response
6916 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6917 struct xdr_stream *xdr,
6920 struct compound_hdr hdr;
6923 status = decode_compound_hdr(xdr, &hdr);
6925 status = decode_setclientid_confirm(xdr);
6930 * Decode DELEGRETURN response
6932 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6933 struct xdr_stream *xdr,
6936 struct nfs4_delegreturnres *res = data;
6937 struct compound_hdr hdr;
6940 status = decode_compound_hdr(xdr, &hdr);
6943 status = decode_sequence(xdr, &res->seq_res, rqstp);
6946 status = decode_putfh(xdr);
6950 status = decode_layoutreturn(xdr, res->lr_res);
6951 res->lr_ret = status;
6956 status = decode_getfattr(xdr, res->fattr, res->server);
6960 status = decode_delegreturn(xdr);
6966 * Decode FS_LOCATIONS response
6968 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6969 struct xdr_stream *xdr,
6972 struct nfs4_fs_locations_res *res = data;
6973 struct compound_hdr hdr;
6976 status = decode_compound_hdr(xdr, &hdr);
6979 status = decode_sequence(xdr, &res->seq_res, req);
6982 status = decode_putfh(xdr);
6985 if (res->migration) {
6986 xdr_enter_page(xdr, PAGE_SIZE);
6987 status = decode_getfattr_generic(xdr,
6988 &res->fs_locations->fattr,
6989 NULL, res->fs_locations,
6990 NULL, res->fs_locations->server);
6994 status = decode_renew(xdr);
6996 status = decode_lookup(xdr);
6999 xdr_enter_page(xdr, PAGE_SIZE);
7000 status = decode_getfattr_generic(xdr,
7001 &res->fs_locations->fattr,
7002 NULL, res->fs_locations,
7003 NULL, res->fs_locations->server);
7010 * Decode SECINFO response
7012 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7013 struct xdr_stream *xdr,
7016 struct nfs4_secinfo_res *res = data;
7017 struct compound_hdr hdr;
7020 status = decode_compound_hdr(xdr, &hdr);
7023 status = decode_sequence(xdr, &res->seq_res, rqstp);
7026 status = decode_putfh(xdr);
7029 status = decode_secinfo(xdr, res);
7035 * Decode FSID_PRESENT response
7037 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7038 struct xdr_stream *xdr,
7041 struct nfs4_fsid_present_res *res = data;
7042 struct compound_hdr hdr;
7045 status = decode_compound_hdr(xdr, &hdr);
7048 status = decode_sequence(xdr, &res->seq_res, rqstp);
7051 status = decode_putfh(xdr);
7054 status = decode_getfh(xdr, res->fh);
7058 status = decode_renew(xdr);
7063 #if defined(CONFIG_NFS_V4_1)
7065 * Decode BIND_CONN_TO_SESSION response
7067 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7068 struct xdr_stream *xdr,
7071 struct compound_hdr hdr;
7074 status = decode_compound_hdr(xdr, &hdr);
7076 status = decode_bind_conn_to_session(xdr, res);
7081 * Decode EXCHANGE_ID response
7083 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7084 struct xdr_stream *xdr,
7087 struct compound_hdr hdr;
7090 status = decode_compound_hdr(xdr, &hdr);
7092 status = decode_exchange_id(xdr, res);
7097 * Decode CREATE_SESSION response
7099 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7100 struct xdr_stream *xdr,
7103 struct compound_hdr hdr;
7106 status = decode_compound_hdr(xdr, &hdr);
7108 status = decode_create_session(xdr, res);
7113 * Decode DESTROY_SESSION response
7115 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7116 struct xdr_stream *xdr,
7119 struct compound_hdr hdr;
7122 status = decode_compound_hdr(xdr, &hdr);
7124 status = decode_destroy_session(xdr, res);
7129 * Decode DESTROY_CLIENTID response
7131 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7132 struct xdr_stream *xdr,
7135 struct compound_hdr hdr;
7138 status = decode_compound_hdr(xdr, &hdr);
7140 status = decode_destroy_clientid(xdr, res);
7145 * Decode SEQUENCE response
7147 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7148 struct xdr_stream *xdr,
7151 struct compound_hdr hdr;
7154 status = decode_compound_hdr(xdr, &hdr);
7156 status = decode_sequence(xdr, res, rqstp);
7163 * Decode GET_LEASE_TIME response
7165 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7166 struct xdr_stream *xdr,
7169 struct nfs4_get_lease_time_res *res = data;
7170 struct compound_hdr hdr;
7173 status = decode_compound_hdr(xdr, &hdr);
7175 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
7177 status = decode_putrootfh(xdr);
7179 status = decode_fsinfo(xdr, res->lr_fsinfo);
7183 #ifdef CONFIG_NFS_V4_1
7186 * Decode RECLAIM_COMPLETE response
7188 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7189 struct xdr_stream *xdr,
7192 struct nfs41_reclaim_complete_res *res = data;
7193 struct compound_hdr hdr;
7196 status = decode_compound_hdr(xdr, &hdr);
7198 status = decode_sequence(xdr, &res->seq_res, rqstp);
7200 status = decode_reclaim_complete(xdr, NULL);
7205 * Decode GETDEVINFO response
7207 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7208 struct xdr_stream *xdr,
7211 struct nfs4_getdeviceinfo_res *res = data;
7212 struct compound_hdr hdr;
7215 status = decode_compound_hdr(xdr, &hdr);
7218 status = decode_sequence(xdr, &res->seq_res, rqstp);
7221 status = decode_getdeviceinfo(xdr, res);
7227 * Decode LAYOUTGET response
7229 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7230 struct xdr_stream *xdr,
7233 struct nfs4_layoutget_res *res = data;
7234 struct compound_hdr hdr;
7237 status = decode_compound_hdr(xdr, &hdr);
7240 status = decode_sequence(xdr, &res->seq_res, rqstp);
7243 status = decode_putfh(xdr);
7246 status = decode_layoutget(xdr, rqstp, res);
7252 * Decode LAYOUTRETURN response
7254 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7255 struct xdr_stream *xdr,
7258 struct nfs4_layoutreturn_res *res = data;
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,
7283 struct nfs4_layoutcommit_res *res = data;
7284 struct compound_hdr hdr;
7287 status = decode_compound_hdr(xdr, &hdr);
7290 status = decode_sequence(xdr, &res->seq_res, rqstp);
7293 status = decode_putfh(xdr);
7296 status = decode_layoutcommit(xdr, rqstp, res);
7299 decode_getfattr(xdr, res->fattr, res->server);
7305 * Decode SECINFO_NO_NAME response
7307 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7308 struct xdr_stream *xdr,
7311 struct nfs4_secinfo_res *res = data;
7312 struct compound_hdr hdr;
7315 status = decode_compound_hdr(xdr, &hdr);
7318 status = decode_sequence(xdr, &res->seq_res, rqstp);
7321 status = decode_putrootfh(xdr);
7324 status = decode_secinfo_no_name(xdr, res);
7330 * Decode TEST_STATEID response
7332 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7333 struct xdr_stream *xdr,
7336 struct nfs41_test_stateid_res *res = data;
7337 struct compound_hdr hdr;
7340 status = decode_compound_hdr(xdr, &hdr);
7343 status = decode_sequence(xdr, &res->seq_res, rqstp);
7346 status = decode_test_stateid(xdr, res);
7352 * Decode FREE_STATEID response
7354 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7355 struct xdr_stream *xdr,
7358 struct nfs41_free_stateid_res *res = data;
7359 struct compound_hdr hdr;
7362 status = decode_compound_hdr(xdr, &hdr);
7365 status = decode_sequence(xdr, &res->seq_res, rqstp);
7368 status = decode_free_stateid(xdr, res);
7372 #endif /* CONFIG_NFS_V4_1 */
7375 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7376 * the local page cache.
7377 * @xdr: XDR stream where entry resides
7378 * @entry: buffer to fill in with entry data
7379 * @plus: boolean indicating whether this should be a readdirplus entry
7381 * Returns zero if successful, otherwise a negative errno value is
7384 * This function is not invoked during READDIR reply decoding, but
7385 * rather whenever an application invokes the getdents(2) system call
7386 * on a directory already in our cache.
7388 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7392 uint32_t bitmap[3] = {0};
7394 uint64_t new_cookie;
7395 __be32 *p = xdr_inline_decode(xdr, 4);
7398 if (*p == xdr_zero) {
7399 p = xdr_inline_decode(xdr, 4);
7408 p = xdr_inline_decode(xdr, 12);
7411 p = xdr_decode_hyper(p, &new_cookie);
7412 entry->len = be32_to_cpup(p);
7414 p = xdr_inline_decode(xdr, entry->len);
7417 entry->name = (const char *) p;
7420 * In case the server doesn't return an inode number,
7421 * we fake one here. (We don't use inode number 0,
7422 * since glibc seems to choke on it...)
7425 entry->fattr->valid = 0;
7427 if (decode_attr_bitmap(xdr, bitmap) < 0)
7430 if (decode_attr_length(xdr, &len, &savep) < 0)
7433 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7434 NULL, entry->label, entry->server) < 0)
7436 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7437 entry->ino = entry->fattr->mounted_on_fileid;
7438 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7439 entry->ino = entry->fattr->fileid;
7441 entry->d_type = DT_UNKNOWN;
7442 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7443 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7445 entry->prev_cookie = entry->cookie;
7446 entry->cookie = new_cookie;
7452 * We need to translate between nfs status return values and
7453 * the local errno values which may not be the same.
7460 { NFS4ERR_PERM, -EPERM },
7461 { NFS4ERR_NOENT, -ENOENT },
7462 { NFS4ERR_IO, -errno_NFSERR_IO},
7463 { NFS4ERR_NXIO, -ENXIO },
7464 { NFS4ERR_ACCESS, -EACCES },
7465 { NFS4ERR_EXIST, -EEXIST },
7466 { NFS4ERR_XDEV, -EXDEV },
7467 { NFS4ERR_NOTDIR, -ENOTDIR },
7468 { NFS4ERR_ISDIR, -EISDIR },
7469 { NFS4ERR_INVAL, -EINVAL },
7470 { NFS4ERR_FBIG, -EFBIG },
7471 { NFS4ERR_NOSPC, -ENOSPC },
7472 { NFS4ERR_ROFS, -EROFS },
7473 { NFS4ERR_MLINK, -EMLINK },
7474 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7475 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7476 { NFS4ERR_DQUOT, -EDQUOT },
7477 { NFS4ERR_STALE, -ESTALE },
7478 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7479 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7480 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7481 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7482 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7483 { NFS4ERR_BADTYPE, -EBADTYPE },
7484 { NFS4ERR_LOCKED, -EAGAIN },
7485 { NFS4ERR_SYMLINK, -ELOOP },
7486 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7487 { NFS4ERR_DEADLOCK, -EDEADLK },
7488 { NFS4ERR_NOXATTR, -ENODATA },
7489 { NFS4ERR_XATTR2BIG, -E2BIG },
7494 * Convert an NFS error code to a local one.
7495 * This one is used jointly by NFSv2 and NFSv3.
7498 nfs4_stat_to_errno(int stat)
7501 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7502 if (nfs_errtbl[i].stat == stat)
7503 return nfs_errtbl[i].errno;
7505 if (stat <= 10000 || stat > 10100) {
7506 /* The server is looney tunes. */
7509 /* If we cannot translate the error, the recovery routines should
7511 * Note: remaining NFSv4 error codes have values > 10000, so should
7512 * not conflict with native Linux error codes.
7517 #ifdef CONFIG_NFS_V4_2
7518 #include "nfs42xdr.c"
7519 #endif /* CONFIG_NFS_V4_2 */
7521 #define PROC(proc, argtype, restype) \
7522 [NFSPROC4_CLNT_##proc] = { \
7523 .p_proc = NFSPROC4_COMPOUND, \
7524 .p_encode = nfs4_xdr_##argtype, \
7525 .p_decode = nfs4_xdr_##restype, \
7526 .p_arglen = NFS4_##argtype##_sz, \
7527 .p_replen = NFS4_##restype##_sz, \
7528 .p_statidx = NFSPROC4_CLNT_##proc, \
7532 #define STUB(proc) \
7533 [NFSPROC4_CLNT_##proc] = { \
7537 #if defined(CONFIG_NFS_V4_1)
7538 #define PROC41(proc, argtype, restype) \
7539 PROC(proc, argtype, restype)
7541 #define PROC41(proc, argtype, restype) \
7545 #if defined(CONFIG_NFS_V4_2)
7546 #define PROC42(proc, argtype, restype) \
7547 PROC(proc, argtype, restype)
7549 #define PROC42(proc, argtype, restype) \
7553 const struct rpc_procinfo nfs4_procedures[] = {
7554 PROC(READ, enc_read, dec_read),
7555 PROC(WRITE, enc_write, dec_write),
7556 PROC(COMMIT, enc_commit, dec_commit),
7557 PROC(OPEN, enc_open, dec_open),
7558 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7559 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7560 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7561 PROC(CLOSE, enc_close, dec_close),
7562 PROC(SETATTR, enc_setattr, dec_setattr),
7563 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7564 PROC(RENEW, enc_renew, dec_renew),
7565 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7566 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7567 PROC(LOCK, enc_lock, dec_lock),
7568 PROC(LOCKT, enc_lockt, dec_lockt),
7569 PROC(LOCKU, enc_locku, dec_locku),
7570 PROC(ACCESS, enc_access, dec_access),
7571 PROC(GETATTR, enc_getattr, dec_getattr),
7572 PROC(LOOKUP, enc_lookup, dec_lookup),
7573 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7574 PROC(REMOVE, enc_remove, dec_remove),
7575 PROC(RENAME, enc_rename, dec_rename),
7576 PROC(LINK, enc_link, dec_link),
7577 PROC(SYMLINK, enc_symlink, dec_symlink),
7578 PROC(CREATE, enc_create, dec_create),
7579 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7580 PROC(STATFS, enc_statfs, dec_statfs),
7581 PROC(READLINK, enc_readlink, dec_readlink),
7582 PROC(READDIR, enc_readdir, dec_readdir),
7583 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7584 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7585 PROC(GETACL, enc_getacl, dec_getacl),
7586 PROC(SETACL, enc_setacl, dec_setacl),
7587 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7588 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7589 PROC(SECINFO, enc_secinfo, dec_secinfo),
7590 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7591 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7592 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7593 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7594 PROC41(SEQUENCE, enc_sequence, dec_sequence),
7595 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7596 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7597 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7598 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7599 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7600 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7601 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7602 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7603 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7604 STUB(GETDEVICELIST),
7605 PROC41(BIND_CONN_TO_SESSION,
7606 enc_bind_conn_to_session, dec_bind_conn_to_session),
7607 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7608 PROC42(SEEK, enc_seek, dec_seek),
7609 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7610 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7611 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7612 PROC42(CLONE, enc_clone, dec_clone),
7613 PROC42(COPY, enc_copy, dec_copy),
7614 PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
7615 PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
7616 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
7617 PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
7618 PROC42(GETXATTR, enc_getxattr, dec_getxattr),
7619 PROC42(SETXATTR, enc_setxattr, dec_setxattr),
7620 PROC42(LISTXATTRS, enc_listxattrs, dec_listxattrs),
7621 PROC42(REMOVEXATTR, enc_removexattr, dec_removexattr),
7622 PROC42(READ_PLUS, enc_read_plus, dec_read_plus),
7625 static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
7626 const struct rpc_version nfs_version4 = {
7628 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7629 .procs = nfs4_procedures,
7630 .counts = nfs_version4_counts,