4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/sunrpc/clnt.h>
48 #include <linux/sunrpc/msg_prot.h>
49 #include <linux/sunrpc/gss_api.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
58 #define NFSDBG_FACILITY NFSDBG_XDR
60 /* Mapping from NFS error code to "errno" error code. */
61 #define errno_NFSERR_IO EIO
63 static int nfs4_stat_to_errno(int);
65 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
67 #define NFS4_MAXTAGLEN 20
69 #define NFS4_MAXTAGLEN 0
72 /* lock,open owner id:
73 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
75 #define open_owner_id_maxsz (1 + 1 + 4)
76 #define lock_owner_id_maxsz (1 + 1 + 4)
77 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
78 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80 #define op_encode_hdr_maxsz (1)
81 #define op_decode_hdr_maxsz (2)
82 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
86 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
88 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
92 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
94 #define nfs4_fattr_bitmap_maxsz 4
95 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
96 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
98 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
100 /* This is based on getfattr, which uses the most attributes: */
101 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
103 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
106 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
111 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
115 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
116 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
117 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118 #define decode_renew_maxsz (op_decode_hdr_maxsz)
119 #define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
127 #define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
130 1024) /* large value for CLID_INUSE */
131 #define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134 #define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
136 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
138 #define encode_share_access_maxsz \
140 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
141 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143 #define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
149 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
151 #define decode_change_info_maxsz (5)
152 #define decode_open_maxsz (op_decode_hdr_maxsz + \
153 decode_stateid_maxsz + \
154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
157 #define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160 #define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163 #define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167 #define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170 #define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172 #define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
177 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179 #define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
187 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188 #define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190 #define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
195 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
197 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
199 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
201 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
204 #define encode_link_maxsz (op_encode_hdr_maxsz + \
206 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
207 #define encode_lockowner_maxsz (7)
208 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
212 #define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
216 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
218 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
223 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
225 #define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228 #define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
230 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
232 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
236 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237 #define encode_create_maxsz (op_encode_hdr_maxsz + \
238 1 + 2 + nfs4_name_maxsz + \
240 #define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
243 #define encode_statfs_maxsz (encode_getattr_maxsz)
244 #define decode_statfs_maxsz (decode_getattr_maxsz)
245 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
247 #define encode_getacl_maxsz (encode_getattr_maxsz)
248 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252 #define decode_setacl_maxsz (decode_setattr_maxsz)
253 #define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255 #define decode_fs_locations_maxsz \
257 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
258 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
260 #if defined(CONFIG_NFS_V4_1)
261 #define NFS4_MAX_MACHINE_NAME_LEN (64)
263 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
284 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285 #define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
288 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
302 1 /* gids.len (0) */)
303 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
309 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
311 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
315 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
317 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
330 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
334 encode_stateid_maxsz + \
335 1 /* new offset (true) */ + \
336 2 /* last byte written */ + \
337 1 /* nt_timechanged (false) */ + \
338 1 /* layoutupdate4 layout type */ + \
339 1 /* NULL filelayout layoutupdate4 payload */)
340 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
341 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
342 encode_stateid_maxsz + \
343 1 /* FIXME: opaque lrf_body always empty at the moment */)
344 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
345 1 + decode_stateid_maxsz)
346 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
347 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
348 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
349 XDR_QUADLEN(NFS4_STATEID_SIZE))
350 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
351 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
352 XDR_QUADLEN(NFS4_STATEID_SIZE))
353 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
354 #else /* CONFIG_NFS_V4_1 */
355 #define encode_sequence_maxsz 0
356 #define decode_sequence_maxsz 0
357 #endif /* CONFIG_NFS_V4_1 */
359 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
360 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
361 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
362 encode_sequence_maxsz + \
363 encode_putfh_maxsz + \
365 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
366 decode_sequence_maxsz + \
367 decode_putfh_maxsz + \
369 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
370 encode_sequence_maxsz + \
371 encode_putfh_maxsz + \
372 encode_readlink_maxsz)
373 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
374 decode_sequence_maxsz + \
375 decode_putfh_maxsz + \
376 decode_readlink_maxsz)
377 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
378 encode_sequence_maxsz + \
379 encode_putfh_maxsz + \
380 encode_readdir_maxsz)
381 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
382 decode_sequence_maxsz + \
383 decode_putfh_maxsz + \
384 decode_readdir_maxsz)
385 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
386 encode_sequence_maxsz + \
387 encode_putfh_maxsz + \
388 encode_write_maxsz + \
389 encode_getattr_maxsz)
390 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
391 decode_sequence_maxsz + \
392 decode_putfh_maxsz + \
393 decode_write_maxsz + \
394 decode_getattr_maxsz)
395 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
396 encode_sequence_maxsz + \
397 encode_putfh_maxsz + \
398 encode_commit_maxsz + \
399 encode_getattr_maxsz)
400 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
401 decode_sequence_maxsz + \
402 decode_putfh_maxsz + \
403 decode_commit_maxsz + \
404 decode_getattr_maxsz)
405 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
406 encode_sequence_maxsz + \
407 encode_putfh_maxsz + \
408 encode_savefh_maxsz + \
409 encode_open_maxsz + \
410 encode_getfh_maxsz + \
411 encode_getattr_maxsz + \
412 encode_restorefh_maxsz + \
413 encode_getattr_maxsz)
414 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
415 decode_sequence_maxsz + \
416 decode_putfh_maxsz + \
417 decode_savefh_maxsz + \
418 decode_open_maxsz + \
419 decode_getfh_maxsz + \
420 decode_getattr_maxsz + \
421 decode_restorefh_maxsz + \
422 decode_getattr_maxsz)
423 #define NFS4_enc_open_confirm_sz \
424 (compound_encode_hdr_maxsz + \
425 encode_putfh_maxsz + \
426 encode_open_confirm_maxsz)
427 #define NFS4_dec_open_confirm_sz \
428 (compound_decode_hdr_maxsz + \
429 decode_putfh_maxsz + \
430 decode_open_confirm_maxsz)
431 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
432 encode_sequence_maxsz + \
433 encode_putfh_maxsz + \
434 encode_open_maxsz + \
435 encode_getattr_maxsz)
436 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
437 decode_sequence_maxsz + \
438 decode_putfh_maxsz + \
439 decode_open_maxsz + \
440 decode_getattr_maxsz)
441 #define NFS4_enc_open_downgrade_sz \
442 (compound_encode_hdr_maxsz + \
443 encode_sequence_maxsz + \
444 encode_putfh_maxsz + \
445 encode_open_downgrade_maxsz + \
446 encode_getattr_maxsz)
447 #define NFS4_dec_open_downgrade_sz \
448 (compound_decode_hdr_maxsz + \
449 decode_sequence_maxsz + \
450 decode_putfh_maxsz + \
451 decode_open_downgrade_maxsz + \
452 decode_getattr_maxsz)
453 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
454 encode_sequence_maxsz + \
455 encode_putfh_maxsz + \
456 encode_close_maxsz + \
457 encode_getattr_maxsz)
458 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
459 decode_sequence_maxsz + \
460 decode_putfh_maxsz + \
461 decode_close_maxsz + \
462 decode_getattr_maxsz)
463 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
464 encode_sequence_maxsz + \
465 encode_putfh_maxsz + \
466 encode_setattr_maxsz + \
467 encode_getattr_maxsz)
468 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
469 decode_sequence_maxsz + \
470 decode_putfh_maxsz + \
471 decode_setattr_maxsz + \
472 decode_getattr_maxsz)
473 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
474 encode_sequence_maxsz + \
475 encode_putfh_maxsz + \
477 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
478 decode_sequence_maxsz + \
479 decode_putfh_maxsz + \
481 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
483 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
485 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
486 encode_setclientid_maxsz)
487 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
488 decode_setclientid_maxsz)
489 #define NFS4_enc_setclientid_confirm_sz \
490 (compound_encode_hdr_maxsz + \
491 encode_setclientid_confirm_maxsz + \
492 encode_putrootfh_maxsz + \
494 #define NFS4_dec_setclientid_confirm_sz \
495 (compound_decode_hdr_maxsz + \
496 decode_setclientid_confirm_maxsz + \
497 decode_putrootfh_maxsz + \
499 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
500 encode_sequence_maxsz + \
501 encode_putfh_maxsz + \
503 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
504 decode_sequence_maxsz + \
505 decode_putfh_maxsz + \
507 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
508 encode_sequence_maxsz + \
509 encode_putfh_maxsz + \
511 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
512 decode_sequence_maxsz + \
513 decode_putfh_maxsz + \
515 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
516 encode_sequence_maxsz + \
517 encode_putfh_maxsz + \
519 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
520 decode_sequence_maxsz + \
521 decode_putfh_maxsz + \
523 #define NFS4_enc_release_lockowner_sz \
524 (compound_encode_hdr_maxsz + \
525 encode_lockowner_maxsz)
526 #define NFS4_dec_release_lockowner_sz \
527 (compound_decode_hdr_maxsz + \
528 decode_lockowner_maxsz)
529 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
530 encode_sequence_maxsz + \
531 encode_putfh_maxsz + \
532 encode_access_maxsz + \
533 encode_getattr_maxsz)
534 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
535 decode_sequence_maxsz + \
536 decode_putfh_maxsz + \
537 decode_access_maxsz + \
538 decode_getattr_maxsz)
539 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
540 encode_sequence_maxsz + \
541 encode_putfh_maxsz + \
542 encode_getattr_maxsz)
543 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
544 decode_sequence_maxsz + \
545 decode_putfh_maxsz + \
546 decode_getattr_maxsz)
547 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
548 encode_sequence_maxsz + \
549 encode_putfh_maxsz + \
550 encode_lookup_maxsz + \
551 encode_getattr_maxsz + \
553 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
554 decode_sequence_maxsz + \
555 decode_putfh_maxsz + \
556 decode_lookup_maxsz + \
557 decode_getattr_maxsz + \
559 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
560 encode_sequence_maxsz + \
561 encode_putrootfh_maxsz + \
562 encode_getattr_maxsz + \
564 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
565 decode_sequence_maxsz + \
566 decode_putrootfh_maxsz + \
567 decode_getattr_maxsz + \
569 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
570 encode_sequence_maxsz + \
571 encode_putfh_maxsz + \
572 encode_remove_maxsz + \
573 encode_getattr_maxsz)
574 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
575 decode_sequence_maxsz + \
576 decode_putfh_maxsz + \
577 decode_remove_maxsz + \
578 decode_getattr_maxsz)
579 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
580 encode_sequence_maxsz + \
581 encode_putfh_maxsz + \
582 encode_savefh_maxsz + \
583 encode_putfh_maxsz + \
584 encode_rename_maxsz + \
585 encode_getattr_maxsz + \
586 encode_restorefh_maxsz + \
587 encode_getattr_maxsz)
588 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
589 decode_sequence_maxsz + \
590 decode_putfh_maxsz + \
591 decode_savefh_maxsz + \
592 decode_putfh_maxsz + \
593 decode_rename_maxsz + \
594 decode_getattr_maxsz + \
595 decode_restorefh_maxsz + \
596 decode_getattr_maxsz)
597 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
598 encode_sequence_maxsz + \
599 encode_putfh_maxsz + \
600 encode_savefh_maxsz + \
601 encode_putfh_maxsz + \
602 encode_link_maxsz + \
603 decode_getattr_maxsz + \
604 encode_restorefh_maxsz + \
605 decode_getattr_maxsz)
606 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
607 decode_sequence_maxsz + \
608 decode_putfh_maxsz + \
609 decode_savefh_maxsz + \
610 decode_putfh_maxsz + \
611 decode_link_maxsz + \
612 decode_getattr_maxsz + \
613 decode_restorefh_maxsz + \
614 decode_getattr_maxsz)
615 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
616 encode_sequence_maxsz + \
617 encode_putfh_maxsz + \
618 encode_symlink_maxsz + \
619 encode_getattr_maxsz + \
621 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
622 decode_sequence_maxsz + \
623 decode_putfh_maxsz + \
624 decode_symlink_maxsz + \
625 decode_getattr_maxsz + \
627 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
628 encode_sequence_maxsz + \
629 encode_putfh_maxsz + \
630 encode_savefh_maxsz + \
631 encode_create_maxsz + \
632 encode_getfh_maxsz + \
633 encode_getattr_maxsz + \
634 encode_restorefh_maxsz + \
635 encode_getattr_maxsz)
636 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
637 decode_sequence_maxsz + \
638 decode_putfh_maxsz + \
639 decode_savefh_maxsz + \
640 decode_create_maxsz + \
641 decode_getfh_maxsz + \
642 decode_getattr_maxsz + \
643 decode_restorefh_maxsz + \
644 decode_getattr_maxsz)
645 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
646 encode_sequence_maxsz + \
647 encode_putfh_maxsz + \
648 encode_getattr_maxsz)
649 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
650 decode_sequence_maxsz + \
651 decode_putfh_maxsz + \
652 decode_getattr_maxsz)
653 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
654 encode_sequence_maxsz + \
655 encode_putfh_maxsz + \
657 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
658 decode_sequence_maxsz + \
659 decode_putfh_maxsz + \
661 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
662 encode_sequence_maxsz + \
663 encode_putfh_maxsz + \
664 encode_getattr_maxsz)
665 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
666 decode_sequence_maxsz + \
667 decode_putfh_maxsz + \
668 decode_getattr_maxsz)
669 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
670 encode_sequence_maxsz + \
671 encode_putfh_maxsz + \
672 encode_delegreturn_maxsz + \
673 encode_getattr_maxsz)
674 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
675 decode_sequence_maxsz + \
676 decode_delegreturn_maxsz + \
677 decode_getattr_maxsz)
678 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
679 encode_sequence_maxsz + \
680 encode_putfh_maxsz + \
682 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
683 decode_sequence_maxsz + \
684 decode_putfh_maxsz + \
686 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
687 encode_sequence_maxsz + \
688 encode_putfh_maxsz + \
690 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
691 decode_sequence_maxsz + \
692 decode_putfh_maxsz + \
694 #define NFS4_enc_fs_locations_sz \
695 (compound_encode_hdr_maxsz + \
696 encode_sequence_maxsz + \
697 encode_putfh_maxsz + \
698 encode_lookup_maxsz + \
699 encode_fs_locations_maxsz)
700 #define NFS4_dec_fs_locations_sz \
701 (compound_decode_hdr_maxsz + \
702 decode_sequence_maxsz + \
703 decode_putfh_maxsz + \
704 decode_lookup_maxsz + \
705 decode_fs_locations_maxsz)
706 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
707 encode_sequence_maxsz + \
708 encode_putfh_maxsz + \
709 encode_secinfo_maxsz)
710 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
711 decode_sequence_maxsz + \
712 decode_putfh_maxsz + \
713 decode_secinfo_maxsz)
714 #if defined(CONFIG_NFS_V4_1)
715 #define NFS4_enc_exchange_id_sz \
716 (compound_encode_hdr_maxsz + \
717 encode_exchange_id_maxsz)
718 #define NFS4_dec_exchange_id_sz \
719 (compound_decode_hdr_maxsz + \
720 decode_exchange_id_maxsz)
721 #define NFS4_enc_create_session_sz \
722 (compound_encode_hdr_maxsz + \
723 encode_create_session_maxsz)
724 #define NFS4_dec_create_session_sz \
725 (compound_decode_hdr_maxsz + \
726 decode_create_session_maxsz)
727 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
728 encode_destroy_session_maxsz)
729 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
730 decode_destroy_session_maxsz)
731 #define NFS4_enc_sequence_sz \
732 (compound_decode_hdr_maxsz + \
733 encode_sequence_maxsz)
734 #define NFS4_dec_sequence_sz \
735 (compound_decode_hdr_maxsz + \
736 decode_sequence_maxsz)
737 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
738 encode_sequence_maxsz + \
739 encode_putrootfh_maxsz + \
741 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
742 decode_sequence_maxsz + \
743 decode_putrootfh_maxsz + \
745 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
746 encode_sequence_maxsz + \
747 encode_reclaim_complete_maxsz)
748 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_reclaim_complete_maxsz)
751 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
752 encode_sequence_maxsz +\
753 encode_getdeviceinfo_maxsz)
754 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
755 decode_sequence_maxsz + \
756 decode_getdeviceinfo_maxsz)
757 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz + \
759 encode_putfh_maxsz + \
760 encode_layoutget_maxsz)
761 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_layoutget_maxsz)
765 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
766 encode_sequence_maxsz +\
767 encode_putfh_maxsz + \
768 encode_layoutcommit_maxsz + \
769 encode_getattr_maxsz)
770 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
771 decode_sequence_maxsz + \
772 decode_putfh_maxsz + \
773 decode_layoutcommit_maxsz + \
774 decode_getattr_maxsz)
775 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
776 encode_sequence_maxsz + \
777 encode_putfh_maxsz + \
778 encode_layoutreturn_maxsz)
779 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
780 decode_sequence_maxsz + \
781 decode_putfh_maxsz + \
782 decode_layoutreturn_maxsz)
783 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
784 encode_sequence_maxsz + \
785 encode_putrootfh_maxsz +\
786 encode_secinfo_no_name_maxsz)
787 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz + \
789 decode_putrootfh_maxsz + \
790 decode_secinfo_no_name_maxsz)
791 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_test_stateid_maxsz)
794 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_test_stateid_maxsz)
797 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_free_stateid_maxsz)
800 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
801 decode_sequence_maxsz + \
802 decode_free_stateid_maxsz)
804 const u32 nfs41_maxwrite_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
805 compound_encode_hdr_maxsz
+
806 encode_sequence_maxsz
+
808 encode_getattr_maxsz
) *
811 const u32 nfs41_maxread_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
812 compound_decode_hdr_maxsz
+
813 decode_sequence_maxsz
+
814 decode_putfh_maxsz
) *
816 #endif /* CONFIG_NFS_V4_1 */
818 static const umode_t nfs_type2fmt
[] = {
825 [NF4SOCK
] = S_IFSOCK
,
831 struct compound_hdr
{
837 uint32_t replen
; /* expected reply words */
841 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
843 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
848 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
852 p
= xdr_reserve_space(xdr
, 4 + len
);
854 xdr_encode_opaque(p
, str
, len
);
857 static void encode_compound_hdr(struct xdr_stream
*xdr
,
858 struct rpc_rqst
*req
,
859 struct compound_hdr
*hdr
)
862 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
864 /* initialize running count of expected bytes in reply.
865 * NOTE: the replied tag SHOULD be the same is the one sent,
866 * but this is not required as a MUST for the server to do so. */
867 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
869 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
870 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
871 p
= reserve_space(xdr
, 4 + hdr
->taglen
+ 8);
872 p
= xdr_encode_opaque(p
, hdr
->tag
, hdr
->taglen
);
873 *p
++ = cpu_to_be32(hdr
->minorversion
);
875 *p
= cpu_to_be32(hdr
->nops
);
878 static void encode_nops(struct compound_hdr
*hdr
)
880 BUG_ON(hdr
->nops
> NFS4_MAX_OPS
);
881 *hdr
->nops_p
= htonl(hdr
->nops
);
884 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
888 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
890 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
893 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
895 char owner_name
[IDMAP_NAMESZ
];
896 char owner_group
[IDMAP_NAMESZ
];
897 int owner_namelen
= 0;
898 int owner_grouplen
= 0;
906 * We reserve enough space to write the entire attribute buffer at once.
907 * In the worst-case, this would be
908 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
909 * = 36 bytes, plus any contribution from variable-length fields
910 * such as owner/group.
915 if (iap
->ia_valid
& ATTR_SIZE
)
917 if (iap
->ia_valid
& ATTR_MODE
)
919 if (iap
->ia_valid
& ATTR_UID
) {
920 owner_namelen
= nfs_map_uid_to_name(server
, iap
->ia_uid
, owner_name
, IDMAP_NAMESZ
);
921 if (owner_namelen
< 0) {
922 dprintk("nfs: couldn't resolve uid %d to string\n",
925 strcpy(owner_name
, "nobody");
926 owner_namelen
= sizeof("nobody") - 1;
929 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
931 if (iap
->ia_valid
& ATTR_GID
) {
932 owner_grouplen
= nfs_map_gid_to_group(server
, iap
->ia_gid
, owner_group
, IDMAP_NAMESZ
);
933 if (owner_grouplen
< 0) {
934 dprintk("nfs: couldn't resolve gid %d to string\n",
936 strcpy(owner_group
, "nobody");
937 owner_grouplen
= sizeof("nobody") - 1;
940 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
942 if (iap
->ia_valid
& ATTR_ATIME_SET
)
944 else if (iap
->ia_valid
& ATTR_ATIME
)
946 if (iap
->ia_valid
& ATTR_MTIME_SET
)
948 else if (iap
->ia_valid
& ATTR_MTIME
)
950 p
= reserve_space(xdr
, len
);
953 * We write the bitmap length now, but leave the bitmap and the attribute
954 * buffer length to be backfilled at the end of this routine.
956 *p
++ = cpu_to_be32(2);
960 if (iap
->ia_valid
& ATTR_SIZE
) {
961 bmval0
|= FATTR4_WORD0_SIZE
;
962 p
= xdr_encode_hyper(p
, iap
->ia_size
);
964 if (iap
->ia_valid
& ATTR_MODE
) {
965 bmval1
|= FATTR4_WORD1_MODE
;
966 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
968 if (iap
->ia_valid
& ATTR_UID
) {
969 bmval1
|= FATTR4_WORD1_OWNER
;
970 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
972 if (iap
->ia_valid
& ATTR_GID
) {
973 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
974 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
976 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
977 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
978 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
979 *p
++ = cpu_to_be32(0);
980 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_sec
);
981 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_nsec
);
983 else if (iap
->ia_valid
& ATTR_ATIME
) {
984 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
985 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
987 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
988 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
989 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
990 *p
++ = cpu_to_be32(0);
991 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_sec
);
992 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
994 else if (iap
->ia_valid
& ATTR_MTIME
) {
995 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
996 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
1000 * Now we backfill the bitmap and the attribute buffer length.
1002 if (len
!= ((char *)p
- (char *)q
) + 4) {
1003 printk(KERN_ERR
"nfs: Attr length error, %u != %Zu\n",
1004 len
, ((char *)p
- (char *)q
) + 4);
1007 len
= (char *)p
- (char *)q
- 12;
1008 *q
++ = htonl(bmval0
);
1009 *q
++ = htonl(bmval1
);
1015 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
1019 p
= reserve_space(xdr
, 8);
1020 *p
++ = cpu_to_be32(OP_ACCESS
);
1021 *p
= cpu_to_be32(access
);
1023 hdr
->replen
+= decode_access_maxsz
;
1026 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1030 p
= reserve_space(xdr
, 8+NFS4_STATEID_SIZE
);
1031 *p
++ = cpu_to_be32(OP_CLOSE
);
1032 *p
++ = cpu_to_be32(arg
->seqid
->sequence
->counter
);
1033 xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1035 hdr
->replen
+= decode_close_maxsz
;
1038 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1042 p
= reserve_space(xdr
, 16);
1043 *p
++ = cpu_to_be32(OP_COMMIT
);
1044 p
= xdr_encode_hyper(p
, args
->offset
);
1045 *p
= cpu_to_be32(args
->count
);
1047 hdr
->replen
+= decode_commit_maxsz
;
1050 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
1054 p
= reserve_space(xdr
, 8);
1055 *p
++ = cpu_to_be32(OP_CREATE
);
1056 *p
= cpu_to_be32(create
->ftype
);
1058 switch (create
->ftype
) {
1060 p
= reserve_space(xdr
, 4);
1061 *p
= cpu_to_be32(create
->u
.symlink
.len
);
1062 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
1065 case NF4BLK
: case NF4CHR
:
1066 p
= reserve_space(xdr
, 8);
1067 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
1068 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
1075 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
1077 hdr
->replen
+= decode_create_maxsz
;
1079 encode_attrs(xdr
, create
->attrs
, create
->server
);
1082 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
1086 p
= reserve_space(xdr
, 12);
1087 *p
++ = cpu_to_be32(OP_GETATTR
);
1088 *p
++ = cpu_to_be32(1);
1089 *p
= cpu_to_be32(bitmap
);
1091 hdr
->replen
+= decode_getattr_maxsz
;
1094 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
1098 p
= reserve_space(xdr
, 16);
1099 *p
++ = cpu_to_be32(OP_GETATTR
);
1100 *p
++ = cpu_to_be32(2);
1101 *p
++ = cpu_to_be32(bm0
);
1102 *p
= cpu_to_be32(bm1
);
1104 hdr
->replen
+= decode_getattr_maxsz
;
1107 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1109 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
1110 bitmask
[1] & nfs4_fattr_bitmap
[1], hdr
);
1113 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1115 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
1116 bitmask
[1] & nfs4_fsinfo_bitmap
[1], hdr
);
1119 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1121 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
1122 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
1125 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1129 p
= reserve_space(xdr
, 4);
1130 *p
= cpu_to_be32(OP_GETFH
);
1132 hdr
->replen
+= decode_getfh_maxsz
;
1135 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1139 p
= reserve_space(xdr
, 8 + name
->len
);
1140 *p
++ = cpu_to_be32(OP_LINK
);
1141 xdr_encode_opaque(p
, name
->name
, name
->len
);
1143 hdr
->replen
+= decode_link_maxsz
;
1146 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1148 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
1149 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1150 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1153 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1155 if (fl
->fl_end
== OFFSET_MAX
)
1156 return ~(uint64_t)0;
1157 return fl
->fl_end
- fl
->fl_start
+ 1;
1160 static void encode_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
)
1164 p
= reserve_space(xdr
, 32);
1165 p
= xdr_encode_hyper(p
, lowner
->clientid
);
1166 *p
++ = cpu_to_be32(20);
1167 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1168 *p
++ = cpu_to_be32(lowner
->s_dev
);
1169 xdr_encode_hyper(p
, lowner
->id
);
1173 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1174 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1176 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1180 p
= reserve_space(xdr
, 32);
1181 *p
++ = cpu_to_be32(OP_LOCK
);
1182 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1183 *p
++ = cpu_to_be32(args
->reclaim
);
1184 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1185 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1186 *p
= cpu_to_be32(args
->new_lock_owner
);
1187 if (args
->new_lock_owner
){
1188 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1189 *p
++ = cpu_to_be32(args
->open_seqid
->sequence
->counter
);
1190 p
= xdr_encode_opaque_fixed(p
, args
->open_stateid
->data
, NFS4_STATEID_SIZE
);
1191 *p
++ = cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1192 encode_lockowner(xdr
, &args
->lock_owner
);
1195 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
+4);
1196 p
= xdr_encode_opaque_fixed(p
, args
->lock_stateid
->data
, NFS4_STATEID_SIZE
);
1197 *p
= cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1200 hdr
->replen
+= decode_lock_maxsz
;
1203 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1207 p
= reserve_space(xdr
, 24);
1208 *p
++ = cpu_to_be32(OP_LOCKT
);
1209 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1210 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1211 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1212 encode_lockowner(xdr
, &args
->lock_owner
);
1214 hdr
->replen
+= decode_lockt_maxsz
;
1217 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1221 p
= reserve_space(xdr
, 12+NFS4_STATEID_SIZE
+16);
1222 *p
++ = cpu_to_be32(OP_LOCKU
);
1223 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1224 *p
++ = cpu_to_be32(args
->seqid
->sequence
->counter
);
1225 p
= xdr_encode_opaque_fixed(p
, args
->stateid
->data
, NFS4_STATEID_SIZE
);
1226 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1227 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1229 hdr
->replen
+= decode_locku_maxsz
;
1232 static void encode_release_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
, struct compound_hdr
*hdr
)
1236 p
= reserve_space(xdr
, 4);
1237 *p
= cpu_to_be32(OP_RELEASE_LOCKOWNER
);
1238 encode_lockowner(xdr
, lowner
);
1240 hdr
->replen
+= decode_release_lockowner_maxsz
;
1243 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1245 int len
= name
->len
;
1248 p
= reserve_space(xdr
, 8 + len
);
1249 *p
++ = cpu_to_be32(OP_LOOKUP
);
1250 xdr_encode_opaque(p
, name
->name
, len
);
1252 hdr
->replen
+= decode_lookup_maxsz
;
1255 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
1259 p
= reserve_space(xdr
, 8);
1260 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1262 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ
);
1265 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE
);
1267 case FMODE_READ
|FMODE_WRITE
:
1268 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH
);
1271 *p
++ = cpu_to_be32(0);
1273 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1276 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1280 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1283 p
= reserve_space(xdr
, 8);
1284 *p
++ = cpu_to_be32(OP_OPEN
);
1285 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1286 encode_share_access(xdr
, arg
->fmode
);
1287 p
= reserve_space(xdr
, 32);
1288 p
= xdr_encode_hyper(p
, arg
->clientid
);
1289 *p
++ = cpu_to_be32(20);
1290 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1291 *p
++ = cpu_to_be32(arg
->server
->s_dev
);
1292 xdr_encode_hyper(p
, arg
->id
);
1295 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1298 struct nfs_client
*clp
;
1300 p
= reserve_space(xdr
, 4);
1301 switch(arg
->open_flags
& O_EXCL
) {
1303 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1304 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1307 clp
= arg
->server
->nfs_client
;
1308 if (clp
->cl_mvops
->minor_version
> 0) {
1309 if (nfs4_has_persistent_session(clp
)) {
1310 *p
= cpu_to_be32(NFS4_CREATE_GUARDED
);
1311 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1315 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1316 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1318 encode_attrs(xdr
, &dummy
, arg
->server
);
1321 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1322 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1327 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1331 p
= reserve_space(xdr
, 4);
1332 switch (arg
->open_flags
& O_CREAT
) {
1334 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1337 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
1338 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1339 encode_createmode(xdr
, arg
);
1343 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1347 p
= reserve_space(xdr
, 4);
1348 switch (delegation_type
) {
1350 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1353 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1355 case FMODE_WRITE
|FMODE_READ
:
1356 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1363 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1367 p
= reserve_space(xdr
, 4);
1368 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1369 encode_string(xdr
, name
->len
, name
->name
);
1372 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1376 p
= reserve_space(xdr
, 4);
1377 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1378 encode_delegation_type(xdr
, type
);
1381 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1385 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1386 *p
++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1387 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1388 encode_string(xdr
, name
->len
, name
->name
);
1391 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1393 encode_openhdr(xdr
, arg
);
1394 encode_opentype(xdr
, arg
);
1395 switch (arg
->claim
) {
1396 case NFS4_OPEN_CLAIM_NULL
:
1397 encode_claim_null(xdr
, arg
->name
);
1399 case NFS4_OPEN_CLAIM_PREVIOUS
:
1400 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1402 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1403 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1409 hdr
->replen
+= decode_open_maxsz
;
1412 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1416 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1417 *p
++ = cpu_to_be32(OP_OPEN_CONFIRM
);
1418 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1419 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1421 hdr
->replen
+= decode_open_confirm_maxsz
;
1424 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1428 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1429 *p
++ = cpu_to_be32(OP_OPEN_DOWNGRADE
);
1430 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1431 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1432 encode_share_access(xdr
, arg
->fmode
);
1434 hdr
->replen
+= decode_open_downgrade_maxsz
;
1438 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1443 p
= reserve_space(xdr
, 8 + len
);
1444 *p
++ = cpu_to_be32(OP_PUTFH
);
1445 xdr_encode_opaque(p
, fh
->data
, len
);
1447 hdr
->replen
+= decode_putfh_maxsz
;
1450 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1454 p
= reserve_space(xdr
, 4);
1455 *p
= cpu_to_be32(OP_PUTROOTFH
);
1457 hdr
->replen
+= decode_putrootfh_maxsz
;
1460 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
, const struct nfs_lock_context
*l_ctx
, int zero_seqid
)
1462 nfs4_stateid stateid
;
1465 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
);
1466 if (ctx
->state
!= NULL
) {
1467 nfs4_copy_stateid(&stateid
, ctx
->state
, l_ctx
->lockowner
, l_ctx
->pid
);
1469 stateid
.stateid
.seqid
= 0;
1470 xdr_encode_opaque_fixed(p
, stateid
.data
, NFS4_STATEID_SIZE
);
1472 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1475 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
, struct compound_hdr
*hdr
)
1479 p
= reserve_space(xdr
, 4);
1480 *p
= cpu_to_be32(OP_READ
);
1482 encode_stateid(xdr
, args
->context
, args
->lock_context
,
1485 p
= reserve_space(xdr
, 12);
1486 p
= xdr_encode_hyper(p
, args
->offset
);
1487 *p
= cpu_to_be32(args
->count
);
1489 hdr
->replen
+= decode_read_maxsz
;
1492 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1494 uint32_t attrs
[2] = {
1495 FATTR4_WORD0_RDATTR_ERROR
,
1496 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1498 uint32_t dircount
= readdir
->count
>> 1;
1501 if (readdir
->plus
) {
1502 attrs
[0] |= FATTR4_WORD0_TYPE
|FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
|
1503 FATTR4_WORD0_FSID
|FATTR4_WORD0_FILEHANDLE
|FATTR4_WORD0_FILEID
;
1504 attrs
[1] |= FATTR4_WORD1_MODE
|FATTR4_WORD1_NUMLINKS
|FATTR4_WORD1_OWNER
|
1505 FATTR4_WORD1_OWNER_GROUP
|FATTR4_WORD1_RAWDEV
|
1506 FATTR4_WORD1_SPACE_USED
|FATTR4_WORD1_TIME_ACCESS
|
1507 FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
1510 /* Use mounted_on_fileid only if the server supports it */
1511 if (!(readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
))
1512 attrs
[0] |= FATTR4_WORD0_FILEID
;
1514 p
= reserve_space(xdr
, 12+NFS4_VERIFIER_SIZE
+20);
1515 *p
++ = cpu_to_be32(OP_READDIR
);
1516 p
= xdr_encode_hyper(p
, readdir
->cookie
);
1517 p
= xdr_encode_opaque_fixed(p
, readdir
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1518 *p
++ = cpu_to_be32(dircount
);
1519 *p
++ = cpu_to_be32(readdir
->count
);
1520 *p
++ = cpu_to_be32(2);
1522 *p
++ = cpu_to_be32(attrs
[0] & readdir
->bitmask
[0]);
1523 *p
= cpu_to_be32(attrs
[1] & readdir
->bitmask
[1]);
1525 hdr
->replen
+= decode_readdir_maxsz
;
1526 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1528 (unsigned long long)readdir
->cookie
,
1529 ((u32
*)readdir
->verifier
.data
)[0],
1530 ((u32
*)readdir
->verifier
.data
)[1],
1531 attrs
[0] & readdir
->bitmask
[0],
1532 attrs
[1] & readdir
->bitmask
[1]);
1535 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1539 p
= reserve_space(xdr
, 4);
1540 *p
= cpu_to_be32(OP_READLINK
);
1542 hdr
->replen
+= decode_readlink_maxsz
;
1545 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1549 p
= reserve_space(xdr
, 8 + name
->len
);
1550 *p
++ = cpu_to_be32(OP_REMOVE
);
1551 xdr_encode_opaque(p
, name
->name
, name
->len
);
1553 hdr
->replen
+= decode_remove_maxsz
;
1556 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1560 p
= reserve_space(xdr
, 4);
1561 *p
= cpu_to_be32(OP_RENAME
);
1562 encode_string(xdr
, oldname
->len
, oldname
->name
);
1563 encode_string(xdr
, newname
->len
, newname
->name
);
1565 hdr
->replen
+= decode_rename_maxsz
;
1568 static void encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
, struct compound_hdr
*hdr
)
1572 p
= reserve_space(xdr
, 12);
1573 *p
++ = cpu_to_be32(OP_RENEW
);
1574 xdr_encode_hyper(p
, client_stateid
->cl_clientid
);
1576 hdr
->replen
+= decode_renew_maxsz
;
1580 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1584 p
= reserve_space(xdr
, 4);
1585 *p
= cpu_to_be32(OP_RESTOREFH
);
1587 hdr
->replen
+= decode_restorefh_maxsz
;
1591 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1595 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1596 *p
++ = cpu_to_be32(OP_SETATTR
);
1597 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1598 p
= reserve_space(xdr
, 2*4);
1599 *p
++ = cpu_to_be32(1);
1600 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1601 BUG_ON(arg
->acl_len
% 4);
1602 p
= reserve_space(xdr
, 4);
1603 *p
= cpu_to_be32(arg
->acl_len
);
1604 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1606 hdr
->replen
+= decode_setacl_maxsz
;
1610 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1614 p
= reserve_space(xdr
, 4);
1615 *p
= cpu_to_be32(OP_SAVEFH
);
1617 hdr
->replen
+= decode_savefh_maxsz
;
1620 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1624 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1625 *p
++ = cpu_to_be32(OP_SETATTR
);
1626 xdr_encode_opaque_fixed(p
, arg
->stateid
.data
, NFS4_STATEID_SIZE
);
1628 hdr
->replen
+= decode_setattr_maxsz
;
1629 encode_attrs(xdr
, arg
->iap
, server
);
1632 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1636 p
= reserve_space(xdr
, 4 + NFS4_VERIFIER_SIZE
);
1637 *p
++ = cpu_to_be32(OP_SETCLIENTID
);
1638 xdr_encode_opaque_fixed(p
, setclientid
->sc_verifier
->data
, NFS4_VERIFIER_SIZE
);
1640 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1641 p
= reserve_space(xdr
, 4);
1642 *p
= cpu_to_be32(setclientid
->sc_prog
);
1643 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1644 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1645 p
= reserve_space(xdr
, 4);
1646 *p
= cpu_to_be32(setclientid
->sc_cb_ident
);
1648 hdr
->replen
+= decode_setclientid_maxsz
;
1651 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_setclientid_res
*arg
, struct compound_hdr
*hdr
)
1655 p
= reserve_space(xdr
, 12 + NFS4_VERIFIER_SIZE
);
1656 *p
++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM
);
1657 p
= xdr_encode_hyper(p
, arg
->clientid
);
1658 xdr_encode_opaque_fixed(p
, arg
->confirm
.data
, NFS4_VERIFIER_SIZE
);
1660 hdr
->replen
+= decode_setclientid_confirm_maxsz
;
1663 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1667 p
= reserve_space(xdr
, 4);
1668 *p
= cpu_to_be32(OP_WRITE
);
1670 encode_stateid(xdr
, args
->context
, args
->lock_context
,
1673 p
= reserve_space(xdr
, 16);
1674 p
= xdr_encode_hyper(p
, args
->offset
);
1675 *p
++ = cpu_to_be32(args
->stable
);
1676 *p
= cpu_to_be32(args
->count
);
1678 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1680 hdr
->replen
+= decode_write_maxsz
;
1683 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1687 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1689 *p
++ = cpu_to_be32(OP_DELEGRETURN
);
1690 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1692 hdr
->replen
+= decode_delegreturn_maxsz
;
1695 static void encode_secinfo(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1697 int len
= name
->len
;
1700 p
= reserve_space(xdr
, 8 + len
);
1701 *p
++ = cpu_to_be32(OP_SECINFO
);
1702 xdr_encode_opaque(p
, name
->name
, len
);
1704 hdr
->replen
+= decode_secinfo_maxsz
;
1707 #if defined(CONFIG_NFS_V4_1)
1708 /* NFSv4.1 operations */
1709 static void encode_exchange_id(struct xdr_stream
*xdr
,
1710 struct nfs41_exchange_id_args
*args
,
1711 struct compound_hdr
*hdr
)
1715 p
= reserve_space(xdr
, 4 + sizeof(args
->verifier
->data
));
1716 *p
++ = cpu_to_be32(OP_EXCHANGE_ID
);
1717 xdr_encode_opaque_fixed(p
, args
->verifier
->data
, sizeof(args
->verifier
->data
));
1719 encode_string(xdr
, args
->id_len
, args
->id
);
1721 p
= reserve_space(xdr
, 12);
1722 *p
++ = cpu_to_be32(args
->flags
);
1723 *p
++ = cpu_to_be32(0); /* zero length state_protect4_a */
1724 *p
= cpu_to_be32(0); /* zero length implementation id array */
1726 hdr
->replen
+= decode_exchange_id_maxsz
;
1729 static void encode_create_session(struct xdr_stream
*xdr
,
1730 struct nfs41_create_session_args
*args
,
1731 struct compound_hdr
*hdr
)
1734 char machine_name
[NFS4_MAX_MACHINE_NAME_LEN
];
1736 struct nfs_client
*clp
= args
->client
;
1737 u32 max_resp_sz_cached
;
1740 * Assumes OPEN is the biggest non-idempotent compound.
1741 * 2 is the verifier.
1743 max_resp_sz_cached
= (NFS4_dec_open_sz
+ RPC_REPHDRSIZE
+
1744 RPC_MAX_AUTH_SIZE
+ 2) * XDR_UNIT
;
1746 len
= scnprintf(machine_name
, sizeof(machine_name
), "%s",
1749 p
= reserve_space(xdr
, 20 + 2*28 + 20 + len
+ 12);
1750 *p
++ = cpu_to_be32(OP_CREATE_SESSION
);
1751 p
= xdr_encode_hyper(p
, clp
->cl_clientid
);
1752 *p
++ = cpu_to_be32(clp
->cl_seqid
); /*Sequence id */
1753 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1756 *p
++ = cpu_to_be32(0); /* header padding size */
1757 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1758 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1759 *p
++ = cpu_to_be32(max_resp_sz_cached
); /* Max resp sz cached */
1760 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1761 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1762 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1765 *p
++ = cpu_to_be32(0); /* header padding size */
1766 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1767 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1768 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1769 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1770 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1771 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1773 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1774 *p
++ = cpu_to_be32(1);
1775 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1777 /* authsys_parms rfc1831 */
1778 *p
++ = cpu_to_be32((u32
)clp
->cl_boot_time
.tv_nsec
); /* stamp */
1779 p
= xdr_encode_opaque(p
, machine_name
, len
);
1780 *p
++ = cpu_to_be32(0); /* UID */
1781 *p
++ = cpu_to_be32(0); /* GID */
1782 *p
= cpu_to_be32(0); /* No more gids */
1784 hdr
->replen
+= decode_create_session_maxsz
;
1787 static void encode_destroy_session(struct xdr_stream
*xdr
,
1788 struct nfs4_session
*session
,
1789 struct compound_hdr
*hdr
)
1792 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
);
1793 *p
++ = cpu_to_be32(OP_DESTROY_SESSION
);
1794 xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1796 hdr
->replen
+= decode_destroy_session_maxsz
;
1799 static void encode_reclaim_complete(struct xdr_stream
*xdr
,
1800 struct nfs41_reclaim_complete_args
*args
,
1801 struct compound_hdr
*hdr
)
1805 p
= reserve_space(xdr
, 8);
1806 *p
++ = cpu_to_be32(OP_RECLAIM_COMPLETE
);
1807 *p
++ = cpu_to_be32(args
->one_fs
);
1809 hdr
->replen
+= decode_reclaim_complete_maxsz
;
1811 #endif /* CONFIG_NFS_V4_1 */
1813 static void encode_sequence(struct xdr_stream
*xdr
,
1814 const struct nfs4_sequence_args
*args
,
1815 struct compound_hdr
*hdr
)
1817 #if defined(CONFIG_NFS_V4_1)
1818 struct nfs4_session
*session
= args
->sa_session
;
1819 struct nfs4_slot_table
*tp
;
1820 struct nfs4_slot
*slot
;
1826 tp
= &session
->fc_slot_table
;
1828 WARN_ON(args
->sa_slotid
== NFS4_MAX_SLOT_TABLE
);
1829 slot
= tp
->slots
+ args
->sa_slotid
;
1831 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
+ 16);
1832 *p
++ = cpu_to_be32(OP_SEQUENCE
);
1835 * Sessionid + seqid + slotid + max slotid + cache_this
1837 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1838 "max_slotid=%d cache_this=%d\n",
1840 ((u32
*)session
->sess_id
.data
)[0],
1841 ((u32
*)session
->sess_id
.data
)[1],
1842 ((u32
*)session
->sess_id
.data
)[2],
1843 ((u32
*)session
->sess_id
.data
)[3],
1844 slot
->seq_nr
, args
->sa_slotid
,
1845 tp
->highest_used_slotid
, args
->sa_cache_this
);
1846 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1847 *p
++ = cpu_to_be32(slot
->seq_nr
);
1848 *p
++ = cpu_to_be32(args
->sa_slotid
);
1849 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1850 *p
= cpu_to_be32(args
->sa_cache_this
);
1852 hdr
->replen
+= decode_sequence_maxsz
;
1853 #endif /* CONFIG_NFS_V4_1 */
1856 #ifdef CONFIG_NFS_V4_1
1858 encode_getdeviceinfo(struct xdr_stream
*xdr
,
1859 const struct nfs4_getdeviceinfo_args
*args
,
1860 struct compound_hdr
*hdr
)
1864 p
= reserve_space(xdr
, 16 + NFS4_DEVICEID4_SIZE
);
1865 *p
++ = cpu_to_be32(OP_GETDEVICEINFO
);
1866 p
= xdr_encode_opaque_fixed(p
, args
->pdev
->dev_id
.data
,
1867 NFS4_DEVICEID4_SIZE
);
1868 *p
++ = cpu_to_be32(args
->pdev
->layout_type
);
1869 *p
++ = cpu_to_be32(args
->pdev
->pglen
); /* gdia_maxcount */
1870 *p
++ = cpu_to_be32(0); /* bitmap length 0 */
1872 hdr
->replen
+= decode_getdeviceinfo_maxsz
;
1876 encode_layoutget(struct xdr_stream
*xdr
,
1877 const struct nfs4_layoutget_args
*args
,
1878 struct compound_hdr
*hdr
)
1882 p
= reserve_space(xdr
, 44 + NFS4_STATEID_SIZE
);
1883 *p
++ = cpu_to_be32(OP_LAYOUTGET
);
1884 *p
++ = cpu_to_be32(0); /* Signal layout available */
1885 *p
++ = cpu_to_be32(args
->type
);
1886 *p
++ = cpu_to_be32(args
->range
.iomode
);
1887 p
= xdr_encode_hyper(p
, args
->range
.offset
);
1888 p
= xdr_encode_hyper(p
, args
->range
.length
);
1889 p
= xdr_encode_hyper(p
, args
->minlength
);
1890 p
= xdr_encode_opaque_fixed(p
, &args
->stateid
.data
, NFS4_STATEID_SIZE
);
1891 *p
= cpu_to_be32(args
->maxcount
);
1893 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1897 (unsigned long)args
->range
.offset
,
1898 (unsigned long)args
->range
.length
,
1901 hdr
->replen
+= decode_layoutget_maxsz
;
1905 encode_layoutcommit(struct xdr_stream
*xdr
,
1906 struct inode
*inode
,
1907 const struct nfs4_layoutcommit_args
*args
,
1908 struct compound_hdr
*hdr
)
1912 dprintk("%s: lbw: %llu type: %d\n", __func__
, args
->lastbytewritten
,
1913 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);
1915 p
= reserve_space(xdr
, 44 + NFS4_STATEID_SIZE
);
1916 *p
++ = cpu_to_be32(OP_LAYOUTCOMMIT
);
1917 /* Only whole file layouts */
1918 p
= xdr_encode_hyper(p
, 0); /* offset */
1919 p
= xdr_encode_hyper(p
, NFS4_MAX_UINT64
); /* length */
1920 *p
++ = cpu_to_be32(0); /* reclaim */
1921 p
= xdr_encode_opaque_fixed(p
, args
->stateid
.data
, NFS4_STATEID_SIZE
);
1922 *p
++ = cpu_to_be32(1); /* newoffset = TRUE */
1923 p
= xdr_encode_hyper(p
, args
->lastbytewritten
);
1924 *p
++ = cpu_to_be32(0); /* Never send time_modify_changed */
1925 *p
++ = cpu_to_be32(NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);/* type */
1927 if (NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit
)
1928 NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit(
1929 NFS_I(inode
)->layout
, xdr
, args
);
1931 p
= reserve_space(xdr
, 4);
1932 *p
= cpu_to_be32(0); /* no layout-type payload */
1936 hdr
->replen
+= decode_layoutcommit_maxsz
;
1941 encode_layoutreturn(struct xdr_stream
*xdr
,
1942 const struct nfs4_layoutreturn_args
*args
,
1943 struct compound_hdr
*hdr
)
1947 p
= reserve_space(xdr
, 20);
1948 *p
++ = cpu_to_be32(OP_LAYOUTRETURN
);
1949 *p
++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1950 *p
++ = cpu_to_be32(args
->layout_type
);
1951 *p
++ = cpu_to_be32(IOMODE_ANY
);
1952 *p
= cpu_to_be32(RETURN_FILE
);
1953 p
= reserve_space(xdr
, 16 + NFS4_STATEID_SIZE
);
1954 p
= xdr_encode_hyper(p
, 0);
1955 p
= xdr_encode_hyper(p
, NFS4_MAX_UINT64
);
1956 spin_lock(&args
->inode
->i_lock
);
1957 xdr_encode_opaque_fixed(p
, &args
->stateid
.data
, NFS4_STATEID_SIZE
);
1958 spin_unlock(&args
->inode
->i_lock
);
1959 if (NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn
) {
1960 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn(
1961 NFS_I(args
->inode
)->layout
, xdr
, args
);
1963 p
= reserve_space(xdr
, 4);
1964 *p
= cpu_to_be32(0);
1967 hdr
->replen
+= decode_layoutreturn_maxsz
;
1971 encode_secinfo_no_name(struct xdr_stream
*xdr
,
1972 const struct nfs41_secinfo_no_name_args
*args
,
1973 struct compound_hdr
*hdr
)
1976 p
= reserve_space(xdr
, 8);
1977 *p
++ = cpu_to_be32(OP_SECINFO_NO_NAME
);
1978 *p
++ = cpu_to_be32(args
->style
);
1980 hdr
->replen
+= decode_secinfo_no_name_maxsz
;
1984 static void encode_test_stateid(struct xdr_stream
*xdr
,
1985 struct nfs41_test_stateid_args
*args
,
1986 struct compound_hdr
*hdr
)
1990 p
= reserve_space(xdr
, 8 + NFS4_STATEID_SIZE
);
1991 *p
++ = cpu_to_be32(OP_TEST_STATEID
);
1992 *p
++ = cpu_to_be32(1);
1993 xdr_encode_opaque_fixed(p
, args
->stateid
->data
, NFS4_STATEID_SIZE
);
1995 hdr
->replen
+= decode_test_stateid_maxsz
;
1998 static void encode_free_stateid(struct xdr_stream
*xdr
,
1999 struct nfs41_free_stateid_args
*args
,
2000 struct compound_hdr
*hdr
)
2003 p
= reserve_space(xdr
, 4 + NFS4_STATEID_SIZE
);
2004 *p
++ = cpu_to_be32(OP_FREE_STATEID
);
2005 xdr_encode_opaque_fixed(p
, args
->stateid
->data
, NFS4_STATEID_SIZE
);
2007 hdr
->replen
+= decode_free_stateid_maxsz
;
2009 #endif /* CONFIG_NFS_V4_1 */
2012 * END OF "GENERIC" ENCODE ROUTINES.
2015 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
2017 #if defined(CONFIG_NFS_V4_1)
2018 if (args
->sa_session
)
2019 return args
->sa_session
->clp
->cl_mvops
->minor_version
;
2020 #endif /* CONFIG_NFS_V4_1 */
2025 * Encode an ACCESS request
2027 static void nfs4_xdr_enc_access(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2028 const struct nfs4_accessargs
*args
)
2030 struct compound_hdr hdr
= {
2031 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2034 encode_compound_hdr(xdr
, req
, &hdr
);
2035 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2036 encode_putfh(xdr
, args
->fh
, &hdr
);
2037 encode_access(xdr
, args
->access
, &hdr
);
2038 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2043 * Encode LOOKUP request
2045 static void nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2046 const struct nfs4_lookup_arg
*args
)
2048 struct compound_hdr hdr
= {
2049 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2052 encode_compound_hdr(xdr
, req
, &hdr
);
2053 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2054 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2055 encode_lookup(xdr
, args
->name
, &hdr
);
2056 encode_getfh(xdr
, &hdr
);
2057 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2062 * Encode LOOKUP_ROOT request
2064 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
,
2065 struct xdr_stream
*xdr
,
2066 const struct nfs4_lookup_root_arg
*args
)
2068 struct compound_hdr hdr
= {
2069 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2072 encode_compound_hdr(xdr
, req
, &hdr
);
2073 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2074 encode_putrootfh(xdr
, &hdr
);
2075 encode_getfh(xdr
, &hdr
);
2076 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2081 * Encode REMOVE request
2083 static void nfs4_xdr_enc_remove(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2084 const struct nfs_removeargs
*args
)
2086 struct compound_hdr hdr
= {
2087 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2090 encode_compound_hdr(xdr
, req
, &hdr
);
2091 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2092 encode_putfh(xdr
, args
->fh
, &hdr
);
2093 encode_remove(xdr
, &args
->name
, &hdr
);
2094 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2099 * Encode RENAME request
2101 static void nfs4_xdr_enc_rename(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2102 const struct nfs_renameargs
*args
)
2104 struct compound_hdr hdr
= {
2105 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2108 encode_compound_hdr(xdr
, req
, &hdr
);
2109 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2110 encode_putfh(xdr
, args
->old_dir
, &hdr
);
2111 encode_savefh(xdr
, &hdr
);
2112 encode_putfh(xdr
, args
->new_dir
, &hdr
);
2113 encode_rename(xdr
, args
->old_name
, args
->new_name
, &hdr
);
2114 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2115 encode_restorefh(xdr
, &hdr
);
2116 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2121 * Encode LINK request
2123 static void nfs4_xdr_enc_link(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2124 const struct nfs4_link_arg
*args
)
2126 struct compound_hdr hdr
= {
2127 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2130 encode_compound_hdr(xdr
, req
, &hdr
);
2131 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2132 encode_putfh(xdr
, args
->fh
, &hdr
);
2133 encode_savefh(xdr
, &hdr
);
2134 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2135 encode_link(xdr
, args
->name
, &hdr
);
2136 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2137 encode_restorefh(xdr
, &hdr
);
2138 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2143 * Encode CREATE request
2145 static void nfs4_xdr_enc_create(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2146 const struct nfs4_create_arg
*args
)
2148 struct compound_hdr hdr
= {
2149 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2152 encode_compound_hdr(xdr
, req
, &hdr
);
2153 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2154 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2155 encode_savefh(xdr
, &hdr
);
2156 encode_create(xdr
, args
, &hdr
);
2157 encode_getfh(xdr
, &hdr
);
2158 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2159 encode_restorefh(xdr
, &hdr
);
2160 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2165 * Encode SYMLINK request
2167 static void nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2168 const struct nfs4_create_arg
*args
)
2170 nfs4_xdr_enc_create(req
, xdr
, args
);
2174 * Encode GETATTR request
2176 static void nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2177 const struct nfs4_getattr_arg
*args
)
2179 struct compound_hdr hdr
= {
2180 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2183 encode_compound_hdr(xdr
, req
, &hdr
);
2184 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2185 encode_putfh(xdr
, args
->fh
, &hdr
);
2186 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2191 * Encode a CLOSE request
2193 static void nfs4_xdr_enc_close(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2194 struct nfs_closeargs
*args
)
2196 struct compound_hdr hdr
= {
2197 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2200 encode_compound_hdr(xdr
, req
, &hdr
);
2201 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2202 encode_putfh(xdr
, args
->fh
, &hdr
);
2203 encode_close(xdr
, args
, &hdr
);
2204 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2209 * Encode an OPEN request
2211 static void nfs4_xdr_enc_open(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2212 struct nfs_openargs
*args
)
2214 struct compound_hdr hdr
= {
2215 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2218 encode_compound_hdr(xdr
, req
, &hdr
);
2219 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2220 encode_putfh(xdr
, args
->fh
, &hdr
);
2221 encode_savefh(xdr
, &hdr
);
2222 encode_open(xdr
, args
, &hdr
);
2223 encode_getfh(xdr
, &hdr
);
2224 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2225 encode_restorefh(xdr
, &hdr
);
2226 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2231 * Encode an OPEN_CONFIRM request
2233 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
,
2234 struct xdr_stream
*xdr
,
2235 struct nfs_open_confirmargs
*args
)
2237 struct compound_hdr hdr
= {
2241 encode_compound_hdr(xdr
, req
, &hdr
);
2242 encode_putfh(xdr
, args
->fh
, &hdr
);
2243 encode_open_confirm(xdr
, args
, &hdr
);
2248 * Encode an OPEN request with no attributes.
2250 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
,
2251 struct xdr_stream
*xdr
,
2252 struct nfs_openargs
*args
)
2254 struct compound_hdr hdr
= {
2255 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2258 encode_compound_hdr(xdr
, req
, &hdr
);
2259 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2260 encode_putfh(xdr
, args
->fh
, &hdr
);
2261 encode_open(xdr
, args
, &hdr
);
2262 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2267 * Encode an OPEN_DOWNGRADE request
2269 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
,
2270 struct xdr_stream
*xdr
,
2271 struct nfs_closeargs
*args
)
2273 struct compound_hdr hdr
= {
2274 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2277 encode_compound_hdr(xdr
, req
, &hdr
);
2278 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2279 encode_putfh(xdr
, args
->fh
, &hdr
);
2280 encode_open_downgrade(xdr
, args
, &hdr
);
2281 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2286 * Encode a LOCK request
2288 static void nfs4_xdr_enc_lock(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2289 struct nfs_lock_args
*args
)
2291 struct compound_hdr hdr
= {
2292 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2295 encode_compound_hdr(xdr
, req
, &hdr
);
2296 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2297 encode_putfh(xdr
, args
->fh
, &hdr
);
2298 encode_lock(xdr
, args
, &hdr
);
2303 * Encode a LOCKT request
2305 static void nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2306 struct nfs_lockt_args
*args
)
2308 struct compound_hdr hdr
= {
2309 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2312 encode_compound_hdr(xdr
, req
, &hdr
);
2313 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2314 encode_putfh(xdr
, args
->fh
, &hdr
);
2315 encode_lockt(xdr
, args
, &hdr
);
2320 * Encode a LOCKU request
2322 static void nfs4_xdr_enc_locku(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2323 struct nfs_locku_args
*args
)
2325 struct compound_hdr hdr
= {
2326 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2329 encode_compound_hdr(xdr
, req
, &hdr
);
2330 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2331 encode_putfh(xdr
, args
->fh
, &hdr
);
2332 encode_locku(xdr
, args
, &hdr
);
2336 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst
*req
,
2337 struct xdr_stream
*xdr
,
2338 struct nfs_release_lockowner_args
*args
)
2340 struct compound_hdr hdr
= {
2344 encode_compound_hdr(xdr
, req
, &hdr
);
2345 encode_release_lockowner(xdr
, &args
->lock_owner
, &hdr
);
2350 * Encode a READLINK request
2352 static void nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2353 const struct nfs4_readlink
*args
)
2355 struct compound_hdr hdr
= {
2356 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2359 encode_compound_hdr(xdr
, req
, &hdr
);
2360 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2361 encode_putfh(xdr
, args
->fh
, &hdr
);
2362 encode_readlink(xdr
, args
, req
, &hdr
);
2364 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2365 args
->pgbase
, args
->pglen
);
2370 * Encode a READDIR request
2372 static void nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2373 const struct nfs4_readdir_arg
*args
)
2375 struct compound_hdr hdr
= {
2376 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2379 encode_compound_hdr(xdr
, req
, &hdr
);
2380 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2381 encode_putfh(xdr
, args
->fh
, &hdr
);
2382 encode_readdir(xdr
, args
, req
, &hdr
);
2384 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2385 args
->pgbase
, args
->count
);
2386 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2387 __func__
, hdr
.replen
<< 2, args
->pages
,
2388 args
->pgbase
, args
->count
);
2393 * Encode a READ request
2395 static void nfs4_xdr_enc_read(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2396 struct nfs_readargs
*args
)
2398 struct compound_hdr hdr
= {
2399 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2402 encode_compound_hdr(xdr
, req
, &hdr
);
2403 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2404 encode_putfh(xdr
, args
->fh
, &hdr
);
2405 encode_read(xdr
, args
, &hdr
);
2407 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2408 args
->pages
, args
->pgbase
, args
->count
);
2409 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2414 * Encode an SETATTR request
2416 static void nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2417 struct nfs_setattrargs
*args
)
2419 struct compound_hdr hdr
= {
2420 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2423 encode_compound_hdr(xdr
, req
, &hdr
);
2424 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2425 encode_putfh(xdr
, args
->fh
, &hdr
);
2426 encode_setattr(xdr
, args
, args
->server
, &hdr
);
2427 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2432 * Encode a GETACL request
2434 static void nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2435 struct nfs_getaclargs
*args
)
2437 struct compound_hdr hdr
= {
2438 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2442 encode_compound_hdr(xdr
, req
, &hdr
);
2443 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2444 encode_putfh(xdr
, args
->fh
, &hdr
);
2445 replen
= hdr
.replen
+ op_decode_hdr_maxsz
+ nfs4_fattr_bitmap_maxsz
+ 1;
2446 encode_getattr_two(xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2448 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2449 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
2454 * Encode a WRITE request
2456 static void nfs4_xdr_enc_write(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2457 struct nfs_writeargs
*args
)
2459 struct compound_hdr hdr
= {
2460 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2463 encode_compound_hdr(xdr
, req
, &hdr
);
2464 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2465 encode_putfh(xdr
, args
->fh
, &hdr
);
2466 encode_write(xdr
, args
, &hdr
);
2467 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2469 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2476 static void nfs4_xdr_enc_commit(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2477 struct nfs_writeargs
*args
)
2479 struct compound_hdr hdr
= {
2480 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2483 encode_compound_hdr(xdr
, req
, &hdr
);
2484 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2485 encode_putfh(xdr
, args
->fh
, &hdr
);
2486 encode_commit(xdr
, args
, &hdr
);
2488 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2495 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2496 struct nfs4_fsinfo_arg
*args
)
2498 struct compound_hdr hdr
= {
2499 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2502 encode_compound_hdr(xdr
, req
, &hdr
);
2503 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2504 encode_putfh(xdr
, args
->fh
, &hdr
);
2505 encode_fsinfo(xdr
, args
->bitmask
, &hdr
);
2510 * a PATHCONF request
2512 static void nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2513 const struct nfs4_pathconf_arg
*args
)
2515 struct compound_hdr hdr
= {
2516 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2519 encode_compound_hdr(xdr
, req
, &hdr
);
2520 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2521 encode_putfh(xdr
, args
->fh
, &hdr
);
2522 encode_getattr_one(xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2530 static void nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2531 const struct nfs4_statfs_arg
*args
)
2533 struct compound_hdr hdr
= {
2534 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2537 encode_compound_hdr(xdr
, req
, &hdr
);
2538 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2539 encode_putfh(xdr
, args
->fh
, &hdr
);
2540 encode_getattr_two(xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2541 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2546 * GETATTR_BITMAP request
2548 static void nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
,
2549 struct xdr_stream
*xdr
,
2550 struct nfs4_server_caps_arg
*args
)
2552 struct compound_hdr hdr
= {
2553 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2556 encode_compound_hdr(xdr
, req
, &hdr
);
2557 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2558 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2559 encode_getattr_one(xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2560 FATTR4_WORD0_LINK_SUPPORT
|
2561 FATTR4_WORD0_SYMLINK_SUPPORT
|
2562 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2569 static void nfs4_xdr_enc_renew(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2570 struct nfs_client
*clp
)
2572 struct compound_hdr hdr
= {
2576 encode_compound_hdr(xdr
, req
, &hdr
);
2577 encode_renew(xdr
, clp
, &hdr
);
2582 * a SETCLIENTID request
2584 static void nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
,
2585 struct xdr_stream
*xdr
,
2586 struct nfs4_setclientid
*sc
)
2588 struct compound_hdr hdr
= {
2592 encode_compound_hdr(xdr
, req
, &hdr
);
2593 encode_setclientid(xdr
, sc
, &hdr
);
2598 * a SETCLIENTID_CONFIRM request
2600 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
,
2601 struct xdr_stream
*xdr
,
2602 struct nfs4_setclientid_res
*arg
)
2604 struct compound_hdr hdr
= {
2607 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2609 encode_compound_hdr(xdr
, req
, &hdr
);
2610 encode_setclientid_confirm(xdr
, arg
, &hdr
);
2611 encode_putrootfh(xdr
, &hdr
);
2612 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2617 * DELEGRETURN request
2619 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
,
2620 struct xdr_stream
*xdr
,
2621 const struct nfs4_delegreturnargs
*args
)
2623 struct compound_hdr hdr
= {
2624 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2627 encode_compound_hdr(xdr
, req
, &hdr
);
2628 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2629 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2630 encode_delegreturn(xdr
, args
->stateid
, &hdr
);
2631 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2636 * Encode FS_LOCATIONS request
2638 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
,
2639 struct xdr_stream
*xdr
,
2640 struct nfs4_fs_locations_arg
*args
)
2642 struct compound_hdr hdr
= {
2643 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2647 encode_compound_hdr(xdr
, req
, &hdr
);
2648 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2649 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2650 encode_lookup(xdr
, args
->name
, &hdr
);
2651 replen
= hdr
.replen
; /* get the attribute into args->page */
2652 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2654 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2660 * Encode SECINFO request
2662 static void nfs4_xdr_enc_secinfo(struct rpc_rqst
*req
,
2663 struct xdr_stream
*xdr
,
2664 struct nfs4_secinfo_arg
*args
)
2666 struct compound_hdr hdr
= {
2667 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2670 encode_compound_hdr(xdr
, req
, &hdr
);
2671 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2672 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2673 encode_secinfo(xdr
, args
->name
, &hdr
);
2677 #if defined(CONFIG_NFS_V4_1)
2679 * EXCHANGE_ID request
2681 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
,
2682 struct xdr_stream
*xdr
,
2683 struct nfs41_exchange_id_args
*args
)
2685 struct compound_hdr hdr
= {
2686 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2689 encode_compound_hdr(xdr
, req
, &hdr
);
2690 encode_exchange_id(xdr
, args
, &hdr
);
2695 * a CREATE_SESSION request
2697 static void nfs4_xdr_enc_create_session(struct rpc_rqst
*req
,
2698 struct xdr_stream
*xdr
,
2699 struct nfs41_create_session_args
*args
)
2701 struct compound_hdr hdr
= {
2702 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2705 encode_compound_hdr(xdr
, req
, &hdr
);
2706 encode_create_session(xdr
, args
, &hdr
);
2711 * a DESTROY_SESSION request
2713 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
,
2714 struct xdr_stream
*xdr
,
2715 struct nfs4_session
*session
)
2717 struct compound_hdr hdr
= {
2718 .minorversion
= session
->clp
->cl_mvops
->minor_version
,
2721 encode_compound_hdr(xdr
, req
, &hdr
);
2722 encode_destroy_session(xdr
, session
, &hdr
);
2727 * a SEQUENCE request
2729 static void nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2730 struct nfs4_sequence_args
*args
)
2732 struct compound_hdr hdr
= {
2733 .minorversion
= nfs4_xdr_minorversion(args
),
2736 encode_compound_hdr(xdr
, req
, &hdr
);
2737 encode_sequence(xdr
, args
, &hdr
);
2742 * a GET_LEASE_TIME request
2744 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
,
2745 struct xdr_stream
*xdr
,
2746 struct nfs4_get_lease_time_args
*args
)
2748 struct compound_hdr hdr
= {
2749 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2751 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2753 encode_compound_hdr(xdr
, req
, &hdr
);
2754 encode_sequence(xdr
, &args
->la_seq_args
, &hdr
);
2755 encode_putrootfh(xdr
, &hdr
);
2756 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2761 * a RECLAIM_COMPLETE request
2763 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
,
2764 struct xdr_stream
*xdr
,
2765 struct nfs41_reclaim_complete_args
*args
)
2767 struct compound_hdr hdr
= {
2768 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2771 encode_compound_hdr(xdr
, req
, &hdr
);
2772 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2773 encode_reclaim_complete(xdr
, args
, &hdr
);
2778 * Encode GETDEVICEINFO request
2780 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst
*req
,
2781 struct xdr_stream
*xdr
,
2782 struct nfs4_getdeviceinfo_args
*args
)
2784 struct compound_hdr hdr
= {
2785 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2788 encode_compound_hdr(xdr
, req
, &hdr
);
2789 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2790 encode_getdeviceinfo(xdr
, args
, &hdr
);
2792 /* set up reply kvec. Subtract notification bitmap max size (2)
2793 * so that notification bitmap is put in xdr_buf tail */
2794 xdr_inline_pages(&req
->rq_rcv_buf
, (hdr
.replen
- 2) << 2,
2795 args
->pdev
->pages
, args
->pdev
->pgbase
,
2802 * Encode LAYOUTGET request
2804 static void nfs4_xdr_enc_layoutget(struct rpc_rqst
*req
,
2805 struct xdr_stream
*xdr
,
2806 struct nfs4_layoutget_args
*args
)
2808 struct compound_hdr hdr
= {
2809 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2812 encode_compound_hdr(xdr
, req
, &hdr
);
2813 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2814 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2815 encode_layoutget(xdr
, args
, &hdr
);
2817 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2818 args
->layout
.pages
, 0, args
->layout
.pglen
);
2824 * Encode LAYOUTCOMMIT request
2826 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst
*req
,
2827 struct xdr_stream
*xdr
,
2828 struct nfs4_layoutcommit_args
*args
)
2830 struct nfs4_layoutcommit_data
*data
=
2831 container_of(args
, struct nfs4_layoutcommit_data
, args
);
2832 struct compound_hdr hdr
= {
2833 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2836 encode_compound_hdr(xdr
, req
, &hdr
);
2837 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2838 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2839 encode_layoutcommit(xdr
, data
->args
.inode
, args
, &hdr
);
2840 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2845 * Encode LAYOUTRETURN request
2847 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst
*req
,
2848 struct xdr_stream
*xdr
,
2849 struct nfs4_layoutreturn_args
*args
)
2851 struct compound_hdr hdr
= {
2852 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2855 encode_compound_hdr(xdr
, req
, &hdr
);
2856 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2857 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2858 encode_layoutreturn(xdr
, args
, &hdr
);
2863 * Encode SECINFO_NO_NAME request
2865 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst
*req
,
2866 struct xdr_stream
*xdr
,
2867 struct nfs41_secinfo_no_name_args
*args
)
2869 struct compound_hdr hdr
= {
2870 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2873 encode_compound_hdr(xdr
, req
, &hdr
);
2874 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2875 encode_putrootfh(xdr
, &hdr
);
2876 encode_secinfo_no_name(xdr
, args
, &hdr
);
2882 * Encode TEST_STATEID request
2884 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst
*req
,
2885 struct xdr_stream
*xdr
,
2886 struct nfs41_test_stateid_args
*args
)
2888 struct compound_hdr hdr
= {
2889 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2892 encode_compound_hdr(xdr
, req
, &hdr
);
2893 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2894 encode_test_stateid(xdr
, args
, &hdr
);
2899 * Encode FREE_STATEID request
2901 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst
*req
,
2902 struct xdr_stream
*xdr
,
2903 struct nfs41_free_stateid_args
*args
)
2905 struct compound_hdr hdr
= {
2906 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2909 encode_compound_hdr(xdr
, req
, &hdr
);
2910 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2911 encode_free_stateid(xdr
, args
, &hdr
);
2914 #endif /* CONFIG_NFS_V4_1 */
2916 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
2918 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2919 "Remaining buffer length is %tu words.\n",
2920 func
, xdr
->end
- xdr
->p
);
2923 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2927 p
= xdr_inline_decode(xdr
, 4);
2930 *len
= be32_to_cpup(p
);
2931 p
= xdr_inline_decode(xdr
, *len
);
2934 *string
= (char *)p
;
2937 print_overflow_msg(__func__
, xdr
);
2941 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2945 p
= xdr_inline_decode(xdr
, 8);
2948 hdr
->status
= be32_to_cpup(p
++);
2949 hdr
->taglen
= be32_to_cpup(p
);
2951 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
2954 hdr
->tag
= (char *)p
;
2955 p
+= XDR_QUADLEN(hdr
->taglen
);
2956 hdr
->nops
= be32_to_cpup(p
);
2957 if (unlikely(hdr
->nops
< 1))
2958 return nfs4_stat_to_errno(hdr
->status
);
2961 print_overflow_msg(__func__
, xdr
);
2965 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2971 p
= xdr_inline_decode(xdr
, 8);
2974 opnum
= be32_to_cpup(p
++);
2975 if (opnum
!= expected
) {
2976 dprintk("nfs: Server returned operation"
2977 " %d but we issued a request for %d\n",
2981 nfserr
= be32_to_cpup(p
);
2982 if (nfserr
!= NFS_OK
)
2983 return nfs4_stat_to_errno(nfserr
);
2986 print_overflow_msg(__func__
, xdr
);
2991 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2994 unsigned int strlen
;
2997 p
= xdr_inline_decode(xdr
, 12);
2999 return decode_opaque_inline(xdr
, &strlen
, &str
);
3000 print_overflow_msg(__func__
, xdr
);
3004 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
3009 p
= xdr_inline_decode(xdr
, 4);
3012 bmlen
= be32_to_cpup(p
);
3014 bitmap
[0] = bitmap
[1] = 0;
3015 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
3019 bitmap
[0] = be32_to_cpup(p
++);
3021 bitmap
[1] = be32_to_cpup(p
);
3025 print_overflow_msg(__func__
, xdr
);
3029 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
3033 p
= xdr_inline_decode(xdr
, 4);
3036 *attrlen
= be32_to_cpup(p
);
3040 print_overflow_msg(__func__
, xdr
);
3044 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
3046 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
3048 ret
= decode_attr_bitmap(xdr
, bitmask
);
3049 if (unlikely(ret
< 0))
3051 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
3053 bitmask
[0] = bitmask
[1] = 0;
3054 dprintk("%s: bitmask=%08x:%08x\n", __func__
, bitmask
[0], bitmask
[1]);
3058 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
3064 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
3066 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
3067 p
= xdr_inline_decode(xdr
, 4);
3070 *type
= be32_to_cpup(p
);
3071 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
3072 dprintk("%s: bad type %d\n", __func__
, *type
);
3075 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
3076 ret
= NFS_ATTR_FATTR_TYPE
;
3078 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
3081 print_overflow_msg(__func__
, xdr
);
3085 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
3091 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
3093 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
3094 p
= xdr_inline_decode(xdr
, 8);
3097 xdr_decode_hyper(p
, change
);
3098 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
3099 ret
= NFS_ATTR_FATTR_CHANGE
;
3101 dprintk("%s: change attribute=%Lu\n", __func__
,
3102 (unsigned long long)*change
);
3105 print_overflow_msg(__func__
, xdr
);
3109 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
3115 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
3117 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
3118 p
= xdr_inline_decode(xdr
, 8);
3121 xdr_decode_hyper(p
, size
);
3122 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
3123 ret
= NFS_ATTR_FATTR_SIZE
;
3125 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
3128 print_overflow_msg(__func__
, xdr
);
3132 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3137 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
3139 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
3140 p
= xdr_inline_decode(xdr
, 4);
3143 *res
= be32_to_cpup(p
);
3144 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
3146 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3149 print_overflow_msg(__func__
, xdr
);
3153 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3158 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
3160 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
3161 p
= xdr_inline_decode(xdr
, 4);
3164 *res
= be32_to_cpup(p
);
3165 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
3167 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3170 print_overflow_msg(__func__
, xdr
);
3174 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
3181 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
3183 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
3184 p
= xdr_inline_decode(xdr
, 16);
3187 p
= xdr_decode_hyper(p
, &fsid
->major
);
3188 xdr_decode_hyper(p
, &fsid
->minor
);
3189 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
3190 ret
= NFS_ATTR_FATTR_FSID
;
3192 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
3193 (unsigned long long)fsid
->major
,
3194 (unsigned long long)fsid
->minor
);
3197 print_overflow_msg(__func__
, xdr
);
3201 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3206 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
3208 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
3209 p
= xdr_inline_decode(xdr
, 4);
3212 *res
= be32_to_cpup(p
);
3213 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
3215 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
3218 print_overflow_msg(__func__
, xdr
);
3222 static int decode_attr_error(struct xdr_stream
*xdr
, uint32_t *bitmap
, int32_t *res
)
3226 if (unlikely(bitmap
[0] & (FATTR4_WORD0_RDATTR_ERROR
- 1U)))
3228 if (likely(bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
)) {
3229 p
= xdr_inline_decode(xdr
, 4);
3232 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
3233 *res
= -be32_to_cpup(p
);
3237 print_overflow_msg(__func__
, xdr
);
3241 static int decode_attr_filehandle(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fh
*fh
)
3247 memset(fh
, 0, sizeof(*fh
));
3249 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEHANDLE
- 1U)))
3251 if (likely(bitmap
[0] & FATTR4_WORD0_FILEHANDLE
)) {
3252 p
= xdr_inline_decode(xdr
, 4);
3255 len
= be32_to_cpup(p
);
3256 if (len
> NFS4_FHSIZE
)
3258 p
= xdr_inline_decode(xdr
, len
);
3262 memcpy(fh
->data
, p
, len
);
3265 bitmap
[0] &= ~FATTR4_WORD0_FILEHANDLE
;
3269 print_overflow_msg(__func__
, xdr
);
3273 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3277 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
3278 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
3280 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
3281 p
= xdr_inline_decode(xdr
, 4);
3284 *res
= be32_to_cpup(p
);
3285 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
3287 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
3290 print_overflow_msg(__func__
, xdr
);
3294 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3300 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
3302 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
3303 p
= xdr_inline_decode(xdr
, 8);
3306 xdr_decode_hyper(p
, fileid
);
3307 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
3308 ret
= NFS_ATTR_FATTR_FILEID
;
3310 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3313 print_overflow_msg(__func__
, xdr
);
3317 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3323 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
3325 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
3326 p
= xdr_inline_decode(xdr
, 8);
3329 xdr_decode_hyper(p
, fileid
);
3330 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
3331 ret
= NFS_ATTR_FATTR_MOUNTED_ON_FILEID
;
3333 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3336 print_overflow_msg(__func__
, xdr
);
3340 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3346 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
3348 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
3349 p
= xdr_inline_decode(xdr
, 8);
3352 xdr_decode_hyper(p
, res
);
3353 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
3355 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
3358 print_overflow_msg(__func__
, xdr
);
3362 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3368 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
3370 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
3371 p
= xdr_inline_decode(xdr
, 8);
3374 xdr_decode_hyper(p
, res
);
3375 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
3377 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
3380 print_overflow_msg(__func__
, xdr
);
3384 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3390 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
3392 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
3393 p
= xdr_inline_decode(xdr
, 8);
3396 xdr_decode_hyper(p
, res
);
3397 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
3399 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
3402 print_overflow_msg(__func__
, xdr
);
3406 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
3412 p
= xdr_inline_decode(xdr
, 4);
3415 n
= be32_to_cpup(p
);
3419 path
->ncomponents
= 0;
3420 while (path
->ncomponents
< n
) {
3421 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
3422 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
3423 if (unlikely(status
!= 0))
3425 if (path
->ncomponents
!= n
)
3427 dprintk("%s", component
->data
);
3428 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
3429 path
->ncomponents
++;
3431 dprintk("cannot parse %d components in path\n", n
);
3439 /* a root pathname is sent as a zero component4 */
3440 path
->ncomponents
= 1;
3441 path
->components
[0].len
=0;
3442 path
->components
[0].data
=NULL
;
3443 dprintk("path /\n");
3446 dprintk(" status %d", status
);
3450 print_overflow_msg(__func__
, xdr
);
3454 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
3460 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
3463 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
3465 dprintk("%s: fsroot ", __func__
);
3466 status
= decode_pathname(xdr
, &res
->fs_path
);
3467 if (unlikely(status
!= 0))
3469 p
= xdr_inline_decode(xdr
, 4);
3472 n
= be32_to_cpup(p
);
3475 res
->nlocations
= 0;
3476 while (res
->nlocations
< n
) {
3478 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
3480 p
= xdr_inline_decode(xdr
, 4);
3483 m
= be32_to_cpup(p
);
3486 dprintk("%s: servers ", __func__
);
3487 while (loc
->nservers
< m
) {
3488 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
3489 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3490 if (unlikely(status
!= 0))
3492 dprintk("%s ", server
->data
);
3493 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
3497 dprintk("%s: using first %u of %u servers "
3498 "returned for location %u\n",
3500 NFS4_FS_LOCATION_MAXSERVERS
,
3501 m
, res
->nlocations
);
3502 for (i
= loc
->nservers
; i
< m
; i
++) {
3505 status
= decode_opaque_inline(xdr
, &len
, &data
);
3506 if (unlikely(status
!= 0))
3511 status
= decode_pathname(xdr
, &loc
->rootpath
);
3512 if (unlikely(status
!= 0))
3514 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
3517 if (res
->nlocations
!= 0)
3518 status
= NFS_ATTR_FATTR_V4_REFERRAL
;
3520 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3523 print_overflow_msg(__func__
, xdr
);
3529 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3535 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3537 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3538 p
= xdr_inline_decode(xdr
, 8);
3541 xdr_decode_hyper(p
, res
);
3542 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3544 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3547 print_overflow_msg(__func__
, xdr
);
3551 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3557 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3559 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3560 p
= xdr_inline_decode(xdr
, 4);
3563 *maxlink
= be32_to_cpup(p
);
3564 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3566 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3569 print_overflow_msg(__func__
, xdr
);
3573 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3579 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3581 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3582 p
= xdr_inline_decode(xdr
, 4);
3585 *maxname
= be32_to_cpup(p
);
3586 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3588 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3591 print_overflow_msg(__func__
, xdr
);
3595 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3601 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3603 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3605 p
= xdr_inline_decode(xdr
, 8);
3608 xdr_decode_hyper(p
, &maxread
);
3609 if (maxread
> 0x7FFFFFFF)
3610 maxread
= 0x7FFFFFFF;
3611 *res
= (uint32_t)maxread
;
3612 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3614 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3617 print_overflow_msg(__func__
, xdr
);
3621 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3627 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3629 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3631 p
= xdr_inline_decode(xdr
, 8);
3634 xdr_decode_hyper(p
, &maxwrite
);
3635 if (maxwrite
> 0x7FFFFFFF)
3636 maxwrite
= 0x7FFFFFFF;
3637 *res
= (uint32_t)maxwrite
;
3638 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3640 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3643 print_overflow_msg(__func__
, xdr
);
3647 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3654 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3656 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3657 p
= xdr_inline_decode(xdr
, 4);
3660 tmp
= be32_to_cpup(p
);
3661 *mode
= tmp
& ~S_IFMT
;
3662 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3663 ret
= NFS_ATTR_FATTR_MODE
;
3665 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3668 print_overflow_msg(__func__
, xdr
);
3672 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3678 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3680 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3681 p
= xdr_inline_decode(xdr
, 4);
3684 *nlink
= be32_to_cpup(p
);
3685 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3686 ret
= NFS_ATTR_FATTR_NLINK
;
3688 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3691 print_overflow_msg(__func__
, xdr
);
3695 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3696 const struct nfs_server
*server
, uint32_t *uid
, int may_sleep
)
3703 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3705 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3706 p
= xdr_inline_decode(xdr
, 4);
3709 len
= be32_to_cpup(p
);
3710 p
= xdr_inline_decode(xdr
, len
);
3715 } else if (len
< XDR_MAX_NETOBJ
) {
3716 if (nfs_map_name_to_uid(server
, (char *)p
, len
, uid
) == 0)
3717 ret
= NFS_ATTR_FATTR_OWNER
;
3719 dprintk("%s: nfs_map_name_to_uid failed!\n",
3722 dprintk("%s: name too long (%u)!\n",
3724 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3726 dprintk("%s: uid=%d\n", __func__
, (int)*uid
);
3729 print_overflow_msg(__func__
, xdr
);
3733 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3734 const struct nfs_server
*server
, uint32_t *gid
, int may_sleep
)
3741 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3743 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3744 p
= xdr_inline_decode(xdr
, 4);
3747 len
= be32_to_cpup(p
);
3748 p
= xdr_inline_decode(xdr
, len
);
3753 } else if (len
< XDR_MAX_NETOBJ
) {
3754 if (nfs_map_group_to_gid(server
, (char *)p
, len
, gid
) == 0)
3755 ret
= NFS_ATTR_FATTR_GROUP
;
3757 dprintk("%s: nfs_map_group_to_gid failed!\n",
3760 dprintk("%s: name too long (%u)!\n",
3762 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3764 dprintk("%s: gid=%d\n", __func__
, (int)*gid
);
3767 print_overflow_msg(__func__
, xdr
);
3771 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3773 uint32_t major
= 0, minor
= 0;
3778 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3780 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3783 p
= xdr_inline_decode(xdr
, 8);
3786 major
= be32_to_cpup(p
++);
3787 minor
= be32_to_cpup(p
);
3788 tmp
= MKDEV(major
, minor
);
3789 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3791 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3792 ret
= NFS_ATTR_FATTR_RDEV
;
3794 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3797 print_overflow_msg(__func__
, xdr
);
3801 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3807 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3809 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3810 p
= xdr_inline_decode(xdr
, 8);
3813 xdr_decode_hyper(p
, res
);
3814 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3816 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3819 print_overflow_msg(__func__
, xdr
);
3823 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3829 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3831 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3832 p
= xdr_inline_decode(xdr
, 8);
3835 xdr_decode_hyper(p
, res
);
3836 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3838 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3841 print_overflow_msg(__func__
, xdr
);
3845 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3851 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
3853 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
3854 p
= xdr_inline_decode(xdr
, 8);
3857 xdr_decode_hyper(p
, res
);
3858 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
3860 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
3863 print_overflow_msg(__func__
, xdr
);
3867 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
3873 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
3875 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
3876 p
= xdr_inline_decode(xdr
, 8);
3879 xdr_decode_hyper(p
, used
);
3880 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
3881 ret
= NFS_ATTR_FATTR_SPACE_USED
;
3883 dprintk("%s: space used=%Lu\n", __func__
,
3884 (unsigned long long)*used
);
3887 print_overflow_msg(__func__
, xdr
);
3891 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
3897 p
= xdr_inline_decode(xdr
, 12);
3900 p
= xdr_decode_hyper(p
, &sec
);
3901 nsec
= be32_to_cpup(p
);
3902 time
->tv_sec
= (time_t)sec
;
3903 time
->tv_nsec
= (long)nsec
;
3906 print_overflow_msg(__func__
, xdr
);
3910 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3916 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
3918 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
3919 status
= decode_attr_time(xdr
, time
);
3921 status
= NFS_ATTR_FATTR_ATIME
;
3922 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
3924 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
3928 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3934 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
3936 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
3937 status
= decode_attr_time(xdr
, time
);
3939 status
= NFS_ATTR_FATTR_CTIME
;
3940 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
3942 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
3946 static int decode_attr_time_delta(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3947 struct timespec
*time
)
3953 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_DELTA
- 1U)))
3955 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_DELTA
)) {
3956 status
= decode_attr_time(xdr
, time
);
3957 bitmap
[1] &= ~FATTR4_WORD1_TIME_DELTA
;
3959 dprintk("%s: time_delta=%ld %ld\n", __func__
, (long)time
->tv_sec
,
3960 (long)time
->tv_nsec
);
3964 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3970 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
3972 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
3973 status
= decode_attr_time(xdr
, time
);
3975 status
= NFS_ATTR_FATTR_MTIME
;
3976 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
3978 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
3982 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
3984 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
3985 unsigned int nwords
= xdr
->p
- savep
;
3987 if (unlikely(attrwords
!= nwords
)) {
3988 dprintk("%s: server returned incorrect attribute length: "
3992 (attrwords
< nwords
) ? '<' : '>',
3999 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4003 p
= xdr_inline_decode(xdr
, 20);
4006 cinfo
->atomic
= be32_to_cpup(p
++);
4007 p
= xdr_decode_hyper(p
, &cinfo
->before
);
4008 xdr_decode_hyper(p
, &cinfo
->after
);
4011 print_overflow_msg(__func__
, xdr
);
4015 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
4021 status
= decode_op_hdr(xdr
, OP_ACCESS
);
4024 p
= xdr_inline_decode(xdr
, 8);
4027 supp
= be32_to_cpup(p
++);
4028 acc
= be32_to_cpup(p
);
4029 access
->supported
= supp
;
4030 access
->access
= acc
;
4033 print_overflow_msg(__func__
, xdr
);
4037 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
4041 p
= xdr_inline_decode(xdr
, len
);
4043 memcpy(buf
, p
, len
);
4046 print_overflow_msg(__func__
, xdr
);
4050 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
4052 return decode_opaque_fixed(xdr
, stateid
->data
, NFS4_STATEID_SIZE
);
4055 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4059 status
= decode_op_hdr(xdr
, OP_CLOSE
);
4061 nfs_increment_open_seqid(status
, res
->seqid
);
4063 status
= decode_stateid(xdr
, &res
->stateid
);
4067 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
4069 return decode_opaque_fixed(xdr
, verifier
, 8);
4072 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
4076 status
= decode_op_hdr(xdr
, OP_COMMIT
);
4078 status
= decode_verifier(xdr
, res
->verf
->verifier
);
4082 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4088 status
= decode_op_hdr(xdr
, OP_CREATE
);
4091 if ((status
= decode_change_info(xdr
, cinfo
)))
4093 p
= xdr_inline_decode(xdr
, 4);
4096 bmlen
= be32_to_cpup(p
);
4097 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4101 print_overflow_msg(__func__
, xdr
);
4105 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
4108 uint32_t attrlen
, bitmap
[2] = {0};
4111 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4113 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4115 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4117 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
4119 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
4121 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
4123 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
4125 status
= verify_attr_len(xdr
, savep
, attrlen
);
4127 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4131 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
4134 uint32_t attrlen
, bitmap
[2] = {0};
4137 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4139 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4141 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4144 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
4146 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
4148 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
4150 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
4152 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
4154 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
4157 status
= verify_attr_len(xdr
, savep
, attrlen
);
4159 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4163 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
4166 uint32_t attrlen
, bitmap
[2] = {0};
4169 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4171 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4173 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4176 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
4178 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
4181 status
= verify_attr_len(xdr
, savep
, attrlen
);
4183 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4187 static int decode_getfattr_attrs(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4188 struct nfs_fattr
*fattr
, struct nfs_fh
*fh
,
4189 const struct nfs_server
*server
, int may_sleep
)
4196 status
= decode_attr_type(xdr
, bitmap
, &type
);
4201 fattr
->mode
|= nfs_type2fmt
[type
];
4202 fattr
->valid
|= status
;
4205 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
4208 fattr
->valid
|= status
;
4210 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
4213 fattr
->valid
|= status
;
4215 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
4218 fattr
->valid
|= status
;
4221 status
= decode_attr_error(xdr
, bitmap
, &err
);
4224 if (err
== -NFS4ERR_WRONGSEC
)
4225 nfs_fixup_secinfo_attributes(fattr
, fh
);
4227 status
= decode_attr_filehandle(xdr
, bitmap
, fh
);
4231 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
4234 fattr
->valid
|= status
;
4236 status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
4237 struct nfs4_fs_locations
,
4241 fattr
->valid
|= status
;
4243 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
4247 fattr
->mode
|= fmode
;
4248 fattr
->valid
|= status
;
4251 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
4254 fattr
->valid
|= status
;
4256 status
= decode_attr_owner(xdr
, bitmap
, server
, &fattr
->uid
, may_sleep
);
4259 fattr
->valid
|= status
;
4261 status
= decode_attr_group(xdr
, bitmap
, server
, &fattr
->gid
, may_sleep
);
4264 fattr
->valid
|= status
;
4266 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
4269 fattr
->valid
|= status
;
4271 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
4274 fattr
->valid
|= status
;
4276 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
4279 fattr
->valid
|= status
;
4281 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
4284 fattr
->valid
|= status
;
4286 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
4289 fattr
->valid
|= status
;
4291 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fattr
->mounted_on_fileid
);
4294 fattr
->valid
|= status
;
4297 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4301 static int decode_getfattr_generic(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4302 struct nfs_fh
*fh
, const struct nfs_server
*server
, int may_sleep
)
4309 status
= decode_op_hdr(xdr
, OP_GETATTR
);
4313 status
= decode_attr_bitmap(xdr
, bitmap
);
4317 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4321 status
= decode_getfattr_attrs(xdr
, bitmap
, fattr
, fh
, server
, may_sleep
);
4325 status
= verify_attr_len(xdr
, savep
, attrlen
);
4327 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4331 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4332 const struct nfs_server
*server
, int may_sleep
)
4334 return decode_getfattr_generic(xdr
, fattr
, NULL
, server
, may_sleep
);
4338 * Decode potentially multiple layout types. Currently we only support
4339 * one layout driver per file system.
4341 static int decode_first_pnfs_layout_type(struct xdr_stream
*xdr
,
4342 uint32_t *layouttype
)
4347 p
= xdr_inline_decode(xdr
, 4);
4350 num
= be32_to_cpup(p
);
4352 /* pNFS is not supported by the underlying file system */
4358 printk(KERN_INFO
"%s: Warning: Multiple pNFS layout drivers "
4359 "per filesystem not supported\n", __func__
);
4361 /* Decode and set first layout type, move xdr->p past unused types */
4362 p
= xdr_inline_decode(xdr
, num
* 4);
4365 *layouttype
= be32_to_cpup(p
);
4368 print_overflow_msg(__func__
, xdr
);
4373 * The type of file system exported.
4374 * Note we must ensure that layouttype is set in any non-error case.
4376 static int decode_attr_pnfstype(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4377 uint32_t *layouttype
)
4381 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[1]);
4382 if (unlikely(bitmap
[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES
- 1U)))
4384 if (bitmap
[1] & FATTR4_WORD1_FS_LAYOUT_TYPES
) {
4385 status
= decode_first_pnfs_layout_type(xdr
, layouttype
);
4386 bitmap
[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES
;
4392 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
4395 uint32_t attrlen
, bitmap
[2];
4398 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4400 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4402 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4405 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
4407 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
4409 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
4411 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
4413 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
4414 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
4416 fsinfo
->wtpref
= fsinfo
->wtmax
;
4417 status
= decode_attr_time_delta(xdr
, bitmap
, &fsinfo
->time_delta
);
4420 status
= decode_attr_pnfstype(xdr
, bitmap
, &fsinfo
->layouttype
);
4424 status
= verify_attr_len(xdr
, savep
, attrlen
);
4426 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4430 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
4436 /* Zero handle first to allow comparisons */
4437 memset(fh
, 0, sizeof(*fh
));
4439 status
= decode_op_hdr(xdr
, OP_GETFH
);
4443 p
= xdr_inline_decode(xdr
, 4);
4446 len
= be32_to_cpup(p
);
4447 if (len
> NFS4_FHSIZE
)
4450 p
= xdr_inline_decode(xdr
, len
);
4453 memcpy(fh
->data
, p
, len
);
4456 print_overflow_msg(__func__
, xdr
);
4460 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4464 status
= decode_op_hdr(xdr
, OP_LINK
);
4467 return decode_change_info(xdr
, cinfo
);
4471 * We create the owner, so we know a proper owner.id length is 4.
4473 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
4475 uint64_t offset
, length
, clientid
;
4477 uint32_t namelen
, type
;
4479 p
= xdr_inline_decode(xdr
, 32); /* read 32 bytes */
4482 p
= xdr_decode_hyper(p
, &offset
); /* read 2 8-byte long words */
4483 p
= xdr_decode_hyper(p
, &length
);
4484 type
= be32_to_cpup(p
++); /* 4 byte read */
4485 if (fl
!= NULL
) { /* manipulate file lock */
4486 fl
->fl_start
= (loff_t
)offset
;
4487 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
4488 if (length
== ~(uint64_t)0)
4489 fl
->fl_end
= OFFSET_MAX
;
4490 fl
->fl_type
= F_WRLCK
;
4492 fl
->fl_type
= F_RDLCK
;
4495 p
= xdr_decode_hyper(p
, &clientid
); /* read 8 bytes */
4496 namelen
= be32_to_cpup(p
); /* read 4 bytes */ /* have read all 32 bytes now */
4497 p
= xdr_inline_decode(xdr
, namelen
); /* variable size field */
4499 return -NFS4ERR_DENIED
;
4501 print_overflow_msg(__func__
, xdr
);
4505 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
4509 status
= decode_op_hdr(xdr
, OP_LOCK
);
4513 status
= decode_stateid(xdr
, &res
->stateid
);
4514 if (unlikely(status
))
4516 } else if (status
== -NFS4ERR_DENIED
)
4517 status
= decode_lock_denied(xdr
, NULL
);
4518 if (res
->open_seqid
!= NULL
)
4519 nfs_increment_open_seqid(status
, res
->open_seqid
);
4520 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
4525 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
4528 status
= decode_op_hdr(xdr
, OP_LOCKT
);
4529 if (status
== -NFS4ERR_DENIED
)
4530 return decode_lock_denied(xdr
, res
->denied
);
4534 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
4538 status
= decode_op_hdr(xdr
, OP_LOCKU
);
4540 nfs_increment_lock_seqid(status
, res
->seqid
);
4542 status
= decode_stateid(xdr
, &res
->stateid
);
4546 static int decode_release_lockowner(struct xdr_stream
*xdr
)
4548 return decode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
);
4551 static int decode_lookup(struct xdr_stream
*xdr
)
4553 return decode_op_hdr(xdr
, OP_LOOKUP
);
4556 /* This is too sick! */
4557 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
4560 uint32_t limit_type
, nblocks
, blocksize
;
4562 p
= xdr_inline_decode(xdr
, 12);
4565 limit_type
= be32_to_cpup(p
++);
4566 switch (limit_type
) {
4568 xdr_decode_hyper(p
, maxsize
);
4571 nblocks
= be32_to_cpup(p
++);
4572 blocksize
= be32_to_cpup(p
);
4573 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
4577 print_overflow_msg(__func__
, xdr
);
4581 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4584 uint32_t delegation_type
;
4587 p
= xdr_inline_decode(xdr
, 4);
4590 delegation_type
= be32_to_cpup(p
);
4591 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
4592 res
->delegation_type
= 0;
4595 status
= decode_stateid(xdr
, &res
->delegation
);
4596 if (unlikely(status
))
4598 p
= xdr_inline_decode(xdr
, 4);
4601 res
->do_recall
= be32_to_cpup(p
);
4603 switch (delegation_type
) {
4604 case NFS4_OPEN_DELEGATE_READ
:
4605 res
->delegation_type
= FMODE_READ
;
4607 case NFS4_OPEN_DELEGATE_WRITE
:
4608 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
4609 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
4612 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
4614 print_overflow_msg(__func__
, xdr
);
4618 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4621 uint32_t savewords
, bmlen
, i
;
4624 status
= decode_op_hdr(xdr
, OP_OPEN
);
4626 nfs_increment_open_seqid(status
, res
->seqid
);
4628 status
= decode_stateid(xdr
, &res
->stateid
);
4629 if (unlikely(status
))
4632 decode_change_info(xdr
, &res
->cinfo
);
4634 p
= xdr_inline_decode(xdr
, 8);
4637 res
->rflags
= be32_to_cpup(p
++);
4638 bmlen
= be32_to_cpup(p
);
4642 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4645 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
4646 for (i
= 0; i
< savewords
; ++i
)
4647 res
->attrset
[i
] = be32_to_cpup(p
++);
4648 for (; i
< NFS4_BITMAP_SIZE
; i
++)
4649 res
->attrset
[i
] = 0;
4651 return decode_delegation(xdr
, res
);
4653 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
4656 print_overflow_msg(__func__
, xdr
);
4660 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
4664 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
4666 nfs_increment_open_seqid(status
, res
->seqid
);
4668 status
= decode_stateid(xdr
, &res
->stateid
);
4672 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4676 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
4678 nfs_increment_open_seqid(status
, res
->seqid
);
4680 status
= decode_stateid(xdr
, &res
->stateid
);
4684 static int decode_putfh(struct xdr_stream
*xdr
)
4686 return decode_op_hdr(xdr
, OP_PUTFH
);
4689 static int decode_putrootfh(struct xdr_stream
*xdr
)
4691 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
4694 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
4696 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4698 uint32_t count
, eof
, recvd
, hdrlen
;
4701 status
= decode_op_hdr(xdr
, OP_READ
);
4704 p
= xdr_inline_decode(xdr
, 8);
4707 eof
= be32_to_cpup(p
++);
4708 count
= be32_to_cpup(p
);
4709 hdrlen
= (u8
*) xdr
->p
- (u8
*) iov
->iov_base
;
4710 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4711 if (count
> recvd
) {
4712 dprintk("NFS: server cheating in read reply: "
4713 "count %u > recvd %u\n", count
, recvd
);
4717 xdr_read_pages(xdr
, count
);
4722 print_overflow_msg(__func__
, xdr
);
4726 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
4728 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4729 struct kvec
*iov
= rcvbuf
->head
;
4731 u32 recvd
, pglen
= rcvbuf
->page_len
;
4734 status
= decode_op_hdr(xdr
, OP_READDIR
);
4736 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
4737 if (unlikely(status
))
4739 dprintk("%s: verifier = %08x:%08x\n",
4741 ((u32
*)readdir
->verifier
.data
)[0],
4742 ((u32
*)readdir
->verifier
.data
)[1]);
4745 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4746 recvd
= rcvbuf
->len
- hdrlen
;
4749 xdr_read_pages(xdr
, pglen
);
4755 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
4757 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4758 struct kvec
*iov
= rcvbuf
->head
;
4764 status
= decode_op_hdr(xdr
, OP_READLINK
);
4768 /* Convert length of symlink */
4769 p
= xdr_inline_decode(xdr
, 4);
4772 len
= be32_to_cpup(p
);
4773 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
4774 dprintk("nfs: server returned giant symlink!\n");
4775 return -ENAMETOOLONG
;
4777 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4778 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4780 dprintk("NFS: server cheating in readlink reply: "
4781 "count %u > recvd %u\n", len
, recvd
);
4784 xdr_read_pages(xdr
, len
);
4786 * The XDR encode routine has set things up so that
4787 * the link text will be copied directly into the
4788 * buffer. We just have to do overflow-checking,
4789 * and and null-terminate the text (the VFS expects
4790 * null-termination).
4792 xdr_terminate_string(rcvbuf
, len
);
4795 print_overflow_msg(__func__
, xdr
);
4799 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4803 status
= decode_op_hdr(xdr
, OP_REMOVE
);
4806 status
= decode_change_info(xdr
, cinfo
);
4811 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
4812 struct nfs4_change_info
*new_cinfo
)
4816 status
= decode_op_hdr(xdr
, OP_RENAME
);
4819 if ((status
= decode_change_info(xdr
, old_cinfo
)))
4821 status
= decode_change_info(xdr
, new_cinfo
);
4826 static int decode_renew(struct xdr_stream
*xdr
)
4828 return decode_op_hdr(xdr
, OP_RENEW
);
4832 decode_restorefh(struct xdr_stream
*xdr
)
4834 return decode_op_hdr(xdr
, OP_RESTOREFH
);
4837 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
4843 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4847 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4849 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4851 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4854 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
4856 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
4860 /* We ignore &savep and don't do consistency checks on
4861 * the attr length. Let userspace figure it out.... */
4862 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
4863 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4864 if (attrlen
> recvd
) {
4865 dprintk("NFS: server cheating in getattr"
4866 " acl reply: attrlen %u > recvd %u\n",
4870 xdr_read_pages(xdr
, attrlen
);
4873 status
= -EOPNOTSUPP
;
4880 decode_savefh(struct xdr_stream
*xdr
)
4882 return decode_op_hdr(xdr
, OP_SAVEFH
);
4885 static int decode_setattr(struct xdr_stream
*xdr
)
4891 status
= decode_op_hdr(xdr
, OP_SETATTR
);
4894 p
= xdr_inline_decode(xdr
, 4);
4897 bmlen
= be32_to_cpup(p
);
4898 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4902 print_overflow_msg(__func__
, xdr
);
4906 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
4912 p
= xdr_inline_decode(xdr
, 8);
4915 opnum
= be32_to_cpup(p
++);
4916 if (opnum
!= OP_SETCLIENTID
) {
4917 dprintk("nfs: decode_setclientid: Server returned operation"
4921 nfserr
= be32_to_cpup(p
);
4922 if (nfserr
== NFS_OK
) {
4923 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
4926 p
= xdr_decode_hyper(p
, &res
->clientid
);
4927 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
4928 } else if (nfserr
== NFSERR_CLID_INUSE
) {
4931 /* skip netid string */
4932 p
= xdr_inline_decode(xdr
, 4);
4935 len
= be32_to_cpup(p
);
4936 p
= xdr_inline_decode(xdr
, len
);
4940 /* skip uaddr string */
4941 p
= xdr_inline_decode(xdr
, 4);
4944 len
= be32_to_cpup(p
);
4945 p
= xdr_inline_decode(xdr
, len
);
4948 return -NFSERR_CLID_INUSE
;
4950 return nfs4_stat_to_errno(nfserr
);
4954 print_overflow_msg(__func__
, xdr
);
4958 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
4960 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
4963 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
4968 status
= decode_op_hdr(xdr
, OP_WRITE
);
4972 p
= xdr_inline_decode(xdr
, 16);
4975 res
->count
= be32_to_cpup(p
++);
4976 res
->verf
->committed
= be32_to_cpup(p
++);
4977 memcpy(res
->verf
->verifier
, p
, 8);
4980 print_overflow_msg(__func__
, xdr
);
4984 static int decode_delegreturn(struct xdr_stream
*xdr
)
4986 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
4989 static int decode_secinfo_gss(struct xdr_stream
*xdr
, struct nfs4_secinfo_flavor
*flavor
)
4993 p
= xdr_inline_decode(xdr
, 4);
4996 flavor
->gss
.sec_oid4
.len
= be32_to_cpup(p
);
4997 if (flavor
->gss
.sec_oid4
.len
> GSS_OID_MAX_LEN
)
5000 p
= xdr_inline_decode(xdr
, flavor
->gss
.sec_oid4
.len
);
5003 memcpy(flavor
->gss
.sec_oid4
.data
, p
, flavor
->gss
.sec_oid4
.len
);
5005 p
= xdr_inline_decode(xdr
, 8);
5008 flavor
->gss
.qop4
= be32_to_cpup(p
++);
5009 flavor
->gss
.service
= be32_to_cpup(p
);
5014 print_overflow_msg(__func__
, xdr
);
5020 static int decode_secinfo(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
5022 struct nfs4_secinfo_flavor
*sec_flavor
;
5027 status
= decode_op_hdr(xdr
, OP_SECINFO
);
5030 p
= xdr_inline_decode(xdr
, 4);
5034 res
->flavors
->num_flavors
= 0;
5035 num_flavors
= be32_to_cpup(p
);
5037 for (i
= 0; i
< num_flavors
; i
++) {
5038 sec_flavor
= &res
->flavors
->flavors
[i
];
5039 if ((char *)&sec_flavor
[1] - (char *)res
->flavors
> PAGE_SIZE
)
5042 p
= xdr_inline_decode(xdr
, 4);
5045 sec_flavor
->flavor
= be32_to_cpup(p
);
5047 if (sec_flavor
->flavor
== RPC_AUTH_GSS
) {
5048 status
= decode_secinfo_gss(xdr
, sec_flavor
);
5052 res
->flavors
->num_flavors
++;
5058 print_overflow_msg(__func__
, xdr
);
5062 #if defined(CONFIG_NFS_V4_1)
5063 static int decode_exchange_id(struct xdr_stream
*xdr
,
5064 struct nfs41_exchange_id_res
*res
)
5070 struct nfs_client
*clp
= res
->client
;
5072 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
5076 p
= xdr_inline_decode(xdr
, 8);
5079 xdr_decode_hyper(p
, &clp
->cl_clientid
);
5080 p
= xdr_inline_decode(xdr
, 12);
5083 clp
->cl_seqid
= be32_to_cpup(p
++);
5084 clp
->cl_exchange_flags
= be32_to_cpup(p
++);
5086 /* We ask for SP4_NONE */
5087 dummy
= be32_to_cpup(p
);
5088 if (dummy
!= SP4_NONE
)
5091 /* Throw away minor_id */
5092 p
= xdr_inline_decode(xdr
, 8);
5096 /* Throw away Major id */
5097 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5098 if (unlikely(status
))
5101 /* Save server_scope */
5102 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5103 if (unlikely(status
))
5106 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5109 memcpy(res
->server_scope
->server_scope
, dummy_str
, dummy
);
5110 res
->server_scope
->server_scope_sz
= dummy
;
5112 /* Throw away Implementation id array */
5113 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5114 if (unlikely(status
))
5119 print_overflow_msg(__func__
, xdr
);
5123 static int decode_chan_attrs(struct xdr_stream
*xdr
,
5124 struct nfs4_channel_attrs
*attrs
)
5129 p
= xdr_inline_decode(xdr
, 28);
5132 val
= be32_to_cpup(p
++); /* headerpadsz */
5134 return -EINVAL
; /* no support for header padding yet */
5135 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
5136 attrs
->max_resp_sz
= be32_to_cpup(p
++);
5137 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
5138 attrs
->max_ops
= be32_to_cpup(p
++);
5139 attrs
->max_reqs
= be32_to_cpup(p
++);
5140 nr_attrs
= be32_to_cpup(p
);
5141 if (unlikely(nr_attrs
> 1)) {
5142 printk(KERN_WARNING
"%s: Invalid rdma channel attrs count %u\n",
5143 __func__
, nr_attrs
);
5146 if (nr_attrs
== 1) {
5147 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
5153 print_overflow_msg(__func__
, xdr
);
5157 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
5159 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
5162 static int decode_create_session(struct xdr_stream
*xdr
,
5163 struct nfs41_create_session_res
*res
)
5167 struct nfs_client
*clp
= res
->client
;
5168 struct nfs4_session
*session
= clp
->cl_session
;
5170 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
5172 status
= decode_sessionid(xdr
, &session
->sess_id
);
5173 if (unlikely(status
))
5177 p
= xdr_inline_decode(xdr
, 8);
5180 clp
->cl_seqid
= be32_to_cpup(p
++);
5181 session
->flags
= be32_to_cpup(p
);
5183 /* Channel attributes */
5184 status
= decode_chan_attrs(xdr
, &session
->fc_attrs
);
5186 status
= decode_chan_attrs(xdr
, &session
->bc_attrs
);
5189 print_overflow_msg(__func__
, xdr
);
5193 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
5195 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
5198 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
5200 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
5202 #endif /* CONFIG_NFS_V4_1 */
5204 static int decode_sequence(struct xdr_stream
*xdr
,
5205 struct nfs4_sequence_res
*res
,
5206 struct rpc_rqst
*rqstp
)
5208 #if defined(CONFIG_NFS_V4_1)
5209 struct nfs4_sessionid id
;
5214 if (!res
->sr_session
)
5217 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
5219 status
= decode_sessionid(xdr
, &id
);
5220 if (unlikely(status
))
5224 * If the server returns different values for sessionID, slotID or
5225 * sequence number, the server is looney tunes.
5227 status
= -EREMOTEIO
;
5229 if (memcmp(id
.data
, res
->sr_session
->sess_id
.data
,
5230 NFS4_MAX_SESSIONID_LEN
)) {
5231 dprintk("%s Invalid session id\n", __func__
);
5235 p
= xdr_inline_decode(xdr
, 20);
5240 dummy
= be32_to_cpup(p
++);
5241 if (dummy
!= res
->sr_slot
->seq_nr
) {
5242 dprintk("%s Invalid sequence number\n", __func__
);
5246 dummy
= be32_to_cpup(p
++);
5247 if (dummy
!= res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
) {
5248 dprintk("%s Invalid slot id\n", __func__
);
5251 /* highest slot id - currently not processed */
5252 dummy
= be32_to_cpup(p
++);
5253 /* target highest slot id - currently not processed */
5254 dummy
= be32_to_cpup(p
++);
5256 res
->sr_status_flags
= be32_to_cpup(p
);
5259 res
->sr_status
= status
;
5262 print_overflow_msg(__func__
, xdr
);
5265 #else /* CONFIG_NFS_V4_1 */
5267 #endif /* CONFIG_NFS_V4_1 */
5270 #if defined(CONFIG_NFS_V4_1)
5272 static int decode_getdeviceinfo(struct xdr_stream
*xdr
,
5273 struct pnfs_device
*pdev
)
5279 status
= decode_op_hdr(xdr
, OP_GETDEVICEINFO
);
5281 if (status
== -ETOOSMALL
) {
5282 p
= xdr_inline_decode(xdr
, 4);
5285 pdev
->mincount
= be32_to_cpup(p
);
5286 dprintk("%s: Min count too small. mincnt = %u\n",
5287 __func__
, pdev
->mincount
);
5292 p
= xdr_inline_decode(xdr
, 8);
5295 type
= be32_to_cpup(p
++);
5296 if (type
!= pdev
->layout_type
) {
5297 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5298 __func__
, pdev
->layout_type
, type
);
5302 * Get the length of the opaque device_addr4. xdr_read_pages places
5303 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5304 * and places the remaining xdr data in xdr_buf->tail
5306 pdev
->mincount
= be32_to_cpup(p
);
5307 xdr_read_pages(xdr
, pdev
->mincount
); /* include space for the length */
5309 /* Parse notification bitmap, verifying that it is zero. */
5310 p
= xdr_inline_decode(xdr
, 4);
5313 len
= be32_to_cpup(p
);
5317 p
= xdr_inline_decode(xdr
, 4 * len
);
5320 for (i
= 0; i
< len
; i
++, p
++) {
5321 if (be32_to_cpup(p
)) {
5322 dprintk("%s: notifications not supported\n",
5330 print_overflow_msg(__func__
, xdr
);
5334 static int decode_layoutget(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5335 struct nfs4_layoutget_res
*res
)
5340 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
5341 struct kvec
*iov
= rcvbuf
->head
;
5344 status
= decode_op_hdr(xdr
, OP_LAYOUTGET
);
5347 p
= xdr_inline_decode(xdr
, 8 + NFS4_STATEID_SIZE
);
5350 res
->return_on_close
= be32_to_cpup(p
++);
5351 p
= xdr_decode_opaque_fixed(p
, res
->stateid
.data
, NFS4_STATEID_SIZE
);
5352 layout_count
= be32_to_cpup(p
);
5353 if (!layout_count
) {
5354 dprintk("%s: server responded with empty layout array\n",
5359 p
= xdr_inline_decode(xdr
, 28);
5362 p
= xdr_decode_hyper(p
, &res
->range
.offset
);
5363 p
= xdr_decode_hyper(p
, &res
->range
.length
);
5364 res
->range
.iomode
= be32_to_cpup(p
++);
5365 res
->type
= be32_to_cpup(p
++);
5366 res
->layoutp
->len
= be32_to_cpup(p
);
5368 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5370 (unsigned long)res
->range
.offset
,
5371 (unsigned long)res
->range
.length
,
5376 hdrlen
= (u8
*) xdr
->p
- (u8
*) iov
->iov_base
;
5377 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
5378 if (res
->layoutp
->len
> recvd
) {
5379 dprintk("NFS: server cheating in layoutget reply: "
5380 "layout len %u > recvd %u\n",
5381 res
->layoutp
->len
, recvd
);
5385 xdr_read_pages(xdr
, res
->layoutp
->len
);
5387 if (layout_count
> 1) {
5388 /* We only handle a length one array at the moment. Any
5389 * further entries are just ignored. Note that this means
5390 * the client may see a response that is less than the
5391 * minimum it requested.
5393 dprintk("%s: server responded with %d layouts, dropping tail\n",
5394 __func__
, layout_count
);
5399 print_overflow_msg(__func__
, xdr
);
5403 static int decode_layoutreturn(struct xdr_stream
*xdr
,
5404 struct nfs4_layoutreturn_res
*res
)
5409 status
= decode_op_hdr(xdr
, OP_LAYOUTRETURN
);
5412 p
= xdr_inline_decode(xdr
, 4);
5415 res
->lrs_present
= be32_to_cpup(p
);
5416 if (res
->lrs_present
)
5417 status
= decode_stateid(xdr
, &res
->stateid
);
5420 print_overflow_msg(__func__
, xdr
);
5424 static int decode_layoutcommit(struct xdr_stream
*xdr
,
5425 struct rpc_rqst
*req
,
5426 struct nfs4_layoutcommit_res
*res
)
5432 status
= decode_op_hdr(xdr
, OP_LAYOUTCOMMIT
);
5436 p
= xdr_inline_decode(xdr
, 4);
5439 sizechanged
= be32_to_cpup(p
);
5442 /* throw away new size */
5443 p
= xdr_inline_decode(xdr
, 8);
5449 print_overflow_msg(__func__
, xdr
);
5453 static int decode_test_stateid(struct xdr_stream
*xdr
,
5454 struct nfs41_test_stateid_res
*res
)
5460 status
= decode_op_hdr(xdr
, OP_TEST_STATEID
);
5464 p
= xdr_inline_decode(xdr
, 4);
5467 num_res
= be32_to_cpup(p
++);
5471 p
= xdr_inline_decode(xdr
, 4);
5474 res
->status
= be32_to_cpup(p
++);
5477 print_overflow_msg(__func__
, xdr
);
5482 static int decode_free_stateid(struct xdr_stream
*xdr
,
5483 struct nfs41_free_stateid_res
*res
)
5488 status
= decode_op_hdr(xdr
, OP_FREE_STATEID
);
5492 p
= xdr_inline_decode(xdr
, 4);
5495 res
->status
= be32_to_cpup(p
++);
5498 print_overflow_msg(__func__
, xdr
);
5501 #endif /* CONFIG_NFS_V4_1 */
5504 * END OF "GENERIC" DECODE ROUTINES.
5508 * Decode OPEN_DOWNGRADE response
5510 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
,
5511 struct xdr_stream
*xdr
,
5512 struct nfs_closeres
*res
)
5514 struct compound_hdr hdr
;
5517 status
= decode_compound_hdr(xdr
, &hdr
);
5520 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5523 status
= decode_putfh(xdr
);
5526 status
= decode_open_downgrade(xdr
, res
);
5529 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5530 !RPC_IS_ASYNC(rqstp
->rq_task
));
5536 * Decode ACCESS response
5538 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5539 struct nfs4_accessres
*res
)
5541 struct compound_hdr hdr
;
5544 status
= decode_compound_hdr(xdr
, &hdr
);
5547 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5550 status
= decode_putfh(xdr
);
5553 status
= decode_access(xdr
, res
);
5556 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5557 !RPC_IS_ASYNC(rqstp
->rq_task
));
5563 * Decode LOOKUP response
5565 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5566 struct nfs4_lookup_res
*res
)
5568 struct compound_hdr hdr
;
5571 status
= decode_compound_hdr(xdr
, &hdr
);
5574 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5577 status
= decode_putfh(xdr
);
5580 status
= decode_lookup(xdr
);
5583 status
= decode_getfh(xdr
, res
->fh
);
5586 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
5587 ,!RPC_IS_ASYNC(rqstp
->rq_task
));
5593 * Decode LOOKUP_ROOT response
5595 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
,
5596 struct xdr_stream
*xdr
,
5597 struct nfs4_lookup_res
*res
)
5599 struct compound_hdr hdr
;
5602 status
= decode_compound_hdr(xdr
, &hdr
);
5605 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5608 status
= decode_putrootfh(xdr
);
5611 status
= decode_getfh(xdr
, res
->fh
);
5613 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
,
5614 !RPC_IS_ASYNC(rqstp
->rq_task
));
5620 * Decode REMOVE response
5622 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5623 struct nfs_removeres
*res
)
5625 struct compound_hdr hdr
;
5628 status
= decode_compound_hdr(xdr
, &hdr
);
5631 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5634 status
= decode_putfh(xdr
);
5637 status
= decode_remove(xdr
, &res
->cinfo
);
5640 decode_getfattr(xdr
, res
->dir_attr
, res
->server
,
5641 !RPC_IS_ASYNC(rqstp
->rq_task
));
5647 * Decode RENAME response
5649 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5650 struct nfs_renameres
*res
)
5652 struct compound_hdr hdr
;
5655 status
= decode_compound_hdr(xdr
, &hdr
);
5658 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5661 status
= decode_putfh(xdr
);
5664 status
= decode_savefh(xdr
);
5667 status
= decode_putfh(xdr
);
5670 status
= decode_rename(xdr
, &res
->old_cinfo
, &res
->new_cinfo
);
5673 /* Current FH is target directory */
5674 if (decode_getfattr(xdr
, res
->new_fattr
, res
->server
,
5675 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5677 status
= decode_restorefh(xdr
);
5680 decode_getfattr(xdr
, res
->old_fattr
, res
->server
,
5681 !RPC_IS_ASYNC(rqstp
->rq_task
));
5687 * Decode LINK response
5689 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5690 struct nfs4_link_res
*res
)
5692 struct compound_hdr hdr
;
5695 status
= decode_compound_hdr(xdr
, &hdr
);
5698 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5701 status
= decode_putfh(xdr
);
5704 status
= decode_savefh(xdr
);
5707 status
= decode_putfh(xdr
);
5710 status
= decode_link(xdr
, &res
->cinfo
);
5714 * Note order: OP_LINK leaves the directory as the current
5717 if (decode_getfattr(xdr
, res
->dir_attr
, res
->server
,
5718 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5720 status
= decode_restorefh(xdr
);
5723 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5724 !RPC_IS_ASYNC(rqstp
->rq_task
));
5730 * Decode CREATE response
5732 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5733 struct nfs4_create_res
*res
)
5735 struct compound_hdr hdr
;
5738 status
= decode_compound_hdr(xdr
, &hdr
);
5741 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5744 status
= decode_putfh(xdr
);
5747 status
= decode_savefh(xdr
);
5750 status
= decode_create(xdr
, &res
->dir_cinfo
);
5753 status
= decode_getfh(xdr
, res
->fh
);
5756 if (decode_getfattr(xdr
, res
->fattr
, res
->server
,
5757 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5759 status
= decode_restorefh(xdr
);
5762 decode_getfattr(xdr
, res
->dir_fattr
, res
->server
,
5763 !RPC_IS_ASYNC(rqstp
->rq_task
));
5769 * Decode SYMLINK response
5771 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5772 struct nfs4_create_res
*res
)
5774 return nfs4_xdr_dec_create(rqstp
, xdr
, res
);
5778 * Decode GETATTR response
5780 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5781 struct nfs4_getattr_res
*res
)
5783 struct compound_hdr hdr
;
5786 status
= decode_compound_hdr(xdr
, &hdr
);
5789 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5792 status
= decode_putfh(xdr
);
5795 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
,
5796 !RPC_IS_ASYNC(rqstp
->rq_task
));
5802 * Encode an SETACL request
5804 static void nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
5805 struct nfs_setaclargs
*args
)
5807 struct compound_hdr hdr
= {
5808 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
5811 encode_compound_hdr(xdr
, req
, &hdr
);
5812 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
5813 encode_putfh(xdr
, args
->fh
, &hdr
);
5814 encode_setacl(xdr
, args
, &hdr
);
5819 * Decode SETACL response
5822 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5823 struct nfs_setaclres
*res
)
5825 struct compound_hdr hdr
;
5828 status
= decode_compound_hdr(xdr
, &hdr
);
5831 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5834 status
= decode_putfh(xdr
);
5837 status
= decode_setattr(xdr
);
5843 * Decode GETACL response
5846 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5847 struct nfs_getaclres
*res
)
5849 struct compound_hdr hdr
;
5852 status
= decode_compound_hdr(xdr
, &hdr
);
5855 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5858 status
= decode_putfh(xdr
);
5861 status
= decode_getacl(xdr
, rqstp
, &res
->acl_len
);
5868 * Decode CLOSE response
5870 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5871 struct nfs_closeres
*res
)
5873 struct compound_hdr hdr
;
5876 status
= decode_compound_hdr(xdr
, &hdr
);
5879 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5882 status
= decode_putfh(xdr
);
5885 status
= decode_close(xdr
, res
);
5889 * Note: Server may do delete on close for this file
5890 * in which case the getattr call will fail with
5891 * an ESTALE error. Shouldn't be a problem,
5892 * though, since fattr->valid will remain unset.
5894 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5895 !RPC_IS_ASYNC(rqstp
->rq_task
));
5901 * Decode OPEN response
5903 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5904 struct nfs_openres
*res
)
5906 struct compound_hdr hdr
;
5909 status
= decode_compound_hdr(xdr
, &hdr
);
5912 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5915 status
= decode_putfh(xdr
);
5918 status
= decode_savefh(xdr
);
5921 status
= decode_open(xdr
, res
);
5924 if (decode_getfh(xdr
, &res
->fh
) != 0)
5926 if (decode_getfattr(xdr
, res
->f_attr
, res
->server
,
5927 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5929 if (decode_restorefh(xdr
) != 0)
5931 decode_getfattr(xdr
, res
->dir_attr
, res
->server
,
5932 !RPC_IS_ASYNC(rqstp
->rq_task
));
5938 * Decode OPEN_CONFIRM response
5940 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
,
5941 struct xdr_stream
*xdr
,
5942 struct nfs_open_confirmres
*res
)
5944 struct compound_hdr hdr
;
5947 status
= decode_compound_hdr(xdr
, &hdr
);
5950 status
= decode_putfh(xdr
);
5953 status
= decode_open_confirm(xdr
, res
);
5959 * Decode OPEN response
5961 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
,
5962 struct xdr_stream
*xdr
,
5963 struct nfs_openres
*res
)
5965 struct compound_hdr hdr
;
5968 status
= decode_compound_hdr(xdr
, &hdr
);
5971 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5974 status
= decode_putfh(xdr
);
5977 status
= decode_open(xdr
, res
);
5980 decode_getfattr(xdr
, res
->f_attr
, res
->server
,
5981 !RPC_IS_ASYNC(rqstp
->rq_task
));
5987 * Decode SETATTR response
5989 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
,
5990 struct xdr_stream
*xdr
,
5991 struct nfs_setattrres
*res
)
5993 struct compound_hdr hdr
;
5996 status
= decode_compound_hdr(xdr
, &hdr
);
5999 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6002 status
= decode_putfh(xdr
);
6005 status
= decode_setattr(xdr
);
6008 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6009 !RPC_IS_ASYNC(rqstp
->rq_task
));
6015 * Decode LOCK response
6017 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6018 struct nfs_lock_res
*res
)
6020 struct compound_hdr hdr
;
6023 status
= decode_compound_hdr(xdr
, &hdr
);
6026 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6029 status
= decode_putfh(xdr
);
6032 status
= decode_lock(xdr
, res
);
6038 * Decode LOCKT response
6040 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6041 struct nfs_lockt_res
*res
)
6043 struct compound_hdr hdr
;
6046 status
= decode_compound_hdr(xdr
, &hdr
);
6049 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6052 status
= decode_putfh(xdr
);
6055 status
= decode_lockt(xdr
, res
);
6061 * Decode LOCKU response
6063 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6064 struct nfs_locku_res
*res
)
6066 struct compound_hdr hdr
;
6069 status
= decode_compound_hdr(xdr
, &hdr
);
6072 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6075 status
= decode_putfh(xdr
);
6078 status
= decode_locku(xdr
, res
);
6083 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst
*rqstp
,
6084 struct xdr_stream
*xdr
, void *dummy
)
6086 struct compound_hdr hdr
;
6089 status
= decode_compound_hdr(xdr
, &hdr
);
6091 status
= decode_release_lockowner(xdr
);
6096 * Decode READLINK response
6098 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
,
6099 struct xdr_stream
*xdr
,
6100 struct nfs4_readlink_res
*res
)
6102 struct compound_hdr hdr
;
6105 status
= decode_compound_hdr(xdr
, &hdr
);
6108 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6111 status
= decode_putfh(xdr
);
6114 status
= decode_readlink(xdr
, rqstp
);
6120 * Decode READDIR response
6122 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6123 struct nfs4_readdir_res
*res
)
6125 struct compound_hdr hdr
;
6128 status
= decode_compound_hdr(xdr
, &hdr
);
6131 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6134 status
= decode_putfh(xdr
);
6137 status
= decode_readdir(xdr
, rqstp
, res
);
6143 * Decode Read response
6145 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6146 struct nfs_readres
*res
)
6148 struct compound_hdr hdr
;
6151 status
= decode_compound_hdr(xdr
, &hdr
);
6154 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6157 status
= decode_putfh(xdr
);
6160 status
= decode_read(xdr
, rqstp
, res
);
6162 status
= res
->count
;
6168 * Decode WRITE response
6170 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6171 struct nfs_writeres
*res
)
6173 struct compound_hdr hdr
;
6176 status
= decode_compound_hdr(xdr
, &hdr
);
6179 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6182 status
= decode_putfh(xdr
);
6185 status
= decode_write(xdr
, res
);
6189 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6190 !RPC_IS_ASYNC(rqstp
->rq_task
));
6192 status
= res
->count
;
6198 * Decode COMMIT response
6200 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6201 struct nfs_writeres
*res
)
6203 struct compound_hdr hdr
;
6206 status
= decode_compound_hdr(xdr
, &hdr
);
6209 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6212 status
= decode_putfh(xdr
);
6215 status
= decode_commit(xdr
, res
);
6219 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6220 !RPC_IS_ASYNC(rqstp
->rq_task
));
6226 * Decode FSINFO response
6228 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6229 struct nfs4_fsinfo_res
*res
)
6231 struct compound_hdr hdr
;
6234 status
= decode_compound_hdr(xdr
, &hdr
);
6236 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6238 status
= decode_putfh(xdr
);
6240 status
= decode_fsinfo(xdr
, res
->fsinfo
);
6245 * Decode PATHCONF response
6247 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6248 struct nfs4_pathconf_res
*res
)
6250 struct compound_hdr hdr
;
6253 status
= decode_compound_hdr(xdr
, &hdr
);
6255 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6257 status
= decode_putfh(xdr
);
6259 status
= decode_pathconf(xdr
, res
->pathconf
);
6264 * Decode STATFS response
6266 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6267 struct nfs4_statfs_res
*res
)
6269 struct compound_hdr hdr
;
6272 status
= decode_compound_hdr(xdr
, &hdr
);
6274 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6276 status
= decode_putfh(xdr
);
6278 status
= decode_statfs(xdr
, res
->fsstat
);
6283 * Decode GETATTR_BITMAP response
6285 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
,
6286 struct xdr_stream
*xdr
,
6287 struct nfs4_server_caps_res
*res
)
6289 struct compound_hdr hdr
;
6292 status
= decode_compound_hdr(xdr
, &hdr
);
6295 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6298 status
= decode_putfh(xdr
);
6301 status
= decode_server_caps(xdr
, res
);
6307 * Decode RENEW response
6309 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6312 struct compound_hdr hdr
;
6315 status
= decode_compound_hdr(xdr
, &hdr
);
6317 status
= decode_renew(xdr
);
6322 * Decode SETCLIENTID response
6324 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
,
6325 struct xdr_stream
*xdr
,
6326 struct nfs4_setclientid_res
*res
)
6328 struct compound_hdr hdr
;
6331 status
= decode_compound_hdr(xdr
, &hdr
);
6333 status
= decode_setclientid(xdr
, res
);
6338 * Decode SETCLIENTID_CONFIRM response
6340 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
,
6341 struct xdr_stream
*xdr
,
6342 struct nfs_fsinfo
*fsinfo
)
6344 struct compound_hdr hdr
;
6347 status
= decode_compound_hdr(xdr
, &hdr
);
6349 status
= decode_setclientid_confirm(xdr
);
6351 status
= decode_putrootfh(xdr
);
6353 status
= decode_fsinfo(xdr
, fsinfo
);
6358 * Decode DELEGRETURN response
6360 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
,
6361 struct xdr_stream
*xdr
,
6362 struct nfs4_delegreturnres
*res
)
6364 struct compound_hdr hdr
;
6367 status
= decode_compound_hdr(xdr
, &hdr
);
6370 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6373 status
= decode_putfh(xdr
);
6376 status
= decode_delegreturn(xdr
);
6379 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6380 !RPC_IS_ASYNC(rqstp
->rq_task
));
6386 * Decode FS_LOCATIONS response
6388 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
,
6389 struct xdr_stream
*xdr
,
6390 struct nfs4_fs_locations_res
*res
)
6392 struct compound_hdr hdr
;
6395 status
= decode_compound_hdr(xdr
, &hdr
);
6398 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6401 status
= decode_putfh(xdr
);
6404 status
= decode_lookup(xdr
);
6407 xdr_enter_page(xdr
, PAGE_SIZE
);
6408 status
= decode_getfattr(xdr
, &res
->fs_locations
->fattr
,
6409 res
->fs_locations
->server
,
6410 !RPC_IS_ASYNC(req
->rq_task
));
6416 * Decode SECINFO response
6418 static int nfs4_xdr_dec_secinfo(struct rpc_rqst
*rqstp
,
6419 struct xdr_stream
*xdr
,
6420 struct nfs4_secinfo_res
*res
)
6422 struct compound_hdr hdr
;
6425 status
= decode_compound_hdr(xdr
, &hdr
);
6428 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6431 status
= decode_putfh(xdr
);
6434 status
= decode_secinfo(xdr
, res
);
6441 #if defined(CONFIG_NFS_V4_1)
6443 * Decode EXCHANGE_ID response
6445 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
,
6446 struct xdr_stream
*xdr
,
6449 struct compound_hdr hdr
;
6452 status
= decode_compound_hdr(xdr
, &hdr
);
6454 status
= decode_exchange_id(xdr
, res
);
6459 * Decode CREATE_SESSION response
6461 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
,
6462 struct xdr_stream
*xdr
,
6463 struct nfs41_create_session_res
*res
)
6465 struct compound_hdr hdr
;
6468 status
= decode_compound_hdr(xdr
, &hdr
);
6470 status
= decode_create_session(xdr
, res
);
6475 * Decode DESTROY_SESSION response
6477 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
,
6478 struct xdr_stream
*xdr
,
6481 struct compound_hdr hdr
;
6484 status
= decode_compound_hdr(xdr
, &hdr
);
6486 status
= decode_destroy_session(xdr
, res
);
6491 * Decode SEQUENCE response
6493 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
,
6494 struct xdr_stream
*xdr
,
6495 struct nfs4_sequence_res
*res
)
6497 struct compound_hdr hdr
;
6500 status
= decode_compound_hdr(xdr
, &hdr
);
6502 status
= decode_sequence(xdr
, res
, rqstp
);
6507 * Decode GET_LEASE_TIME response
6509 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
,
6510 struct xdr_stream
*xdr
,
6511 struct nfs4_get_lease_time_res
*res
)
6513 struct compound_hdr hdr
;
6516 status
= decode_compound_hdr(xdr
, &hdr
);
6518 status
= decode_sequence(xdr
, &res
->lr_seq_res
, rqstp
);
6520 status
= decode_putrootfh(xdr
);
6522 status
= decode_fsinfo(xdr
, res
->lr_fsinfo
);
6527 * Decode RECLAIM_COMPLETE response
6529 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
,
6530 struct xdr_stream
*xdr
,
6531 struct nfs41_reclaim_complete_res
*res
)
6533 struct compound_hdr hdr
;
6536 status
= decode_compound_hdr(xdr
, &hdr
);
6538 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6540 status
= decode_reclaim_complete(xdr
, (void *)NULL
);
6545 * Decode GETDEVINFO response
6547 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst
*rqstp
,
6548 struct xdr_stream
*xdr
,
6549 struct nfs4_getdeviceinfo_res
*res
)
6551 struct compound_hdr hdr
;
6554 status
= decode_compound_hdr(xdr
, &hdr
);
6557 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6560 status
= decode_getdeviceinfo(xdr
, res
->pdev
);
6566 * Decode LAYOUTGET response
6568 static int nfs4_xdr_dec_layoutget(struct rpc_rqst
*rqstp
,
6569 struct xdr_stream
*xdr
,
6570 struct nfs4_layoutget_res
*res
)
6572 struct compound_hdr hdr
;
6575 status
= decode_compound_hdr(xdr
, &hdr
);
6578 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6581 status
= decode_putfh(xdr
);
6584 status
= decode_layoutget(xdr
, rqstp
, res
);
6590 * Decode LAYOUTRETURN response
6592 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst
*rqstp
,
6593 struct xdr_stream
*xdr
,
6594 struct nfs4_layoutreturn_res
*res
)
6596 struct compound_hdr hdr
;
6599 status
= decode_compound_hdr(xdr
, &hdr
);
6602 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6605 status
= decode_putfh(xdr
);
6608 status
= decode_layoutreturn(xdr
, res
);
6614 * Decode LAYOUTCOMMIT response
6616 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst
*rqstp
,
6617 struct xdr_stream
*xdr
,
6618 struct nfs4_layoutcommit_res
*res
)
6620 struct compound_hdr hdr
;
6623 status
= decode_compound_hdr(xdr
, &hdr
);
6626 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6629 status
= decode_putfh(xdr
);
6632 status
= decode_layoutcommit(xdr
, rqstp
, res
);
6635 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6636 !RPC_IS_ASYNC(rqstp
->rq_task
));
6642 * Decode SECINFO_NO_NAME response
6644 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst
*rqstp
,
6645 struct xdr_stream
*xdr
,
6646 struct nfs4_secinfo_res
*res
)
6648 struct compound_hdr hdr
;
6651 status
= decode_compound_hdr(xdr
, &hdr
);
6654 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6657 status
= decode_putrootfh(xdr
);
6660 status
= decode_secinfo(xdr
, res
);
6666 * Decode TEST_STATEID response
6668 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst
*rqstp
,
6669 struct xdr_stream
*xdr
,
6670 struct nfs41_test_stateid_res
*res
)
6672 struct compound_hdr hdr
;
6675 status
= decode_compound_hdr(xdr
, &hdr
);
6678 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6681 status
= decode_test_stateid(xdr
, res
);
6687 * Decode FREE_STATEID response
6689 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst
*rqstp
,
6690 struct xdr_stream
*xdr
,
6691 struct nfs41_free_stateid_res
*res
)
6693 struct compound_hdr hdr
;
6696 status
= decode_compound_hdr(xdr
, &hdr
);
6699 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6702 status
= decode_free_stateid(xdr
, res
);
6706 #endif /* CONFIG_NFS_V4_1 */
6709 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6710 * the local page cache.
6711 * @xdr: XDR stream where entry resides
6712 * @entry: buffer to fill in with entry data
6713 * @plus: boolean indicating whether this should be a readdirplus entry
6715 * Returns zero if successful, otherwise a negative errno value is
6718 * This function is not invoked during READDIR reply decoding, but
6719 * rather whenever an application invokes the getdents(2) system call
6720 * on a directory already in our cache.
6722 int nfs4_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
6725 uint32_t bitmap
[2] = {0};
6727 __be32
*p
= xdr_inline_decode(xdr
, 4);
6730 if (*p
== xdr_zero
) {
6731 p
= xdr_inline_decode(xdr
, 4);
6740 p
= xdr_inline_decode(xdr
, 12);
6743 entry
->prev_cookie
= entry
->cookie
;
6744 p
= xdr_decode_hyper(p
, &entry
->cookie
);
6745 entry
->len
= be32_to_cpup(p
);
6747 p
= xdr_inline_decode(xdr
, entry
->len
);
6750 entry
->name
= (const char *) p
;
6753 * In case the server doesn't return an inode number,
6754 * we fake one here. (We don't use inode number 0,
6755 * since glibc seems to choke on it...)
6758 entry
->fattr
->valid
= 0;
6760 if (decode_attr_bitmap(xdr
, bitmap
) < 0)
6763 if (decode_attr_length(xdr
, &len
, &p
) < 0)
6766 if (decode_getfattr_attrs(xdr
, bitmap
, entry
->fattr
, entry
->fh
,
6767 entry
->server
, 1) < 0)
6769 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
)
6770 entry
->ino
= entry
->fattr
->mounted_on_fileid
;
6771 else if (entry
->fattr
->valid
& NFS_ATTR_FATTR_FILEID
)
6772 entry
->ino
= entry
->fattr
->fileid
;
6774 entry
->d_type
= DT_UNKNOWN
;
6775 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_TYPE
)
6776 entry
->d_type
= nfs_umode_to_dtype(entry
->fattr
->mode
);
6781 print_overflow_msg(__func__
, xdr
);
6786 * We need to translate between nfs status return values and
6787 * the local errno values which may not be the same.
6794 { NFS4ERR_PERM
, -EPERM
},
6795 { NFS4ERR_NOENT
, -ENOENT
},
6796 { NFS4ERR_IO
, -errno_NFSERR_IO
},
6797 { NFS4ERR_NXIO
, -ENXIO
},
6798 { NFS4ERR_ACCESS
, -EACCES
},
6799 { NFS4ERR_EXIST
, -EEXIST
},
6800 { NFS4ERR_XDEV
, -EXDEV
},
6801 { NFS4ERR_NOTDIR
, -ENOTDIR
},
6802 { NFS4ERR_ISDIR
, -EISDIR
},
6803 { NFS4ERR_INVAL
, -EINVAL
},
6804 { NFS4ERR_FBIG
, -EFBIG
},
6805 { NFS4ERR_NOSPC
, -ENOSPC
},
6806 { NFS4ERR_ROFS
, -EROFS
},
6807 { NFS4ERR_MLINK
, -EMLINK
},
6808 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
6809 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
6810 { NFS4ERR_DQUOT
, -EDQUOT
},
6811 { NFS4ERR_STALE
, -ESTALE
},
6812 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
6813 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
6814 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
6815 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
6816 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
6817 { NFS4ERR_BADTYPE
, -EBADTYPE
},
6818 { NFS4ERR_LOCKED
, -EAGAIN
},
6819 { NFS4ERR_SYMLINK
, -ELOOP
},
6820 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
6821 { NFS4ERR_DEADLOCK
, -EDEADLK
},
6826 * Convert an NFS error code to a local one.
6827 * This one is used jointly by NFSv2 and NFSv3.
6830 nfs4_stat_to_errno(int stat
)
6833 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
6834 if (nfs_errtbl
[i
].stat
== stat
)
6835 return nfs_errtbl
[i
].errno
;
6837 if (stat
<= 10000 || stat
> 10100) {
6838 /* The server is looney tunes. */
6841 /* If we cannot translate the error, the recovery routines should
6843 * Note: remaining NFSv4 error codes have values > 10000, so should
6844 * not conflict with native Linux error codes.
6849 #define PROC(proc, argtype, restype) \
6850 [NFSPROC4_CLNT_##proc] = { \
6851 .p_proc = NFSPROC4_COMPOUND, \
6852 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6853 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6854 .p_arglen = NFS4_##argtype##_sz, \
6855 .p_replen = NFS4_##restype##_sz, \
6856 .p_statidx = NFSPROC4_CLNT_##proc, \
6860 struct rpc_procinfo nfs4_procedures
[] = {
6861 PROC(READ
, enc_read
, dec_read
),
6862 PROC(WRITE
, enc_write
, dec_write
),
6863 PROC(COMMIT
, enc_commit
, dec_commit
),
6864 PROC(OPEN
, enc_open
, dec_open
),
6865 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
6866 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
6867 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
6868 PROC(CLOSE
, enc_close
, dec_close
),
6869 PROC(SETATTR
, enc_setattr
, dec_setattr
),
6870 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
6871 PROC(RENEW
, enc_renew
, dec_renew
),
6872 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
6873 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
6874 PROC(LOCK
, enc_lock
, dec_lock
),
6875 PROC(LOCKT
, enc_lockt
, dec_lockt
),
6876 PROC(LOCKU
, enc_locku
, dec_locku
),
6877 PROC(ACCESS
, enc_access
, dec_access
),
6878 PROC(GETATTR
, enc_getattr
, dec_getattr
),
6879 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
6880 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
6881 PROC(REMOVE
, enc_remove
, dec_remove
),
6882 PROC(RENAME
, enc_rename
, dec_rename
),
6883 PROC(LINK
, enc_link
, dec_link
),
6884 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
6885 PROC(CREATE
, enc_create
, dec_create
),
6886 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
6887 PROC(STATFS
, enc_statfs
, dec_statfs
),
6888 PROC(READLINK
, enc_readlink
, dec_readlink
),
6889 PROC(READDIR
, enc_readdir
, dec_readdir
),
6890 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
6891 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
6892 PROC(GETACL
, enc_getacl
, dec_getacl
),
6893 PROC(SETACL
, enc_setacl
, dec_setacl
),
6894 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
6895 PROC(RELEASE_LOCKOWNER
, enc_release_lockowner
, dec_release_lockowner
),
6896 PROC(SECINFO
, enc_secinfo
, dec_secinfo
),
6897 #if defined(CONFIG_NFS_V4_1)
6898 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
6899 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
6900 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
6901 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
6902 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
6903 PROC(RECLAIM_COMPLETE
, enc_reclaim_complete
, dec_reclaim_complete
),
6904 PROC(GETDEVICEINFO
, enc_getdeviceinfo
, dec_getdeviceinfo
),
6905 PROC(LAYOUTGET
, enc_layoutget
, dec_layoutget
),
6906 PROC(LAYOUTCOMMIT
, enc_layoutcommit
, dec_layoutcommit
),
6907 PROC(LAYOUTRETURN
, enc_layoutreturn
, dec_layoutreturn
),
6908 PROC(SECINFO_NO_NAME
, enc_secinfo_no_name
, dec_secinfo_no_name
),
6909 PROC(TEST_STATEID
, enc_test_stateid
, dec_test_stateid
),
6910 PROC(FREE_STATEID
, enc_free_stateid
, dec_free_stateid
),
6911 #endif /* CONFIG_NFS_V4_1 */
6914 struct rpc_version nfs_version4
= {
6916 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
6917 .procs
= nfs4_procedures