4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/module.h>
48 #include <linux/utsname.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/sunrpc/msg_prot.h>
51 #include <linux/sunrpc/gss_api.h>
52 #include <linux/nfs.h>
53 #include <linux/nfs4.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/fs_struct.h>
59 #include "nfs4idmap.h"
60 #include "nfs4session.h"
64 #define NFSDBG_FACILITY NFSDBG_XDR
66 /* Mapping from NFS error code to "errno" error code. */
67 #define errno_NFSERR_IO EIO
69 static int nfs4_stat_to_errno(int);
71 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
73 #define NFS4_MAXTAGLEN 20
75 #define NFS4_MAXTAGLEN 0
78 /* lock,open owner id:
79 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
81 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
82 #define lock_owner_id_maxsz (1 + 1 + 4)
83 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
84 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
86 #define op_encode_hdr_maxsz (1)
87 #define op_decode_hdr_maxsz (2)
88 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
90 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
92 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
94 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
95 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
96 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
97 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
98 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
99 ((3+NFS4_FHSIZE) >> 2))
100 #define nfs4_fattr_bitmap_maxsz 4
101 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
102 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
103 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
104 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
106 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
107 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108 #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
110 #define nfs4_label_maxsz 0
112 /* We support only one layout type per file system */
113 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
114 /* This is based on getfattr, which uses the most attributes: */
115 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
116 3 + 3 + 3 + nfs4_owner_maxsz + \
117 nfs4_group_maxsz + nfs4_label_maxsz + \
118 decode_mdsthreshold_maxsz))
119 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
120 nfs4_fattr_value_maxsz)
121 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
122 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
128 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
129 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
130 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
131 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
132 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
133 /* The 5 accounts for the PNFS attributes, and assumes that at most three
134 * layout types will be returned.
136 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
137 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
138 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
139 #define decode_renew_maxsz (op_decode_hdr_maxsz)
140 #define encode_setclientid_maxsz \
141 (op_encode_hdr_maxsz + \
142 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
144 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
147 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
149 #define decode_setclientid_maxsz \
150 (op_decode_hdr_maxsz + \
152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
154 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
155 #define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158 #define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
160 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
162 #define encode_lookupp_maxsz (op_encode_hdr_maxsz)
163 #define decode_lookupp_maxsz (op_decode_hdr_maxsz)
164 #define encode_share_access_maxsz \
166 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
167 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
168 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
169 #define encode_open_maxsz (op_encode_hdr_maxsz + \
170 2 + encode_share_access_maxsz + 2 + \
171 open_owner_id_maxsz + \
172 encode_opentype_maxsz + \
173 encode_claim_null_maxsz)
174 #define decode_space_limit_maxsz (3)
175 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
176 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
177 decode_space_limit_maxsz + \
179 #define decode_change_info_maxsz (5)
180 #define decode_open_maxsz (op_decode_hdr_maxsz + \
181 decode_stateid_maxsz + \
182 decode_change_info_maxsz + 1 + \
183 nfs4_fattr_bitmap_maxsz + \
184 decode_delegation_maxsz)
185 #define encode_open_confirm_maxsz \
186 (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 1)
188 #define decode_open_confirm_maxsz \
189 (op_decode_hdr_maxsz + \
190 decode_stateid_maxsz)
191 #define encode_open_downgrade_maxsz \
192 (op_encode_hdr_maxsz + \
193 encode_stateid_maxsz + 1 + \
194 encode_share_access_maxsz)
195 #define decode_open_downgrade_maxsz \
196 (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198 #define encode_close_maxsz (op_encode_hdr_maxsz + \
199 1 + encode_stateid_maxsz)
200 #define decode_close_maxsz (op_decode_hdr_maxsz + \
201 decode_stateid_maxsz)
202 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + \
205 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
206 nfs4_fattr_bitmap_maxsz)
207 #define encode_read_maxsz (op_encode_hdr_maxsz + \
208 encode_stateid_maxsz + 3)
209 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
210 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
211 2 + encode_verifier_maxsz + 5 + \
213 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
214 decode_verifier_maxsz)
215 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
216 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
217 #define encode_write_maxsz (op_encode_hdr_maxsz + \
218 encode_stateid_maxsz + 4)
219 #define decode_write_maxsz (op_decode_hdr_maxsz + \
220 2 + decode_verifier_maxsz)
221 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
222 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
223 decode_verifier_maxsz)
224 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
226 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz)
228 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
230 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 decode_change_info_maxsz)
233 #define encode_link_maxsz (op_encode_hdr_maxsz + \
235 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
236 #define encode_lockowner_maxsz (7)
237 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
239 1 + encode_stateid_maxsz + 1 + \
240 encode_lockowner_maxsz)
241 #define decode_lock_denied_maxsz \
242 (8 + decode_lockowner_maxsz)
243 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
244 decode_lock_denied_maxsz)
245 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
246 encode_lockowner_maxsz)
247 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
248 decode_lock_denied_maxsz)
249 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
250 encode_stateid_maxsz + \
252 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
253 decode_stateid_maxsz)
254 #define encode_release_lockowner_maxsz \
255 (op_encode_hdr_maxsz + \
256 encode_lockowner_maxsz)
257 #define decode_release_lockowner_maxsz \
258 (op_decode_hdr_maxsz)
259 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
260 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
261 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
262 1 + nfs4_name_maxsz + \
265 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
266 #define encode_create_maxsz (op_encode_hdr_maxsz + \
267 1 + 2 + nfs4_name_maxsz + \
269 #define decode_create_maxsz (op_decode_hdr_maxsz + \
270 decode_change_info_maxsz + \
271 nfs4_fattr_bitmap_maxsz)
272 #define encode_statfs_maxsz (encode_getattr_maxsz)
273 #define decode_statfs_maxsz (decode_getattr_maxsz)
274 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
275 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
276 #define encode_getacl_maxsz (encode_getattr_maxsz)
277 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
278 nfs4_fattr_bitmap_maxsz + 1)
279 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
280 encode_stateid_maxsz + 3)
281 #define decode_setacl_maxsz (decode_setattr_maxsz)
282 #define encode_fs_locations_maxsz \
283 (encode_getattr_maxsz)
284 #define decode_fs_locations_maxsz \
286 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
287 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
289 #if defined(CONFIG_NFS_V4_1)
290 #define NFS4_MAX_MACHINE_NAME_LEN (64)
291 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
292 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
294 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
295 encode_verifier_maxsz + \
296 1 /* co_ownerid.len */ + \
297 /* eia_clientowner */ \
298 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 /* max is SP4_MACH_CRED (for now) */ + \
302 1 + NFS4_OP_MAP_NUM_WORDS + \
303 1 + NFS4_OP_MAP_NUM_WORDS + \
304 1 /* implementation id array of size 1 */ + \
305 1 /* nii_domain */ + \
306 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
308 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
310 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
311 2 /* eir_clientid */ + \
312 1 /* eir_sequenceid */ + \
313 1 /* eir_flags */ + \
315 /* max is SP4_MACH_CRED (for now) */ + \
316 1 + NFS4_OP_MAP_NUM_WORDS + \
317 1 + NFS4_OP_MAP_NUM_WORDS + \
318 2 /* eir_server_owner.so_minor_id */ + \
319 /* eir_server_owner.so_major_id<> */ \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
321 /* eir_server_scope<> */ \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
323 1 /* eir_server_impl_id array length */ + \
324 1 /* nii_domain */ + \
325 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
327 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
329 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
330 #define decode_channel_attrs_maxsz (6 + \
331 1 /* ca_rdma_ird.len */ + \
333 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
334 2 /* csa_clientid */ + \
335 1 /* csa_sequence */ + \
336 1 /* csa_flags */ + \
337 encode_channel_attrs_maxsz + \
338 encode_channel_attrs_maxsz + \
339 1 /* csa_cb_program */ + \
340 1 /* csa_sec_parms.len (1) */ + \
341 1 /* cb_secflavor (AUTH_SYS) */ + \
343 1 /* machinename.len */ + \
344 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
347 1 /* gids.len (0) */)
348 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
350 1 /* csr_sequence */ + \
351 1 /* csr_flags */ + \
352 decode_channel_attrs_maxsz + \
353 decode_channel_attrs_maxsz)
354 #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsa_dir */ + \
358 1 /* bctsa_use_conn_in_rdma_mode */)
359 #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
361 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
362 1 /* bctsr_dir */ + \
363 1 /* bctsr_use_conn_in_rdma_mode */)
364 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
365 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
366 #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
367 #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
368 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
369 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
370 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
371 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
372 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
373 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
374 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
375 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
376 1 /* layout type */ + \
378 1 /* bitmap size */ + \
379 1 /* notification bitmap length */ + \
380 1 /* notification bitmap, word 0 */)
381 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
382 1 /* layout type */ + \
383 1 /* opaque devaddr4 length */ + \
384 /* devaddr4 payload is read into page */ \
385 1 /* notification bitmap length */ + \
386 1 /* notification bitmap, word 0 */)
387 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
388 encode_stateid_maxsz)
389 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
390 decode_stateid_maxsz + \
391 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
392 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
396 encode_stateid_maxsz + \
397 1 /* new offset (true) */ + \
398 2 /* last byte written */ + \
399 1 /* nt_timechanged (false) */ + \
400 1 /* layoutupdate4 layout type */ + \
401 1 /* layoutupdate4 opaqueue len */)
402 /* the actual content of layoutupdate4 should
403 be allocated by drivers and spliced in
404 using xdr_write_pages */
405 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
406 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
407 encode_stateid_maxsz + \
409 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
410 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
411 1 + decode_stateid_maxsz)
412 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
413 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
414 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
415 XDR_QUADLEN(NFS4_STATEID_SIZE))
416 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
417 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
418 XDR_QUADLEN(NFS4_STATEID_SIZE))
419 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
420 #else /* CONFIG_NFS_V4_1 */
421 #define encode_sequence_maxsz 0
422 #define decode_sequence_maxsz 0
423 #define encode_layoutreturn_maxsz 0
424 #define decode_layoutreturn_maxsz 0
425 #endif /* CONFIG_NFS_V4_1 */
427 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
428 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
429 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
430 encode_sequence_maxsz + \
431 encode_putfh_maxsz + \
433 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
434 decode_sequence_maxsz + \
435 decode_putfh_maxsz + \
437 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
438 encode_sequence_maxsz + \
439 encode_putfh_maxsz + \
440 encode_readlink_maxsz)
441 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
442 decode_sequence_maxsz + \
443 decode_putfh_maxsz + \
444 decode_readlink_maxsz)
445 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
446 encode_sequence_maxsz + \
447 encode_putfh_maxsz + \
448 encode_readdir_maxsz)
449 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
450 decode_sequence_maxsz + \
451 decode_putfh_maxsz + \
452 decode_readdir_maxsz)
453 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
454 encode_sequence_maxsz + \
455 encode_putfh_maxsz + \
456 encode_write_maxsz + \
457 encode_getattr_maxsz)
458 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
459 decode_sequence_maxsz + \
460 decode_putfh_maxsz + \
461 decode_write_maxsz + \
462 decode_getattr_maxsz)
463 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
464 encode_sequence_maxsz + \
465 encode_putfh_maxsz + \
467 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
468 decode_sequence_maxsz + \
469 decode_putfh_maxsz + \
471 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
472 encode_sequence_maxsz + \
473 encode_putfh_maxsz + \
474 encode_open_maxsz + \
475 encode_access_maxsz + \
476 encode_getfh_maxsz + \
477 encode_getattr_maxsz)
478 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
479 decode_sequence_maxsz + \
480 decode_putfh_maxsz + \
481 decode_open_maxsz + \
482 decode_access_maxsz + \
483 decode_getfh_maxsz + \
484 decode_getattr_maxsz)
485 #define NFS4_enc_open_confirm_sz \
486 (compound_encode_hdr_maxsz + \
487 encode_putfh_maxsz + \
488 encode_open_confirm_maxsz)
489 #define NFS4_dec_open_confirm_sz \
490 (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
492 decode_open_confirm_maxsz)
493 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
494 encode_sequence_maxsz + \
495 encode_putfh_maxsz + \
496 encode_open_maxsz + \
497 encode_access_maxsz + \
498 encode_getattr_maxsz)
499 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
500 decode_sequence_maxsz + \
501 decode_putfh_maxsz + \
502 decode_open_maxsz + \
503 decode_access_maxsz + \
504 decode_getattr_maxsz)
505 #define NFS4_enc_open_downgrade_sz \
506 (compound_encode_hdr_maxsz + \
507 encode_sequence_maxsz + \
508 encode_putfh_maxsz + \
509 encode_layoutreturn_maxsz + \
510 encode_open_downgrade_maxsz)
511 #define NFS4_dec_open_downgrade_sz \
512 (compound_decode_hdr_maxsz + \
513 decode_sequence_maxsz + \
514 decode_putfh_maxsz + \
515 decode_layoutreturn_maxsz + \
516 decode_open_downgrade_maxsz)
517 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
518 encode_sequence_maxsz + \
519 encode_putfh_maxsz + \
520 encode_layoutreturn_maxsz + \
521 encode_close_maxsz + \
522 encode_getattr_maxsz)
523 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
524 decode_sequence_maxsz + \
525 decode_putfh_maxsz + \
526 decode_layoutreturn_maxsz + \
527 decode_close_maxsz + \
528 decode_getattr_maxsz)
529 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
530 encode_sequence_maxsz + \
531 encode_putfh_maxsz + \
532 encode_setattr_maxsz + \
533 encode_getattr_maxsz)
534 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
535 decode_sequence_maxsz + \
536 decode_putfh_maxsz + \
537 decode_setattr_maxsz + \
538 decode_getattr_maxsz)
539 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
540 encode_sequence_maxsz + \
541 encode_putfh_maxsz + \
543 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
544 decode_sequence_maxsz + \
545 decode_putfh_maxsz + \
547 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
549 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
551 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
552 encode_setclientid_maxsz)
553 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
554 decode_setclientid_maxsz)
555 #define NFS4_enc_setclientid_confirm_sz \
556 (compound_encode_hdr_maxsz + \
557 encode_setclientid_confirm_maxsz)
558 #define NFS4_dec_setclientid_confirm_sz \
559 (compound_decode_hdr_maxsz + \
560 decode_setclientid_confirm_maxsz)
561 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
562 encode_sequence_maxsz + \
563 encode_putfh_maxsz + \
565 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
566 decode_sequence_maxsz + \
567 decode_putfh_maxsz + \
569 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
570 encode_sequence_maxsz + \
571 encode_putfh_maxsz + \
573 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
574 decode_sequence_maxsz + \
575 decode_putfh_maxsz + \
577 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
578 encode_sequence_maxsz + \
579 encode_putfh_maxsz + \
581 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
582 decode_sequence_maxsz + \
583 decode_putfh_maxsz + \
585 #define NFS4_enc_release_lockowner_sz \
586 (compound_encode_hdr_maxsz + \
587 encode_lockowner_maxsz)
588 #define NFS4_dec_release_lockowner_sz \
589 (compound_decode_hdr_maxsz + \
590 decode_lockowner_maxsz)
591 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
592 encode_sequence_maxsz + \
593 encode_putfh_maxsz + \
594 encode_access_maxsz + \
595 encode_getattr_maxsz)
596 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
597 decode_sequence_maxsz + \
598 decode_putfh_maxsz + \
599 decode_access_maxsz + \
600 decode_getattr_maxsz)
601 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
602 encode_sequence_maxsz + \
603 encode_putfh_maxsz + \
604 encode_getattr_maxsz + \
606 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
607 decode_sequence_maxsz + \
608 decode_putfh_maxsz + \
609 decode_getattr_maxsz + \
611 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
612 encode_sequence_maxsz + \
613 encode_putfh_maxsz + \
614 encode_lookup_maxsz + \
615 encode_getattr_maxsz + \
617 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
618 decode_sequence_maxsz + \
619 decode_putfh_maxsz + \
620 decode_lookup_maxsz + \
621 decode_getattr_maxsz + \
623 #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
624 encode_sequence_maxsz + \
625 encode_putfh_maxsz + \
626 encode_lookupp_maxsz + \
627 encode_getattr_maxsz + \
629 #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
630 decode_sequence_maxsz + \
631 decode_putfh_maxsz + \
632 decode_lookupp_maxsz + \
633 decode_getattr_maxsz + \
635 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
636 encode_sequence_maxsz + \
637 encode_putrootfh_maxsz + \
638 encode_getattr_maxsz + \
640 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
641 decode_sequence_maxsz + \
642 decode_putrootfh_maxsz + \
643 decode_getattr_maxsz + \
645 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
646 encode_sequence_maxsz + \
647 encode_putfh_maxsz + \
649 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
650 decode_sequence_maxsz + \
651 decode_putfh_maxsz + \
653 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
654 encode_sequence_maxsz + \
655 encode_putfh_maxsz + \
656 encode_savefh_maxsz + \
657 encode_putfh_maxsz + \
659 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
660 decode_sequence_maxsz + \
661 decode_putfh_maxsz + \
662 decode_savefh_maxsz + \
663 decode_putfh_maxsz + \
665 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
666 encode_sequence_maxsz + \
667 encode_putfh_maxsz + \
668 encode_savefh_maxsz + \
669 encode_putfh_maxsz + \
670 encode_link_maxsz + \
671 encode_restorefh_maxsz + \
672 encode_getattr_maxsz)
673 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
674 decode_sequence_maxsz + \
675 decode_putfh_maxsz + \
676 decode_savefh_maxsz + \
677 decode_putfh_maxsz + \
678 decode_link_maxsz + \
679 decode_restorefh_maxsz + \
680 decode_getattr_maxsz)
681 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
682 encode_sequence_maxsz + \
683 encode_putfh_maxsz + \
684 encode_symlink_maxsz + \
685 encode_getattr_maxsz + \
687 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
688 decode_sequence_maxsz + \
689 decode_putfh_maxsz + \
690 decode_symlink_maxsz + \
691 decode_getattr_maxsz + \
693 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
694 encode_sequence_maxsz + \
695 encode_putfh_maxsz + \
696 encode_create_maxsz + \
697 encode_getfh_maxsz + \
698 encode_getattr_maxsz)
699 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_putfh_maxsz + \
702 decode_create_maxsz + \
703 decode_getfh_maxsz + \
704 decode_getattr_maxsz)
705 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
706 encode_sequence_maxsz + \
707 encode_putfh_maxsz + \
708 encode_getattr_maxsz)
709 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
710 decode_sequence_maxsz + \
711 decode_putfh_maxsz + \
712 decode_getattr_maxsz)
713 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
714 encode_sequence_maxsz + \
715 encode_putfh_maxsz + \
717 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
718 decode_sequence_maxsz + \
719 decode_putfh_maxsz + \
721 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
722 encode_sequence_maxsz + \
723 encode_putfh_maxsz + \
724 encode_getattr_maxsz)
725 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
726 decode_sequence_maxsz + \
727 decode_putfh_maxsz + \
728 decode_getattr_maxsz)
729 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
730 encode_sequence_maxsz + \
731 encode_putfh_maxsz + \
732 encode_layoutreturn_maxsz + \
733 encode_delegreturn_maxsz + \
734 encode_getattr_maxsz)
735 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
736 decode_sequence_maxsz + \
737 decode_putfh_maxsz + \
738 decode_layoutreturn_maxsz + \
739 decode_delegreturn_maxsz + \
740 decode_getattr_maxsz)
741 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
742 encode_sequence_maxsz + \
743 encode_putfh_maxsz + \
745 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
746 decode_sequence_maxsz + \
747 decode_putfh_maxsz + \
749 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
750 encode_sequence_maxsz + \
751 encode_putfh_maxsz + \
753 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
754 decode_sequence_maxsz + \
755 decode_putfh_maxsz + \
757 #define NFS4_enc_fs_locations_sz \
758 (compound_encode_hdr_maxsz + \
759 encode_sequence_maxsz + \
760 encode_putfh_maxsz + \
761 encode_lookup_maxsz + \
762 encode_fs_locations_maxsz + \
764 #define NFS4_dec_fs_locations_sz \
765 (compound_decode_hdr_maxsz + \
766 decode_sequence_maxsz + \
767 decode_putfh_maxsz + \
768 decode_lookup_maxsz + \
769 decode_fs_locations_maxsz + \
771 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_putfh_maxsz + \
774 encode_secinfo_maxsz)
775 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
776 decode_sequence_maxsz + \
777 decode_putfh_maxsz + \
778 decode_secinfo_maxsz)
779 #define NFS4_enc_fsid_present_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz + \
782 encode_putfh_maxsz + \
783 encode_getfh_maxsz + \
785 #define NFS4_dec_fsid_present_sz \
786 (compound_decode_hdr_maxsz + \
787 decode_sequence_maxsz + \
788 decode_putfh_maxsz + \
789 decode_getfh_maxsz + \
791 #if defined(CONFIG_NFS_V4_1)
792 #define NFS4_enc_bind_conn_to_session_sz \
793 (compound_encode_hdr_maxsz + \
794 encode_bind_conn_to_session_maxsz)
795 #define NFS4_dec_bind_conn_to_session_sz \
796 (compound_decode_hdr_maxsz + \
797 decode_bind_conn_to_session_maxsz)
798 #define NFS4_enc_exchange_id_sz \
799 (compound_encode_hdr_maxsz + \
800 encode_exchange_id_maxsz)
801 #define NFS4_dec_exchange_id_sz \
802 (compound_decode_hdr_maxsz + \
803 decode_exchange_id_maxsz)
804 #define NFS4_enc_create_session_sz \
805 (compound_encode_hdr_maxsz + \
806 encode_create_session_maxsz)
807 #define NFS4_dec_create_session_sz \
808 (compound_decode_hdr_maxsz + \
809 decode_create_session_maxsz)
810 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
811 encode_destroy_session_maxsz)
812 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
813 decode_destroy_session_maxsz)
814 #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
815 encode_destroy_clientid_maxsz)
816 #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
817 decode_destroy_clientid_maxsz)
818 #define NFS4_enc_sequence_sz \
819 (compound_decode_hdr_maxsz + \
820 encode_sequence_maxsz)
821 #define NFS4_dec_sequence_sz \
822 (compound_decode_hdr_maxsz + \
823 decode_sequence_maxsz)
824 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
825 encode_sequence_maxsz + \
826 encode_putrootfh_maxsz + \
828 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_putrootfh_maxsz + \
832 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
833 encode_sequence_maxsz + \
834 encode_reclaim_complete_maxsz)
835 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
836 decode_sequence_maxsz + \
837 decode_reclaim_complete_maxsz)
838 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
839 encode_sequence_maxsz +\
840 encode_getdeviceinfo_maxsz)
841 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_getdeviceinfo_maxsz)
844 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
845 encode_sequence_maxsz + \
846 encode_putfh_maxsz + \
847 encode_layoutget_maxsz)
848 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_putfh_maxsz + \
851 decode_layoutget_maxsz)
852 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz +\
854 encode_putfh_maxsz + \
855 encode_layoutcommit_maxsz + \
856 encode_getattr_maxsz)
857 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
858 decode_sequence_maxsz + \
859 decode_putfh_maxsz + \
860 decode_layoutcommit_maxsz + \
861 decode_getattr_maxsz)
862 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
863 encode_sequence_maxsz + \
864 encode_putfh_maxsz + \
865 encode_layoutreturn_maxsz)
866 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
867 decode_sequence_maxsz + \
868 decode_putfh_maxsz + \
869 decode_layoutreturn_maxsz)
870 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
871 encode_sequence_maxsz + \
872 encode_putrootfh_maxsz +\
873 encode_secinfo_no_name_maxsz)
874 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
875 decode_sequence_maxsz + \
876 decode_putrootfh_maxsz + \
877 decode_secinfo_no_name_maxsz)
878 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
879 encode_sequence_maxsz + \
880 encode_test_stateid_maxsz)
881 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
882 decode_sequence_maxsz + \
883 decode_test_stateid_maxsz)
884 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
885 encode_sequence_maxsz + \
886 encode_free_stateid_maxsz)
887 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
888 decode_sequence_maxsz + \
889 decode_free_stateid_maxsz)
891 const u32 nfs41_maxwrite_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
892 compound_encode_hdr_maxsz
+
893 encode_sequence_maxsz
+
895 encode_getattr_maxsz
) *
898 const u32 nfs41_maxread_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
899 compound_decode_hdr_maxsz
+
900 decode_sequence_maxsz
+
901 decode_putfh_maxsz
) *
904 const u32 nfs41_maxgetdevinfo_overhead
= ((RPC_MAX_REPHEADER_WITH_AUTH
+
905 compound_decode_hdr_maxsz
+
906 decode_sequence_maxsz
) *
908 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead
);
909 #endif /* CONFIG_NFS_V4_1 */
911 static const umode_t nfs_type2fmt
[] = {
918 [NF4SOCK
] = S_IFSOCK
,
924 struct compound_hdr
{
930 uint32_t replen
; /* expected reply words */
934 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
936 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
941 static void encode_opaque_fixed(struct xdr_stream
*xdr
, const void *buf
, size_t len
)
943 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr
, buf
, len
) < 0);
946 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
948 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr
, str
, len
) < 0);
951 static void encode_uint32(struct xdr_stream
*xdr
, u32 n
)
953 WARN_ON_ONCE(xdr_stream_encode_u32(xdr
, n
) < 0);
956 static void encode_uint64(struct xdr_stream
*xdr
, u64 n
)
958 WARN_ON_ONCE(xdr_stream_encode_u64(xdr
, n
) < 0);
961 static void encode_nfs4_seqid(struct xdr_stream
*xdr
,
962 const struct nfs_seqid
*seqid
)
965 encode_uint32(xdr
, seqid
->sequence
->counter
);
967 encode_uint32(xdr
, 0);
970 static void encode_compound_hdr(struct xdr_stream
*xdr
,
971 struct rpc_rqst
*req
,
972 struct compound_hdr
*hdr
)
975 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
977 /* initialize running count of expected bytes in reply.
978 * NOTE: the replied tag SHOULD be the same is the one sent,
979 * but this is not required as a MUST for the server to do so. */
980 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
982 WARN_ON_ONCE(hdr
->taglen
> NFS4_MAXTAGLEN
);
983 encode_string(xdr
, hdr
->taglen
, hdr
->tag
);
984 p
= reserve_space(xdr
, 8);
985 *p
++ = cpu_to_be32(hdr
->minorversion
);
987 *p
= cpu_to_be32(hdr
->nops
);
990 static void encode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 op
,
992 struct compound_hdr
*hdr
)
994 encode_uint32(xdr
, op
);
996 hdr
->replen
+= replen
;
999 static void encode_nops(struct compound_hdr
*hdr
)
1001 WARN_ON_ONCE(hdr
->nops
> NFS4_MAX_OPS
);
1002 *hdr
->nops_p
= htonl(hdr
->nops
);
1005 static void encode_nfs4_stateid(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1007 encode_opaque_fixed(xdr
, stateid
, NFS4_STATEID_SIZE
);
1010 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
1012 encode_opaque_fixed(xdr
, verf
->data
, NFS4_VERIFIER_SIZE
);
1015 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
,
1016 const struct nfs4_label
*label
,
1017 const umode_t
*umask
,
1018 const struct nfs_server
*server
,
1019 const uint32_t attrmask
[])
1021 char owner_name
[IDMAP_NAMESZ
];
1022 char owner_group
[IDMAP_NAMESZ
];
1023 int owner_namelen
= 0;
1024 int owner_grouplen
= 0;
1029 uint32_t bmval
[3] = { 0 };
1032 * We reserve enough space to write the entire attribute buffer at once.
1034 if ((iap
->ia_valid
& ATTR_SIZE
) && (attrmask
[0] & FATTR4_WORD0_SIZE
)) {
1035 bmval
[0] |= FATTR4_WORD0_SIZE
;
1038 if (iap
->ia_valid
& ATTR_MODE
) {
1039 if (umask
&& (attrmask
[2] & FATTR4_WORD2_MODE_UMASK
)) {
1040 bmval
[2] |= FATTR4_WORD2_MODE_UMASK
;
1042 } else if (attrmask
[1] & FATTR4_WORD1_MODE
) {
1043 bmval
[1] |= FATTR4_WORD1_MODE
;
1047 if ((iap
->ia_valid
& ATTR_UID
) && (attrmask
[1] & FATTR4_WORD1_OWNER
)) {
1048 owner_namelen
= nfs_map_uid_to_name(server
, iap
->ia_uid
, owner_name
, IDMAP_NAMESZ
);
1049 if (owner_namelen
< 0) {
1050 dprintk("nfs: couldn't resolve uid %d to string\n",
1051 from_kuid(&init_user_ns
, iap
->ia_uid
));
1053 strcpy(owner_name
, "nobody");
1054 owner_namelen
= sizeof("nobody") - 1;
1057 bmval
[1] |= FATTR4_WORD1_OWNER
;
1058 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
1060 if ((iap
->ia_valid
& ATTR_GID
) &&
1061 (attrmask
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
1062 owner_grouplen
= nfs_map_gid_to_group(server
, iap
->ia_gid
, owner_group
, IDMAP_NAMESZ
);
1063 if (owner_grouplen
< 0) {
1064 dprintk("nfs: couldn't resolve gid %d to string\n",
1065 from_kgid(&init_user_ns
, iap
->ia_gid
));
1066 strcpy(owner_group
, "nobody");
1067 owner_grouplen
= sizeof("nobody") - 1;
1070 bmval
[1] |= FATTR4_WORD1_OWNER_GROUP
;
1071 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
1073 if (attrmask
[1] & FATTR4_WORD1_TIME_ACCESS_SET
) {
1074 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
1075 bmval
[1] |= FATTR4_WORD1_TIME_ACCESS_SET
;
1077 } else if (iap
->ia_valid
& ATTR_ATIME
) {
1078 bmval
[1] |= FATTR4_WORD1_TIME_ACCESS_SET
;
1082 if (attrmask
[1] & FATTR4_WORD1_TIME_MODIFY_SET
) {
1083 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
1084 bmval
[1] |= FATTR4_WORD1_TIME_MODIFY_SET
;
1086 } else if (iap
->ia_valid
& ATTR_MTIME
) {
1087 bmval
[1] |= FATTR4_WORD1_TIME_MODIFY_SET
;
1092 if (label
&& (attrmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)) {
1093 len
+= 4 + 4 + 4 + (XDR_QUADLEN(label
->len
) << 2);
1094 bmval
[2] |= FATTR4_WORD2_SECURITY_LABEL
;
1099 else if (bmval
[1] != 0)
1104 p
= reserve_space(xdr
, 4 + (bmval_len
<< 2) + 4 + len
);
1106 *p
++ = cpu_to_be32(bmval_len
);
1107 for (i
= 0; i
< bmval_len
; i
++)
1108 *p
++ = cpu_to_be32(bmval
[i
]);
1109 *p
++ = cpu_to_be32(len
);
1111 if (bmval
[0] & FATTR4_WORD0_SIZE
)
1112 p
= xdr_encode_hyper(p
, iap
->ia_size
);
1113 if (bmval
[1] & FATTR4_WORD1_MODE
)
1114 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
1115 if (bmval
[1] & FATTR4_WORD1_OWNER
)
1116 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
1117 if (bmval
[1] & FATTR4_WORD1_OWNER_GROUP
)
1118 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
1119 if (bmval
[1] & FATTR4_WORD1_TIME_ACCESS_SET
) {
1120 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
1121 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
1122 p
= xdr_encode_hyper(p
, (s64
)iap
->ia_atime
.tv_sec
);
1123 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_nsec
);
1125 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
1127 if (bmval
[1] & FATTR4_WORD1_TIME_MODIFY_SET
) {
1128 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
1129 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
1130 p
= xdr_encode_hyper(p
, (s64
)iap
->ia_mtime
.tv_sec
);
1131 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
1133 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
1135 if (bmval
[2] & FATTR4_WORD2_SECURITY_LABEL
) {
1136 *p
++ = cpu_to_be32(label
->lfs
);
1137 *p
++ = cpu_to_be32(label
->pi
);
1138 *p
++ = cpu_to_be32(label
->len
);
1139 p
= xdr_encode_opaque_fixed(p
, label
->label
, label
->len
);
1141 if (bmval
[2] & FATTR4_WORD2_MODE_UMASK
) {
1142 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
1143 *p
++ = cpu_to_be32(*umask
);
1149 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
1151 encode_op_hdr(xdr
, OP_ACCESS
, decode_access_maxsz
, hdr
);
1152 encode_uint32(xdr
, access
);
1155 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1157 encode_op_hdr(xdr
, OP_CLOSE
, decode_close_maxsz
, hdr
);
1158 encode_nfs4_seqid(xdr
, arg
->seqid
);
1159 encode_nfs4_stateid(xdr
, &arg
->stateid
);
1162 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_commitargs
*args
, struct compound_hdr
*hdr
)
1166 encode_op_hdr(xdr
, OP_COMMIT
, decode_commit_maxsz
, hdr
);
1167 p
= reserve_space(xdr
, 12);
1168 p
= xdr_encode_hyper(p
, args
->offset
);
1169 *p
= cpu_to_be32(args
->count
);
1172 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
1176 encode_op_hdr(xdr
, OP_CREATE
, decode_create_maxsz
, hdr
);
1177 encode_uint32(xdr
, create
->ftype
);
1179 switch (create
->ftype
) {
1181 p
= reserve_space(xdr
, 4);
1182 *p
= cpu_to_be32(create
->u
.symlink
.len
);
1183 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0,
1184 create
->u
.symlink
.len
);
1185 xdr
->buf
->flags
|= XDRBUF_WRITE
;
1188 case NF4BLK
: case NF4CHR
:
1189 p
= reserve_space(xdr
, 8);
1190 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
1191 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
1198 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
1199 encode_attrs(xdr
, create
->attrs
, create
->label
, &create
->umask
,
1200 create
->server
, create
->server
->attr_bitmask
);
1203 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
1207 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1208 p
= reserve_space(xdr
, 8);
1209 *p
++ = cpu_to_be32(1);
1210 *p
= cpu_to_be32(bitmap
);
1213 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
1217 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1218 p
= reserve_space(xdr
, 12);
1219 *p
++ = cpu_to_be32(2);
1220 *p
++ = cpu_to_be32(bm0
);
1221 *p
= cpu_to_be32(bm1
);
1225 encode_getattr_three(struct xdr_stream
*xdr
,
1226 uint32_t bm0
, uint32_t bm1
, uint32_t bm2
,
1227 struct compound_hdr
*hdr
)
1231 encode_op_hdr(xdr
, OP_GETATTR
, decode_getattr_maxsz
, hdr
);
1233 p
= reserve_space(xdr
, 16);
1234 *p
++ = cpu_to_be32(3);
1235 *p
++ = cpu_to_be32(bm0
);
1236 *p
++ = cpu_to_be32(bm1
);
1237 *p
= cpu_to_be32(bm2
);
1239 p
= reserve_space(xdr
, 12);
1240 *p
++ = cpu_to_be32(2);
1241 *p
++ = cpu_to_be32(bm0
);
1242 *p
= cpu_to_be32(bm1
);
1244 p
= reserve_space(xdr
, 8);
1245 *p
++ = cpu_to_be32(1);
1246 *p
= cpu_to_be32(bm0
);
1250 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1252 encode_getattr_three(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
1253 bitmask
[1] & nfs4_fattr_bitmap
[1],
1254 bitmask
[2] & nfs4_fattr_bitmap
[2],
1258 static void encode_getfattr_open(struct xdr_stream
*xdr
, const u32
*bitmask
,
1259 const u32
*open_bitmap
,
1260 struct compound_hdr
*hdr
)
1262 encode_getattr_three(xdr
,
1263 bitmask
[0] & open_bitmap
[0],
1264 bitmask
[1] & open_bitmap
[1],
1265 bitmask
[2] & open_bitmap
[2],
1269 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1271 encode_getattr_three(xdr
,
1272 bitmask
[0] & nfs4_fsinfo_bitmap
[0],
1273 bitmask
[1] & nfs4_fsinfo_bitmap
[1],
1274 bitmask
[2] & nfs4_fsinfo_bitmap
[2],
1278 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1280 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
1281 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
1284 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1286 encode_op_hdr(xdr
, OP_GETFH
, decode_getfh_maxsz
, hdr
);
1289 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1291 encode_op_hdr(xdr
, OP_LINK
, decode_link_maxsz
, hdr
);
1292 encode_string(xdr
, name
->len
, name
->name
);
1295 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1297 if (fl
->fl_type
== F_RDLCK
)
1298 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1299 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1302 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1304 if (fl
->fl_end
== OFFSET_MAX
)
1305 return ~(uint64_t)0;
1306 return fl
->fl_end
- fl
->fl_start
+ 1;
1309 static void encode_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
)
1313 p
= reserve_space(xdr
, 32);
1314 p
= xdr_encode_hyper(p
, lowner
->clientid
);
1315 *p
++ = cpu_to_be32(20);
1316 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1317 *p
++ = cpu_to_be32(lowner
->s_dev
);
1318 xdr_encode_hyper(p
, lowner
->id
);
1322 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1323 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1325 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1329 encode_op_hdr(xdr
, OP_LOCK
, decode_lock_maxsz
, hdr
);
1330 p
= reserve_space(xdr
, 28);
1331 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1332 *p
++ = cpu_to_be32(args
->reclaim
);
1333 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1334 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1335 *p
= cpu_to_be32(args
->new_lock_owner
);
1336 if (args
->new_lock_owner
){
1337 encode_nfs4_seqid(xdr
, args
->open_seqid
);
1338 encode_nfs4_stateid(xdr
, &args
->open_stateid
);
1339 encode_nfs4_seqid(xdr
, args
->lock_seqid
);
1340 encode_lockowner(xdr
, &args
->lock_owner
);
1343 encode_nfs4_stateid(xdr
, &args
->lock_stateid
);
1344 encode_nfs4_seqid(xdr
, args
->lock_seqid
);
1348 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1352 encode_op_hdr(xdr
, OP_LOCKT
, decode_lockt_maxsz
, hdr
);
1353 p
= reserve_space(xdr
, 20);
1354 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1355 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1356 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1357 encode_lockowner(xdr
, &args
->lock_owner
);
1360 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1364 encode_op_hdr(xdr
, OP_LOCKU
, decode_locku_maxsz
, hdr
);
1365 encode_uint32(xdr
, nfs4_lock_type(args
->fl
, 0));
1366 encode_nfs4_seqid(xdr
, args
->seqid
);
1367 encode_nfs4_stateid(xdr
, &args
->stateid
);
1368 p
= reserve_space(xdr
, 16);
1369 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1370 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1373 static void encode_release_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
, struct compound_hdr
*hdr
)
1375 encode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
, decode_release_lockowner_maxsz
, hdr
);
1376 encode_lockowner(xdr
, lowner
);
1379 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1381 encode_op_hdr(xdr
, OP_LOOKUP
, decode_lookup_maxsz
, hdr
);
1382 encode_string(xdr
, name
->len
, name
->name
);
1385 static void encode_lookupp(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1387 encode_op_hdr(xdr
, OP_LOOKUPP
, decode_lookupp_maxsz
, hdr
);
1390 static void encode_share_access(struct xdr_stream
*xdr
, u32 share_access
)
1394 p
= reserve_space(xdr
, 8);
1395 *p
++ = cpu_to_be32(share_access
);
1396 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1399 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1403 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1406 encode_nfs4_seqid(xdr
, arg
->seqid
);
1407 encode_share_access(xdr
, arg
->share_access
);
1408 p
= reserve_space(xdr
, 36);
1409 p
= xdr_encode_hyper(p
, arg
->clientid
);
1410 *p
++ = cpu_to_be32(24);
1411 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1412 *p
++ = cpu_to_be32(arg
->server
->s_dev
);
1413 *p
++ = cpu_to_be32(arg
->id
.uniquifier
);
1414 xdr_encode_hyper(p
, arg
->id
.create_time
);
1417 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1421 p
= reserve_space(xdr
, 4);
1422 switch(arg
->createmode
) {
1423 case NFS4_CREATE_UNCHECKED
:
1424 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1425 encode_attrs(xdr
, arg
->u
.attrs
, arg
->label
, &arg
->umask
,
1426 arg
->server
, arg
->server
->attr_bitmask
);
1428 case NFS4_CREATE_GUARDED
:
1429 *p
= cpu_to_be32(NFS4_CREATE_GUARDED
);
1430 encode_attrs(xdr
, arg
->u
.attrs
, arg
->label
, &arg
->umask
,
1431 arg
->server
, arg
->server
->attr_bitmask
);
1433 case NFS4_CREATE_EXCLUSIVE
:
1434 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1435 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1437 case NFS4_CREATE_EXCLUSIVE4_1
:
1438 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1439 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1440 encode_attrs(xdr
, arg
->u
.attrs
, arg
->label
, &arg
->umask
,
1441 arg
->server
, arg
->server
->exclcreat_bitmask
);
1445 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1449 p
= reserve_space(xdr
, 4);
1450 switch (arg
->open_flags
& O_CREAT
) {
1452 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1455 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1456 encode_createmode(xdr
, arg
);
1460 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1464 p
= reserve_space(xdr
, 4);
1465 switch (delegation_type
) {
1467 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1470 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1472 case FMODE_WRITE
|FMODE_READ
:
1473 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1480 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1484 p
= reserve_space(xdr
, 4);
1485 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1486 encode_string(xdr
, name
->len
, name
->name
);
1489 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1493 p
= reserve_space(xdr
, 4);
1494 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1495 encode_delegation_type(xdr
, type
);
1498 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1502 p
= reserve_space(xdr
, 4);
1503 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1504 encode_nfs4_stateid(xdr
, stateid
);
1505 encode_string(xdr
, name
->len
, name
->name
);
1508 static inline void encode_claim_fh(struct xdr_stream
*xdr
)
1512 p
= reserve_space(xdr
, 4);
1513 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_FH
);
1516 static inline void encode_claim_delegate_cur_fh(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1520 p
= reserve_space(xdr
, 4);
1521 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1522 encode_nfs4_stateid(xdr
, stateid
);
1525 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1527 encode_op_hdr(xdr
, OP_OPEN
, decode_open_maxsz
, hdr
);
1528 encode_openhdr(xdr
, arg
);
1529 encode_opentype(xdr
, arg
);
1530 switch (arg
->claim
) {
1531 case NFS4_OPEN_CLAIM_NULL
:
1532 encode_claim_null(xdr
, arg
->name
);
1534 case NFS4_OPEN_CLAIM_PREVIOUS
:
1535 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1537 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1538 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1540 case NFS4_OPEN_CLAIM_FH
:
1541 encode_claim_fh(xdr
);
1543 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1544 encode_claim_delegate_cur_fh(xdr
, &arg
->u
.delegation
);
1551 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1553 encode_op_hdr(xdr
, OP_OPEN_CONFIRM
, decode_open_confirm_maxsz
, hdr
);
1554 encode_nfs4_stateid(xdr
, arg
->stateid
);
1555 encode_nfs4_seqid(xdr
, arg
->seqid
);
1558 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1560 encode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
, decode_open_downgrade_maxsz
, hdr
);
1561 encode_nfs4_stateid(xdr
, &arg
->stateid
);
1562 encode_nfs4_seqid(xdr
, arg
->seqid
);
1563 encode_share_access(xdr
, arg
->share_access
);
1567 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1569 encode_op_hdr(xdr
, OP_PUTFH
, decode_putfh_maxsz
, hdr
);
1570 encode_string(xdr
, fh
->size
, fh
->data
);
1573 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1575 encode_op_hdr(xdr
, OP_PUTROOTFH
, decode_putrootfh_maxsz
, hdr
);
1578 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_pgio_args
*args
,
1579 struct compound_hdr
*hdr
)
1583 encode_op_hdr(xdr
, OP_READ
, decode_read_maxsz
, hdr
);
1584 encode_nfs4_stateid(xdr
, &args
->stateid
);
1586 p
= reserve_space(xdr
, 12);
1587 p
= xdr_encode_hyper(p
, args
->offset
);
1588 *p
= cpu_to_be32(args
->count
);
1591 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1593 uint32_t attrs
[3] = {
1594 FATTR4_WORD0_RDATTR_ERROR
,
1595 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1597 uint32_t dircount
= readdir
->count
>> 1;
1599 uint32_t attrlen
= 0;
1602 if (readdir
->plus
) {
1603 attrs
[0] |= FATTR4_WORD0_TYPE
|FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
|
1604 FATTR4_WORD0_FSID
|FATTR4_WORD0_FILEHANDLE
|FATTR4_WORD0_FILEID
;
1605 attrs
[1] |= FATTR4_WORD1_MODE
|FATTR4_WORD1_NUMLINKS
|FATTR4_WORD1_OWNER
|
1606 FATTR4_WORD1_OWNER_GROUP
|FATTR4_WORD1_RAWDEV
|
1607 FATTR4_WORD1_SPACE_USED
|FATTR4_WORD1_TIME_ACCESS
|
1608 FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
1609 attrs
[2] |= FATTR4_WORD2_SECURITY_LABEL
;
1612 /* Use mounted_on_fileid only if the server supports it */
1613 if (!(readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
))
1614 attrs
[0] |= FATTR4_WORD0_FILEID
;
1615 for (i
= 0; i
< ARRAY_SIZE(attrs
); i
++) {
1616 attrs
[i
] &= readdir
->bitmask
[i
];
1621 encode_op_hdr(xdr
, OP_READDIR
, decode_readdir_maxsz
, hdr
);
1622 encode_uint64(xdr
, readdir
->cookie
);
1623 encode_nfs4_verifier(xdr
, &readdir
->verifier
);
1624 p
= reserve_space(xdr
, 12 + (attrlen
<< 2));
1625 *p
++ = cpu_to_be32(dircount
);
1626 *p
++ = cpu_to_be32(readdir
->count
);
1627 *p
++ = cpu_to_be32(attrlen
);
1628 for (i
= 0; i
< attrlen
; i
++)
1629 *p
++ = cpu_to_be32(attrs
[i
]);
1630 memcpy(verf
, readdir
->verifier
.data
, sizeof(verf
));
1632 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1634 (unsigned long long)readdir
->cookie
,
1636 attrs
[0] & readdir
->bitmask
[0],
1637 attrs
[1] & readdir
->bitmask
[1],
1638 attrs
[2] & readdir
->bitmask
[2]);
1641 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1643 encode_op_hdr(xdr
, OP_READLINK
, decode_readlink_maxsz
, hdr
);
1646 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1648 encode_op_hdr(xdr
, OP_REMOVE
, decode_remove_maxsz
, hdr
);
1649 encode_string(xdr
, name
->len
, name
->name
);
1652 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1654 encode_op_hdr(xdr
, OP_RENAME
, decode_rename_maxsz
, hdr
);
1655 encode_string(xdr
, oldname
->len
, oldname
->name
);
1656 encode_string(xdr
, newname
->len
, newname
->name
);
1659 static void encode_renew(struct xdr_stream
*xdr
, clientid4 clid
,
1660 struct compound_hdr
*hdr
)
1662 encode_op_hdr(xdr
, OP_RENEW
, decode_renew_maxsz
, hdr
);
1663 encode_uint64(xdr
, clid
);
1667 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1669 encode_op_hdr(xdr
, OP_RESTOREFH
, decode_restorefh_maxsz
, hdr
);
1673 encode_setacl(struct xdr_stream
*xdr
, const struct nfs_setaclargs
*arg
,
1674 struct compound_hdr
*hdr
)
1678 encode_op_hdr(xdr
, OP_SETATTR
, decode_setacl_maxsz
, hdr
);
1679 encode_nfs4_stateid(xdr
, &zero_stateid
);
1680 p
= reserve_space(xdr
, 2*4);
1681 *p
++ = cpu_to_be32(1);
1682 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1683 p
= reserve_space(xdr
, 4);
1684 *p
= cpu_to_be32(arg
->acl_len
);
1685 xdr_write_pages(xdr
, arg
->acl_pages
, 0, arg
->acl_len
);
1689 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1691 encode_op_hdr(xdr
, OP_SAVEFH
, decode_savefh_maxsz
, hdr
);
1694 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1696 encode_op_hdr(xdr
, OP_SETATTR
, decode_setattr_maxsz
, hdr
);
1697 encode_nfs4_stateid(xdr
, &arg
->stateid
);
1698 encode_attrs(xdr
, arg
->iap
, arg
->label
, NULL
, server
,
1699 server
->attr_bitmask
);
1702 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1706 encode_op_hdr(xdr
, OP_SETCLIENTID
, decode_setclientid_maxsz
, hdr
);
1707 encode_nfs4_verifier(xdr
, setclientid
->sc_verifier
);
1709 encode_string(xdr
, strlen(setclientid
->sc_clnt
->cl_owner_id
),
1710 setclientid
->sc_clnt
->cl_owner_id
);
1711 p
= reserve_space(xdr
, 4);
1712 *p
= cpu_to_be32(setclientid
->sc_prog
);
1713 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1714 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1715 p
= reserve_space(xdr
, 4);
1716 *p
= cpu_to_be32(setclientid
->sc_clnt
->cl_cb_ident
);
1719 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_setclientid_res
*arg
, struct compound_hdr
*hdr
)
1721 encode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
,
1722 decode_setclientid_confirm_maxsz
, hdr
);
1723 encode_uint64(xdr
, arg
->clientid
);
1724 encode_nfs4_verifier(xdr
, &arg
->confirm
);
1727 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_pgio_args
*args
,
1728 struct compound_hdr
*hdr
)
1732 encode_op_hdr(xdr
, OP_WRITE
, decode_write_maxsz
, hdr
);
1733 encode_nfs4_stateid(xdr
, &args
->stateid
);
1735 p
= reserve_space(xdr
, 16);
1736 p
= xdr_encode_hyper(p
, args
->offset
);
1737 *p
++ = cpu_to_be32(args
->stable
);
1738 *p
= cpu_to_be32(args
->count
);
1740 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1743 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1745 encode_op_hdr(xdr
, OP_DELEGRETURN
, decode_delegreturn_maxsz
, hdr
);
1746 encode_nfs4_stateid(xdr
, stateid
);
1749 static void encode_secinfo(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1751 encode_op_hdr(xdr
, OP_SECINFO
, decode_secinfo_maxsz
, hdr
);
1752 encode_string(xdr
, name
->len
, name
->name
);
1755 #if defined(CONFIG_NFS_V4_1)
1756 /* NFSv4.1 operations */
1757 static void encode_bind_conn_to_session(struct xdr_stream
*xdr
,
1758 const struct nfs41_bind_conn_to_session_args
*args
,
1759 struct compound_hdr
*hdr
)
1763 encode_op_hdr(xdr
, OP_BIND_CONN_TO_SESSION
,
1764 decode_bind_conn_to_session_maxsz
, hdr
);
1765 encode_opaque_fixed(xdr
, args
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
1766 p
= xdr_reserve_space(xdr
, 8);
1767 *p
++ = cpu_to_be32(args
->dir
);
1768 *p
= (args
->use_conn_in_rdma_mode
) ? cpu_to_be32(1) : cpu_to_be32(0);
1771 static void encode_op_map(struct xdr_stream
*xdr
, const struct nfs4_op_map
*op_map
)
1774 encode_uint32(xdr
, NFS4_OP_MAP_NUM_WORDS
);
1775 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++)
1776 encode_uint32(xdr
, op_map
->u
.words
[i
]);
1779 static void encode_exchange_id(struct xdr_stream
*xdr
,
1780 const struct nfs41_exchange_id_args
*args
,
1781 struct compound_hdr
*hdr
)
1784 char impl_name
[IMPL_NAME_LIMIT
];
1787 encode_op_hdr(xdr
, OP_EXCHANGE_ID
, decode_exchange_id_maxsz
, hdr
);
1788 encode_nfs4_verifier(xdr
, &args
->verifier
);
1790 encode_string(xdr
, strlen(args
->client
->cl_owner_id
),
1791 args
->client
->cl_owner_id
);
1793 encode_uint32(xdr
, args
->flags
);
1794 encode_uint32(xdr
, args
->state_protect
.how
);
1796 switch (args
->state_protect
.how
) {
1800 encode_op_map(xdr
, &args
->state_protect
.enforce
);
1801 encode_op_map(xdr
, &args
->state_protect
.allow
);
1808 if (send_implementation_id
&&
1809 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
) > 1 &&
1810 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
)
1811 <= sizeof(impl_name
) + 1)
1812 len
= snprintf(impl_name
, sizeof(impl_name
), "%s %s %s %s",
1813 utsname()->sysname
, utsname()->release
,
1814 utsname()->version
, utsname()->machine
);
1817 encode_uint32(xdr
, 1); /* implementation id array length=1 */
1820 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
) - 1,
1821 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
);
1822 encode_string(xdr
, len
, impl_name
);
1823 /* just send zeros for nii_date - the date is in nii_name */
1824 p
= reserve_space(xdr
, 12);
1825 p
= xdr_encode_hyper(p
, 0);
1826 *p
= cpu_to_be32(0);
1828 encode_uint32(xdr
, 0); /* implementation id array length=0 */
1831 static void encode_create_session(struct xdr_stream
*xdr
,
1832 const struct nfs41_create_session_args
*args
,
1833 struct compound_hdr
*hdr
)
1836 struct nfs_client
*clp
= args
->client
;
1837 struct rpc_clnt
*clnt
= clp
->cl_rpcclient
;
1838 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
1839 u32 max_resp_sz_cached
;
1842 * Assumes OPEN is the biggest non-idempotent compound.
1843 * 2 is the verifier.
1845 max_resp_sz_cached
= (NFS4_dec_open_sz
+ RPC_REPHDRSIZE
+ 2)
1846 * XDR_UNIT
+ RPC_MAX_AUTH_SIZE
;
1848 encode_op_hdr(xdr
, OP_CREATE_SESSION
, decode_create_session_maxsz
, hdr
);
1849 p
= reserve_space(xdr
, 16 + 2*28 + 20 + clnt
->cl_nodelen
+ 12);
1850 p
= xdr_encode_hyper(p
, args
->clientid
);
1851 *p
++ = cpu_to_be32(args
->seqid
); /*Sequence id */
1852 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1855 *p
++ = cpu_to_be32(0); /* header padding size */
1856 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1857 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1858 *p
++ = cpu_to_be32(max_resp_sz_cached
); /* Max resp sz cached */
1859 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1860 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1861 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1864 *p
++ = cpu_to_be32(0); /* header padding size */
1865 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1866 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1867 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1868 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1869 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1870 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1872 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1873 *p
++ = cpu_to_be32(1);
1874 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1876 /* authsys_parms rfc1831 */
1877 *p
++ = cpu_to_be32(ktime_to_ns(nn
->boot_time
)); /* stamp */
1878 p
= xdr_encode_array(p
, clnt
->cl_nodename
, clnt
->cl_nodelen
);
1879 *p
++ = cpu_to_be32(0); /* UID */
1880 *p
++ = cpu_to_be32(0); /* GID */
1881 *p
= cpu_to_be32(0); /* No more gids */
1884 static void encode_destroy_session(struct xdr_stream
*xdr
,
1885 const struct nfs4_session
*session
,
1886 struct compound_hdr
*hdr
)
1888 encode_op_hdr(xdr
, OP_DESTROY_SESSION
, decode_destroy_session_maxsz
, hdr
);
1889 encode_opaque_fixed(xdr
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1892 static void encode_destroy_clientid(struct xdr_stream
*xdr
,
1894 struct compound_hdr
*hdr
)
1896 encode_op_hdr(xdr
, OP_DESTROY_CLIENTID
, decode_destroy_clientid_maxsz
, hdr
);
1897 encode_uint64(xdr
, clientid
);
1900 static void encode_reclaim_complete(struct xdr_stream
*xdr
,
1901 const struct nfs41_reclaim_complete_args
*args
,
1902 struct compound_hdr
*hdr
)
1904 encode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
, decode_reclaim_complete_maxsz
, hdr
);
1905 encode_uint32(xdr
, args
->one_fs
);
1907 #endif /* CONFIG_NFS_V4_1 */
1909 static void encode_sequence(struct xdr_stream
*xdr
,
1910 const struct nfs4_sequence_args
*args
,
1911 struct compound_hdr
*hdr
)
1913 #if defined(CONFIG_NFS_V4_1)
1914 struct nfs4_session
*session
;
1915 struct nfs4_slot_table
*tp
;
1916 struct nfs4_slot
*slot
= args
->sa_slot
;
1920 session
= tp
->session
;
1924 encode_op_hdr(xdr
, OP_SEQUENCE
, decode_sequence_maxsz
, hdr
);
1927 * Sessionid + seqid + slotid + max slotid + cache_this
1929 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1930 "max_slotid=%d cache_this=%d\n",
1932 ((u32
*)session
->sess_id
.data
)[0],
1933 ((u32
*)session
->sess_id
.data
)[1],
1934 ((u32
*)session
->sess_id
.data
)[2],
1935 ((u32
*)session
->sess_id
.data
)[3],
1936 slot
->seq_nr
, slot
->slot_nr
,
1937 tp
->highest_used_slotid
, args
->sa_cache_this
);
1938 p
= reserve_space(xdr
, NFS4_MAX_SESSIONID_LEN
+ 16);
1939 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1940 *p
++ = cpu_to_be32(slot
->seq_nr
);
1941 *p
++ = cpu_to_be32(slot
->slot_nr
);
1942 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1943 *p
= cpu_to_be32(args
->sa_cache_this
);
1944 #endif /* CONFIG_NFS_V4_1 */
1947 #ifdef CONFIG_NFS_V4_1
1949 encode_getdeviceinfo(struct xdr_stream
*xdr
,
1950 const struct nfs4_getdeviceinfo_args
*args
,
1951 struct compound_hdr
*hdr
)
1955 encode_op_hdr(xdr
, OP_GETDEVICEINFO
, decode_getdeviceinfo_maxsz
, hdr
);
1956 p
= reserve_space(xdr
, NFS4_DEVICEID4_SIZE
+ 4 + 4);
1957 p
= xdr_encode_opaque_fixed(p
, args
->pdev
->dev_id
.data
,
1958 NFS4_DEVICEID4_SIZE
);
1959 *p
++ = cpu_to_be32(args
->pdev
->layout_type
);
1960 *p
++ = cpu_to_be32(args
->pdev
->maxcount
); /* gdia_maxcount */
1962 p
= reserve_space(xdr
, 4 + 4);
1963 *p
++ = cpu_to_be32(1); /* bitmap length */
1964 *p
++ = cpu_to_be32(args
->notify_types
);
1968 encode_layoutget(struct xdr_stream
*xdr
,
1969 const struct nfs4_layoutget_args
*args
,
1970 struct compound_hdr
*hdr
)
1974 encode_op_hdr(xdr
, OP_LAYOUTGET
, decode_layoutget_maxsz
, hdr
);
1975 p
= reserve_space(xdr
, 36);
1976 *p
++ = cpu_to_be32(0); /* Signal layout available */
1977 *p
++ = cpu_to_be32(args
->type
);
1978 *p
++ = cpu_to_be32(args
->range
.iomode
);
1979 p
= xdr_encode_hyper(p
, args
->range
.offset
);
1980 p
= xdr_encode_hyper(p
, args
->range
.length
);
1981 p
= xdr_encode_hyper(p
, args
->minlength
);
1982 encode_nfs4_stateid(xdr
, &args
->stateid
);
1983 encode_uint32(xdr
, args
->maxcount
);
1985 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1989 (unsigned long)args
->range
.offset
,
1990 (unsigned long)args
->range
.length
,
1995 encode_layoutcommit(struct xdr_stream
*xdr
,
1996 struct inode
*inode
,
1997 const struct nfs4_layoutcommit_args
*args
,
1998 struct compound_hdr
*hdr
)
2002 dprintk("%s: lbw: %llu type: %d\n", __func__
, args
->lastbytewritten
,
2003 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);
2005 encode_op_hdr(xdr
, OP_LAYOUTCOMMIT
, decode_layoutcommit_maxsz
, hdr
);
2006 p
= reserve_space(xdr
, 20);
2007 /* Only whole file layouts */
2008 p
= xdr_encode_hyper(p
, 0); /* offset */
2009 p
= xdr_encode_hyper(p
, args
->lastbytewritten
+ 1); /* length */
2010 *p
= cpu_to_be32(0); /* reclaim */
2011 encode_nfs4_stateid(xdr
, &args
->stateid
);
2012 if (args
->lastbytewritten
!= U64_MAX
) {
2013 p
= reserve_space(xdr
, 20);
2014 *p
++ = cpu_to_be32(1); /* newoffset = TRUE */
2015 p
= xdr_encode_hyper(p
, args
->lastbytewritten
);
2017 p
= reserve_space(xdr
, 12);
2018 *p
++ = cpu_to_be32(0); /* newoffset = FALSE */
2020 *p
++ = cpu_to_be32(0); /* Never send time_modify_changed */
2021 *p
++ = cpu_to_be32(NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);/* type */
2023 encode_uint32(xdr
, args
->layoutupdate_len
);
2024 if (args
->layoutupdate_pages
)
2025 xdr_write_pages(xdr
, args
->layoutupdate_pages
, 0,
2026 args
->layoutupdate_len
);
2032 encode_layoutreturn(struct xdr_stream
*xdr
,
2033 const struct nfs4_layoutreturn_args
*args
,
2034 struct compound_hdr
*hdr
)
2038 encode_op_hdr(xdr
, OP_LAYOUTRETURN
, decode_layoutreturn_maxsz
, hdr
);
2039 p
= reserve_space(xdr
, 16);
2040 *p
++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2041 *p
++ = cpu_to_be32(args
->layout_type
);
2042 *p
++ = cpu_to_be32(args
->range
.iomode
);
2043 *p
= cpu_to_be32(RETURN_FILE
);
2044 p
= reserve_space(xdr
, 16);
2045 p
= xdr_encode_hyper(p
, args
->range
.offset
);
2046 p
= xdr_encode_hyper(p
, args
->range
.length
);
2047 spin_lock(&args
->inode
->i_lock
);
2048 encode_nfs4_stateid(xdr
, &args
->stateid
);
2049 spin_unlock(&args
->inode
->i_lock
);
2050 if (args
->ld_private
->ops
&& args
->ld_private
->ops
->encode
)
2051 args
->ld_private
->ops
->encode(xdr
, args
, args
->ld_private
);
2053 encode_uint32(xdr
, 0);
2057 encode_secinfo_no_name(struct xdr_stream
*xdr
,
2058 const struct nfs41_secinfo_no_name_args
*args
,
2059 struct compound_hdr
*hdr
)
2061 encode_op_hdr(xdr
, OP_SECINFO_NO_NAME
, decode_secinfo_no_name_maxsz
, hdr
);
2062 encode_uint32(xdr
, args
->style
);
2066 static void encode_test_stateid(struct xdr_stream
*xdr
,
2067 const struct nfs41_test_stateid_args
*args
,
2068 struct compound_hdr
*hdr
)
2070 encode_op_hdr(xdr
, OP_TEST_STATEID
, decode_test_stateid_maxsz
, hdr
);
2071 encode_uint32(xdr
, 1);
2072 encode_nfs4_stateid(xdr
, args
->stateid
);
2075 static void encode_free_stateid(struct xdr_stream
*xdr
,
2076 const struct nfs41_free_stateid_args
*args
,
2077 struct compound_hdr
*hdr
)
2079 encode_op_hdr(xdr
, OP_FREE_STATEID
, decode_free_stateid_maxsz
, hdr
);
2080 encode_nfs4_stateid(xdr
, &args
->stateid
);
2084 encode_layoutreturn(struct xdr_stream
*xdr
,
2085 const struct nfs4_layoutreturn_args
*args
,
2086 struct compound_hdr
*hdr
)
2089 #endif /* CONFIG_NFS_V4_1 */
2092 * END OF "GENERIC" ENCODE ROUTINES.
2095 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
2097 #if defined(CONFIG_NFS_V4_1)
2098 struct nfs4_session
*session
= args
->sa_slot
->table
->session
;
2100 return session
->clp
->cl_mvops
->minor_version
;
2101 #endif /* CONFIG_NFS_V4_1 */
2106 * Encode an ACCESS request
2108 static void nfs4_xdr_enc_access(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2111 const struct nfs4_accessargs
*args
= data
;
2112 struct compound_hdr hdr
= {
2113 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2116 encode_compound_hdr(xdr
, req
, &hdr
);
2117 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2118 encode_putfh(xdr
, args
->fh
, &hdr
);
2119 encode_access(xdr
, args
->access
, &hdr
);
2120 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2125 * Encode LOOKUP request
2127 static void nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2130 const struct nfs4_lookup_arg
*args
= data
;
2131 struct compound_hdr hdr
= {
2132 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2135 encode_compound_hdr(xdr
, req
, &hdr
);
2136 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2137 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2138 encode_lookup(xdr
, args
->name
, &hdr
);
2139 encode_getfh(xdr
, &hdr
);
2140 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2145 * Encode LOOKUPP request
2147 static void nfs4_xdr_enc_lookupp(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2150 const struct nfs4_lookupp_arg
*args
= data
;
2151 struct compound_hdr hdr
= {
2152 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2155 encode_compound_hdr(xdr
, req
, &hdr
);
2156 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2157 encode_putfh(xdr
, args
->fh
, &hdr
);
2158 encode_lookupp(xdr
, &hdr
);
2159 encode_getfh(xdr
, &hdr
);
2160 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2165 * Encode LOOKUP_ROOT request
2167 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
,
2168 struct xdr_stream
*xdr
,
2171 const struct nfs4_lookup_root_arg
*args
= data
;
2172 struct compound_hdr hdr
= {
2173 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2176 encode_compound_hdr(xdr
, req
, &hdr
);
2177 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2178 encode_putrootfh(xdr
, &hdr
);
2179 encode_getfh(xdr
, &hdr
);
2180 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2185 * Encode REMOVE request
2187 static void nfs4_xdr_enc_remove(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2190 const struct nfs_removeargs
*args
= data
;
2191 struct compound_hdr hdr
= {
2192 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2195 encode_compound_hdr(xdr
, req
, &hdr
);
2196 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2197 encode_putfh(xdr
, args
->fh
, &hdr
);
2198 encode_remove(xdr
, &args
->name
, &hdr
);
2203 * Encode RENAME request
2205 static void nfs4_xdr_enc_rename(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2208 const struct nfs_renameargs
*args
= data
;
2209 struct compound_hdr hdr
= {
2210 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2213 encode_compound_hdr(xdr
, req
, &hdr
);
2214 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2215 encode_putfh(xdr
, args
->old_dir
, &hdr
);
2216 encode_savefh(xdr
, &hdr
);
2217 encode_putfh(xdr
, args
->new_dir
, &hdr
);
2218 encode_rename(xdr
, args
->old_name
, args
->new_name
, &hdr
);
2223 * Encode LINK request
2225 static void nfs4_xdr_enc_link(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2228 const struct nfs4_link_arg
*args
= data
;
2229 struct compound_hdr hdr
= {
2230 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2233 encode_compound_hdr(xdr
, req
, &hdr
);
2234 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2235 encode_putfh(xdr
, args
->fh
, &hdr
);
2236 encode_savefh(xdr
, &hdr
);
2237 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2238 encode_link(xdr
, args
->name
, &hdr
);
2239 encode_restorefh(xdr
, &hdr
);
2240 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2245 * Encode CREATE request
2247 static void nfs4_xdr_enc_create(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2250 const struct nfs4_create_arg
*args
= data
;
2251 struct compound_hdr hdr
= {
2252 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2255 encode_compound_hdr(xdr
, req
, &hdr
);
2256 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2257 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2258 encode_create(xdr
, args
, &hdr
);
2259 encode_getfh(xdr
, &hdr
);
2260 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2265 * Encode SYMLINK request
2267 static void nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2270 const struct nfs4_create_arg
*args
= data
;
2272 nfs4_xdr_enc_create(req
, xdr
, args
);
2276 * Encode GETATTR request
2278 static void nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2281 const struct nfs4_getattr_arg
*args
= data
;
2282 struct compound_hdr hdr
= {
2283 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2286 encode_compound_hdr(xdr
, req
, &hdr
);
2287 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2288 encode_putfh(xdr
, args
->fh
, &hdr
);
2289 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2294 * Encode a CLOSE request
2296 static void nfs4_xdr_enc_close(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2299 const struct nfs_closeargs
*args
= data
;
2300 struct compound_hdr hdr
= {
2301 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2304 encode_compound_hdr(xdr
, req
, &hdr
);
2305 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2306 encode_putfh(xdr
, args
->fh
, &hdr
);
2308 encode_layoutreturn(xdr
, args
->lr_args
, &hdr
);
2309 if (args
->bitmask
!= NULL
)
2310 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2311 encode_close(xdr
, args
, &hdr
);
2316 * Encode an OPEN request
2318 static void nfs4_xdr_enc_open(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2321 const struct nfs_openargs
*args
= data
;
2322 struct compound_hdr hdr
= {
2323 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2326 encode_compound_hdr(xdr
, req
, &hdr
);
2327 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2328 encode_putfh(xdr
, args
->fh
, &hdr
);
2329 encode_open(xdr
, args
, &hdr
);
2330 encode_getfh(xdr
, &hdr
);
2332 encode_access(xdr
, args
->access
, &hdr
);
2333 encode_getfattr_open(xdr
, args
->bitmask
, args
->open_bitmap
, &hdr
);
2338 * Encode an OPEN_CONFIRM request
2340 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
,
2341 struct xdr_stream
*xdr
,
2344 const struct nfs_open_confirmargs
*args
= data
;
2345 struct compound_hdr hdr
= {
2349 encode_compound_hdr(xdr
, req
, &hdr
);
2350 encode_putfh(xdr
, args
->fh
, &hdr
);
2351 encode_open_confirm(xdr
, args
, &hdr
);
2356 * Encode an OPEN request with no attributes.
2358 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
,
2359 struct xdr_stream
*xdr
,
2362 const struct nfs_openargs
*args
= data
;
2363 struct compound_hdr hdr
= {
2364 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2367 encode_compound_hdr(xdr
, req
, &hdr
);
2368 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2369 encode_putfh(xdr
, args
->fh
, &hdr
);
2370 encode_open(xdr
, args
, &hdr
);
2372 encode_access(xdr
, args
->access
, &hdr
);
2373 encode_getfattr_open(xdr
, args
->bitmask
, args
->open_bitmap
, &hdr
);
2378 * Encode an OPEN_DOWNGRADE request
2380 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
,
2381 struct xdr_stream
*xdr
,
2384 const struct nfs_closeargs
*args
= data
;
2385 struct compound_hdr hdr
= {
2386 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2389 encode_compound_hdr(xdr
, req
, &hdr
);
2390 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2391 encode_putfh(xdr
, args
->fh
, &hdr
);
2393 encode_layoutreturn(xdr
, args
->lr_args
, &hdr
);
2394 encode_open_downgrade(xdr
, args
, &hdr
);
2399 * Encode a LOCK request
2401 static void nfs4_xdr_enc_lock(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2404 const struct nfs_lock_args
*args
= data
;
2405 struct compound_hdr hdr
= {
2406 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2409 encode_compound_hdr(xdr
, req
, &hdr
);
2410 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2411 encode_putfh(xdr
, args
->fh
, &hdr
);
2412 encode_lock(xdr
, args
, &hdr
);
2417 * Encode a LOCKT request
2419 static void nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2422 const struct nfs_lockt_args
*args
= data
;
2423 struct compound_hdr hdr
= {
2424 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2427 encode_compound_hdr(xdr
, req
, &hdr
);
2428 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2429 encode_putfh(xdr
, args
->fh
, &hdr
);
2430 encode_lockt(xdr
, args
, &hdr
);
2435 * Encode a LOCKU request
2437 static void nfs4_xdr_enc_locku(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2440 const struct nfs_locku_args
*args
= data
;
2441 struct compound_hdr hdr
= {
2442 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2445 encode_compound_hdr(xdr
, req
, &hdr
);
2446 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2447 encode_putfh(xdr
, args
->fh
, &hdr
);
2448 encode_locku(xdr
, args
, &hdr
);
2452 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst
*req
,
2453 struct xdr_stream
*xdr
,
2456 const struct nfs_release_lockowner_args
*args
= data
;
2457 struct compound_hdr hdr
= {
2461 encode_compound_hdr(xdr
, req
, &hdr
);
2462 encode_release_lockowner(xdr
, &args
->lock_owner
, &hdr
);
2467 * Encode a READLINK request
2469 static void nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2472 const struct nfs4_readlink
*args
= data
;
2473 struct compound_hdr hdr
= {
2474 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2477 encode_compound_hdr(xdr
, req
, &hdr
);
2478 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2479 encode_putfh(xdr
, args
->fh
, &hdr
);
2480 encode_readlink(xdr
, args
, req
, &hdr
);
2482 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2483 args
->pgbase
, args
->pglen
);
2488 * Encode a READDIR request
2490 static void nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2493 const struct nfs4_readdir_arg
*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_readdir(xdr
, args
, req
, &hdr
);
2503 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2504 args
->pgbase
, args
->count
);
2505 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2506 __func__
, hdr
.replen
<< 2, args
->pages
,
2507 args
->pgbase
, args
->count
);
2512 * Encode a READ request
2514 static void nfs4_xdr_enc_read(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2517 const struct nfs_pgio_args
*args
= data
;
2518 struct compound_hdr hdr
= {
2519 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2522 encode_compound_hdr(xdr
, req
, &hdr
);
2523 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2524 encode_putfh(xdr
, args
->fh
, &hdr
);
2525 encode_read(xdr
, args
, &hdr
);
2527 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2528 args
->pages
, args
->pgbase
, args
->count
);
2529 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2534 * Encode an SETATTR request
2536 static void nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2539 const struct nfs_setattrargs
*args
= data
;
2540 struct compound_hdr hdr
= {
2541 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2544 encode_compound_hdr(xdr
, req
, &hdr
);
2545 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2546 encode_putfh(xdr
, args
->fh
, &hdr
);
2547 encode_setattr(xdr
, args
, args
->server
, &hdr
);
2548 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2553 * Encode a GETACL request
2555 static void nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2558 const struct nfs_getaclargs
*args
= data
;
2559 struct compound_hdr hdr
= {
2560 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2564 encode_compound_hdr(xdr
, req
, &hdr
);
2565 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2566 encode_putfh(xdr
, args
->fh
, &hdr
);
2567 replen
= hdr
.replen
+ op_decode_hdr_maxsz
;
2568 encode_getattr_two(xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2570 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2571 args
->acl_pages
, 0, args
->acl_len
);
2577 * Encode a WRITE request
2579 static void nfs4_xdr_enc_write(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2582 const struct nfs_pgio_args
*args
= data
;
2583 struct compound_hdr hdr
= {
2584 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2587 encode_compound_hdr(xdr
, req
, &hdr
);
2588 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2589 encode_putfh(xdr
, args
->fh
, &hdr
);
2590 encode_write(xdr
, args
, &hdr
);
2591 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2593 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2600 static void nfs4_xdr_enc_commit(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2603 const struct nfs_commitargs
*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_commit(xdr
, args
, &hdr
);
2618 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2621 const struct nfs4_fsinfo_arg
*args
= data
;
2622 struct compound_hdr hdr
= {
2623 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2626 encode_compound_hdr(xdr
, req
, &hdr
);
2627 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2628 encode_putfh(xdr
, args
->fh
, &hdr
);
2629 encode_fsinfo(xdr
, args
->bitmask
, &hdr
);
2634 * a PATHCONF request
2636 static void nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2639 const struct nfs4_pathconf_arg
*args
= data
;
2640 struct compound_hdr hdr
= {
2641 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2644 encode_compound_hdr(xdr
, req
, &hdr
);
2645 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2646 encode_putfh(xdr
, args
->fh
, &hdr
);
2647 encode_getattr_one(xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2655 static void nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2658 const struct nfs4_statfs_arg
*args
= data
;
2659 struct compound_hdr hdr
= {
2660 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2663 encode_compound_hdr(xdr
, req
, &hdr
);
2664 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2665 encode_putfh(xdr
, args
->fh
, &hdr
);
2666 encode_getattr_two(xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2667 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2672 * GETATTR_BITMAP request
2674 static void nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
,
2675 struct xdr_stream
*xdr
,
2678 const struct nfs4_server_caps_arg
*args
= data
;
2679 const u32
*bitmask
= args
->bitmask
;
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
->fhandle
, &hdr
);
2687 encode_getattr_three(xdr
, bitmask
[0], bitmask
[1], bitmask
[2], &hdr
);
2694 static void nfs4_xdr_enc_renew(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2698 const struct nfs_client
*clp
= data
;
2699 struct compound_hdr hdr
= {
2703 encode_compound_hdr(xdr
, req
, &hdr
);
2704 encode_renew(xdr
, clp
->cl_clientid
, &hdr
);
2709 * a SETCLIENTID request
2711 static void nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
,
2712 struct xdr_stream
*xdr
,
2715 const struct nfs4_setclientid
*sc
= data
;
2716 struct compound_hdr hdr
= {
2720 encode_compound_hdr(xdr
, req
, &hdr
);
2721 encode_setclientid(xdr
, sc
, &hdr
);
2726 * a SETCLIENTID_CONFIRM request
2728 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
,
2729 struct xdr_stream
*xdr
,
2732 const struct nfs4_setclientid_res
*arg
= data
;
2733 struct compound_hdr hdr
= {
2737 encode_compound_hdr(xdr
, req
, &hdr
);
2738 encode_setclientid_confirm(xdr
, arg
, &hdr
);
2743 * DELEGRETURN request
2745 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
,
2746 struct xdr_stream
*xdr
,
2749 const struct nfs4_delegreturnargs
*args
= data
;
2750 struct compound_hdr hdr
= {
2751 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2754 encode_compound_hdr(xdr
, req
, &hdr
);
2755 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2756 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2758 encode_layoutreturn(xdr
, args
->lr_args
, &hdr
);
2760 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2761 encode_delegreturn(xdr
, args
->stateid
, &hdr
);
2766 * Encode FS_LOCATIONS request
2768 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
,
2769 struct xdr_stream
*xdr
,
2772 const struct nfs4_fs_locations_arg
*args
= data
;
2773 struct compound_hdr hdr
= {
2774 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2778 encode_compound_hdr(xdr
, req
, &hdr
);
2779 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2780 if (args
->migration
) {
2781 encode_putfh(xdr
, args
->fh
, &hdr
);
2782 replen
= hdr
.replen
;
2783 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2785 encode_renew(xdr
, args
->clientid
, &hdr
);
2787 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2788 encode_lookup(xdr
, args
->name
, &hdr
);
2789 replen
= hdr
.replen
;
2790 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2793 /* Set up reply kvec to capture returned fs_locations array. */
2794 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2795 (struct page
**)&args
->page
, 0, PAGE_SIZE
);
2800 * Encode SECINFO request
2802 static void nfs4_xdr_enc_secinfo(struct rpc_rqst
*req
,
2803 struct xdr_stream
*xdr
,
2806 const struct nfs4_secinfo_arg
*args
= data
;
2807 struct compound_hdr hdr
= {
2808 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2811 encode_compound_hdr(xdr
, req
, &hdr
);
2812 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2813 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2814 encode_secinfo(xdr
, args
->name
, &hdr
);
2819 * Encode FSID_PRESENT request
2821 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst
*req
,
2822 struct xdr_stream
*xdr
,
2825 const struct nfs4_fsid_present_arg
*args
= data
;
2826 struct compound_hdr hdr
= {
2827 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2830 encode_compound_hdr(xdr
, req
, &hdr
);
2831 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2832 encode_putfh(xdr
, args
->fh
, &hdr
);
2833 encode_getfh(xdr
, &hdr
);
2835 encode_renew(xdr
, args
->clientid
, &hdr
);
2839 #if defined(CONFIG_NFS_V4_1)
2841 * BIND_CONN_TO_SESSION request
2843 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst
*req
,
2844 struct xdr_stream
*xdr
,
2847 const struct nfs41_bind_conn_to_session_args
*args
= data
;
2848 struct compound_hdr hdr
= {
2849 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2852 encode_compound_hdr(xdr
, req
, &hdr
);
2853 encode_bind_conn_to_session(xdr
, args
, &hdr
);
2858 * EXCHANGE_ID request
2860 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
,
2861 struct xdr_stream
*xdr
,
2864 const struct nfs41_exchange_id_args
*args
= data
;
2865 struct compound_hdr hdr
= {
2866 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2869 encode_compound_hdr(xdr
, req
, &hdr
);
2870 encode_exchange_id(xdr
, args
, &hdr
);
2875 * a CREATE_SESSION request
2877 static void nfs4_xdr_enc_create_session(struct rpc_rqst
*req
,
2878 struct xdr_stream
*xdr
,
2881 const struct nfs41_create_session_args
*args
= data
;
2882 struct compound_hdr hdr
= {
2883 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2886 encode_compound_hdr(xdr
, req
, &hdr
);
2887 encode_create_session(xdr
, args
, &hdr
);
2892 * a DESTROY_SESSION request
2894 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
,
2895 struct xdr_stream
*xdr
,
2898 const struct nfs4_session
*session
= data
;
2899 struct compound_hdr hdr
= {
2900 .minorversion
= session
->clp
->cl_mvops
->minor_version
,
2903 encode_compound_hdr(xdr
, req
, &hdr
);
2904 encode_destroy_session(xdr
, session
, &hdr
);
2909 * a DESTROY_CLIENTID request
2911 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst
*req
,
2912 struct xdr_stream
*xdr
,
2915 const struct nfs_client
*clp
= data
;
2916 struct compound_hdr hdr
= {
2917 .minorversion
= clp
->cl_mvops
->minor_version
,
2920 encode_compound_hdr(xdr
, req
, &hdr
);
2921 encode_destroy_clientid(xdr
, clp
->cl_clientid
, &hdr
);
2926 * a SEQUENCE request
2928 static void nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2931 const struct nfs4_sequence_args
*args
= data
;
2932 struct compound_hdr hdr
= {
2933 .minorversion
= nfs4_xdr_minorversion(args
),
2936 encode_compound_hdr(xdr
, req
, &hdr
);
2937 encode_sequence(xdr
, args
, &hdr
);
2942 * a GET_LEASE_TIME request
2944 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
,
2945 struct xdr_stream
*xdr
,
2948 const struct nfs4_get_lease_time_args
*args
= data
;
2949 struct compound_hdr hdr
= {
2950 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2952 const u32 lease_bitmap
[3] = { FATTR4_WORD0_LEASE_TIME
};
2954 encode_compound_hdr(xdr
, req
, &hdr
);
2955 encode_sequence(xdr
, &args
->la_seq_args
, &hdr
);
2956 encode_putrootfh(xdr
, &hdr
);
2957 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2962 * a RECLAIM_COMPLETE request
2964 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
,
2965 struct xdr_stream
*xdr
,
2968 const struct nfs41_reclaim_complete_args
*args
= data
;
2969 struct compound_hdr hdr
= {
2970 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2973 encode_compound_hdr(xdr
, req
, &hdr
);
2974 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2975 encode_reclaim_complete(xdr
, args
, &hdr
);
2980 * Encode GETDEVICEINFO request
2982 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst
*req
,
2983 struct xdr_stream
*xdr
,
2986 const struct nfs4_getdeviceinfo_args
*args
= data
;
2987 struct compound_hdr hdr
= {
2988 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2991 encode_compound_hdr(xdr
, req
, &hdr
);
2992 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2993 encode_getdeviceinfo(xdr
, args
, &hdr
);
2995 /* set up reply kvec. Subtract notification bitmap max size (2)
2996 * so that notification bitmap is put in xdr_buf tail */
2997 xdr_inline_pages(&req
->rq_rcv_buf
, (hdr
.replen
- 2) << 2,
2998 args
->pdev
->pages
, args
->pdev
->pgbase
,
3005 * Encode LAYOUTGET request
3007 static void nfs4_xdr_enc_layoutget(struct rpc_rqst
*req
,
3008 struct xdr_stream
*xdr
,
3011 const struct nfs4_layoutget_args
*args
= data
;
3012 struct compound_hdr hdr
= {
3013 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3016 encode_compound_hdr(xdr
, req
, &hdr
);
3017 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3018 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
3019 encode_layoutget(xdr
, args
, &hdr
);
3021 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
3022 args
->layout
.pages
, 0, args
->layout
.pglen
);
3028 * Encode LAYOUTCOMMIT request
3030 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst
*req
,
3031 struct xdr_stream
*xdr
,
3034 const struct nfs4_layoutcommit_args
*args
= priv
;
3035 struct nfs4_layoutcommit_data
*data
=
3036 container_of(args
, struct nfs4_layoutcommit_data
, args
);
3037 struct compound_hdr hdr
= {
3038 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3041 encode_compound_hdr(xdr
, req
, &hdr
);
3042 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3043 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
3044 encode_layoutcommit(xdr
, data
->args
.inode
, args
, &hdr
);
3045 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
3050 * Encode LAYOUTRETURN request
3052 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst
*req
,
3053 struct xdr_stream
*xdr
,
3056 const struct nfs4_layoutreturn_args
*args
= data
;
3057 struct compound_hdr hdr
= {
3058 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3061 encode_compound_hdr(xdr
, req
, &hdr
);
3062 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3063 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
3064 encode_layoutreturn(xdr
, args
, &hdr
);
3069 * Encode SECINFO_NO_NAME request
3071 static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst
*req
,
3072 struct xdr_stream
*xdr
,
3075 const struct nfs41_secinfo_no_name_args
*args
= data
;
3076 struct compound_hdr hdr
= {
3077 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3080 encode_compound_hdr(xdr
, req
, &hdr
);
3081 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3082 encode_putrootfh(xdr
, &hdr
);
3083 encode_secinfo_no_name(xdr
, args
, &hdr
);
3088 * Encode TEST_STATEID request
3090 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst
*req
,
3091 struct xdr_stream
*xdr
,
3094 const struct nfs41_test_stateid_args
*args
= data
;
3095 struct compound_hdr hdr
= {
3096 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3099 encode_compound_hdr(xdr
, req
, &hdr
);
3100 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3101 encode_test_stateid(xdr
, args
, &hdr
);
3106 * Encode FREE_STATEID request
3108 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst
*req
,
3109 struct xdr_stream
*xdr
,
3112 const struct nfs41_free_stateid_args
*args
= data
;
3113 struct compound_hdr hdr
= {
3114 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
3117 encode_compound_hdr(xdr
, req
, &hdr
);
3118 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
3119 encode_free_stateid(xdr
, args
, &hdr
);
3122 #endif /* CONFIG_NFS_V4_1 */
3124 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
3126 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3127 "Remaining buffer length is %tu words.\n",
3128 func
, xdr
->end
- xdr
->p
);
3131 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
3133 ssize_t ret
= xdr_stream_decode_opaque_inline(xdr
, (void **)string
,
3135 if (unlikely(ret
< 0)) {
3136 if (ret
== -EBADMSG
)
3137 print_overflow_msg(__func__
, xdr
);
3144 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
3148 p
= xdr_inline_decode(xdr
, 8);
3151 hdr
->status
= be32_to_cpup(p
++);
3152 hdr
->taglen
= be32_to_cpup(p
);
3154 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
3157 hdr
->tag
= (char *)p
;
3158 p
+= XDR_QUADLEN(hdr
->taglen
);
3159 hdr
->nops
= be32_to_cpup(p
);
3160 if (unlikely(hdr
->nops
< 1))
3161 return nfs4_stat_to_errno(hdr
->status
);
3164 print_overflow_msg(__func__
, xdr
);
3168 static bool __decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
,
3175 p
= xdr_inline_decode(xdr
, 8);
3178 opnum
= be32_to_cpup(p
++);
3179 if (unlikely(opnum
!= expected
))
3180 goto out_bad_operation
;
3181 nfserr
= be32_to_cpup(p
);
3182 if (nfserr
== NFS_OK
)
3185 *nfs_retval
= nfs4_stat_to_errno(nfserr
);
3188 dprintk("nfs: Server returned operation"
3189 " %d but we issued a request for %d\n",
3191 *nfs_retval
= -EREMOTEIO
;
3194 print_overflow_msg(__func__
, xdr
);
3199 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
3203 __decode_op_hdr(xdr
, expected
, &retval
);
3208 static int decode_ace(struct xdr_stream
*xdr
, void *ace
)
3211 unsigned int strlen
;
3214 p
= xdr_inline_decode(xdr
, 12);
3216 return decode_opaque_inline(xdr
, &strlen
, &str
);
3217 print_overflow_msg(__func__
, xdr
);
3221 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
3226 p
= xdr_inline_decode(xdr
, 4);
3229 bmlen
= be32_to_cpup(p
);
3231 bitmap
[0] = bitmap
[1] = bitmap
[2] = 0;
3232 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
3236 bitmap
[0] = be32_to_cpup(p
++);
3238 bitmap
[1] = be32_to_cpup(p
++);
3240 bitmap
[2] = be32_to_cpup(p
);
3245 print_overflow_msg(__func__
, xdr
);
3249 static int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, unsigned int *savep
)
3253 p
= xdr_inline_decode(xdr
, 4);
3256 *attrlen
= be32_to_cpup(p
);
3257 *savep
= xdr_stream_pos(xdr
);
3260 print_overflow_msg(__func__
, xdr
);
3264 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
3266 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
3268 ret
= decode_attr_bitmap(xdr
, bitmask
);
3269 if (unlikely(ret
< 0))
3271 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
3273 bitmask
[0] = bitmask
[1] = bitmask
[2] = 0;
3274 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__
,
3275 bitmask
[0], bitmask
[1], bitmask
[2]);
3279 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
3285 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
3287 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
3288 p
= xdr_inline_decode(xdr
, 4);
3291 *type
= be32_to_cpup(p
);
3292 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
3293 dprintk("%s: bad type %d\n", __func__
, *type
);
3296 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
3297 ret
= NFS_ATTR_FATTR_TYPE
;
3299 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
3302 print_overflow_msg(__func__
, xdr
);
3306 static int decode_attr_fh_expire_type(struct xdr_stream
*xdr
,
3307 uint32_t *bitmap
, uint32_t *type
)
3312 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE
- 1U)))
3314 if (likely(bitmap
[0] & FATTR4_WORD0_FH_EXPIRE_TYPE
)) {
3315 p
= xdr_inline_decode(xdr
, 4);
3318 *type
= be32_to_cpup(p
);
3319 bitmap
[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE
;
3321 dprintk("%s: expire type=0x%x\n", __func__
, *type
);
3324 print_overflow_msg(__func__
, xdr
);
3328 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
3334 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
3336 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
3337 p
= xdr_inline_decode(xdr
, 8);
3340 xdr_decode_hyper(p
, change
);
3341 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
3342 ret
= NFS_ATTR_FATTR_CHANGE
;
3344 dprintk("%s: change attribute=%Lu\n", __func__
,
3345 (unsigned long long)*change
);
3348 print_overflow_msg(__func__
, xdr
);
3352 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
3358 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
3360 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
3361 p
= xdr_inline_decode(xdr
, 8);
3364 xdr_decode_hyper(p
, size
);
3365 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
3366 ret
= NFS_ATTR_FATTR_SIZE
;
3368 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
3371 print_overflow_msg(__func__
, xdr
);
3375 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3380 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
3382 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
3383 p
= xdr_inline_decode(xdr
, 4);
3386 *res
= be32_to_cpup(p
);
3387 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
3389 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3392 print_overflow_msg(__func__
, xdr
);
3396 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3401 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
3403 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
3404 p
= xdr_inline_decode(xdr
, 4);
3407 *res
= be32_to_cpup(p
);
3408 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
3410 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3413 print_overflow_msg(__func__
, xdr
);
3417 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
3424 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
3426 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
3427 p
= xdr_inline_decode(xdr
, 16);
3430 p
= xdr_decode_hyper(p
, &fsid
->major
);
3431 xdr_decode_hyper(p
, &fsid
->minor
);
3432 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
3433 ret
= NFS_ATTR_FATTR_FSID
;
3435 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
3436 (unsigned long long)fsid
->major
,
3437 (unsigned long long)fsid
->minor
);
3440 print_overflow_msg(__func__
, xdr
);
3444 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3449 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
3451 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
3452 p
= xdr_inline_decode(xdr
, 4);
3455 *res
= be32_to_cpup(p
);
3456 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
3458 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
3461 print_overflow_msg(__func__
, xdr
);
3465 static int decode_attr_error(struct xdr_stream
*xdr
, uint32_t *bitmap
, int32_t *res
)
3469 if (unlikely(bitmap
[0] & (FATTR4_WORD0_RDATTR_ERROR
- 1U)))
3471 if (likely(bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
)) {
3472 p
= xdr_inline_decode(xdr
, 4);
3475 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
3476 *res
= -be32_to_cpup(p
);
3480 print_overflow_msg(__func__
, xdr
);
3484 static int decode_attr_exclcreat_supported(struct xdr_stream
*xdr
,
3485 uint32_t *bitmap
, uint32_t *bitmask
)
3487 if (likely(bitmap
[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT
)) {
3489 ret
= decode_attr_bitmap(xdr
, bitmask
);
3490 if (unlikely(ret
< 0))
3492 bitmap
[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT
;
3494 bitmask
[0] = bitmask
[1] = bitmask
[2] = 0;
3495 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__
,
3496 bitmask
[0], bitmask
[1], bitmask
[2]);
3500 static int decode_attr_filehandle(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fh
*fh
)
3506 memset(fh
, 0, sizeof(*fh
));
3508 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEHANDLE
- 1U)))
3510 if (likely(bitmap
[0] & FATTR4_WORD0_FILEHANDLE
)) {
3511 p
= xdr_inline_decode(xdr
, 4);
3514 len
= be32_to_cpup(p
);
3515 if (len
> NFS4_FHSIZE
)
3517 p
= xdr_inline_decode(xdr
, len
);
3521 memcpy(fh
->data
, p
, len
);
3524 bitmap
[0] &= ~FATTR4_WORD0_FILEHANDLE
;
3528 print_overflow_msg(__func__
, xdr
);
3532 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3537 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
3539 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
3540 p
= xdr_inline_decode(xdr
, 4);
3543 *res
= be32_to_cpup(p
);
3544 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
3546 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
3549 print_overflow_msg(__func__
, xdr
);
3553 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3559 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
3561 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
3562 p
= xdr_inline_decode(xdr
, 8);
3565 xdr_decode_hyper(p
, fileid
);
3566 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
3567 ret
= NFS_ATTR_FATTR_FILEID
;
3569 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3572 print_overflow_msg(__func__
, xdr
);
3576 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3582 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
3584 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
3585 p
= xdr_inline_decode(xdr
, 8);
3588 xdr_decode_hyper(p
, fileid
);
3589 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
3590 ret
= NFS_ATTR_FATTR_MOUNTED_ON_FILEID
;
3592 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3595 print_overflow_msg(__func__
, xdr
);
3599 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3605 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
3607 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
3608 p
= xdr_inline_decode(xdr
, 8);
3611 xdr_decode_hyper(p
, res
);
3612 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
3614 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
3617 print_overflow_msg(__func__
, xdr
);
3621 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3627 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
3629 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
3630 p
= xdr_inline_decode(xdr
, 8);
3633 xdr_decode_hyper(p
, res
);
3634 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
3636 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
3639 print_overflow_msg(__func__
, xdr
);
3643 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3649 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
3651 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
3652 p
= xdr_inline_decode(xdr
, 8);
3655 xdr_decode_hyper(p
, res
);
3656 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
3658 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
3661 print_overflow_msg(__func__
, xdr
);
3665 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
3671 p
= xdr_inline_decode(xdr
, 4);
3674 n
= be32_to_cpup(p
);
3677 dprintk("pathname4: ");
3678 if (n
> NFS4_PATHNAME_MAXCOMPONENTS
) {
3679 dprintk("cannot parse %d components in path\n", n
);
3682 for (path
->ncomponents
= 0; path
->ncomponents
< n
; path
->ncomponents
++) {
3683 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
3684 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
3685 if (unlikely(status
!= 0))
3689 (path
->ncomponents
!= n
? "/ " : ""),
3690 component
->len
, component
->data
);
3695 /* a root pathname is sent as a zero component4 */
3696 path
->ncomponents
= 1;
3697 path
->components
[0].len
=0;
3698 path
->components
[0].data
=NULL
;
3699 dprintk("pathname4: /\n");
3702 dprintk(" status %d", status
);
3706 print_overflow_msg(__func__
, xdr
);
3710 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
3716 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
3719 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
3721 bitmap
[0] &= ~FATTR4_WORD0_FS_LOCATIONS
;
3723 /* Ignore borken servers that return unrequested attrs */
3724 if (unlikely(res
== NULL
))
3726 dprintk("%s: fsroot:\n", __func__
);
3727 status
= decode_pathname(xdr
, &res
->fs_path
);
3728 if (unlikely(status
!= 0))
3730 p
= xdr_inline_decode(xdr
, 4);
3733 n
= be32_to_cpup(p
);
3736 for (res
->nlocations
= 0; res
->nlocations
< n
; res
->nlocations
++) {
3738 struct nfs4_fs_location
*loc
;
3740 if (res
->nlocations
== NFS4_FS_LOCATIONS_MAXENTRIES
)
3742 loc
= &res
->locations
[res
->nlocations
];
3743 p
= xdr_inline_decode(xdr
, 4);
3746 m
= be32_to_cpup(p
);
3748 dprintk("%s: servers:\n", __func__
);
3749 for (loc
->nservers
= 0; loc
->nservers
< m
; loc
->nservers
++) {
3750 struct nfs4_string
*server
;
3752 if (loc
->nservers
== NFS4_FS_LOCATION_MAXSERVERS
) {
3754 dprintk("%s: using first %u of %u servers "
3755 "returned for location %u\n",
3757 NFS4_FS_LOCATION_MAXSERVERS
,
3758 m
, res
->nlocations
);
3759 for (i
= loc
->nservers
; i
< m
; i
++) {
3762 status
= decode_opaque_inline(xdr
, &len
, &data
);
3763 if (unlikely(status
!= 0))
3768 server
= &loc
->servers
[loc
->nservers
];
3769 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3770 if (unlikely(status
!= 0))
3772 dprintk("%s ", server
->data
);
3774 status
= decode_pathname(xdr
, &loc
->rootpath
);
3775 if (unlikely(status
!= 0))
3778 if (res
->nlocations
!= 0)
3779 status
= NFS_ATTR_FATTR_V4_LOCATIONS
;
3781 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3784 print_overflow_msg(__func__
, xdr
);
3790 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3796 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3798 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3799 p
= xdr_inline_decode(xdr
, 8);
3802 xdr_decode_hyper(p
, res
);
3803 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3805 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3808 print_overflow_msg(__func__
, xdr
);
3812 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3818 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3820 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3821 p
= xdr_inline_decode(xdr
, 4);
3824 *maxlink
= be32_to_cpup(p
);
3825 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3827 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3830 print_overflow_msg(__func__
, xdr
);
3834 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3840 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3842 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3843 p
= xdr_inline_decode(xdr
, 4);
3846 *maxname
= be32_to_cpup(p
);
3847 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3849 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3852 print_overflow_msg(__func__
, xdr
);
3856 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3862 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3864 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3866 p
= xdr_inline_decode(xdr
, 8);
3869 xdr_decode_hyper(p
, &maxread
);
3870 if (maxread
> 0x7FFFFFFF)
3871 maxread
= 0x7FFFFFFF;
3872 *res
= (uint32_t)maxread
;
3873 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3875 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3878 print_overflow_msg(__func__
, xdr
);
3882 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3888 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3890 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3892 p
= xdr_inline_decode(xdr
, 8);
3895 xdr_decode_hyper(p
, &maxwrite
);
3896 if (maxwrite
> 0x7FFFFFFF)
3897 maxwrite
= 0x7FFFFFFF;
3898 *res
= (uint32_t)maxwrite
;
3899 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3901 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3904 print_overflow_msg(__func__
, xdr
);
3908 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3915 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3917 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3918 p
= xdr_inline_decode(xdr
, 4);
3921 tmp
= be32_to_cpup(p
);
3922 *mode
= tmp
& ~S_IFMT
;
3923 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3924 ret
= NFS_ATTR_FATTR_MODE
;
3926 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3929 print_overflow_msg(__func__
, xdr
);
3933 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3939 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3941 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3942 p
= xdr_inline_decode(xdr
, 4);
3945 *nlink
= be32_to_cpup(p
);
3946 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3947 ret
= NFS_ATTR_FATTR_NLINK
;
3949 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3952 print_overflow_msg(__func__
, xdr
);
3956 static ssize_t
decode_nfs4_string(struct xdr_stream
*xdr
,
3957 struct nfs4_string
*name
, gfp_t gfp_flags
)
3961 ret
= xdr_stream_decode_string_dup(xdr
, &name
->data
,
3962 XDR_MAX_NETOBJ
, gfp_flags
);
3969 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3970 const struct nfs_server
*server
, kuid_t
*uid
,
3971 struct nfs4_string
*owner_name
)
3976 *uid
= make_kuid(&init_user_ns
, -2);
3977 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3979 if (!(bitmap
[1] & FATTR4_WORD1_OWNER
))
3981 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3983 if (owner_name
!= NULL
) {
3984 len
= decode_nfs4_string(xdr
, owner_name
, GFP_NOWAIT
);
3987 dprintk("%s: name=%s\n", __func__
, owner_name
->data
);
3988 return NFS_ATTR_FATTR_OWNER_NAME
;
3990 len
= xdr_stream_decode_opaque_inline(xdr
, (void **)&p
,
3992 if (len
<= 0 || nfs_map_name_to_uid(server
, p
, len
, uid
) != 0)
3994 dprintk("%s: uid=%d\n", __func__
, (int)from_kuid(&init_user_ns
, *uid
));
3995 return NFS_ATTR_FATTR_OWNER
;
3998 if (len
!= -EBADMSG
)
4000 print_overflow_msg(__func__
, xdr
);
4004 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4005 const struct nfs_server
*server
, kgid_t
*gid
,
4006 struct nfs4_string
*group_name
)
4011 *gid
= make_kgid(&init_user_ns
, -2);
4012 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
4014 if (!(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
))
4016 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
4018 if (group_name
!= NULL
) {
4019 len
= decode_nfs4_string(xdr
, group_name
, GFP_NOWAIT
);
4022 dprintk("%s: name=%s\n", __func__
, group_name
->data
);
4023 return NFS_ATTR_FATTR_GROUP_NAME
;
4025 len
= xdr_stream_decode_opaque_inline(xdr
, (void **)&p
,
4027 if (len
<= 0 || nfs_map_group_to_gid(server
, p
, len
, gid
) != 0)
4029 dprintk("%s: gid=%d\n", __func__
, (int)from_kgid(&init_user_ns
, *gid
));
4030 return NFS_ATTR_FATTR_GROUP
;
4033 if (len
!= -EBADMSG
)
4035 print_overflow_msg(__func__
, xdr
);
4039 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
4041 uint32_t major
= 0, minor
= 0;
4046 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
4048 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
4051 p
= xdr_inline_decode(xdr
, 8);
4054 major
= be32_to_cpup(p
++);
4055 minor
= be32_to_cpup(p
);
4056 tmp
= MKDEV(major
, minor
);
4057 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
4059 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
4060 ret
= NFS_ATTR_FATTR_RDEV
;
4062 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
4065 print_overflow_msg(__func__
, xdr
);
4069 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
4075 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
4077 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
4078 p
= xdr_inline_decode(xdr
, 8);
4081 xdr_decode_hyper(p
, res
);
4082 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
4084 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
4087 print_overflow_msg(__func__
, xdr
);
4091 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
4097 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
4099 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
4100 p
= xdr_inline_decode(xdr
, 8);
4103 xdr_decode_hyper(p
, res
);
4104 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
4106 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
4109 print_overflow_msg(__func__
, xdr
);
4113 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
4119 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
4121 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
4122 p
= xdr_inline_decode(xdr
, 8);
4125 xdr_decode_hyper(p
, res
);
4126 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
4128 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
4131 print_overflow_msg(__func__
, xdr
);
4135 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
4141 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
4143 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
4144 p
= xdr_inline_decode(xdr
, 8);
4147 xdr_decode_hyper(p
, used
);
4148 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
4149 ret
= NFS_ATTR_FATTR_SPACE_USED
;
4151 dprintk("%s: space used=%Lu\n", __func__
,
4152 (unsigned long long)*used
);
4155 print_overflow_msg(__func__
, xdr
);
4159 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
4165 p
= xdr_inline_decode(xdr
, 12);
4168 p
= xdr_decode_hyper(p
, &sec
);
4169 nsec
= be32_to_cpup(p
);
4170 time
->tv_sec
= (time_t)sec
;
4171 time
->tv_nsec
= (long)nsec
;
4174 print_overflow_msg(__func__
, xdr
);
4178 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4184 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
4186 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
4187 status
= decode_attr_time(xdr
, time
);
4189 status
= NFS_ATTR_FATTR_ATIME
;
4190 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
4192 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
4196 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4202 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
4204 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
4205 status
= decode_attr_time(xdr
, time
);
4207 status
= NFS_ATTR_FATTR_CTIME
;
4208 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
4210 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
4214 static int decode_attr_time_delta(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4215 struct timespec
*time
)
4221 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_DELTA
- 1U)))
4223 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_DELTA
)) {
4224 status
= decode_attr_time(xdr
, time
);
4225 bitmap
[1] &= ~FATTR4_WORD1_TIME_DELTA
;
4227 dprintk("%s: time_delta=%ld %ld\n", __func__
, (long)time
->tv_sec
,
4228 (long)time
->tv_nsec
);
4232 static int decode_attr_security_label(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4233 struct nfs4_label
*label
)
4241 if (unlikely(bitmap
[2] & (FATTR4_WORD2_SECURITY_LABEL
- 1U)))
4243 if (likely(bitmap
[2] & FATTR4_WORD2_SECURITY_LABEL
)) {
4244 p
= xdr_inline_decode(xdr
, 4);
4247 lfs
= be32_to_cpup(p
++);
4248 p
= xdr_inline_decode(xdr
, 4);
4251 pi
= be32_to_cpup(p
++);
4252 p
= xdr_inline_decode(xdr
, 4);
4255 len
= be32_to_cpup(p
++);
4256 p
= xdr_inline_decode(xdr
, len
);
4259 if (len
< NFS4_MAXLABELLEN
) {
4261 memcpy(label
->label
, p
, len
);
4265 status
= NFS_ATTR_FATTR_V4_SECURITY_LABEL
;
4267 bitmap
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
4269 printk(KERN_WARNING
"%s: label too long (%u)!\n",
4272 if (label
&& label
->label
)
4273 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__
,
4274 (char *)label
->label
, label
->len
, label
->pi
, label
->lfs
);
4278 print_overflow_msg(__func__
, xdr
);
4282 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
4288 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
4290 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
4291 status
= decode_attr_time(xdr
, time
);
4293 status
= NFS_ATTR_FATTR_MTIME
;
4294 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
4296 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
4300 static int verify_attr_len(struct xdr_stream
*xdr
, unsigned int savep
, uint32_t attrlen
)
4302 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
4303 unsigned int nwords
= (xdr_stream_pos(xdr
) - savep
) >> 2;
4305 if (unlikely(attrwords
!= nwords
)) {
4306 dprintk("%s: server returned incorrect attribute length: "
4310 (attrwords
< nwords
) ? '<' : '>',
4317 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4321 p
= xdr_inline_decode(xdr
, 20);
4324 cinfo
->atomic
= be32_to_cpup(p
++);
4325 p
= xdr_decode_hyper(p
, &cinfo
->before
);
4326 xdr_decode_hyper(p
, &cinfo
->after
);
4329 print_overflow_msg(__func__
, xdr
);
4333 static int decode_access(struct xdr_stream
*xdr
, u32
*supported
, u32
*access
)
4339 status
= decode_op_hdr(xdr
, OP_ACCESS
);
4342 p
= xdr_inline_decode(xdr
, 8);
4345 supp
= be32_to_cpup(p
++);
4346 acc
= be32_to_cpup(p
);
4351 print_overflow_msg(__func__
, xdr
);
4355 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
4357 ssize_t ret
= xdr_stream_decode_opaque_fixed(xdr
, buf
, len
);
4358 if (unlikely(ret
< 0)) {
4359 print_overflow_msg(__func__
, xdr
);
4365 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4367 return decode_opaque_fixed(xdr
, stateid
, NFS4_STATEID_SIZE
);
4370 static int decode_open_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4372 stateid
->type
= NFS4_OPEN_STATEID_TYPE
;
4373 return decode_stateid(xdr
, stateid
);
4376 static int decode_lock_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4378 stateid
->type
= NFS4_LOCK_STATEID_TYPE
;
4379 return decode_stateid(xdr
, stateid
);
4382 static int decode_delegation_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4384 stateid
->type
= NFS4_DELEGATION_STATEID_TYPE
;
4385 return decode_stateid(xdr
, stateid
);
4388 static int decode_invalid_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4392 nfs4_stateid_copy(stateid
, &invalid_stateid
);
4393 return decode_stateid(xdr
, &dummy
);
4396 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4400 status
= decode_op_hdr(xdr
, OP_CLOSE
);
4402 nfs_increment_open_seqid(status
, res
->seqid
);
4404 status
= decode_invalid_stateid(xdr
, &res
->stateid
);
4408 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
4410 return decode_opaque_fixed(xdr
, verifier
, NFS4_VERIFIER_SIZE
);
4413 static int decode_write_verifier(struct xdr_stream
*xdr
, struct nfs_write_verifier
*verifier
)
4415 return decode_opaque_fixed(xdr
, verifier
->data
, NFS4_VERIFIER_SIZE
);
4418 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_commitres
*res
)
4422 status
= decode_op_hdr(xdr
, OP_COMMIT
);
4424 status
= decode_write_verifier(xdr
, &res
->verf
->verifier
);
4428 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4434 status
= decode_op_hdr(xdr
, OP_CREATE
);
4437 if ((status
= decode_change_info(xdr
, cinfo
)))
4439 p
= xdr_inline_decode(xdr
, 4);
4442 bmlen
= be32_to_cpup(p
);
4443 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4447 print_overflow_msg(__func__
, xdr
);
4451 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
4454 uint32_t attrlen
, bitmap
[3] = {0};
4457 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4459 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4461 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4463 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
4465 if ((status
= decode_attr_fh_expire_type(xdr
, bitmap
,
4466 &res
->fh_expire_type
)) != 0)
4468 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
4470 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
4472 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
4474 if ((status
= decode_attr_exclcreat_supported(xdr
, bitmap
,
4475 res
->exclcreat_bitmask
)) != 0)
4477 status
= verify_attr_len(xdr
, savep
, attrlen
);
4479 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4483 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
4486 uint32_t attrlen
, bitmap
[3] = {0};
4489 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4491 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4493 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4496 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
4498 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
4500 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
4504 if (unlikely(bitmap
[0]))
4507 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
4509 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
4511 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
4514 status
= verify_attr_len(xdr
, savep
, attrlen
);
4516 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4520 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
4523 uint32_t attrlen
, bitmap
[3] = {0};
4526 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4528 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4530 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4533 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
4535 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
4538 status
= verify_attr_len(xdr
, savep
, attrlen
);
4540 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4544 static int decode_threshold_hint(struct xdr_stream
*xdr
,
4552 if (likely(bitmap
[0] & hint_bit
)) {
4553 p
= xdr_inline_decode(xdr
, 8);
4556 xdr_decode_hyper(p
, res
);
4560 print_overflow_msg(__func__
, xdr
);
4564 static int decode_first_threshold_item4(struct xdr_stream
*xdr
,
4565 struct nfs4_threshold
*res
)
4569 uint32_t bitmap
[3] = {0,}, attrlen
;
4573 p
= xdr_inline_decode(xdr
, 4);
4575 print_overflow_msg(__func__
, xdr
);
4578 res
->l_type
= be32_to_cpup(p
);
4580 /* thi_hintset bitmap */
4581 status
= decode_attr_bitmap(xdr
, bitmap
);
4585 /* thi_hintlist length */
4586 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4590 status
= decode_threshold_hint(xdr
, bitmap
, &res
->rd_sz
, THRESHOLD_RD
);
4593 status
= decode_threshold_hint(xdr
, bitmap
, &res
->wr_sz
, THRESHOLD_WR
);
4596 status
= decode_threshold_hint(xdr
, bitmap
, &res
->rd_io_sz
,
4600 status
= decode_threshold_hint(xdr
, bitmap
, &res
->wr_io_sz
,
4605 status
= verify_attr_len(xdr
, savep
, attrlen
);
4606 res
->bm
= bitmap
[0];
4608 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4609 __func__
, res
->bm
, res
->rd_sz
, res
->wr_sz
, res
->rd_io_sz
,
4612 dprintk("%s ret=%d!\n", __func__
, status
);
4617 * Thresholds on pNFS direct I/O vrs MDS I/O
4619 static int decode_attr_mdsthreshold(struct xdr_stream
*xdr
,
4621 struct nfs4_threshold
*res
)
4627 if (unlikely(bitmap
[2] & (FATTR4_WORD2_MDSTHRESHOLD
- 1U)))
4629 if (bitmap
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
4630 /* Did the server return an unrequested attribute? */
4631 if (unlikely(res
== NULL
))
4633 p
= xdr_inline_decode(xdr
, 4);
4636 num
= be32_to_cpup(p
);
4640 printk(KERN_INFO
"%s: Warning: Multiple pNFS layout "
4641 "drivers per filesystem not supported\n",
4644 status
= decode_first_threshold_item4(xdr
, res
);
4645 bitmap
[2] &= ~FATTR4_WORD2_MDSTHRESHOLD
;
4649 print_overflow_msg(__func__
, xdr
);
4653 static int decode_getfattr_attrs(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4654 struct nfs_fattr
*fattr
, struct nfs_fh
*fh
,
4655 struct nfs4_fs_locations
*fs_loc
, struct nfs4_label
*label
,
4656 const struct nfs_server
*server
)
4663 status
= decode_attr_type(xdr
, bitmap
, &type
);
4668 fattr
->mode
|= nfs_type2fmt
[type
];
4669 fattr
->valid
|= status
;
4672 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
4675 fattr
->valid
|= status
;
4677 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
4680 fattr
->valid
|= status
;
4682 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
4685 fattr
->valid
|= status
;
4688 status
= decode_attr_error(xdr
, bitmap
, &err
);
4692 status
= decode_attr_filehandle(xdr
, bitmap
, fh
);
4696 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
4699 fattr
->valid
|= status
;
4701 status
= decode_attr_fs_locations(xdr
, bitmap
, fs_loc
);
4704 fattr
->valid
|= status
;
4707 if (unlikely(bitmap
[0]))
4710 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
4714 fattr
->mode
|= fmode
;
4715 fattr
->valid
|= status
;
4718 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
4721 fattr
->valid
|= status
;
4723 status
= decode_attr_owner(xdr
, bitmap
, server
, &fattr
->uid
, fattr
->owner_name
);
4726 fattr
->valid
|= status
;
4728 status
= decode_attr_group(xdr
, bitmap
, server
, &fattr
->gid
, fattr
->group_name
);
4731 fattr
->valid
|= status
;
4733 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
4736 fattr
->valid
|= status
;
4738 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
4741 fattr
->valid
|= status
;
4743 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
4746 fattr
->valid
|= status
;
4748 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
4751 fattr
->valid
|= status
;
4753 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
4756 fattr
->valid
|= status
;
4758 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fattr
->mounted_on_fileid
);
4761 fattr
->valid
|= status
;
4764 if (unlikely(bitmap
[1]))
4767 status
= decode_attr_mdsthreshold(xdr
, bitmap
, fattr
->mdsthreshold
);
4772 status
= decode_attr_security_label(xdr
, bitmap
, label
);
4775 fattr
->valid
|= status
;
4779 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4783 static int decode_getfattr_generic(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4784 struct nfs_fh
*fh
, struct nfs4_fs_locations
*fs_loc
,
4785 struct nfs4_label
*label
, const struct nfs_server
*server
)
4792 status
= decode_op_hdr(xdr
, OP_GETATTR
);
4796 status
= decode_attr_bitmap(xdr
, bitmap
);
4800 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4804 status
= decode_getfattr_attrs(xdr
, bitmap
, fattr
, fh
, fs_loc
,
4809 status
= verify_attr_len(xdr
, savep
, attrlen
);
4811 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4815 static int decode_getfattr_label(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4816 struct nfs4_label
*label
, const struct nfs_server
*server
)
4818 return decode_getfattr_generic(xdr
, fattr
, NULL
, NULL
, label
, server
);
4821 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4822 const struct nfs_server
*server
)
4824 return decode_getfattr_generic(xdr
, fattr
, NULL
, NULL
, NULL
, server
);
4828 * Decode potentially multiple layout types.
4830 static int decode_pnfs_layout_types(struct xdr_stream
*xdr
,
4831 struct nfs_fsinfo
*fsinfo
)
4836 p
= xdr_inline_decode(xdr
, 4);
4839 fsinfo
->nlayouttypes
= be32_to_cpup(p
);
4841 /* pNFS is not supported by the underlying file system */
4842 if (fsinfo
->nlayouttypes
== 0)
4845 /* Decode and set first layout type, move xdr->p past unused types */
4846 p
= xdr_inline_decode(xdr
, fsinfo
->nlayouttypes
* 4);
4850 /* If we get too many, then just cap it at the max */
4851 if (fsinfo
->nlayouttypes
> NFS_MAX_LAYOUT_TYPES
) {
4852 printk(KERN_INFO
"NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4853 __func__
, fsinfo
->nlayouttypes
);
4854 fsinfo
->nlayouttypes
= NFS_MAX_LAYOUT_TYPES
;
4857 for(i
= 0; i
< fsinfo
->nlayouttypes
; ++i
)
4858 fsinfo
->layouttype
[i
] = be32_to_cpup(p
++);
4861 print_overflow_msg(__func__
, xdr
);
4866 * The type of file system exported.
4867 * Note we must ensure that layouttype is set in any non-error case.
4869 static int decode_attr_pnfstype(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4870 struct nfs_fsinfo
*fsinfo
)
4874 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[1]);
4875 if (unlikely(bitmap
[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES
- 1U)))
4877 if (bitmap
[1] & FATTR4_WORD1_FS_LAYOUT_TYPES
) {
4878 status
= decode_pnfs_layout_types(xdr
, fsinfo
);
4879 bitmap
[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES
;
4885 * The prefered block size for layout directed io
4887 static int decode_attr_layout_blksize(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4892 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[2]);
4894 if (bitmap
[2] & FATTR4_WORD2_LAYOUT_BLKSIZE
) {
4895 p
= xdr_inline_decode(xdr
, 4);
4897 print_overflow_msg(__func__
, xdr
);
4900 *res
= be32_to_cpup(p
);
4901 bitmap
[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE
;
4907 * The granularity of a CLONE operation.
4909 static int decode_attr_clone_blksize(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4914 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[2]);
4916 if (bitmap
[2] & FATTR4_WORD2_CLONE_BLKSIZE
) {
4917 p
= xdr_inline_decode(xdr
, 4);
4919 print_overflow_msg(__func__
, xdr
);
4922 *res
= be32_to_cpup(p
);
4923 bitmap
[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE
;
4928 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
4931 uint32_t attrlen
, bitmap
[3];
4934 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4936 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4938 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4941 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
4943 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
4945 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
4947 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
4949 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
4950 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
4952 fsinfo
->wtpref
= fsinfo
->wtmax
;
4955 if (unlikely(bitmap
[0]))
4958 status
= decode_attr_time_delta(xdr
, bitmap
, &fsinfo
->time_delta
);
4961 status
= decode_attr_pnfstype(xdr
, bitmap
, fsinfo
);
4966 if (unlikely(bitmap
[1]))
4969 status
= decode_attr_layout_blksize(xdr
, bitmap
, &fsinfo
->blksize
);
4972 status
= decode_attr_clone_blksize(xdr
, bitmap
, &fsinfo
->clone_blksize
);
4976 status
= verify_attr_len(xdr
, savep
, attrlen
);
4978 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4982 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
4988 /* Zero handle first to allow comparisons */
4989 memset(fh
, 0, sizeof(*fh
));
4991 status
= decode_op_hdr(xdr
, OP_GETFH
);
4995 p
= xdr_inline_decode(xdr
, 4);
4998 len
= be32_to_cpup(p
);
4999 if (len
> NFS4_FHSIZE
)
5002 p
= xdr_inline_decode(xdr
, len
);
5005 memcpy(fh
->data
, p
, len
);
5008 print_overflow_msg(__func__
, xdr
);
5012 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
5016 status
= decode_op_hdr(xdr
, OP_LINK
);
5019 return decode_change_info(xdr
, cinfo
);
5023 * We create the owner, so we know a proper owner.id length is 4.
5025 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
5027 uint64_t offset
, length
, clientid
;
5029 uint32_t namelen
, type
;
5031 p
= xdr_inline_decode(xdr
, 32); /* read 32 bytes */
5034 p
= xdr_decode_hyper(p
, &offset
); /* read 2 8-byte long words */
5035 p
= xdr_decode_hyper(p
, &length
);
5036 type
= be32_to_cpup(p
++); /* 4 byte read */
5037 if (fl
!= NULL
) { /* manipulate file lock */
5038 fl
->fl_start
= (loff_t
)offset
;
5039 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
5040 if (length
== ~(uint64_t)0)
5041 fl
->fl_end
= OFFSET_MAX
;
5042 fl
->fl_type
= F_WRLCK
;
5044 fl
->fl_type
= F_RDLCK
;
5047 p
= xdr_decode_hyper(p
, &clientid
); /* read 8 bytes */
5048 namelen
= be32_to_cpup(p
); /* read 4 bytes */ /* have read all 32 bytes now */
5049 p
= xdr_inline_decode(xdr
, namelen
); /* variable size field */
5051 return -NFS4ERR_DENIED
;
5053 print_overflow_msg(__func__
, xdr
);
5057 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
5061 status
= decode_op_hdr(xdr
, OP_LOCK
);
5065 status
= decode_lock_stateid(xdr
, &res
->stateid
);
5066 if (unlikely(status
))
5068 } else if (status
== -NFS4ERR_DENIED
)
5069 status
= decode_lock_denied(xdr
, NULL
);
5070 if (res
->open_seqid
!= NULL
)
5071 nfs_increment_open_seqid(status
, res
->open_seqid
);
5072 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
5077 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
5080 status
= decode_op_hdr(xdr
, OP_LOCKT
);
5081 if (status
== -NFS4ERR_DENIED
)
5082 return decode_lock_denied(xdr
, res
->denied
);
5086 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
5090 status
= decode_op_hdr(xdr
, OP_LOCKU
);
5092 nfs_increment_lock_seqid(status
, res
->seqid
);
5094 status
= decode_lock_stateid(xdr
, &res
->stateid
);
5098 static int decode_release_lockowner(struct xdr_stream
*xdr
)
5100 return decode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
);
5103 static int decode_lookup(struct xdr_stream
*xdr
)
5105 return decode_op_hdr(xdr
, OP_LOOKUP
);
5108 static int decode_lookupp(struct xdr_stream
*xdr
)
5110 return decode_op_hdr(xdr
, OP_LOOKUPP
);
5113 /* This is too sick! */
5114 static int decode_space_limit(struct xdr_stream
*xdr
,
5115 unsigned long *pagemod_limit
)
5118 uint32_t limit_type
, nblocks
, blocksize
;
5121 p
= xdr_inline_decode(xdr
, 12);
5124 limit_type
= be32_to_cpup(p
++);
5125 switch (limit_type
) {
5126 case NFS4_LIMIT_SIZE
:
5127 xdr_decode_hyper(p
, &maxsize
);
5129 case NFS4_LIMIT_BLOCKS
:
5130 nblocks
= be32_to_cpup(p
++);
5131 blocksize
= be32_to_cpup(p
);
5132 maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
5134 maxsize
>>= PAGE_SHIFT
;
5135 *pagemod_limit
= min_t(u64
, maxsize
, ULONG_MAX
);
5138 print_overflow_msg(__func__
, xdr
);
5142 static int decode_rw_delegation(struct xdr_stream
*xdr
,
5143 uint32_t delegation_type
,
5144 struct nfs_openres
*res
)
5149 status
= decode_delegation_stateid(xdr
, &res
->delegation
);
5150 if (unlikely(status
))
5152 p
= xdr_inline_decode(xdr
, 4);
5155 res
->do_recall
= be32_to_cpup(p
);
5157 switch (delegation_type
) {
5158 case NFS4_OPEN_DELEGATE_READ
:
5159 res
->delegation_type
= FMODE_READ
;
5161 case NFS4_OPEN_DELEGATE_WRITE
:
5162 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
5163 if (decode_space_limit(xdr
, &res
->pagemod_limit
) < 0)
5166 return decode_ace(xdr
, NULL
);
5168 print_overflow_msg(__func__
, xdr
);
5172 static int decode_no_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
5175 uint32_t why_no_delegation
;
5177 p
= xdr_inline_decode(xdr
, 4);
5180 why_no_delegation
= be32_to_cpup(p
);
5181 switch (why_no_delegation
) {
5182 case WND4_CONTENTION
:
5184 xdr_inline_decode(xdr
, 4);
5185 /* Ignore for now */
5189 print_overflow_msg(__func__
, xdr
);
5193 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
5196 uint32_t delegation_type
;
5198 p
= xdr_inline_decode(xdr
, 4);
5201 delegation_type
= be32_to_cpup(p
);
5202 res
->delegation_type
= 0;
5203 switch (delegation_type
) {
5204 case NFS4_OPEN_DELEGATE_NONE
:
5206 case NFS4_OPEN_DELEGATE_READ
:
5207 case NFS4_OPEN_DELEGATE_WRITE
:
5208 return decode_rw_delegation(xdr
, delegation_type
, res
);
5209 case NFS4_OPEN_DELEGATE_NONE_EXT
:
5210 return decode_no_delegation(xdr
, res
);
5214 print_overflow_msg(__func__
, xdr
);
5218 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
5221 uint32_t savewords
, bmlen
, i
;
5224 if (!__decode_op_hdr(xdr
, OP_OPEN
, &status
))
5226 nfs_increment_open_seqid(status
, res
->seqid
);
5229 status
= decode_open_stateid(xdr
, &res
->stateid
);
5230 if (unlikely(status
))
5233 decode_change_info(xdr
, &res
->cinfo
);
5235 p
= xdr_inline_decode(xdr
, 8);
5238 res
->rflags
= be32_to_cpup(p
++);
5239 bmlen
= be32_to_cpup(p
);
5243 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
5246 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
5247 for (i
= 0; i
< savewords
; ++i
)
5248 res
->attrset
[i
] = be32_to_cpup(p
++);
5249 for (; i
< NFS4_BITMAP_SIZE
; i
++)
5250 res
->attrset
[i
] = 0;
5252 return decode_delegation(xdr
, res
);
5254 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
5257 print_overflow_msg(__func__
, xdr
);
5261 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
5265 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
5267 nfs_increment_open_seqid(status
, res
->seqid
);
5269 status
= decode_open_stateid(xdr
, &res
->stateid
);
5273 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
5277 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
5279 nfs_increment_open_seqid(status
, res
->seqid
);
5281 status
= decode_open_stateid(xdr
, &res
->stateid
);
5285 static int decode_putfh(struct xdr_stream
*xdr
)
5287 return decode_op_hdr(xdr
, OP_PUTFH
);
5290 static int decode_putrootfh(struct xdr_stream
*xdr
)
5292 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
5295 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5296 struct nfs_pgio_res
*res
)
5299 uint32_t count
, eof
, recvd
;
5302 status
= decode_op_hdr(xdr
, OP_READ
);
5305 p
= xdr_inline_decode(xdr
, 8);
5308 eof
= be32_to_cpup(p
++);
5309 count
= be32_to_cpup(p
);
5310 recvd
= xdr_read_pages(xdr
, count
);
5311 if (count
> recvd
) {
5312 dprintk("NFS: server cheating in read reply: "
5313 "count %u > recvd %u\n", count
, recvd
);
5321 print_overflow_msg(__func__
, xdr
);
5325 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
5330 status
= decode_op_hdr(xdr
, OP_READDIR
);
5332 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
5333 if (unlikely(status
))
5335 memcpy(verf
, readdir
->verifier
.data
, sizeof(verf
));
5336 dprintk("%s: verifier = %08x:%08x\n",
5337 __func__
, verf
[0], verf
[1]);
5338 return xdr_read_pages(xdr
, xdr
->buf
->page_len
);
5341 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
5343 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
5348 status
= decode_op_hdr(xdr
, OP_READLINK
);
5352 /* Convert length of symlink */
5353 p
= xdr_inline_decode(xdr
, 4);
5356 len
= be32_to_cpup(p
);
5357 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
5358 dprintk("nfs: server returned giant symlink!\n");
5359 return -ENAMETOOLONG
;
5361 recvd
= xdr_read_pages(xdr
, len
);
5363 dprintk("NFS: server cheating in readlink reply: "
5364 "count %u > recvd %u\n", len
, recvd
);
5368 * The XDR encode routine has set things up so that
5369 * the link text will be copied directly into the
5370 * buffer. We just have to do overflow-checking,
5371 * and and null-terminate the text (the VFS expects
5372 * null-termination).
5374 xdr_terminate_string(rcvbuf
, len
);
5377 print_overflow_msg(__func__
, xdr
);
5381 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
5385 status
= decode_op_hdr(xdr
, OP_REMOVE
);
5388 status
= decode_change_info(xdr
, cinfo
);
5393 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
5394 struct nfs4_change_info
*new_cinfo
)
5398 status
= decode_op_hdr(xdr
, OP_RENAME
);
5401 if ((status
= decode_change_info(xdr
, old_cinfo
)))
5403 status
= decode_change_info(xdr
, new_cinfo
);
5408 static int decode_renew(struct xdr_stream
*xdr
)
5410 return decode_op_hdr(xdr
, OP_RENEW
);
5414 decode_restorefh(struct xdr_stream
*xdr
)
5416 return decode_op_hdr(xdr
, OP_RESTOREFH
);
5419 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5420 struct nfs_getaclres
*res
)
5426 unsigned int pg_offset
;
5429 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
5432 xdr_enter_page(xdr
, xdr
->buf
->page_len
);
5434 /* Calculate the offset of the page data */
5435 pg_offset
= xdr
->buf
->head
[0].iov_len
;
5437 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
5439 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
5442 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
5444 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
5446 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5447 * are stored with the acl data to handle the problem of
5448 * variable length bitmaps.*/
5449 res
->acl_data_offset
= xdr_stream_pos(xdr
) - pg_offset
;
5450 res
->acl_len
= attrlen
;
5452 /* Check for receive buffer overflow */
5453 if (res
->acl_len
> (xdr
->nwords
<< 2) ||
5454 res
->acl_len
+ res
->acl_data_offset
> xdr
->buf
->page_len
) {
5455 res
->acl_flags
|= NFS4_ACL_TRUNC
;
5456 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5457 attrlen
, xdr
->nwords
<< 2);
5460 status
= -EOPNOTSUPP
;
5467 decode_savefh(struct xdr_stream
*xdr
)
5469 return decode_op_hdr(xdr
, OP_SAVEFH
);
5472 static int decode_setattr(struct xdr_stream
*xdr
)
5478 status
= decode_op_hdr(xdr
, OP_SETATTR
);
5481 p
= xdr_inline_decode(xdr
, 4);
5484 bmlen
= be32_to_cpup(p
);
5485 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
5489 print_overflow_msg(__func__
, xdr
);
5493 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
5499 p
= xdr_inline_decode(xdr
, 8);
5502 opnum
= be32_to_cpup(p
++);
5503 if (opnum
!= OP_SETCLIENTID
) {
5504 dprintk("nfs: decode_setclientid: Server returned operation"
5508 nfserr
= be32_to_cpup(p
);
5509 if (nfserr
== NFS_OK
) {
5510 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
5513 p
= xdr_decode_hyper(p
, &res
->clientid
);
5514 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
5515 } else if (nfserr
== NFSERR_CLID_INUSE
) {
5518 /* skip netid string */
5519 p
= xdr_inline_decode(xdr
, 4);
5522 len
= be32_to_cpup(p
);
5523 p
= xdr_inline_decode(xdr
, len
);
5527 /* skip uaddr string */
5528 p
= xdr_inline_decode(xdr
, 4);
5531 len
= be32_to_cpup(p
);
5532 p
= xdr_inline_decode(xdr
, len
);
5535 return -NFSERR_CLID_INUSE
;
5537 return nfs4_stat_to_errno(nfserr
);
5541 print_overflow_msg(__func__
, xdr
);
5545 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
5547 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
5550 static int decode_write(struct xdr_stream
*xdr
, struct nfs_pgio_res
*res
)
5555 status
= decode_op_hdr(xdr
, OP_WRITE
);
5559 p
= xdr_inline_decode(xdr
, 8);
5562 res
->count
= be32_to_cpup(p
++);
5563 res
->verf
->committed
= be32_to_cpup(p
++);
5564 return decode_write_verifier(xdr
, &res
->verf
->verifier
);
5566 print_overflow_msg(__func__
, xdr
);
5570 static int decode_delegreturn(struct xdr_stream
*xdr
)
5572 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
5575 static int decode_secinfo_gss(struct xdr_stream
*xdr
,
5576 struct nfs4_secinfo4
*flavor
)
5581 p
= xdr_inline_decode(xdr
, 4);
5584 oid_len
= be32_to_cpup(p
);
5585 if (oid_len
> GSS_OID_MAX_LEN
)
5588 p
= xdr_inline_decode(xdr
, oid_len
);
5591 memcpy(flavor
->flavor_info
.oid
.data
, p
, oid_len
);
5592 flavor
->flavor_info
.oid
.len
= oid_len
;
5594 p
= xdr_inline_decode(xdr
, 8);
5597 flavor
->flavor_info
.qop
= be32_to_cpup(p
++);
5598 flavor
->flavor_info
.service
= be32_to_cpup(p
);
5603 print_overflow_msg(__func__
, xdr
);
5609 static int decode_secinfo_common(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5611 struct nfs4_secinfo4
*sec_flavor
;
5612 unsigned int i
, num_flavors
;
5616 p
= xdr_inline_decode(xdr
, 4);
5620 res
->flavors
->num_flavors
= 0;
5621 num_flavors
= be32_to_cpup(p
);
5623 for (i
= 0; i
< num_flavors
; i
++) {
5624 sec_flavor
= &res
->flavors
->flavors
[i
];
5625 if ((char *)&sec_flavor
[1] - (char *)res
->flavors
> PAGE_SIZE
)
5628 p
= xdr_inline_decode(xdr
, 4);
5631 sec_flavor
->flavor
= be32_to_cpup(p
);
5633 if (sec_flavor
->flavor
== RPC_AUTH_GSS
) {
5634 status
= decode_secinfo_gss(xdr
, sec_flavor
);
5638 res
->flavors
->num_flavors
++;
5645 print_overflow_msg(__func__
, xdr
);
5649 static int decode_secinfo(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5651 int status
= decode_op_hdr(xdr
, OP_SECINFO
);
5654 return decode_secinfo_common(xdr
, res
);
5657 #if defined(CONFIG_NFS_V4_1)
5658 static int decode_secinfo_no_name(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5660 int status
= decode_op_hdr(xdr
, OP_SECINFO_NO_NAME
);
5663 return decode_secinfo_common(xdr
, res
);
5666 static int decode_op_map(struct xdr_stream
*xdr
, struct nfs4_op_map
*op_map
)
5669 uint32_t bitmap_words
;
5672 p
= xdr_inline_decode(xdr
, 4);
5675 bitmap_words
= be32_to_cpup(p
++);
5676 if (bitmap_words
> NFS4_OP_MAP_NUM_WORDS
)
5678 p
= xdr_inline_decode(xdr
, 4 * bitmap_words
);
5679 for (i
= 0; i
< bitmap_words
; i
++)
5680 op_map
->u
.words
[i
] = be32_to_cpup(p
++);
5685 static int decode_exchange_id(struct xdr_stream
*xdr
,
5686 struct nfs41_exchange_id_res
*res
)
5692 uint32_t impl_id_count
;
5694 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
5698 p
= xdr_inline_decode(xdr
, 8);
5701 xdr_decode_hyper(p
, &res
->clientid
);
5702 p
= xdr_inline_decode(xdr
, 12);
5705 res
->seqid
= be32_to_cpup(p
++);
5706 res
->flags
= be32_to_cpup(p
++);
5708 res
->state_protect
.how
= be32_to_cpup(p
);
5709 switch (res
->state_protect
.how
) {
5713 status
= decode_op_map(xdr
, &res
->state_protect
.enforce
);
5716 status
= decode_op_map(xdr
, &res
->state_protect
.allow
);
5725 /* server_owner4.so_minor_id */
5726 p
= xdr_inline_decode(xdr
, 8);
5729 p
= xdr_decode_hyper(p
, &res
->server_owner
->minor_id
);
5731 /* server_owner4.so_major_id */
5732 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5733 if (unlikely(status
))
5735 memcpy(res
->server_owner
->major_id
, dummy_str
, dummy
);
5736 res
->server_owner
->major_id_sz
= dummy
;
5739 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5740 if (unlikely(status
))
5742 memcpy(res
->server_scope
->server_scope
, dummy_str
, dummy
);
5743 res
->server_scope
->server_scope_sz
= dummy
;
5745 /* Implementation Id */
5746 p
= xdr_inline_decode(xdr
, 4);
5749 impl_id_count
= be32_to_cpup(p
++);
5751 if (impl_id_count
) {
5753 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5754 if (unlikely(status
))
5756 memcpy(res
->impl_id
->domain
, dummy_str
, dummy
);
5759 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5760 if (unlikely(status
))
5762 memcpy(res
->impl_id
->name
, dummy_str
, dummy
);
5765 p
= xdr_inline_decode(xdr
, 12);
5768 p
= xdr_decode_hyper(p
, &res
->impl_id
->date
.seconds
);
5769 res
->impl_id
->date
.nseconds
= be32_to_cpup(p
);
5771 /* if there's more than one entry, ignore the rest */
5775 print_overflow_msg(__func__
, xdr
);
5779 static int decode_chan_attrs(struct xdr_stream
*xdr
,
5780 struct nfs4_channel_attrs
*attrs
)
5785 p
= xdr_inline_decode(xdr
, 28);
5788 val
= be32_to_cpup(p
++); /* headerpadsz */
5790 return -EINVAL
; /* no support for header padding yet */
5791 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
5792 attrs
->max_resp_sz
= be32_to_cpup(p
++);
5793 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
5794 attrs
->max_ops
= be32_to_cpup(p
++);
5795 attrs
->max_reqs
= be32_to_cpup(p
++);
5796 nr_attrs
= be32_to_cpup(p
);
5797 if (unlikely(nr_attrs
> 1)) {
5798 printk(KERN_WARNING
"NFS: %s: Invalid rdma channel attrs "
5799 "count %u\n", __func__
, nr_attrs
);
5802 if (nr_attrs
== 1) {
5803 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
5809 print_overflow_msg(__func__
, xdr
);
5813 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
5815 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
5818 static int decode_bind_conn_to_session(struct xdr_stream
*xdr
,
5819 struct nfs41_bind_conn_to_session_res
*res
)
5824 status
= decode_op_hdr(xdr
, OP_BIND_CONN_TO_SESSION
);
5826 status
= decode_sessionid(xdr
, &res
->sessionid
);
5827 if (unlikely(status
))
5830 /* dir flags, rdma mode bool */
5831 p
= xdr_inline_decode(xdr
, 8);
5835 res
->dir
= be32_to_cpup(p
++);
5836 if (res
->dir
== 0 || res
->dir
> NFS4_CDFS4_BOTH
)
5838 if (be32_to_cpup(p
) == 0)
5839 res
->use_conn_in_rdma_mode
= false;
5841 res
->use_conn_in_rdma_mode
= true;
5845 print_overflow_msg(__func__
, xdr
);
5849 static int decode_create_session(struct xdr_stream
*xdr
,
5850 struct nfs41_create_session_res
*res
)
5855 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
5857 status
= decode_sessionid(xdr
, &res
->sessionid
);
5858 if (unlikely(status
))
5862 p
= xdr_inline_decode(xdr
, 8);
5865 res
->seqid
= be32_to_cpup(p
++);
5866 res
->flags
= be32_to_cpup(p
);
5868 /* Channel attributes */
5869 status
= decode_chan_attrs(xdr
, &res
->fc_attrs
);
5871 status
= decode_chan_attrs(xdr
, &res
->bc_attrs
);
5874 print_overflow_msg(__func__
, xdr
);
5878 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
5880 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
5883 static int decode_destroy_clientid(struct xdr_stream
*xdr
, void *dummy
)
5885 return decode_op_hdr(xdr
, OP_DESTROY_CLIENTID
);
5888 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
5890 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
5892 #endif /* CONFIG_NFS_V4_1 */
5894 static int decode_sequence(struct xdr_stream
*xdr
,
5895 struct nfs4_sequence_res
*res
,
5896 struct rpc_rqst
*rqstp
)
5898 #if defined(CONFIG_NFS_V4_1)
5899 struct nfs4_session
*session
;
5900 struct nfs4_sessionid id
;
5905 if (res
->sr_slot
== NULL
)
5907 if (!res
->sr_slot
->table
->session
)
5910 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
5912 status
= decode_sessionid(xdr
, &id
);
5913 if (unlikely(status
))
5917 * If the server returns different values for sessionID, slotID or
5918 * sequence number, the server is looney tunes.
5920 status
= -EREMOTEIO
;
5921 session
= res
->sr_slot
->table
->session
;
5923 if (memcmp(id
.data
, session
->sess_id
.data
,
5924 NFS4_MAX_SESSIONID_LEN
)) {
5925 dprintk("%s Invalid session id\n", __func__
);
5929 p
= xdr_inline_decode(xdr
, 20);
5934 dummy
= be32_to_cpup(p
++);
5935 if (dummy
!= res
->sr_slot
->seq_nr
) {
5936 dprintk("%s Invalid sequence number\n", __func__
);
5940 dummy
= be32_to_cpup(p
++);
5941 if (dummy
!= res
->sr_slot
->slot_nr
) {
5942 dprintk("%s Invalid slot id\n", __func__
);
5945 /* highest slot id */
5946 res
->sr_highest_slotid
= be32_to_cpup(p
++);
5947 /* target highest slot id */
5948 res
->sr_target_highest_slotid
= be32_to_cpup(p
++);
5950 res
->sr_status_flags
= be32_to_cpup(p
);
5953 res
->sr_status
= status
;
5956 print_overflow_msg(__func__
, xdr
);
5959 #else /* CONFIG_NFS_V4_1 */
5961 #endif /* CONFIG_NFS_V4_1 */
5964 #if defined(CONFIG_NFS_V4_1)
5965 static int decode_layout_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
5967 stateid
->type
= NFS4_LAYOUT_STATEID_TYPE
;
5968 return decode_stateid(xdr
, stateid
);
5971 static int decode_getdeviceinfo(struct xdr_stream
*xdr
,
5972 struct nfs4_getdeviceinfo_res
*res
)
5974 struct pnfs_device
*pdev
= res
->pdev
;
5979 status
= decode_op_hdr(xdr
, OP_GETDEVICEINFO
);
5981 if (status
== -ETOOSMALL
) {
5982 p
= xdr_inline_decode(xdr
, 4);
5985 pdev
->mincount
= be32_to_cpup(p
);
5986 dprintk("%s: Min count too small. mincnt = %u\n",
5987 __func__
, pdev
->mincount
);
5992 p
= xdr_inline_decode(xdr
, 8);
5995 type
= be32_to_cpup(p
++);
5996 if (type
!= pdev
->layout_type
) {
5997 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5998 __func__
, pdev
->layout_type
, type
);
6002 * Get the length of the opaque device_addr4. xdr_read_pages places
6003 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
6004 * and places the remaining xdr data in xdr_buf->tail
6006 pdev
->mincount
= be32_to_cpup(p
);
6007 if (xdr_read_pages(xdr
, pdev
->mincount
) != pdev
->mincount
)
6010 /* Parse notification bitmap, verifying that it is zero. */
6011 p
= xdr_inline_decode(xdr
, 4);
6014 len
= be32_to_cpup(p
);
6018 p
= xdr_inline_decode(xdr
, 4 * len
);
6022 res
->notification
= be32_to_cpup(p
++);
6023 for (i
= 1; i
< len
; i
++) {
6024 if (be32_to_cpup(p
++)) {
6025 dprintk("%s: unsupported notification\n",
6033 print_overflow_msg(__func__
, xdr
);
6037 static int decode_layoutget(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
6038 struct nfs4_layoutget_res
*res
)
6045 status
= decode_op_hdr(xdr
, OP_LAYOUTGET
);
6048 p
= xdr_inline_decode(xdr
, 4);
6051 res
->return_on_close
= be32_to_cpup(p
);
6052 decode_layout_stateid(xdr
, &res
->stateid
);
6053 p
= xdr_inline_decode(xdr
, 4);
6056 layout_count
= be32_to_cpup(p
);
6057 if (!layout_count
) {
6058 dprintk("%s: server responded with empty layout array\n",
6063 p
= xdr_inline_decode(xdr
, 28);
6066 p
= xdr_decode_hyper(p
, &res
->range
.offset
);
6067 p
= xdr_decode_hyper(p
, &res
->range
.length
);
6068 res
->range
.iomode
= be32_to_cpup(p
++);
6069 res
->type
= be32_to_cpup(p
++);
6070 res
->layoutp
->len
= be32_to_cpup(p
);
6072 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6074 (unsigned long)res
->range
.offset
,
6075 (unsigned long)res
->range
.length
,
6080 recvd
= xdr_read_pages(xdr
, res
->layoutp
->len
);
6081 if (res
->layoutp
->len
> recvd
) {
6082 dprintk("NFS: server cheating in layoutget reply: "
6083 "layout len %u > recvd %u\n",
6084 res
->layoutp
->len
, recvd
);
6088 if (layout_count
> 1) {
6089 /* We only handle a length one array at the moment. Any
6090 * further entries are just ignored. Note that this means
6091 * the client may see a response that is less than the
6092 * minimum it requested.
6094 dprintk("%s: server responded with %d layouts, dropping tail\n",
6095 __func__
, layout_count
);
6100 print_overflow_msg(__func__
, xdr
);
6104 static int decode_layoutreturn(struct xdr_stream
*xdr
,
6105 struct nfs4_layoutreturn_res
*res
)
6110 status
= decode_op_hdr(xdr
, OP_LAYOUTRETURN
);
6113 p
= xdr_inline_decode(xdr
, 4);
6116 res
->lrs_present
= be32_to_cpup(p
);
6117 if (res
->lrs_present
)
6118 status
= decode_layout_stateid(xdr
, &res
->stateid
);
6120 nfs4_stateid_copy(&res
->stateid
, &invalid_stateid
);
6123 print_overflow_msg(__func__
, xdr
);
6127 static int decode_layoutcommit(struct xdr_stream
*xdr
,
6128 struct rpc_rqst
*req
,
6129 struct nfs4_layoutcommit_res
*res
)
6135 status
= decode_op_hdr(xdr
, OP_LAYOUTCOMMIT
);
6136 res
->status
= status
;
6140 p
= xdr_inline_decode(xdr
, 4);
6143 sizechanged
= be32_to_cpup(p
);
6146 /* throw away new size */
6147 p
= xdr_inline_decode(xdr
, 8);
6153 print_overflow_msg(__func__
, xdr
);
6157 static int decode_test_stateid(struct xdr_stream
*xdr
,
6158 struct nfs41_test_stateid_res
*res
)
6164 status
= decode_op_hdr(xdr
, OP_TEST_STATEID
);
6168 p
= xdr_inline_decode(xdr
, 4);
6171 num_res
= be32_to_cpup(p
++);
6175 p
= xdr_inline_decode(xdr
, 4);
6178 res
->status
= be32_to_cpup(p
++);
6182 print_overflow_msg(__func__
, xdr
);
6187 static int decode_free_stateid(struct xdr_stream
*xdr
,
6188 struct nfs41_free_stateid_res
*res
)
6190 res
->status
= decode_op_hdr(xdr
, OP_FREE_STATEID
);
6195 int decode_layoutreturn(struct xdr_stream
*xdr
,
6196 struct nfs4_layoutreturn_res
*res
)
6200 #endif /* CONFIG_NFS_V4_1 */
6203 * END OF "GENERIC" DECODE ROUTINES.
6207 * Decode OPEN_DOWNGRADE response
6209 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
,
6210 struct xdr_stream
*xdr
,
6213 struct nfs_closeres
*res
= data
;
6214 struct compound_hdr hdr
;
6217 status
= decode_compound_hdr(xdr
, &hdr
);
6220 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6223 status
= decode_putfh(xdr
);
6227 status
= decode_layoutreturn(xdr
, res
->lr_res
);
6228 res
->lr_ret
= status
;
6232 status
= decode_open_downgrade(xdr
, res
);
6238 * Decode ACCESS response
6240 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6243 struct nfs4_accessres
*res
= data
;
6244 struct compound_hdr hdr
;
6247 status
= decode_compound_hdr(xdr
, &hdr
);
6250 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6253 status
= decode_putfh(xdr
);
6256 status
= decode_access(xdr
, &res
->supported
, &res
->access
);
6259 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6265 * Decode LOOKUP response
6267 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6270 struct nfs4_lookup_res
*res
= data
;
6271 struct compound_hdr hdr
;
6274 status
= decode_compound_hdr(xdr
, &hdr
);
6277 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6280 status
= decode_putfh(xdr
);
6283 status
= decode_lookup(xdr
);
6286 status
= decode_getfh(xdr
, res
->fh
);
6289 status
= decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6295 * Decode LOOKUPP response
6297 static int nfs4_xdr_dec_lookupp(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6300 struct nfs4_lookupp_res
*res
= data
;
6301 struct compound_hdr hdr
;
6304 status
= decode_compound_hdr(xdr
, &hdr
);
6307 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6310 status
= decode_putfh(xdr
);
6313 status
= decode_lookupp(xdr
);
6316 status
= decode_getfh(xdr
, res
->fh
);
6319 status
= decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6325 * Decode LOOKUP_ROOT response
6327 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
,
6328 struct xdr_stream
*xdr
,
6331 struct nfs4_lookup_res
*res
= data
;
6332 struct compound_hdr hdr
;
6335 status
= decode_compound_hdr(xdr
, &hdr
);
6338 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6341 status
= decode_putrootfh(xdr
);
6344 status
= decode_getfh(xdr
, res
->fh
);
6346 status
= decode_getfattr_label(xdr
, res
->fattr
,
6347 res
->label
, res
->server
);
6353 * Decode REMOVE response
6355 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6358 struct nfs_removeres
*res
= data
;
6359 struct compound_hdr hdr
;
6362 status
= decode_compound_hdr(xdr
, &hdr
);
6365 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6368 status
= decode_putfh(xdr
);
6371 status
= decode_remove(xdr
, &res
->cinfo
);
6377 * Decode RENAME response
6379 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6382 struct nfs_renameres
*res
= data
;
6383 struct compound_hdr hdr
;
6386 status
= decode_compound_hdr(xdr
, &hdr
);
6389 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6392 status
= decode_putfh(xdr
);
6395 status
= decode_savefh(xdr
);
6398 status
= decode_putfh(xdr
);
6401 status
= decode_rename(xdr
, &res
->old_cinfo
, &res
->new_cinfo
);
6407 * Decode LINK response
6409 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6412 struct nfs4_link_res
*res
= data
;
6413 struct compound_hdr hdr
;
6416 status
= decode_compound_hdr(xdr
, &hdr
);
6419 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6422 status
= decode_putfh(xdr
);
6425 status
= decode_savefh(xdr
);
6428 status
= decode_putfh(xdr
);
6431 status
= decode_link(xdr
, &res
->cinfo
);
6435 * Note order: OP_LINK leaves the directory as the current
6438 status
= decode_restorefh(xdr
);
6441 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6447 * Decode CREATE response
6449 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6452 struct nfs4_create_res
*res
= data
;
6453 struct compound_hdr hdr
;
6456 status
= decode_compound_hdr(xdr
, &hdr
);
6459 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6462 status
= decode_putfh(xdr
);
6465 status
= decode_create(xdr
, &res
->dir_cinfo
);
6468 status
= decode_getfh(xdr
, res
->fh
);
6471 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6477 * Decode SYMLINK response
6479 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6482 return nfs4_xdr_dec_create(rqstp
, xdr
, res
);
6486 * Decode GETATTR response
6488 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6491 struct nfs4_getattr_res
*res
= data
;
6492 struct compound_hdr hdr
;
6495 status
= decode_compound_hdr(xdr
, &hdr
);
6498 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6501 status
= decode_putfh(xdr
);
6504 status
= decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6510 * Encode an SETACL request
6512 static void nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6515 const struct nfs_setaclargs
*args
= data
;
6516 struct compound_hdr hdr
= {
6517 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
6520 encode_compound_hdr(xdr
, req
, &hdr
);
6521 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
6522 encode_putfh(xdr
, args
->fh
, &hdr
);
6523 encode_setacl(xdr
, args
, &hdr
);
6528 * Decode SETACL response
6531 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6534 struct nfs_setaclres
*res
= data
;
6535 struct compound_hdr hdr
;
6538 status
= decode_compound_hdr(xdr
, &hdr
);
6541 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6544 status
= decode_putfh(xdr
);
6547 status
= decode_setattr(xdr
);
6553 * Decode GETACL response
6556 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6559 struct nfs_getaclres
*res
= data
;
6560 struct compound_hdr hdr
;
6563 if (res
->acl_scratch
!= NULL
) {
6564 void *p
= page_address(res
->acl_scratch
);
6565 xdr_set_scratch_buffer(xdr
, p
, PAGE_SIZE
);
6567 status
= decode_compound_hdr(xdr
, &hdr
);
6570 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6573 status
= decode_putfh(xdr
);
6576 status
= decode_getacl(xdr
, rqstp
, res
);
6583 * Decode CLOSE response
6585 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6588 struct nfs_closeres
*res
= data
;
6589 struct compound_hdr hdr
;
6592 status
= decode_compound_hdr(xdr
, &hdr
);
6595 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6598 status
= decode_putfh(xdr
);
6602 status
= decode_layoutreturn(xdr
, res
->lr_res
);
6603 res
->lr_ret
= status
;
6607 if (res
->fattr
!= NULL
) {
6608 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
);
6612 status
= decode_close(xdr
, res
);
6618 * Decode OPEN response
6620 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6623 struct nfs_openres
*res
= data
;
6624 struct compound_hdr hdr
;
6627 status
= decode_compound_hdr(xdr
, &hdr
);
6630 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6633 status
= decode_putfh(xdr
);
6636 status
= decode_open(xdr
, res
);
6639 status
= decode_getfh(xdr
, &res
->fh
);
6642 if (res
->access_request
)
6643 decode_access(xdr
, &res
->access_supported
, &res
->access_result
);
6644 decode_getfattr_label(xdr
, res
->f_attr
, res
->f_label
, res
->server
);
6650 * Decode OPEN_CONFIRM response
6652 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
,
6653 struct xdr_stream
*xdr
,
6656 struct nfs_open_confirmres
*res
= data
;
6657 struct compound_hdr hdr
;
6660 status
= decode_compound_hdr(xdr
, &hdr
);
6663 status
= decode_putfh(xdr
);
6666 status
= decode_open_confirm(xdr
, res
);
6672 * Decode OPEN response
6674 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
,
6675 struct xdr_stream
*xdr
,
6678 struct nfs_openres
*res
= data
;
6679 struct compound_hdr hdr
;
6682 status
= decode_compound_hdr(xdr
, &hdr
);
6685 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6688 status
= decode_putfh(xdr
);
6691 status
= decode_open(xdr
, res
);
6694 if (res
->access_request
)
6695 decode_access(xdr
, &res
->access_supported
, &res
->access_result
);
6696 decode_getfattr(xdr
, res
->f_attr
, res
->server
);
6702 * Decode SETATTR response
6704 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
,
6705 struct xdr_stream
*xdr
,
6708 struct nfs_setattrres
*res
= data
;
6709 struct compound_hdr hdr
;
6712 status
= decode_compound_hdr(xdr
, &hdr
);
6715 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6718 status
= decode_putfh(xdr
);
6721 status
= decode_setattr(xdr
);
6724 decode_getfattr_label(xdr
, res
->fattr
, res
->label
, res
->server
);
6730 * Decode LOCK response
6732 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6735 struct nfs_lock_res
*res
= data
;
6736 struct compound_hdr hdr
;
6739 status
= decode_compound_hdr(xdr
, &hdr
);
6742 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6745 status
= decode_putfh(xdr
);
6748 status
= decode_lock(xdr
, res
);
6754 * Decode LOCKT response
6756 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6759 struct nfs_lockt_res
*res
= data
;
6760 struct compound_hdr hdr
;
6763 status
= decode_compound_hdr(xdr
, &hdr
);
6766 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6769 status
= decode_putfh(xdr
);
6772 status
= decode_lockt(xdr
, res
);
6778 * Decode LOCKU response
6780 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6783 struct nfs_locku_res
*res
= data
;
6784 struct compound_hdr hdr
;
6787 status
= decode_compound_hdr(xdr
, &hdr
);
6790 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6793 status
= decode_putfh(xdr
);
6796 status
= decode_locku(xdr
, res
);
6801 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst
*rqstp
,
6802 struct xdr_stream
*xdr
, void *dummy
)
6804 struct compound_hdr hdr
;
6807 status
= decode_compound_hdr(xdr
, &hdr
);
6809 status
= decode_release_lockowner(xdr
);
6814 * Decode READLINK response
6816 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
,
6817 struct xdr_stream
*xdr
,
6820 struct nfs4_readlink_res
*res
= data
;
6821 struct compound_hdr hdr
;
6824 status
= decode_compound_hdr(xdr
, &hdr
);
6827 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6830 status
= decode_putfh(xdr
);
6833 status
= decode_readlink(xdr
, rqstp
);
6839 * Decode READDIR response
6841 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6844 struct nfs4_readdir_res
*res
= data
;
6845 struct compound_hdr hdr
;
6848 status
= decode_compound_hdr(xdr
, &hdr
);
6851 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6854 status
= decode_putfh(xdr
);
6857 status
= decode_readdir(xdr
, rqstp
, res
);
6863 * Decode Read response
6865 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6868 struct nfs_pgio_res
*res
= data
;
6869 struct compound_hdr hdr
;
6872 status
= decode_compound_hdr(xdr
, &hdr
);
6873 res
->op_status
= hdr
.status
;
6876 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6879 status
= decode_putfh(xdr
);
6882 status
= decode_read(xdr
, rqstp
, res
);
6884 status
= res
->count
;
6890 * Decode WRITE response
6892 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6895 struct nfs_pgio_res
*res
= data
;
6896 struct compound_hdr hdr
;
6899 status
= decode_compound_hdr(xdr
, &hdr
);
6900 res
->op_status
= hdr
.status
;
6903 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6906 status
= decode_putfh(xdr
);
6909 status
= decode_write(xdr
, res
);
6913 decode_getfattr(xdr
, res
->fattr
, res
->server
);
6915 status
= res
->count
;
6921 * Decode COMMIT response
6923 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6926 struct nfs_commitres
*res
= data
;
6927 struct compound_hdr hdr
;
6930 status
= decode_compound_hdr(xdr
, &hdr
);
6931 res
->op_status
= hdr
.status
;
6934 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6937 status
= decode_putfh(xdr
);
6940 status
= decode_commit(xdr
, res
);
6946 * Decode FSINFO response
6948 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6951 struct nfs4_fsinfo_res
*res
= data
;
6952 struct compound_hdr hdr
;
6955 status
= decode_compound_hdr(xdr
, &hdr
);
6957 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6959 status
= decode_putfh(xdr
);
6961 status
= decode_fsinfo(xdr
, res
->fsinfo
);
6966 * Decode PATHCONF response
6968 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6971 struct nfs4_pathconf_res
*res
= data
;
6972 struct compound_hdr hdr
;
6975 status
= decode_compound_hdr(xdr
, &hdr
);
6977 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6979 status
= decode_putfh(xdr
);
6981 status
= decode_pathconf(xdr
, res
->pathconf
);
6986 * Decode STATFS response
6988 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6991 struct nfs4_statfs_res
*res
= data
;
6992 struct compound_hdr hdr
;
6995 status
= decode_compound_hdr(xdr
, &hdr
);
6997 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6999 status
= decode_putfh(xdr
);
7001 status
= decode_statfs(xdr
, res
->fsstat
);
7006 * Decode GETATTR_BITMAP response
7008 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
,
7009 struct xdr_stream
*xdr
,
7012 struct nfs4_server_caps_res
*res
= data
;
7013 struct compound_hdr hdr
;
7016 status
= decode_compound_hdr(xdr
, &hdr
);
7019 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
7022 status
= decode_putfh(xdr
);
7025 status
= decode_server_caps(xdr
, res
);
7031 * Decode RENEW response
7033 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
7036 struct compound_hdr hdr
;
7039 status
= decode_compound_hdr(xdr
, &hdr
);
7041 status
= decode_renew(xdr
);
7046 * Decode SETCLIENTID response
7048 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
,
7049 struct xdr_stream
*xdr
,
7052 struct nfs4_setclientid_res
*res
= data
;
7053 struct compound_hdr hdr
;
7056 status
= decode_compound_hdr(xdr
, &hdr
);
7058 status
= decode_setclientid(xdr
, res
);
7063 * Decode SETCLIENTID_CONFIRM response
7065 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
,
7066 struct xdr_stream
*xdr
,
7069 struct compound_hdr hdr
;
7072 status
= decode_compound_hdr(xdr
, &hdr
);
7074 status
= decode_setclientid_confirm(xdr
);
7079 * Decode DELEGRETURN response
7081 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
,
7082 struct xdr_stream
*xdr
,
7085 struct nfs4_delegreturnres
*res
= data
;
7086 struct compound_hdr hdr
;
7089 status
= decode_compound_hdr(xdr
, &hdr
);
7092 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7095 status
= decode_putfh(xdr
);
7099 status
= decode_layoutreturn(xdr
, res
->lr_res
);
7100 res
->lr_ret
= status
;
7105 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
);
7109 status
= decode_delegreturn(xdr
);
7115 * Decode FS_LOCATIONS response
7117 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
,
7118 struct xdr_stream
*xdr
,
7121 struct nfs4_fs_locations_res
*res
= data
;
7122 struct compound_hdr hdr
;
7125 status
= decode_compound_hdr(xdr
, &hdr
);
7128 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
7131 status
= decode_putfh(xdr
);
7134 if (res
->migration
) {
7135 xdr_enter_page(xdr
, PAGE_SIZE
);
7136 status
= decode_getfattr_generic(xdr
,
7137 &res
->fs_locations
->fattr
,
7138 NULL
, res
->fs_locations
,
7139 NULL
, res
->fs_locations
->server
);
7143 status
= decode_renew(xdr
);
7145 status
= decode_lookup(xdr
);
7148 xdr_enter_page(xdr
, PAGE_SIZE
);
7149 status
= decode_getfattr_generic(xdr
,
7150 &res
->fs_locations
->fattr
,
7151 NULL
, res
->fs_locations
,
7152 NULL
, res
->fs_locations
->server
);
7159 * Decode SECINFO response
7161 static int nfs4_xdr_dec_secinfo(struct rpc_rqst
*rqstp
,
7162 struct xdr_stream
*xdr
,
7165 struct nfs4_secinfo_res
*res
= data
;
7166 struct compound_hdr hdr
;
7169 status
= decode_compound_hdr(xdr
, &hdr
);
7172 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7175 status
= decode_putfh(xdr
);
7178 status
= decode_secinfo(xdr
, res
);
7184 * Decode FSID_PRESENT response
7186 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst
*rqstp
,
7187 struct xdr_stream
*xdr
,
7190 struct nfs4_fsid_present_res
*res
= data
;
7191 struct compound_hdr hdr
;
7194 status
= decode_compound_hdr(xdr
, &hdr
);
7197 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7200 status
= decode_putfh(xdr
);
7203 status
= decode_getfh(xdr
, res
->fh
);
7207 status
= decode_renew(xdr
);
7212 #if defined(CONFIG_NFS_V4_1)
7214 * Decode BIND_CONN_TO_SESSION response
7216 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst
*rqstp
,
7217 struct xdr_stream
*xdr
,
7220 struct compound_hdr hdr
;
7223 status
= decode_compound_hdr(xdr
, &hdr
);
7225 status
= decode_bind_conn_to_session(xdr
, res
);
7230 * Decode EXCHANGE_ID response
7232 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
,
7233 struct xdr_stream
*xdr
,
7236 struct compound_hdr hdr
;
7239 status
= decode_compound_hdr(xdr
, &hdr
);
7241 status
= decode_exchange_id(xdr
, res
);
7246 * Decode CREATE_SESSION response
7248 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
,
7249 struct xdr_stream
*xdr
,
7252 struct compound_hdr hdr
;
7255 status
= decode_compound_hdr(xdr
, &hdr
);
7257 status
= decode_create_session(xdr
, res
);
7262 * Decode DESTROY_SESSION response
7264 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
,
7265 struct xdr_stream
*xdr
,
7268 struct compound_hdr hdr
;
7271 status
= decode_compound_hdr(xdr
, &hdr
);
7273 status
= decode_destroy_session(xdr
, res
);
7278 * Decode DESTROY_CLIENTID response
7280 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst
*rqstp
,
7281 struct xdr_stream
*xdr
,
7284 struct compound_hdr hdr
;
7287 status
= decode_compound_hdr(xdr
, &hdr
);
7289 status
= decode_destroy_clientid(xdr
, res
);
7294 * Decode SEQUENCE response
7296 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
,
7297 struct xdr_stream
*xdr
,
7300 struct compound_hdr hdr
;
7303 status
= decode_compound_hdr(xdr
, &hdr
);
7305 status
= decode_sequence(xdr
, res
, rqstp
);
7310 * Decode GET_LEASE_TIME response
7312 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
,
7313 struct xdr_stream
*xdr
,
7316 struct nfs4_get_lease_time_res
*res
= data
;
7317 struct compound_hdr hdr
;
7320 status
= decode_compound_hdr(xdr
, &hdr
);
7322 status
= decode_sequence(xdr
, &res
->lr_seq_res
, rqstp
);
7324 status
= decode_putrootfh(xdr
);
7326 status
= decode_fsinfo(xdr
, res
->lr_fsinfo
);
7331 * Decode RECLAIM_COMPLETE response
7333 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
,
7334 struct xdr_stream
*xdr
,
7337 struct nfs41_reclaim_complete_res
*res
= data
;
7338 struct compound_hdr hdr
;
7341 status
= decode_compound_hdr(xdr
, &hdr
);
7343 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7345 status
= decode_reclaim_complete(xdr
, NULL
);
7350 * Decode GETDEVINFO response
7352 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst
*rqstp
,
7353 struct xdr_stream
*xdr
,
7356 struct nfs4_getdeviceinfo_res
*res
= data
;
7357 struct compound_hdr hdr
;
7360 status
= decode_compound_hdr(xdr
, &hdr
);
7363 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7366 status
= decode_getdeviceinfo(xdr
, res
);
7372 * Decode LAYOUTGET response
7374 static int nfs4_xdr_dec_layoutget(struct rpc_rqst
*rqstp
,
7375 struct xdr_stream
*xdr
,
7378 struct nfs4_layoutget_res
*res
= data
;
7379 struct compound_hdr hdr
;
7382 status
= decode_compound_hdr(xdr
, &hdr
);
7385 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7388 status
= decode_putfh(xdr
);
7391 status
= decode_layoutget(xdr
, rqstp
, res
);
7397 * Decode LAYOUTRETURN response
7399 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst
*rqstp
,
7400 struct xdr_stream
*xdr
,
7403 struct nfs4_layoutreturn_res
*res
= data
;
7404 struct compound_hdr hdr
;
7407 status
= decode_compound_hdr(xdr
, &hdr
);
7410 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7413 status
= decode_putfh(xdr
);
7416 status
= decode_layoutreturn(xdr
, res
);
7422 * Decode LAYOUTCOMMIT response
7424 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst
*rqstp
,
7425 struct xdr_stream
*xdr
,
7428 struct nfs4_layoutcommit_res
*res
= data
;
7429 struct compound_hdr hdr
;
7432 status
= decode_compound_hdr(xdr
, &hdr
);
7435 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7438 status
= decode_putfh(xdr
);
7441 status
= decode_layoutcommit(xdr
, rqstp
, res
);
7444 decode_getfattr(xdr
, res
->fattr
, res
->server
);
7450 * Decode SECINFO_NO_NAME response
7452 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst
*rqstp
,
7453 struct xdr_stream
*xdr
,
7456 struct nfs4_secinfo_res
*res
= data
;
7457 struct compound_hdr hdr
;
7460 status
= decode_compound_hdr(xdr
, &hdr
);
7463 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7466 status
= decode_putrootfh(xdr
);
7469 status
= decode_secinfo_no_name(xdr
, res
);
7475 * Decode TEST_STATEID response
7477 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst
*rqstp
,
7478 struct xdr_stream
*xdr
,
7481 struct nfs41_test_stateid_res
*res
= data
;
7482 struct compound_hdr hdr
;
7485 status
= decode_compound_hdr(xdr
, &hdr
);
7488 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7491 status
= decode_test_stateid(xdr
, res
);
7497 * Decode FREE_STATEID response
7499 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst
*rqstp
,
7500 struct xdr_stream
*xdr
,
7503 struct nfs41_free_stateid_res
*res
= data
;
7504 struct compound_hdr hdr
;
7507 status
= decode_compound_hdr(xdr
, &hdr
);
7510 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
7513 status
= decode_free_stateid(xdr
, res
);
7517 #endif /* CONFIG_NFS_V4_1 */
7520 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7521 * the local page cache.
7522 * @xdr: XDR stream where entry resides
7523 * @entry: buffer to fill in with entry data
7524 * @plus: boolean indicating whether this should be a readdirplus entry
7526 * Returns zero if successful, otherwise a negative errno value is
7529 * This function is not invoked during READDIR reply decoding, but
7530 * rather whenever an application invokes the getdents(2) system call
7531 * on a directory already in our cache.
7533 int nfs4_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
7537 uint32_t bitmap
[3] = {0};
7539 __be32
*p
= xdr_inline_decode(xdr
, 4);
7542 if (*p
== xdr_zero
) {
7543 p
= xdr_inline_decode(xdr
, 4);
7552 p
= xdr_inline_decode(xdr
, 12);
7555 entry
->prev_cookie
= entry
->cookie
;
7556 p
= xdr_decode_hyper(p
, &entry
->cookie
);
7557 entry
->len
= be32_to_cpup(p
);
7559 p
= xdr_inline_decode(xdr
, entry
->len
);
7562 entry
->name
= (const char *) p
;
7565 * In case the server doesn't return an inode number,
7566 * we fake one here. (We don't use inode number 0,
7567 * since glibc seems to choke on it...)
7570 entry
->fattr
->valid
= 0;
7572 if (decode_attr_bitmap(xdr
, bitmap
) < 0)
7575 if (decode_attr_length(xdr
, &len
, &savep
) < 0)
7578 if (decode_getfattr_attrs(xdr
, bitmap
, entry
->fattr
, entry
->fh
,
7579 NULL
, entry
->label
, entry
->server
) < 0)
7581 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
)
7582 entry
->ino
= entry
->fattr
->mounted_on_fileid
;
7583 else if (entry
->fattr
->valid
& NFS_ATTR_FATTR_FILEID
)
7584 entry
->ino
= entry
->fattr
->fileid
;
7586 entry
->d_type
= DT_UNKNOWN
;
7587 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_TYPE
)
7588 entry
->d_type
= nfs_umode_to_dtype(entry
->fattr
->mode
);
7593 print_overflow_msg(__func__
, xdr
);
7598 * We need to translate between nfs status return values and
7599 * the local errno values which may not be the same.
7606 { NFS4ERR_PERM
, -EPERM
},
7607 { NFS4ERR_NOENT
, -ENOENT
},
7608 { NFS4ERR_IO
, -errno_NFSERR_IO
},
7609 { NFS4ERR_NXIO
, -ENXIO
},
7610 { NFS4ERR_ACCESS
, -EACCES
},
7611 { NFS4ERR_EXIST
, -EEXIST
},
7612 { NFS4ERR_XDEV
, -EXDEV
},
7613 { NFS4ERR_NOTDIR
, -ENOTDIR
},
7614 { NFS4ERR_ISDIR
, -EISDIR
},
7615 { NFS4ERR_INVAL
, -EINVAL
},
7616 { NFS4ERR_FBIG
, -EFBIG
},
7617 { NFS4ERR_NOSPC
, -ENOSPC
},
7618 { NFS4ERR_ROFS
, -EROFS
},
7619 { NFS4ERR_MLINK
, -EMLINK
},
7620 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
7621 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
7622 { NFS4ERR_DQUOT
, -EDQUOT
},
7623 { NFS4ERR_STALE
, -ESTALE
},
7624 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
7625 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
7626 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
7627 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
7628 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
7629 { NFS4ERR_BADTYPE
, -EBADTYPE
},
7630 { NFS4ERR_LOCKED
, -EAGAIN
},
7631 { NFS4ERR_SYMLINK
, -ELOOP
},
7632 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
7633 { NFS4ERR_DEADLOCK
, -EDEADLK
},
7638 * Convert an NFS error code to a local one.
7639 * This one is used jointly by NFSv2 and NFSv3.
7642 nfs4_stat_to_errno(int stat
)
7645 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
7646 if (nfs_errtbl
[i
].stat
== stat
)
7647 return nfs_errtbl
[i
].errno
;
7649 if (stat
<= 10000 || stat
> 10100) {
7650 /* The server is looney tunes. */
7653 /* If we cannot translate the error, the recovery routines should
7655 * Note: remaining NFSv4 error codes have values > 10000, so should
7656 * not conflict with native Linux error codes.
7661 #ifdef CONFIG_NFS_V4_2
7662 #include "nfs42xdr.c"
7663 #endif /* CONFIG_NFS_V4_2 */
7665 #define PROC(proc, argtype, restype) \
7666 [NFSPROC4_CLNT_##proc] = { \
7667 .p_proc = NFSPROC4_COMPOUND, \
7668 .p_encode = nfs4_xdr_##argtype, \
7669 .p_decode = nfs4_xdr_##restype, \
7670 .p_arglen = NFS4_##argtype##_sz, \
7671 .p_replen = NFS4_##restype##_sz, \
7672 .p_statidx = NFSPROC4_CLNT_##proc, \
7676 #define STUB(proc) \
7677 [NFSPROC4_CLNT_##proc] = { \
7681 #if defined(CONFIG_NFS_V4_1)
7682 #define PROC41(proc, argtype, restype) \
7683 PROC(proc, argtype, restype)
7685 #define PROC41(proc, argtype, restype) \
7689 #if defined(CONFIG_NFS_V4_2)
7690 #define PROC42(proc, argtype, restype) \
7691 PROC(proc, argtype, restype)
7693 #define PROC42(proc, argtype, restype) \
7697 const struct rpc_procinfo nfs4_procedures
[] = {
7698 PROC(READ
, enc_read
, dec_read
),
7699 PROC(WRITE
, enc_write
, dec_write
),
7700 PROC(COMMIT
, enc_commit
, dec_commit
),
7701 PROC(OPEN
, enc_open
, dec_open
),
7702 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
7703 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
7704 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
7705 PROC(CLOSE
, enc_close
, dec_close
),
7706 PROC(SETATTR
, enc_setattr
, dec_setattr
),
7707 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
7708 PROC(RENEW
, enc_renew
, dec_renew
),
7709 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
7710 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
7711 PROC(LOCK
, enc_lock
, dec_lock
),
7712 PROC(LOCKT
, enc_lockt
, dec_lockt
),
7713 PROC(LOCKU
, enc_locku
, dec_locku
),
7714 PROC(ACCESS
, enc_access
, dec_access
),
7715 PROC(GETATTR
, enc_getattr
, dec_getattr
),
7716 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
7717 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
7718 PROC(REMOVE
, enc_remove
, dec_remove
),
7719 PROC(RENAME
, enc_rename
, dec_rename
),
7720 PROC(LINK
, enc_link
, dec_link
),
7721 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
7722 PROC(CREATE
, enc_create
, dec_create
),
7723 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
7724 PROC(STATFS
, enc_statfs
, dec_statfs
),
7725 PROC(READLINK
, enc_readlink
, dec_readlink
),
7726 PROC(READDIR
, enc_readdir
, dec_readdir
),
7727 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
7728 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
7729 PROC(GETACL
, enc_getacl
, dec_getacl
),
7730 PROC(SETACL
, enc_setacl
, dec_setacl
),
7731 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
7732 PROC(RELEASE_LOCKOWNER
, enc_release_lockowner
, dec_release_lockowner
),
7733 PROC(SECINFO
, enc_secinfo
, dec_secinfo
),
7734 PROC(FSID_PRESENT
, enc_fsid_present
, dec_fsid_present
),
7735 PROC41(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
7736 PROC41(CREATE_SESSION
, enc_create_session
, dec_create_session
),
7737 PROC41(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
7738 PROC41(SEQUENCE
, enc_sequence
, dec_sequence
),
7739 PROC41(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
7740 PROC41(RECLAIM_COMPLETE
,enc_reclaim_complete
, dec_reclaim_complete
),
7741 PROC41(GETDEVICEINFO
, enc_getdeviceinfo
, dec_getdeviceinfo
),
7742 PROC41(LAYOUTGET
, enc_layoutget
, dec_layoutget
),
7743 PROC41(LAYOUTCOMMIT
, enc_layoutcommit
, dec_layoutcommit
),
7744 PROC41(LAYOUTRETURN
, enc_layoutreturn
, dec_layoutreturn
),
7745 PROC41(SECINFO_NO_NAME
, enc_secinfo_no_name
, dec_secinfo_no_name
),
7746 PROC41(TEST_STATEID
, enc_test_stateid
, dec_test_stateid
),
7747 PROC41(FREE_STATEID
, enc_free_stateid
, dec_free_stateid
),
7748 STUB(GETDEVICELIST
),
7749 PROC41(BIND_CONN_TO_SESSION
,
7750 enc_bind_conn_to_session
, dec_bind_conn_to_session
),
7751 PROC41(DESTROY_CLIENTID
,enc_destroy_clientid
, dec_destroy_clientid
),
7752 PROC42(SEEK
, enc_seek
, dec_seek
),
7753 PROC42(ALLOCATE
, enc_allocate
, dec_allocate
),
7754 PROC42(DEALLOCATE
, enc_deallocate
, dec_deallocate
),
7755 PROC42(LAYOUTSTATS
, enc_layoutstats
, dec_layoutstats
),
7756 PROC42(CLONE
, enc_clone
, dec_clone
),
7757 PROC42(COPY
, enc_copy
, dec_copy
),
7758 PROC(LOOKUPP
, enc_lookupp
, dec_lookupp
),
7761 static unsigned int nfs_version4_counts
[ARRAY_SIZE(nfs4_procedures
)];
7762 const struct rpc_version nfs_version4
= {
7764 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
7765 .procs
= nfs4_procedures
,
7766 .counts
= nfs_version4_counts
,