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 /* The 5 accounts for the PNFS attributes, and assumes that at most three
117 * layout types will be returned.
119 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
120 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
121 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
122 #define decode_renew_maxsz (op_decode_hdr_maxsz)
123 #define encode_setclientid_maxsz \
124 (op_encode_hdr_maxsz + \
125 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
126 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
128 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
129 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
131 #define decode_setclientid_maxsz \
132 (op_decode_hdr_maxsz + \
134 1024) /* large value for CLID_INUSE */
135 #define encode_setclientid_confirm_maxsz \
136 (op_encode_hdr_maxsz + \
137 3 + (NFS4_VERIFIER_SIZE >> 2))
138 #define decode_setclientid_confirm_maxsz \
139 (op_decode_hdr_maxsz)
140 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
141 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
142 #define encode_share_access_maxsz \
144 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
145 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
146 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
147 #define encode_open_maxsz (op_encode_hdr_maxsz + \
148 2 + encode_share_access_maxsz + 2 + \
149 open_owner_id_maxsz + \
150 encode_opentype_maxsz + \
151 encode_claim_null_maxsz)
152 #define decode_space_limit_maxsz (3)
153 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
154 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
155 decode_space_limit_maxsz + \
157 #define decode_change_info_maxsz (5)
158 #define decode_open_maxsz (op_decode_hdr_maxsz + \
159 decode_stateid_maxsz + \
160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
163 #define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166 #define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169 #define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173 #define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176 #define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178 #define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
183 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185 #define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
193 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194 #define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196 #define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
201 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
203 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
205 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
207 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
210 #define encode_link_maxsz (op_encode_hdr_maxsz + \
212 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
213 #define encode_lockowner_maxsz (7)
214 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
218 #define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
222 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
224 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
229 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
231 #define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234 #define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
236 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
238 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
242 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243 #define encode_create_maxsz (op_encode_hdr_maxsz + \
244 1 + 2 + nfs4_name_maxsz + \
246 #define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
249 #define encode_statfs_maxsz (encode_getattr_maxsz)
250 #define decode_statfs_maxsz (decode_getattr_maxsz)
251 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
253 #define encode_getacl_maxsz (encode_getattr_maxsz)
254 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258 #define decode_setacl_maxsz (decode_setattr_maxsz)
259 #define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261 #define decode_fs_locations_maxsz \
263 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
264 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
266 #if defined(CONFIG_NFS_V4_1)
267 #define NFS4_MAX_MACHINE_NAME_LEN (64)
269 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
275 0 /* SP4_NONE (for now) */ + \
276 1 /* zero implemetation id array */)
277 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
278 2 /* eir_clientid */ + \
279 1 /* eir_sequenceid */ + \
280 1 /* eir_flags */ + \
282 0 /* SP4_NONE (for now) */ + \
283 2 /* eir_server_owner.so_minor_id */ + \
284 /* eir_server_owner.so_major_id<> */ \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
286 /* eir_server_scope<> */ \
287 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
288 1 /* eir_server_impl_id array length */ + \
289 0 /* ignored eir_server_impl_id contents */)
290 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
291 #define decode_channel_attrs_maxsz (6 + \
292 1 /* ca_rdma_ird.len */ + \
294 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
295 2 /* csa_clientid */ + \
296 1 /* csa_sequence */ + \
297 1 /* csa_flags */ + \
298 encode_channel_attrs_maxsz + \
299 encode_channel_attrs_maxsz + \
300 1 /* csa_cb_program */ + \
301 1 /* csa_sec_parms.len (1) */ + \
302 1 /* cb_secflavor (AUTH_SYS) */ + \
304 1 /* machinename.len */ + \
305 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
308 1 /* gids.len (0) */)
309 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
310 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
311 1 /* csr_sequence */ + \
312 1 /* csr_flags */ + \
313 decode_channel_attrs_maxsz + \
314 decode_channel_attrs_maxsz)
315 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
316 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
317 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
318 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
319 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
320 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
321 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
322 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
323 #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
324 encode_verifier_maxsz)
325 #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
326 2 /* nfs_cookie4 gdlr_cookie */ + \
327 decode_verifier_maxsz \
328 /* verifier4 gdlr_verifier */ + \
329 1 /* gdlr_deviceid_list count */ + \
330 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
331 NFS4_DEVICEID4_SIZE) \
332 /* gdlr_deviceid_list */ + \
333 1 /* bool gdlr_eof */)
334 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
335 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
336 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
337 1 /* layout type */ + \
338 1 /* opaque devaddr4 length */ + \
339 /* devaddr4 payload is read into page */ \
340 1 /* notification bitmap length */ + \
341 1 /* notification bitmap */)
342 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
343 encode_stateid_maxsz)
344 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
345 decode_stateid_maxsz + \
346 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
347 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
351 encode_stateid_maxsz + \
352 1 /* new offset (true) */ + \
353 2 /* last byte written */ + \
354 1 /* nt_timechanged (false) */ + \
355 1 /* layoutupdate4 layout type */ + \
356 1 /* NULL filelayout layoutupdate4 payload */)
357 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
358 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
359 encode_stateid_maxsz + \
360 1 /* FIXME: opaque lrf_body always empty at the moment */)
361 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
362 1 + decode_stateid_maxsz)
363 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
364 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
365 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
366 XDR_QUADLEN(NFS4_STATEID_SIZE))
367 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
368 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
369 XDR_QUADLEN(NFS4_STATEID_SIZE))
370 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
371 #else /* CONFIG_NFS_V4_1 */
372 #define encode_sequence_maxsz 0
373 #define decode_sequence_maxsz 0
374 #endif /* CONFIG_NFS_V4_1 */
376 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
377 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
378 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
379 encode_sequence_maxsz + \
380 encode_putfh_maxsz + \
382 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
383 decode_sequence_maxsz + \
384 decode_putfh_maxsz + \
386 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
387 encode_sequence_maxsz + \
388 encode_putfh_maxsz + \
389 encode_readlink_maxsz)
390 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
391 decode_sequence_maxsz + \
392 decode_putfh_maxsz + \
393 decode_readlink_maxsz)
394 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
395 encode_sequence_maxsz + \
396 encode_putfh_maxsz + \
397 encode_readdir_maxsz)
398 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
399 decode_sequence_maxsz + \
400 decode_putfh_maxsz + \
401 decode_readdir_maxsz)
402 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
403 encode_sequence_maxsz + \
404 encode_putfh_maxsz + \
405 encode_write_maxsz + \
406 encode_getattr_maxsz)
407 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
408 decode_sequence_maxsz + \
409 decode_putfh_maxsz + \
410 decode_write_maxsz + \
411 decode_getattr_maxsz)
412 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
413 encode_sequence_maxsz + \
414 encode_putfh_maxsz + \
415 encode_commit_maxsz + \
416 encode_getattr_maxsz)
417 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
418 decode_sequence_maxsz + \
419 decode_putfh_maxsz + \
420 decode_commit_maxsz + \
421 decode_getattr_maxsz)
422 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
423 encode_sequence_maxsz + \
424 encode_putfh_maxsz + \
425 encode_savefh_maxsz + \
426 encode_open_maxsz + \
427 encode_getfh_maxsz + \
428 encode_getattr_maxsz + \
429 encode_restorefh_maxsz + \
430 encode_getattr_maxsz)
431 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
432 decode_sequence_maxsz + \
433 decode_putfh_maxsz + \
434 decode_savefh_maxsz + \
435 decode_open_maxsz + \
436 decode_getfh_maxsz + \
437 decode_getattr_maxsz + \
438 decode_restorefh_maxsz + \
439 decode_getattr_maxsz)
440 #define NFS4_enc_open_confirm_sz \
441 (compound_encode_hdr_maxsz + \
442 encode_putfh_maxsz + \
443 encode_open_confirm_maxsz)
444 #define NFS4_dec_open_confirm_sz \
445 (compound_decode_hdr_maxsz + \
446 decode_putfh_maxsz + \
447 decode_open_confirm_maxsz)
448 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
449 encode_sequence_maxsz + \
450 encode_putfh_maxsz + \
451 encode_open_maxsz + \
452 encode_getattr_maxsz)
453 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
454 decode_sequence_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_maxsz + \
457 decode_getattr_maxsz)
458 #define NFS4_enc_open_downgrade_sz \
459 (compound_encode_hdr_maxsz + \
460 encode_sequence_maxsz + \
461 encode_putfh_maxsz + \
462 encode_open_downgrade_maxsz + \
463 encode_getattr_maxsz)
464 #define NFS4_dec_open_downgrade_sz \
465 (compound_decode_hdr_maxsz + \
466 decode_sequence_maxsz + \
467 decode_putfh_maxsz + \
468 decode_open_downgrade_maxsz + \
469 decode_getattr_maxsz)
470 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
471 encode_sequence_maxsz + \
472 encode_putfh_maxsz + \
473 encode_close_maxsz + \
474 encode_getattr_maxsz)
475 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
476 decode_sequence_maxsz + \
477 decode_putfh_maxsz + \
478 decode_close_maxsz + \
479 decode_getattr_maxsz)
480 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
481 encode_sequence_maxsz + \
482 encode_putfh_maxsz + \
483 encode_setattr_maxsz + \
484 encode_getattr_maxsz)
485 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
486 decode_sequence_maxsz + \
487 decode_putfh_maxsz + \
488 decode_setattr_maxsz + \
489 decode_getattr_maxsz)
490 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
491 encode_sequence_maxsz + \
492 encode_putfh_maxsz + \
494 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
495 decode_sequence_maxsz + \
496 decode_putfh_maxsz + \
498 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
500 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
502 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
503 encode_setclientid_maxsz)
504 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
505 decode_setclientid_maxsz)
506 #define NFS4_enc_setclientid_confirm_sz \
507 (compound_encode_hdr_maxsz + \
508 encode_setclientid_confirm_maxsz + \
509 encode_putrootfh_maxsz + \
511 #define NFS4_dec_setclientid_confirm_sz \
512 (compound_decode_hdr_maxsz + \
513 decode_setclientid_confirm_maxsz + \
514 decode_putrootfh_maxsz + \
516 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
517 encode_sequence_maxsz + \
518 encode_putfh_maxsz + \
520 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
521 decode_sequence_maxsz + \
522 decode_putfh_maxsz + \
524 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
525 encode_sequence_maxsz + \
526 encode_putfh_maxsz + \
528 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
529 decode_sequence_maxsz + \
530 decode_putfh_maxsz + \
532 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
533 encode_sequence_maxsz + \
534 encode_putfh_maxsz + \
536 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
537 decode_sequence_maxsz + \
538 decode_putfh_maxsz + \
540 #define NFS4_enc_release_lockowner_sz \
541 (compound_encode_hdr_maxsz + \
542 encode_lockowner_maxsz)
543 #define NFS4_dec_release_lockowner_sz \
544 (compound_decode_hdr_maxsz + \
545 decode_lockowner_maxsz)
546 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
547 encode_sequence_maxsz + \
548 encode_putfh_maxsz + \
549 encode_access_maxsz + \
550 encode_getattr_maxsz)
551 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
552 decode_sequence_maxsz + \
553 decode_putfh_maxsz + \
554 decode_access_maxsz + \
555 decode_getattr_maxsz)
556 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
557 encode_sequence_maxsz + \
558 encode_putfh_maxsz + \
559 encode_getattr_maxsz)
560 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
561 decode_sequence_maxsz + \
562 decode_putfh_maxsz + \
563 decode_getattr_maxsz)
564 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
565 encode_sequence_maxsz + \
566 encode_putfh_maxsz + \
567 encode_lookup_maxsz + \
568 encode_getattr_maxsz + \
570 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
571 decode_sequence_maxsz + \
572 decode_putfh_maxsz + \
573 decode_lookup_maxsz + \
574 decode_getattr_maxsz + \
576 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
577 encode_sequence_maxsz + \
578 encode_putrootfh_maxsz + \
579 encode_getattr_maxsz + \
581 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
582 decode_sequence_maxsz + \
583 decode_putrootfh_maxsz + \
584 decode_getattr_maxsz + \
586 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
587 encode_sequence_maxsz + \
588 encode_putfh_maxsz + \
589 encode_remove_maxsz + \
590 encode_getattr_maxsz)
591 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
592 decode_sequence_maxsz + \
593 decode_putfh_maxsz + \
594 decode_remove_maxsz + \
595 decode_getattr_maxsz)
596 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
597 encode_sequence_maxsz + \
598 encode_putfh_maxsz + \
599 encode_savefh_maxsz + \
600 encode_putfh_maxsz + \
601 encode_rename_maxsz + \
602 encode_getattr_maxsz + \
603 encode_restorefh_maxsz + \
604 encode_getattr_maxsz)
605 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
606 decode_sequence_maxsz + \
607 decode_putfh_maxsz + \
608 decode_savefh_maxsz + \
609 decode_putfh_maxsz + \
610 decode_rename_maxsz + \
611 decode_getattr_maxsz + \
612 decode_restorefh_maxsz + \
613 decode_getattr_maxsz)
614 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
615 encode_sequence_maxsz + \
616 encode_putfh_maxsz + \
617 encode_savefh_maxsz + \
618 encode_putfh_maxsz + \
619 encode_link_maxsz + \
620 decode_getattr_maxsz + \
621 encode_restorefh_maxsz + \
622 decode_getattr_maxsz)
623 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
624 decode_sequence_maxsz + \
625 decode_putfh_maxsz + \
626 decode_savefh_maxsz + \
627 decode_putfh_maxsz + \
628 decode_link_maxsz + \
629 decode_getattr_maxsz + \
630 decode_restorefh_maxsz + \
631 decode_getattr_maxsz)
632 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
633 encode_sequence_maxsz + \
634 encode_putfh_maxsz + \
635 encode_symlink_maxsz + \
636 encode_getattr_maxsz + \
638 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
639 decode_sequence_maxsz + \
640 decode_putfh_maxsz + \
641 decode_symlink_maxsz + \
642 decode_getattr_maxsz + \
644 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
645 encode_sequence_maxsz + \
646 encode_putfh_maxsz + \
647 encode_savefh_maxsz + \
648 encode_create_maxsz + \
649 encode_getfh_maxsz + \
650 encode_getattr_maxsz + \
651 encode_restorefh_maxsz + \
652 encode_getattr_maxsz)
653 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
654 decode_sequence_maxsz + \
655 decode_putfh_maxsz + \
656 decode_savefh_maxsz + \
657 decode_create_maxsz + \
658 decode_getfh_maxsz + \
659 decode_getattr_maxsz + \
660 decode_restorefh_maxsz + \
661 decode_getattr_maxsz)
662 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
663 encode_sequence_maxsz + \
664 encode_putfh_maxsz + \
665 encode_getattr_maxsz)
666 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
667 decode_sequence_maxsz + \
668 decode_putfh_maxsz + \
669 decode_getattr_maxsz)
670 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
671 encode_sequence_maxsz + \
672 encode_putfh_maxsz + \
674 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
675 decode_sequence_maxsz + \
676 decode_putfh_maxsz + \
678 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
679 encode_sequence_maxsz + \
680 encode_putfh_maxsz + \
681 encode_getattr_maxsz)
682 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
683 decode_sequence_maxsz + \
684 decode_putfh_maxsz + \
685 decode_getattr_maxsz)
686 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
687 encode_sequence_maxsz + \
688 encode_putfh_maxsz + \
689 encode_delegreturn_maxsz + \
690 encode_getattr_maxsz)
691 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
692 decode_sequence_maxsz + \
693 decode_delegreturn_maxsz + \
694 decode_getattr_maxsz)
695 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
696 encode_sequence_maxsz + \
697 encode_putfh_maxsz + \
699 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_putfh_maxsz + \
703 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
704 encode_sequence_maxsz + \
705 encode_putfh_maxsz + \
707 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
708 decode_sequence_maxsz + \
709 decode_putfh_maxsz + \
711 #define NFS4_enc_fs_locations_sz \
712 (compound_encode_hdr_maxsz + \
713 encode_sequence_maxsz + \
714 encode_putfh_maxsz + \
715 encode_lookup_maxsz + \
716 encode_fs_locations_maxsz)
717 #define NFS4_dec_fs_locations_sz \
718 (compound_decode_hdr_maxsz + \
719 decode_sequence_maxsz + \
720 decode_putfh_maxsz + \
721 decode_lookup_maxsz + \
722 decode_fs_locations_maxsz)
723 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
724 encode_sequence_maxsz + \
725 encode_putfh_maxsz + \
726 encode_secinfo_maxsz)
727 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz + \
729 decode_putfh_maxsz + \
730 decode_secinfo_maxsz)
731 #if defined(CONFIG_NFS_V4_1)
732 #define NFS4_enc_exchange_id_sz \
733 (compound_encode_hdr_maxsz + \
734 encode_exchange_id_maxsz)
735 #define NFS4_dec_exchange_id_sz \
736 (compound_decode_hdr_maxsz + \
737 decode_exchange_id_maxsz)
738 #define NFS4_enc_create_session_sz \
739 (compound_encode_hdr_maxsz + \
740 encode_create_session_maxsz)
741 #define NFS4_dec_create_session_sz \
742 (compound_decode_hdr_maxsz + \
743 decode_create_session_maxsz)
744 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
745 encode_destroy_session_maxsz)
746 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
747 decode_destroy_session_maxsz)
748 #define NFS4_enc_sequence_sz \
749 (compound_decode_hdr_maxsz + \
750 encode_sequence_maxsz)
751 #define NFS4_dec_sequence_sz \
752 (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz)
754 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
755 encode_sequence_maxsz + \
756 encode_putrootfh_maxsz + \
758 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
759 decode_sequence_maxsz + \
760 decode_putrootfh_maxsz + \
762 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
763 encode_sequence_maxsz + \
764 encode_reclaim_complete_maxsz)
765 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
766 decode_sequence_maxsz + \
767 decode_reclaim_complete_maxsz)
768 #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
769 encode_sequence_maxsz + \
770 encode_putfh_maxsz + \
771 encode_getdevicelist_maxsz)
772 #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
773 decode_sequence_maxsz + \
774 decode_putfh_maxsz + \
775 decode_getdevicelist_maxsz)
776 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
777 encode_sequence_maxsz +\
778 encode_getdeviceinfo_maxsz)
779 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
780 decode_sequence_maxsz + \
781 decode_getdeviceinfo_maxsz)
782 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
783 encode_sequence_maxsz + \
784 encode_putfh_maxsz + \
785 encode_layoutget_maxsz)
786 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
787 decode_sequence_maxsz + \
788 decode_putfh_maxsz + \
789 decode_layoutget_maxsz)
790 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
791 encode_sequence_maxsz +\
792 encode_putfh_maxsz + \
793 encode_layoutcommit_maxsz + \
794 encode_getattr_maxsz)
795 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutcommit_maxsz + \
799 decode_getattr_maxsz)
800 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
801 encode_sequence_maxsz + \
802 encode_putfh_maxsz + \
803 encode_layoutreturn_maxsz)
804 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutreturn_maxsz)
808 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
809 encode_sequence_maxsz + \
810 encode_putrootfh_maxsz +\
811 encode_secinfo_no_name_maxsz)
812 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_putrootfh_maxsz + \
815 decode_secinfo_no_name_maxsz)
816 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
817 encode_sequence_maxsz + \
818 encode_test_stateid_maxsz)
819 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_test_stateid_maxsz)
822 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
823 encode_sequence_maxsz + \
824 encode_free_stateid_maxsz)
825 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
826 decode_sequence_maxsz + \
827 decode_free_stateid_maxsz)
829 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
830 compound_encode_hdr_maxsz +
831 encode_sequence_maxsz +
833 encode_getattr_maxsz) *
836 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
837 compound_decode_hdr_maxsz +
838 decode_sequence_maxsz +
839 decode_putfh_maxsz) *
841 #endif /* CONFIG_NFS_V4_1 */
843 static const umode_t nfs_type2fmt[] = {
850 [NF4SOCK] = S_IFSOCK,
856 struct compound_hdr {
862 uint32_t replen; /* expected reply words */
866 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
868 __be32 *p = xdr_reserve_space(xdr, nbytes);
873 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
877 p = xdr_reserve_space(xdr, 4 + len);
879 xdr_encode_opaque(p, str, len);
882 static void encode_compound_hdr(struct xdr_stream *xdr,
883 struct rpc_rqst *req,
884 struct compound_hdr *hdr)
887 struct rpc_auth *auth = req->rq_cred->cr_auth;
889 /* initialize running count of expected bytes in reply.
890 * NOTE: the replied tag SHOULD be the same is the one sent,
891 * but this is not required as a MUST for the server to do so. */
892 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
894 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
895 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
896 p = reserve_space(xdr, 4 + hdr->taglen + 8);
897 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
898 *p++ = cpu_to_be32(hdr->minorversion);
900 *p = cpu_to_be32(hdr->nops);
903 static void encode_nops(struct compound_hdr *hdr)
905 BUG_ON(hdr->nops > NFS4_MAX_OPS);
906 *hdr->nops_p = htonl(hdr->nops);
909 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
913 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
915 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
918 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
920 char owner_name[IDMAP_NAMESZ];
921 char owner_group[IDMAP_NAMESZ];
922 int owner_namelen = 0;
923 int owner_grouplen = 0;
931 * We reserve enough space to write the entire attribute buffer at once.
932 * In the worst-case, this would be
933 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
934 * = 36 bytes, plus any contribution from variable-length fields
935 * such as owner/group.
940 if (iap->ia_valid & ATTR_SIZE)
942 if (iap->ia_valid & ATTR_MODE)
944 if (iap->ia_valid & ATTR_UID) {
945 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
946 if (owner_namelen < 0) {
947 dprintk("nfs: couldn't resolve uid %d to string\n",
950 strcpy(owner_name, "nobody");
951 owner_namelen = sizeof("nobody") - 1;
954 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
956 if (iap->ia_valid & ATTR_GID) {
957 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
958 if (owner_grouplen < 0) {
959 dprintk("nfs: couldn't resolve gid %d to string\n",
961 strcpy(owner_group, "nobody");
962 owner_grouplen = sizeof("nobody") - 1;
965 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
967 if (iap->ia_valid & ATTR_ATIME_SET)
969 else if (iap->ia_valid & ATTR_ATIME)
971 if (iap->ia_valid & ATTR_MTIME_SET)
973 else if (iap->ia_valid & ATTR_MTIME)
975 p = reserve_space(xdr, len);
978 * We write the bitmap length now, but leave the bitmap and the attribute
979 * buffer length to be backfilled at the end of this routine.
981 *p++ = cpu_to_be32(2);
985 if (iap->ia_valid & ATTR_SIZE) {
986 bmval0 |= FATTR4_WORD0_SIZE;
987 p = xdr_encode_hyper(p, iap->ia_size);
989 if (iap->ia_valid & ATTR_MODE) {
990 bmval1 |= FATTR4_WORD1_MODE;
991 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
993 if (iap->ia_valid & ATTR_UID) {
994 bmval1 |= FATTR4_WORD1_OWNER;
995 p = xdr_encode_opaque(p, owner_name, owner_namelen);
997 if (iap->ia_valid & ATTR_GID) {
998 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
999 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1001 if (iap->ia_valid & ATTR_ATIME_SET) {
1002 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1003 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1004 *p++ = cpu_to_be32(0);
1005 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1006 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1008 else if (iap->ia_valid & ATTR_ATIME) {
1009 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1010 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1012 if (iap->ia_valid & ATTR_MTIME_SET) {
1013 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1014 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1015 *p++ = cpu_to_be32(0);
1016 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1017 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1019 else if (iap->ia_valid & ATTR_MTIME) {
1020 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1021 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1025 * Now we backfill the bitmap and the attribute buffer length.
1027 if (len != ((char *)p - (char *)q) + 4) {
1028 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
1029 len, ((char *)p - (char *)q) + 4);
1032 len = (char *)p - (char *)q - 12;
1033 *q++ = htonl(bmval0);
1034 *q++ = htonl(bmval1);
1040 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1044 p = reserve_space(xdr, 8);
1045 *p++ = cpu_to_be32(OP_ACCESS);
1046 *p = cpu_to_be32(access);
1048 hdr->replen += decode_access_maxsz;
1051 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1055 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1056 *p++ = cpu_to_be32(OP_CLOSE);
1057 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1058 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1060 hdr->replen += decode_close_maxsz;
1063 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1067 p = reserve_space(xdr, 16);
1068 *p++ = cpu_to_be32(OP_COMMIT);
1069 p = xdr_encode_hyper(p, args->offset);
1070 *p = cpu_to_be32(args->count);
1072 hdr->replen += decode_commit_maxsz;
1075 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1079 p = reserve_space(xdr, 8);
1080 *p++ = cpu_to_be32(OP_CREATE);
1081 *p = cpu_to_be32(create->ftype);
1083 switch (create->ftype) {
1085 p = reserve_space(xdr, 4);
1086 *p = cpu_to_be32(create->u.symlink.len);
1087 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1090 case NF4BLK: case NF4CHR:
1091 p = reserve_space(xdr, 8);
1092 *p++ = cpu_to_be32(create->u.device.specdata1);
1093 *p = cpu_to_be32(create->u.device.specdata2);
1100 encode_string(xdr, create->name->len, create->name->name);
1102 hdr->replen += decode_create_maxsz;
1104 encode_attrs(xdr, create->attrs, create->server);
1107 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1111 p = reserve_space(xdr, 12);
1112 *p++ = cpu_to_be32(OP_GETATTR);
1113 *p++ = cpu_to_be32(1);
1114 *p = cpu_to_be32(bitmap);
1116 hdr->replen += decode_getattr_maxsz;
1119 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1123 p = reserve_space(xdr, 16);
1124 *p++ = cpu_to_be32(OP_GETATTR);
1125 *p++ = cpu_to_be32(2);
1126 *p++ = cpu_to_be32(bm0);
1127 *p = cpu_to_be32(bm1);
1129 hdr->replen += decode_getattr_maxsz;
1133 encode_getattr_three(struct xdr_stream *xdr,
1134 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1135 struct compound_hdr *hdr)
1139 p = reserve_space(xdr, 4);
1140 *p = cpu_to_be32(OP_GETATTR);
1142 p = reserve_space(xdr, 16);
1143 *p++ = cpu_to_be32(3);
1144 *p++ = cpu_to_be32(bm0);
1145 *p++ = cpu_to_be32(bm1);
1146 *p = cpu_to_be32(bm2);
1148 p = reserve_space(xdr, 12);
1149 *p++ = cpu_to_be32(2);
1150 *p++ = cpu_to_be32(bm0);
1151 *p = cpu_to_be32(bm1);
1153 p = reserve_space(xdr, 8);
1154 *p++ = cpu_to_be32(1);
1155 *p = cpu_to_be32(bm0);
1158 hdr->replen += decode_getattr_maxsz;
1161 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1163 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1164 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1167 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1169 encode_getattr_three(xdr,
1170 bitmask[0] & nfs4_fsinfo_bitmap[0],
1171 bitmask[1] & nfs4_fsinfo_bitmap[1],
1172 bitmask[2] & nfs4_fsinfo_bitmap[2],
1176 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1178 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1179 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1182 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1186 p = reserve_space(xdr, 4);
1187 *p = cpu_to_be32(OP_GETFH);
1189 hdr->replen += decode_getfh_maxsz;
1192 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1196 p = reserve_space(xdr, 8 + name->len);
1197 *p++ = cpu_to_be32(OP_LINK);
1198 xdr_encode_opaque(p, name->name, name->len);
1200 hdr->replen += decode_link_maxsz;
1203 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1205 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1206 return block ? NFS4_READW_LT : NFS4_READ_LT;
1207 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1210 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1212 if (fl->fl_end == OFFSET_MAX)
1213 return ~(uint64_t)0;
1214 return fl->fl_end - fl->fl_start + 1;
1217 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1221 p = reserve_space(xdr, 32);
1222 p = xdr_encode_hyper(p, lowner->clientid);
1223 *p++ = cpu_to_be32(20);
1224 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1225 *p++ = cpu_to_be32(lowner->s_dev);
1226 xdr_encode_hyper(p, lowner->id);
1230 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1231 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1233 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1237 p = reserve_space(xdr, 32);
1238 *p++ = cpu_to_be32(OP_LOCK);
1239 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1240 *p++ = cpu_to_be32(args->reclaim);
1241 p = xdr_encode_hyper(p, args->fl->fl_start);
1242 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1243 *p = cpu_to_be32(args->new_lock_owner);
1244 if (args->new_lock_owner){
1245 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1246 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1247 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1248 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1249 encode_lockowner(xdr, &args->lock_owner);
1252 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1253 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1254 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1257 hdr->replen += decode_lock_maxsz;
1260 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1264 p = reserve_space(xdr, 24);
1265 *p++ = cpu_to_be32(OP_LOCKT);
1266 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1267 p = xdr_encode_hyper(p, args->fl->fl_start);
1268 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1269 encode_lockowner(xdr, &args->lock_owner);
1271 hdr->replen += decode_lockt_maxsz;
1274 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1278 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1279 *p++ = cpu_to_be32(OP_LOCKU);
1280 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1281 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1282 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1283 p = xdr_encode_hyper(p, args->fl->fl_start);
1284 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1286 hdr->replen += decode_locku_maxsz;
1289 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1293 p = reserve_space(xdr, 4);
1294 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1295 encode_lockowner(xdr, lowner);
1297 hdr->replen += decode_release_lockowner_maxsz;
1300 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1302 int len = name->len;
1305 p = reserve_space(xdr, 8 + len);
1306 *p++ = cpu_to_be32(OP_LOOKUP);
1307 xdr_encode_opaque(p, name->name, len);
1309 hdr->replen += decode_lookup_maxsz;
1312 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1316 p = reserve_space(xdr, 8);
1317 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1319 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1322 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1324 case FMODE_READ|FMODE_WRITE:
1325 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1328 *p++ = cpu_to_be32(0);
1330 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1333 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1337 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1340 p = reserve_space(xdr, 8);
1341 *p++ = cpu_to_be32(OP_OPEN);
1342 *p = cpu_to_be32(arg->seqid->sequence->counter);
1343 encode_share_access(xdr, arg->fmode);
1344 p = reserve_space(xdr, 32);
1345 p = xdr_encode_hyper(p, arg->clientid);
1346 *p++ = cpu_to_be32(20);
1347 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1348 *p++ = cpu_to_be32(arg->server->s_dev);
1349 xdr_encode_hyper(p, arg->id);
1352 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1355 struct nfs_client *clp;
1357 p = reserve_space(xdr, 4);
1358 switch(arg->open_flags & O_EXCL) {
1360 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1361 encode_attrs(xdr, arg->u.attrs, arg->server);
1364 clp = arg->server->nfs_client;
1365 if (clp->cl_mvops->minor_version > 0) {
1366 if (nfs4_has_persistent_session(clp)) {
1367 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1368 encode_attrs(xdr, arg->u.attrs, arg->server);
1372 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1373 encode_nfs4_verifier(xdr, &arg->u.verifier);
1375 encode_attrs(xdr, &dummy, arg->server);
1378 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1379 encode_nfs4_verifier(xdr, &arg->u.verifier);
1384 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1388 p = reserve_space(xdr, 4);
1389 switch (arg->open_flags & O_CREAT) {
1391 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1394 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1395 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1396 encode_createmode(xdr, arg);
1400 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1404 p = reserve_space(xdr, 4);
1405 switch (delegation_type) {
1407 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1410 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1412 case FMODE_WRITE|FMODE_READ:
1413 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1420 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1424 p = reserve_space(xdr, 4);
1425 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1426 encode_string(xdr, name->len, name->name);
1429 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1433 p = reserve_space(xdr, 4);
1434 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1435 encode_delegation_type(xdr, type);
1438 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1442 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1443 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1444 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1445 encode_string(xdr, name->len, name->name);
1448 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1450 encode_openhdr(xdr, arg);
1451 encode_opentype(xdr, arg);
1452 switch (arg->claim) {
1453 case NFS4_OPEN_CLAIM_NULL:
1454 encode_claim_null(xdr, arg->name);
1456 case NFS4_OPEN_CLAIM_PREVIOUS:
1457 encode_claim_previous(xdr, arg->u.delegation_type);
1459 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1460 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1466 hdr->replen += decode_open_maxsz;
1469 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1473 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1474 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1475 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1476 *p = cpu_to_be32(arg->seqid->sequence->counter);
1478 hdr->replen += decode_open_confirm_maxsz;
1481 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1485 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1486 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1487 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1488 *p = cpu_to_be32(arg->seqid->sequence->counter);
1489 encode_share_access(xdr, arg->fmode);
1491 hdr->replen += decode_open_downgrade_maxsz;
1495 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1500 p = reserve_space(xdr, 8 + len);
1501 *p++ = cpu_to_be32(OP_PUTFH);
1502 xdr_encode_opaque(p, fh->data, len);
1504 hdr->replen += decode_putfh_maxsz;
1507 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(OP_PUTROOTFH);
1514 hdr->replen += decode_putrootfh_maxsz;
1517 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
1519 nfs4_stateid stateid;
1522 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1523 if (ctx->state != NULL) {
1524 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1526 stateid.stateid.seqid = 0;
1527 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1529 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1532 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1536 p = reserve_space(xdr, 4);
1537 *p = cpu_to_be32(OP_READ);
1539 encode_stateid(xdr, args->context, args->lock_context,
1542 p = reserve_space(xdr, 12);
1543 p = xdr_encode_hyper(p, args->offset);
1544 *p = cpu_to_be32(args->count);
1546 hdr->replen += decode_read_maxsz;
1549 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1551 uint32_t attrs[2] = {
1552 FATTR4_WORD0_RDATTR_ERROR,
1553 FATTR4_WORD1_MOUNTED_ON_FILEID,
1555 uint32_t dircount = readdir->count >> 1;
1558 if (readdir->plus) {
1559 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1560 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1561 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1562 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1563 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1564 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1567 /* Use mounted_on_fileid only if the server supports it */
1568 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1569 attrs[0] |= FATTR4_WORD0_FILEID;
1571 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1572 *p++ = cpu_to_be32(OP_READDIR);
1573 p = xdr_encode_hyper(p, readdir->cookie);
1574 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1575 *p++ = cpu_to_be32(dircount);
1576 *p++ = cpu_to_be32(readdir->count);
1577 *p++ = cpu_to_be32(2);
1579 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1580 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1582 hdr->replen += decode_readdir_maxsz;
1583 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1585 (unsigned long long)readdir->cookie,
1586 ((u32 *)readdir->verifier.data)[0],
1587 ((u32 *)readdir->verifier.data)[1],
1588 attrs[0] & readdir->bitmask[0],
1589 attrs[1] & readdir->bitmask[1]);
1592 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1596 p = reserve_space(xdr, 4);
1597 *p = cpu_to_be32(OP_READLINK);
1599 hdr->replen += decode_readlink_maxsz;
1602 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1606 p = reserve_space(xdr, 8 + name->len);
1607 *p++ = cpu_to_be32(OP_REMOVE);
1608 xdr_encode_opaque(p, name->name, name->len);
1610 hdr->replen += decode_remove_maxsz;
1613 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1617 p = reserve_space(xdr, 4);
1618 *p = cpu_to_be32(OP_RENAME);
1619 encode_string(xdr, oldname->len, oldname->name);
1620 encode_string(xdr, newname->len, newname->name);
1622 hdr->replen += decode_rename_maxsz;
1625 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1629 p = reserve_space(xdr, 12);
1630 *p++ = cpu_to_be32(OP_RENEW);
1631 xdr_encode_hyper(p, client_stateid->cl_clientid);
1633 hdr->replen += decode_renew_maxsz;
1637 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1641 p = reserve_space(xdr, 4);
1642 *p = cpu_to_be32(OP_RESTOREFH);
1644 hdr->replen += decode_restorefh_maxsz;
1648 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1652 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1653 *p++ = cpu_to_be32(OP_SETATTR);
1654 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1655 p = reserve_space(xdr, 2*4);
1656 *p++ = cpu_to_be32(1);
1657 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1658 BUG_ON(arg->acl_len % 4);
1659 p = reserve_space(xdr, 4);
1660 *p = cpu_to_be32(arg->acl_len);
1661 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1663 hdr->replen += decode_setacl_maxsz;
1667 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1671 p = reserve_space(xdr, 4);
1672 *p = cpu_to_be32(OP_SAVEFH);
1674 hdr->replen += decode_savefh_maxsz;
1677 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1681 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1682 *p++ = cpu_to_be32(OP_SETATTR);
1683 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1685 hdr->replen += decode_setattr_maxsz;
1686 encode_attrs(xdr, arg->iap, server);
1689 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1693 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1694 *p++ = cpu_to_be32(OP_SETCLIENTID);
1695 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1697 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1698 p = reserve_space(xdr, 4);
1699 *p = cpu_to_be32(setclientid->sc_prog);
1700 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1701 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1702 p = reserve_space(xdr, 4);
1703 *p = cpu_to_be32(setclientid->sc_cb_ident);
1705 hdr->replen += decode_setclientid_maxsz;
1708 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1712 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1713 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1714 p = xdr_encode_hyper(p, arg->clientid);
1715 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1717 hdr->replen += decode_setclientid_confirm_maxsz;
1720 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1724 p = reserve_space(xdr, 4);
1725 *p = cpu_to_be32(OP_WRITE);
1727 encode_stateid(xdr, args->context, args->lock_context,
1730 p = reserve_space(xdr, 16);
1731 p = xdr_encode_hyper(p, args->offset);
1732 *p++ = cpu_to_be32(args->stable);
1733 *p = cpu_to_be32(args->count);
1735 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1737 hdr->replen += decode_write_maxsz;
1740 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1744 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1746 *p++ = cpu_to_be32(OP_DELEGRETURN);
1747 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1749 hdr->replen += decode_delegreturn_maxsz;
1752 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1754 int len = name->len;
1757 p = reserve_space(xdr, 8 + len);
1758 *p++ = cpu_to_be32(OP_SECINFO);
1759 xdr_encode_opaque(p, name->name, len);
1761 hdr->replen += decode_secinfo_maxsz;
1764 #if defined(CONFIG_NFS_V4_1)
1765 /* NFSv4.1 operations */
1766 static void encode_exchange_id(struct xdr_stream *xdr,
1767 struct nfs41_exchange_id_args *args,
1768 struct compound_hdr *hdr)
1772 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1773 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1774 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1776 encode_string(xdr, args->id_len, args->id);
1778 p = reserve_space(xdr, 12);
1779 *p++ = cpu_to_be32(args->flags);
1780 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1781 *p = cpu_to_be32(0); /* zero length implementation id array */
1783 hdr->replen += decode_exchange_id_maxsz;
1786 static void encode_create_session(struct xdr_stream *xdr,
1787 struct nfs41_create_session_args *args,
1788 struct compound_hdr *hdr)
1791 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1793 struct nfs_client *clp = args->client;
1794 u32 max_resp_sz_cached;
1797 * Assumes OPEN is the biggest non-idempotent compound.
1798 * 2 is the verifier.
1800 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1801 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1803 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1806 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1807 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1808 p = xdr_encode_hyper(p, clp->cl_clientid);
1809 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1810 *p++ = cpu_to_be32(args->flags); /*flags */
1813 *p++ = cpu_to_be32(0); /* header padding size */
1814 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1815 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1816 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1817 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1818 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1819 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1822 *p++ = cpu_to_be32(0); /* header padding size */
1823 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1824 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1825 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1826 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1827 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1828 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1830 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1831 *p++ = cpu_to_be32(1);
1832 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1834 /* authsys_parms rfc1831 */
1835 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1836 p = xdr_encode_opaque(p, machine_name, len);
1837 *p++ = cpu_to_be32(0); /* UID */
1838 *p++ = cpu_to_be32(0); /* GID */
1839 *p = cpu_to_be32(0); /* No more gids */
1841 hdr->replen += decode_create_session_maxsz;
1844 static void encode_destroy_session(struct xdr_stream *xdr,
1845 struct nfs4_session *session,
1846 struct compound_hdr *hdr)
1849 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1850 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1851 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1853 hdr->replen += decode_destroy_session_maxsz;
1856 static void encode_reclaim_complete(struct xdr_stream *xdr,
1857 struct nfs41_reclaim_complete_args *args,
1858 struct compound_hdr *hdr)
1862 p = reserve_space(xdr, 8);
1863 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1864 *p++ = cpu_to_be32(args->one_fs);
1866 hdr->replen += decode_reclaim_complete_maxsz;
1868 #endif /* CONFIG_NFS_V4_1 */
1870 static void encode_sequence(struct xdr_stream *xdr,
1871 const struct nfs4_sequence_args *args,
1872 struct compound_hdr *hdr)
1874 #if defined(CONFIG_NFS_V4_1)
1875 struct nfs4_session *session = args->sa_session;
1876 struct nfs4_slot_table *tp;
1877 struct nfs4_slot *slot;
1883 tp = &session->fc_slot_table;
1885 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1886 slot = tp->slots + args->sa_slotid;
1888 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1889 *p++ = cpu_to_be32(OP_SEQUENCE);
1892 * Sessionid + seqid + slotid + max slotid + cache_this
1894 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1895 "max_slotid=%d cache_this=%d\n",
1897 ((u32 *)session->sess_id.data)[0],
1898 ((u32 *)session->sess_id.data)[1],
1899 ((u32 *)session->sess_id.data)[2],
1900 ((u32 *)session->sess_id.data)[3],
1901 slot->seq_nr, args->sa_slotid,
1902 tp->highest_used_slotid, args->sa_cache_this);
1903 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1904 *p++ = cpu_to_be32(slot->seq_nr);
1905 *p++ = cpu_to_be32(args->sa_slotid);
1906 *p++ = cpu_to_be32(tp->highest_used_slotid);
1907 *p = cpu_to_be32(args->sa_cache_this);
1909 hdr->replen += decode_sequence_maxsz;
1910 #endif /* CONFIG_NFS_V4_1 */
1913 #ifdef CONFIG_NFS_V4_1
1915 encode_getdevicelist(struct xdr_stream *xdr,
1916 const struct nfs4_getdevicelist_args *args,
1917 struct compound_hdr *hdr)
1920 nfs4_verifier dummy = {
1924 p = reserve_space(xdr, 20);
1925 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1926 *p++ = cpu_to_be32(args->layoutclass);
1927 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1928 xdr_encode_hyper(p, 0ULL); /* cookie */
1929 encode_nfs4_verifier(xdr, &dummy);
1931 hdr->replen += decode_getdevicelist_maxsz;
1935 encode_getdeviceinfo(struct xdr_stream *xdr,
1936 const struct nfs4_getdeviceinfo_args *args,
1937 struct compound_hdr *hdr)
1941 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1942 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1943 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1944 NFS4_DEVICEID4_SIZE);
1945 *p++ = cpu_to_be32(args->pdev->layout_type);
1946 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1947 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1949 hdr->replen += decode_getdeviceinfo_maxsz;
1953 encode_layoutget(struct xdr_stream *xdr,
1954 const struct nfs4_layoutget_args *args,
1955 struct compound_hdr *hdr)
1959 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1960 *p++ = cpu_to_be32(OP_LAYOUTGET);
1961 *p++ = cpu_to_be32(0); /* Signal layout available */
1962 *p++ = cpu_to_be32(args->type);
1963 *p++ = cpu_to_be32(args->range.iomode);
1964 p = xdr_encode_hyper(p, args->range.offset);
1965 p = xdr_encode_hyper(p, args->range.length);
1966 p = xdr_encode_hyper(p, args->minlength);
1967 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1968 *p = cpu_to_be32(args->maxcount);
1970 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1974 (unsigned long)args->range.offset,
1975 (unsigned long)args->range.length,
1978 hdr->replen += decode_layoutget_maxsz;
1982 encode_layoutcommit(struct xdr_stream *xdr,
1983 struct inode *inode,
1984 const struct nfs4_layoutcommit_args *args,
1985 struct compound_hdr *hdr)
1989 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1990 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1992 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1993 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1994 /* Only whole file layouts */
1995 p = xdr_encode_hyper(p, 0); /* offset */
1996 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1997 *p++ = cpu_to_be32(0); /* reclaim */
1998 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1999 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2000 p = xdr_encode_hyper(p, args->lastbytewritten);
2001 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2002 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2004 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2005 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2006 NFS_I(inode)->layout, xdr, args);
2008 p = reserve_space(xdr, 4);
2009 *p = cpu_to_be32(0); /* no layout-type payload */
2013 hdr->replen += decode_layoutcommit_maxsz;
2018 encode_layoutreturn(struct xdr_stream *xdr,
2019 const struct nfs4_layoutreturn_args *args,
2020 struct compound_hdr *hdr)
2024 p = reserve_space(xdr, 20);
2025 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2026 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2027 *p++ = cpu_to_be32(args->layout_type);
2028 *p++ = cpu_to_be32(IOMODE_ANY);
2029 *p = cpu_to_be32(RETURN_FILE);
2030 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2031 p = xdr_encode_hyper(p, 0);
2032 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2033 spin_lock(&args->inode->i_lock);
2034 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2035 spin_unlock(&args->inode->i_lock);
2036 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2037 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2038 NFS_I(args->inode)->layout, xdr, args);
2040 p = reserve_space(xdr, 4);
2041 *p = cpu_to_be32(0);
2044 hdr->replen += decode_layoutreturn_maxsz;
2048 encode_secinfo_no_name(struct xdr_stream *xdr,
2049 const struct nfs41_secinfo_no_name_args *args,
2050 struct compound_hdr *hdr)
2053 p = reserve_space(xdr, 8);
2054 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2055 *p++ = cpu_to_be32(args->style);
2057 hdr->replen += decode_secinfo_no_name_maxsz;
2061 static void encode_test_stateid(struct xdr_stream *xdr,
2062 struct nfs41_test_stateid_args *args,
2063 struct compound_hdr *hdr)
2067 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2068 *p++ = cpu_to_be32(OP_TEST_STATEID);
2069 *p++ = cpu_to_be32(1);
2070 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2072 hdr->replen += decode_test_stateid_maxsz;
2075 static void encode_free_stateid(struct xdr_stream *xdr,
2076 struct nfs41_free_stateid_args *args,
2077 struct compound_hdr *hdr)
2080 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2081 *p++ = cpu_to_be32(OP_FREE_STATEID);
2082 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2084 hdr->replen += decode_free_stateid_maxsz;
2086 #endif /* CONFIG_NFS_V4_1 */
2089 * END OF "GENERIC" ENCODE ROUTINES.
2092 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2094 #if defined(CONFIG_NFS_V4_1)
2095 if (args->sa_session)
2096 return args->sa_session->clp->cl_mvops->minor_version;
2097 #endif /* CONFIG_NFS_V4_1 */
2102 * Encode an ACCESS request
2104 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2105 const struct nfs4_accessargs *args)
2107 struct compound_hdr hdr = {
2108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putfh(xdr, args->fh, &hdr);
2114 encode_access(xdr, args->access, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
2120 * Encode LOOKUP request
2122 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2123 const struct nfs4_lookup_arg *args)
2125 struct compound_hdr hdr = {
2126 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2129 encode_compound_hdr(xdr, req, &hdr);
2130 encode_sequence(xdr, &args->seq_args, &hdr);
2131 encode_putfh(xdr, args->dir_fh, &hdr);
2132 encode_lookup(xdr, args->name, &hdr);
2133 encode_getfh(xdr, &hdr);
2134 encode_getfattr(xdr, args->bitmask, &hdr);
2139 * Encode LOOKUP_ROOT request
2141 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2142 struct xdr_stream *xdr,
2143 const struct nfs4_lookup_root_arg *args)
2145 struct compound_hdr hdr = {
2146 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2149 encode_compound_hdr(xdr, req, &hdr);
2150 encode_sequence(xdr, &args->seq_args, &hdr);
2151 encode_putrootfh(xdr, &hdr);
2152 encode_getfh(xdr, &hdr);
2153 encode_getfattr(xdr, args->bitmask, &hdr);
2158 * Encode REMOVE request
2160 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2161 const struct nfs_removeargs *args)
2163 struct compound_hdr hdr = {
2164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2167 encode_compound_hdr(xdr, req, &hdr);
2168 encode_sequence(xdr, &args->seq_args, &hdr);
2169 encode_putfh(xdr, args->fh, &hdr);
2170 encode_remove(xdr, &args->name, &hdr);
2171 encode_getfattr(xdr, args->bitmask, &hdr);
2176 * Encode RENAME request
2178 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 const struct nfs_renameargs *args)
2181 struct compound_hdr hdr = {
2182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->old_dir, &hdr);
2188 encode_savefh(xdr, &hdr);
2189 encode_putfh(xdr, args->new_dir, &hdr);
2190 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
2192 encode_restorefh(xdr, &hdr);
2193 encode_getfattr(xdr, args->bitmask, &hdr);
2198 * Encode LINK request
2200 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2201 const struct nfs4_link_arg *args)
2203 struct compound_hdr hdr = {
2204 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2207 encode_compound_hdr(xdr, req, &hdr);
2208 encode_sequence(xdr, &args->seq_args, &hdr);
2209 encode_putfh(xdr, args->fh, &hdr);
2210 encode_savefh(xdr, &hdr);
2211 encode_putfh(xdr, args->dir_fh, &hdr);
2212 encode_link(xdr, args->name, &hdr);
2213 encode_getfattr(xdr, args->bitmask, &hdr);
2214 encode_restorefh(xdr, &hdr);
2215 encode_getfattr(xdr, args->bitmask, &hdr);
2220 * Encode CREATE request
2222 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2223 const struct nfs4_create_arg *args)
2225 struct compound_hdr hdr = {
2226 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2229 encode_compound_hdr(xdr, req, &hdr);
2230 encode_sequence(xdr, &args->seq_args, &hdr);
2231 encode_putfh(xdr, args->dir_fh, &hdr);
2232 encode_savefh(xdr, &hdr);
2233 encode_create(xdr, args, &hdr);
2234 encode_getfh(xdr, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
2236 encode_restorefh(xdr, &hdr);
2237 encode_getfattr(xdr, args->bitmask, &hdr);
2242 * Encode SYMLINK request
2244 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2245 const struct nfs4_create_arg *args)
2247 nfs4_xdr_enc_create(req, xdr, args);
2251 * Encode GETATTR request
2253 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2254 const struct nfs4_getattr_arg *args)
2256 struct compound_hdr hdr = {
2257 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2260 encode_compound_hdr(xdr, req, &hdr);
2261 encode_sequence(xdr, &args->seq_args, &hdr);
2262 encode_putfh(xdr, args->fh, &hdr);
2263 encode_getfattr(xdr, args->bitmask, &hdr);
2268 * Encode a CLOSE request
2270 static void nfs4_xdr_enc_close(struct rpc_rqst *req, 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_close(xdr, args, &hdr);
2281 encode_getfattr(xdr, args->bitmask, &hdr);
2286 * Encode an OPEN request
2288 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2289 struct nfs_openargs *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_savefh(xdr, &hdr);
2299 encode_open(xdr, args, &hdr);
2300 encode_getfh(xdr, &hdr);
2301 encode_getfattr(xdr, args->bitmask, &hdr);
2302 encode_restorefh(xdr, &hdr);
2303 encode_getfattr(xdr, args->bitmask, &hdr);
2308 * Encode an OPEN_CONFIRM request
2310 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2311 struct xdr_stream *xdr,
2312 struct nfs_open_confirmargs *args)
2314 struct compound_hdr hdr = {
2318 encode_compound_hdr(xdr, req, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_open_confirm(xdr, args, &hdr);
2325 * Encode an OPEN request with no attributes.
2327 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2328 struct xdr_stream *xdr,
2329 struct nfs_openargs *args)
2331 struct compound_hdr hdr = {
2332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
2338 encode_open(xdr, args, &hdr);
2339 encode_getfattr(xdr, args->bitmask, &hdr);
2344 * Encode an OPEN_DOWNGRADE request
2346 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2347 struct xdr_stream *xdr,
2348 struct nfs_closeargs *args)
2350 struct compound_hdr hdr = {
2351 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2354 encode_compound_hdr(xdr, req, &hdr);
2355 encode_sequence(xdr, &args->seq_args, &hdr);
2356 encode_putfh(xdr, args->fh, &hdr);
2357 encode_open_downgrade(xdr, args, &hdr);
2358 encode_getfattr(xdr, args->bitmask, &hdr);
2363 * Encode a LOCK request
2365 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2366 struct nfs_lock_args *args)
2368 struct compound_hdr hdr = {
2369 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2372 encode_compound_hdr(xdr, req, &hdr);
2373 encode_sequence(xdr, &args->seq_args, &hdr);
2374 encode_putfh(xdr, args->fh, &hdr);
2375 encode_lock(xdr, args, &hdr);
2380 * Encode a LOCKT request
2382 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2383 struct nfs_lockt_args *args)
2385 struct compound_hdr hdr = {
2386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2389 encode_compound_hdr(xdr, req, &hdr);
2390 encode_sequence(xdr, &args->seq_args, &hdr);
2391 encode_putfh(xdr, args->fh, &hdr);
2392 encode_lockt(xdr, args, &hdr);
2397 * Encode a LOCKU request
2399 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2400 struct nfs_locku_args *args)
2402 struct compound_hdr hdr = {
2403 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2406 encode_compound_hdr(xdr, req, &hdr);
2407 encode_sequence(xdr, &args->seq_args, &hdr);
2408 encode_putfh(xdr, args->fh, &hdr);
2409 encode_locku(xdr, args, &hdr);
2413 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2414 struct xdr_stream *xdr,
2415 struct nfs_release_lockowner_args *args)
2417 struct compound_hdr hdr = {
2421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2427 * Encode a READLINK request
2429 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2430 const struct nfs4_readlink *args)
2432 struct compound_hdr hdr = {
2433 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2436 encode_compound_hdr(xdr, req, &hdr);
2437 encode_sequence(xdr, &args->seq_args, &hdr);
2438 encode_putfh(xdr, args->fh, &hdr);
2439 encode_readlink(xdr, args, req, &hdr);
2441 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2442 args->pgbase, args->pglen);
2447 * Encode a READDIR request
2449 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2450 const struct nfs4_readdir_arg *args)
2452 struct compound_hdr hdr = {
2453 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2456 encode_compound_hdr(xdr, req, &hdr);
2457 encode_sequence(xdr, &args->seq_args, &hdr);
2458 encode_putfh(xdr, args->fh, &hdr);
2459 encode_readdir(xdr, args, req, &hdr);
2461 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2462 args->pgbase, args->count);
2463 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2464 __func__, hdr.replen << 2, args->pages,
2465 args->pgbase, args->count);
2470 * Encode a READ request
2472 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2473 struct nfs_readargs *args)
2475 struct compound_hdr hdr = {
2476 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2479 encode_compound_hdr(xdr, req, &hdr);
2480 encode_sequence(xdr, &args->seq_args, &hdr);
2481 encode_putfh(xdr, args->fh, &hdr);
2482 encode_read(xdr, args, &hdr);
2484 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2485 args->pages, args->pgbase, args->count);
2486 req->rq_rcv_buf.flags |= XDRBUF_READ;
2491 * Encode an SETATTR request
2493 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2494 struct nfs_setattrargs *args)
2496 struct compound_hdr hdr = {
2497 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2500 encode_compound_hdr(xdr, req, &hdr);
2501 encode_sequence(xdr, &args->seq_args, &hdr);
2502 encode_putfh(xdr, args->fh, &hdr);
2503 encode_setattr(xdr, args, args->server, &hdr);
2504 encode_getfattr(xdr, args->bitmask, &hdr);
2509 * Encode a GETACL request
2511 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2512 struct nfs_getaclargs *args)
2514 struct compound_hdr hdr = {
2515 .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 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2523 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2525 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2526 args->acl_pages, args->acl_pgbase, args->acl_len);
2532 * Encode a WRITE request
2534 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2535 struct nfs_writeargs *args)
2537 struct compound_hdr hdr = {
2538 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2541 encode_compound_hdr(xdr, req, &hdr);
2542 encode_sequence(xdr, &args->seq_args, &hdr);
2543 encode_putfh(xdr, args->fh, &hdr);
2544 encode_write(xdr, args, &hdr);
2545 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2547 encode_getfattr(xdr, args->bitmask, &hdr);
2554 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2555 struct nfs_writeargs *args)
2557 struct compound_hdr hdr = {
2558 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2561 encode_compound_hdr(xdr, req, &hdr);
2562 encode_sequence(xdr, &args->seq_args, &hdr);
2563 encode_putfh(xdr, args->fh, &hdr);
2564 encode_commit(xdr, args, &hdr);
2566 encode_getfattr(xdr, args->bitmask, &hdr);
2573 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 struct nfs4_fsinfo_arg *args)
2576 struct compound_hdr hdr = {
2577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_fsinfo(xdr, args->bitmask, &hdr);
2588 * a PATHCONF request
2590 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2591 const struct nfs4_pathconf_arg *args)
2593 struct compound_hdr hdr = {
2594 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2597 encode_compound_hdr(xdr, req, &hdr);
2598 encode_sequence(xdr, &args->seq_args, &hdr);
2599 encode_putfh(xdr, args->fh, &hdr);
2600 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2608 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2609 const struct nfs4_statfs_arg *args)
2611 struct compound_hdr hdr = {
2612 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2615 encode_compound_hdr(xdr, req, &hdr);
2616 encode_sequence(xdr, &args->seq_args, &hdr);
2617 encode_putfh(xdr, args->fh, &hdr);
2618 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2619 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2624 * GETATTR_BITMAP request
2626 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2627 struct xdr_stream *xdr,
2628 struct nfs4_server_caps_arg *args)
2630 struct compound_hdr hdr = {
2631 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2634 encode_compound_hdr(xdr, req, &hdr);
2635 encode_sequence(xdr, &args->seq_args, &hdr);
2636 encode_putfh(xdr, args->fhandle, &hdr);
2637 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2638 FATTR4_WORD0_LINK_SUPPORT|
2639 FATTR4_WORD0_SYMLINK_SUPPORT|
2640 FATTR4_WORD0_ACLSUPPORT, &hdr);
2647 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2648 struct nfs_client *clp)
2650 struct compound_hdr hdr = {
2654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_renew(xdr, clp, &hdr);
2660 * a SETCLIENTID request
2662 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2663 struct xdr_stream *xdr,
2664 struct nfs4_setclientid *sc)
2666 struct compound_hdr hdr = {
2670 encode_compound_hdr(xdr, req, &hdr);
2671 encode_setclientid(xdr, sc, &hdr);
2676 * a SETCLIENTID_CONFIRM request
2678 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2679 struct xdr_stream *xdr,
2680 struct nfs4_setclientid_res *arg)
2682 struct compound_hdr hdr = {
2685 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2687 encode_compound_hdr(xdr, req, &hdr);
2688 encode_setclientid_confirm(xdr, arg, &hdr);
2689 encode_putrootfh(xdr, &hdr);
2690 encode_fsinfo(xdr, lease_bitmap, &hdr);
2695 * DELEGRETURN request
2697 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2698 struct xdr_stream *xdr,
2699 const struct nfs4_delegreturnargs *args)
2701 struct compound_hdr hdr = {
2702 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2705 encode_compound_hdr(xdr, req, &hdr);
2706 encode_sequence(xdr, &args->seq_args, &hdr);
2707 encode_putfh(xdr, args->fhandle, &hdr);
2708 encode_delegreturn(xdr, args->stateid, &hdr);
2709 encode_getfattr(xdr, args->bitmask, &hdr);
2714 * Encode FS_LOCATIONS request
2716 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2717 struct xdr_stream *xdr,
2718 struct nfs4_fs_locations_arg *args)
2720 struct compound_hdr hdr = {
2721 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_sequence(xdr, &args->seq_args, &hdr);
2727 encode_putfh(xdr, args->dir_fh, &hdr);
2728 encode_lookup(xdr, args->name, &hdr);
2729 replen = hdr.replen; /* get the attribute into args->page */
2730 encode_fs_locations(xdr, args->bitmask, &hdr);
2732 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2738 * Encode SECINFO request
2740 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2741 struct xdr_stream *xdr,
2742 struct nfs4_secinfo_arg *args)
2744 struct compound_hdr hdr = {
2745 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2748 encode_compound_hdr(xdr, req, &hdr);
2749 encode_sequence(xdr, &args->seq_args, &hdr);
2750 encode_putfh(xdr, args->dir_fh, &hdr);
2751 encode_secinfo(xdr, args->name, &hdr);
2755 #if defined(CONFIG_NFS_V4_1)
2757 * EXCHANGE_ID request
2759 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2760 struct xdr_stream *xdr,
2761 struct nfs41_exchange_id_args *args)
2763 struct compound_hdr hdr = {
2764 .minorversion = args->client->cl_mvops->minor_version,
2767 encode_compound_hdr(xdr, req, &hdr);
2768 encode_exchange_id(xdr, args, &hdr);
2773 * a CREATE_SESSION request
2775 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2776 struct xdr_stream *xdr,
2777 struct nfs41_create_session_args *args)
2779 struct compound_hdr hdr = {
2780 .minorversion = args->client->cl_mvops->minor_version,
2783 encode_compound_hdr(xdr, req, &hdr);
2784 encode_create_session(xdr, args, &hdr);
2789 * a DESTROY_SESSION request
2791 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2792 struct xdr_stream *xdr,
2793 struct nfs4_session *session)
2795 struct compound_hdr hdr = {
2796 .minorversion = session->clp->cl_mvops->minor_version,
2799 encode_compound_hdr(xdr, req, &hdr);
2800 encode_destroy_session(xdr, session, &hdr);
2805 * a SEQUENCE request
2807 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2808 struct nfs4_sequence_args *args)
2810 struct compound_hdr hdr = {
2811 .minorversion = nfs4_xdr_minorversion(args),
2814 encode_compound_hdr(xdr, req, &hdr);
2815 encode_sequence(xdr, args, &hdr);
2820 * a GET_LEASE_TIME request
2822 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2823 struct xdr_stream *xdr,
2824 struct nfs4_get_lease_time_args *args)
2826 struct compound_hdr hdr = {
2827 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2829 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2831 encode_compound_hdr(xdr, req, &hdr);
2832 encode_sequence(xdr, &args->la_seq_args, &hdr);
2833 encode_putrootfh(xdr, &hdr);
2834 encode_fsinfo(xdr, lease_bitmap, &hdr);
2839 * a RECLAIM_COMPLETE request
2841 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
2843 struct nfs41_reclaim_complete_args *args)
2845 struct compound_hdr hdr = {
2846 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2849 encode_compound_hdr(xdr, req, &hdr);
2850 encode_sequence(xdr, &args->seq_args, &hdr);
2851 encode_reclaim_complete(xdr, args, &hdr);
2856 * Encode GETDEVICELIST request
2858 static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2859 struct xdr_stream *xdr,
2860 struct nfs4_getdevicelist_args *args)
2862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, &args->seq_args, &hdr);
2868 encode_putfh(xdr, args->fh, &hdr);
2869 encode_getdevicelist(xdr, args, &hdr);
2874 * Encode GETDEVICEINFO request
2876 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2877 struct xdr_stream *xdr,
2878 struct nfs4_getdeviceinfo_args *args)
2880 struct compound_hdr hdr = {
2881 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2884 encode_compound_hdr(xdr, req, &hdr);
2885 encode_sequence(xdr, &args->seq_args, &hdr);
2886 encode_getdeviceinfo(xdr, args, &hdr);
2888 /* set up reply kvec. Subtract notification bitmap max size (2)
2889 * so that notification bitmap is put in xdr_buf tail */
2890 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2891 args->pdev->pages, args->pdev->pgbase,
2898 * Encode LAYOUTGET request
2900 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2901 struct xdr_stream *xdr,
2902 struct nfs4_layoutget_args *args)
2904 struct compound_hdr hdr = {
2905 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2908 encode_compound_hdr(xdr, req, &hdr);
2909 encode_sequence(xdr, &args->seq_args, &hdr);
2910 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2911 encode_layoutget(xdr, args, &hdr);
2913 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2914 args->layout.pages, 0, args->layout.pglen);
2920 * Encode LAYOUTCOMMIT request
2922 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2923 struct xdr_stream *xdr,
2924 struct nfs4_layoutcommit_args *args)
2926 struct nfs4_layoutcommit_data *data =
2927 container_of(args, struct nfs4_layoutcommit_data, args);
2928 struct compound_hdr hdr = {
2929 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2932 encode_compound_hdr(xdr, req, &hdr);
2933 encode_sequence(xdr, &args->seq_args, &hdr);
2934 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2935 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2936 encode_getfattr(xdr, args->bitmask, &hdr);
2941 * Encode LAYOUTRETURN request
2943 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2944 struct xdr_stream *xdr,
2945 struct nfs4_layoutreturn_args *args)
2947 struct compound_hdr hdr = {
2948 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2951 encode_compound_hdr(xdr, req, &hdr);
2952 encode_sequence(xdr, &args->seq_args, &hdr);
2953 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2954 encode_layoutreturn(xdr, args, &hdr);
2959 * Encode SECINFO_NO_NAME request
2961 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2962 struct xdr_stream *xdr,
2963 struct nfs41_secinfo_no_name_args *args)
2965 struct compound_hdr hdr = {
2966 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2969 encode_compound_hdr(xdr, req, &hdr);
2970 encode_sequence(xdr, &args->seq_args, &hdr);
2971 encode_putrootfh(xdr, &hdr);
2972 encode_secinfo_no_name(xdr, args, &hdr);
2978 * Encode TEST_STATEID request
2980 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2981 struct xdr_stream *xdr,
2982 struct nfs41_test_stateid_args *args)
2984 struct compound_hdr hdr = {
2985 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2988 encode_compound_hdr(xdr, req, &hdr);
2989 encode_sequence(xdr, &args->seq_args, &hdr);
2990 encode_test_stateid(xdr, args, &hdr);
2995 * Encode FREE_STATEID request
2997 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2998 struct xdr_stream *xdr,
2999 struct nfs41_free_stateid_args *args)
3001 struct compound_hdr hdr = {
3002 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3005 encode_compound_hdr(xdr, req, &hdr);
3006 encode_sequence(xdr, &args->seq_args, &hdr);
3007 encode_free_stateid(xdr, args, &hdr);
3010 #endif /* CONFIG_NFS_V4_1 */
3012 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3014 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3015 "Remaining buffer length is %tu words.\n",
3016 func, xdr->end - xdr->p);
3019 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3023 p = xdr_inline_decode(xdr, 4);
3026 *len = be32_to_cpup(p);
3027 p = xdr_inline_decode(xdr, *len);
3030 *string = (char *)p;
3033 print_overflow_msg(__func__, xdr);
3037 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3041 p = xdr_inline_decode(xdr, 8);
3044 hdr->status = be32_to_cpup(p++);
3045 hdr->taglen = be32_to_cpup(p);
3047 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3050 hdr->tag = (char *)p;
3051 p += XDR_QUADLEN(hdr->taglen);
3052 hdr->nops = be32_to_cpup(p);
3053 if (unlikely(hdr->nops < 1))
3054 return nfs4_stat_to_errno(hdr->status);
3057 print_overflow_msg(__func__, xdr);
3061 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3068 p = xdr_inline_decode(xdr, 8);
3071 opnum = be32_to_cpup(p++);
3072 if (unlikely(opnum != expected))
3073 goto out_bad_operation;
3074 nfserr = be32_to_cpup(p);
3075 if (nfserr == NFS_OK)
3078 *nfs_retval = nfs4_stat_to_errno(nfserr);
3081 dprintk("nfs: Server returned operation"
3082 " %d but we issued a request for %d\n",
3084 *nfs_retval = -EREMOTEIO;
3087 print_overflow_msg(__func__, xdr);
3092 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3096 __decode_op_hdr(xdr, expected, &retval);
3101 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3104 unsigned int strlen;
3107 p = xdr_inline_decode(xdr, 12);
3109 return decode_opaque_inline(xdr, &strlen, &str);
3110 print_overflow_msg(__func__, xdr);
3114 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)