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 #else /* CONFIG_NFS_V4_1 */
349 #define encode_sequence_maxsz 0
350 #define decode_sequence_maxsz 0
351 #endif /* CONFIG_NFS_V4_1 */
353 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
354 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
355 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
356 encode_sequence_maxsz + \
357 encode_putfh_maxsz + \
359 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
360 decode_sequence_maxsz + \
361 decode_putfh_maxsz + \
363 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
364 encode_sequence_maxsz + \
365 encode_putfh_maxsz + \
366 encode_readlink_maxsz)
367 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
368 decode_sequence_maxsz + \
369 decode_putfh_maxsz + \
370 decode_readlink_maxsz)
371 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
372 encode_sequence_maxsz + \
373 encode_putfh_maxsz + \
374 encode_readdir_maxsz)
375 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
376 decode_sequence_maxsz + \
377 decode_putfh_maxsz + \
378 decode_readdir_maxsz)
379 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
380 encode_sequence_maxsz + \
381 encode_putfh_maxsz + \
382 encode_write_maxsz + \
383 encode_getattr_maxsz)
384 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
385 decode_sequence_maxsz + \
386 decode_putfh_maxsz + \
387 decode_write_maxsz + \
388 decode_getattr_maxsz)
389 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
390 encode_sequence_maxsz + \
391 encode_putfh_maxsz + \
392 encode_commit_maxsz + \
393 encode_getattr_maxsz)
394 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
395 decode_sequence_maxsz + \
396 decode_putfh_maxsz + \
397 decode_commit_maxsz + \
398 decode_getattr_maxsz)
399 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
400 encode_sequence_maxsz + \
401 encode_putfh_maxsz + \
402 encode_savefh_maxsz + \
403 encode_open_maxsz + \
404 encode_getfh_maxsz + \
405 encode_getattr_maxsz + \
406 encode_restorefh_maxsz + \
407 encode_getattr_maxsz)
408 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
409 decode_sequence_maxsz + \
410 decode_putfh_maxsz + \
411 decode_savefh_maxsz + \
412 decode_open_maxsz + \
413 decode_getfh_maxsz + \
414 decode_getattr_maxsz + \
415 decode_restorefh_maxsz + \
416 decode_getattr_maxsz)
417 #define NFS4_enc_open_confirm_sz \
418 (compound_encode_hdr_maxsz + \
419 encode_putfh_maxsz + \
420 encode_open_confirm_maxsz)
421 #define NFS4_dec_open_confirm_sz \
422 (compound_decode_hdr_maxsz + \
423 decode_putfh_maxsz + \
424 decode_open_confirm_maxsz)
425 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
426 encode_sequence_maxsz + \
427 encode_putfh_maxsz + \
428 encode_open_maxsz + \
429 encode_getattr_maxsz)
430 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
431 decode_sequence_maxsz + \
432 decode_putfh_maxsz + \
433 decode_open_maxsz + \
434 decode_getattr_maxsz)
435 #define NFS4_enc_open_downgrade_sz \
436 (compound_encode_hdr_maxsz + \
437 encode_sequence_maxsz + \
438 encode_putfh_maxsz + \
439 encode_open_downgrade_maxsz + \
440 encode_getattr_maxsz)
441 #define NFS4_dec_open_downgrade_sz \
442 (compound_decode_hdr_maxsz + \
443 decode_sequence_maxsz + \
444 decode_putfh_maxsz + \
445 decode_open_downgrade_maxsz + \
446 decode_getattr_maxsz)
447 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
448 encode_sequence_maxsz + \
449 encode_putfh_maxsz + \
450 encode_close_maxsz + \
451 encode_getattr_maxsz)
452 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
453 decode_sequence_maxsz + \
454 decode_putfh_maxsz + \
455 decode_close_maxsz + \
456 decode_getattr_maxsz)
457 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
458 encode_sequence_maxsz + \
459 encode_putfh_maxsz + \
460 encode_setattr_maxsz + \
461 encode_getattr_maxsz)
462 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
463 decode_sequence_maxsz + \
464 decode_putfh_maxsz + \
465 decode_setattr_maxsz + \
466 decode_getattr_maxsz)
467 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
468 encode_sequence_maxsz + \
469 encode_putfh_maxsz + \
471 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
472 decode_sequence_maxsz + \
473 decode_putfh_maxsz + \
475 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
477 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
479 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
480 encode_setclientid_maxsz)
481 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
482 decode_setclientid_maxsz)
483 #define NFS4_enc_setclientid_confirm_sz \
484 (compound_encode_hdr_maxsz + \
485 encode_setclientid_confirm_maxsz + \
486 encode_putrootfh_maxsz + \
488 #define NFS4_dec_setclientid_confirm_sz \
489 (compound_decode_hdr_maxsz + \
490 decode_setclientid_confirm_maxsz + \
491 decode_putrootfh_maxsz + \
493 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
494 encode_sequence_maxsz + \
495 encode_putfh_maxsz + \
497 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
498 decode_sequence_maxsz + \
499 decode_putfh_maxsz + \
501 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
502 encode_sequence_maxsz + \
503 encode_putfh_maxsz + \
505 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
506 decode_sequence_maxsz + \
507 decode_putfh_maxsz + \
509 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
510 encode_sequence_maxsz + \
511 encode_putfh_maxsz + \
513 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
514 decode_sequence_maxsz + \
515 decode_putfh_maxsz + \
517 #define NFS4_enc_release_lockowner_sz \
518 (compound_encode_hdr_maxsz + \
519 encode_lockowner_maxsz)
520 #define NFS4_dec_release_lockowner_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_lockowner_maxsz)
523 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
524 encode_sequence_maxsz + \
525 encode_putfh_maxsz + \
526 encode_access_maxsz + \
527 encode_getattr_maxsz)
528 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
529 decode_sequence_maxsz + \
530 decode_putfh_maxsz + \
531 decode_access_maxsz + \
532 decode_getattr_maxsz)
533 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
534 encode_sequence_maxsz + \
535 encode_putfh_maxsz + \
536 encode_getattr_maxsz)
537 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
538 decode_sequence_maxsz + \
539 decode_putfh_maxsz + \
540 decode_getattr_maxsz)
541 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
542 encode_sequence_maxsz + \
543 encode_putfh_maxsz + \
544 encode_lookup_maxsz + \
545 encode_getattr_maxsz + \
547 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
548 decode_sequence_maxsz + \
549 decode_putfh_maxsz + \
550 decode_lookup_maxsz + \
551 decode_getattr_maxsz + \
553 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
554 encode_sequence_maxsz + \
555 encode_putrootfh_maxsz + \
556 encode_getattr_maxsz + \
558 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
559 decode_sequence_maxsz + \
560 decode_putrootfh_maxsz + \
561 decode_getattr_maxsz + \
563 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
564 encode_sequence_maxsz + \
565 encode_putfh_maxsz + \
566 encode_remove_maxsz + \
567 encode_getattr_maxsz)
568 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
569 decode_sequence_maxsz + \
570 decode_putfh_maxsz + \
571 decode_remove_maxsz + \
572 decode_getattr_maxsz)
573 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
574 encode_sequence_maxsz + \
575 encode_putfh_maxsz + \
576 encode_savefh_maxsz + \
577 encode_putfh_maxsz + \
578 encode_rename_maxsz + \
579 encode_getattr_maxsz + \
580 encode_restorefh_maxsz + \
581 encode_getattr_maxsz)
582 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
583 decode_sequence_maxsz + \
584 decode_putfh_maxsz + \
585 decode_savefh_maxsz + \
586 decode_putfh_maxsz + \
587 decode_rename_maxsz + \
588 decode_getattr_maxsz + \
589 decode_restorefh_maxsz + \
590 decode_getattr_maxsz)
591 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
592 encode_sequence_maxsz + \
593 encode_putfh_maxsz + \
594 encode_savefh_maxsz + \
595 encode_putfh_maxsz + \
596 encode_link_maxsz + \
597 decode_getattr_maxsz + \
598 encode_restorefh_maxsz + \
599 decode_getattr_maxsz)
600 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
601 decode_sequence_maxsz + \
602 decode_putfh_maxsz + \
603 decode_savefh_maxsz + \
604 decode_putfh_maxsz + \
605 decode_link_maxsz + \
606 decode_getattr_maxsz + \
607 decode_restorefh_maxsz + \
608 decode_getattr_maxsz)
609 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
610 encode_sequence_maxsz + \
611 encode_putfh_maxsz + \
612 encode_symlink_maxsz + \
613 encode_getattr_maxsz + \
615 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
616 decode_sequence_maxsz + \
617 decode_putfh_maxsz + \
618 decode_symlink_maxsz + \
619 decode_getattr_maxsz + \
621 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
622 encode_sequence_maxsz + \
623 encode_putfh_maxsz + \
624 encode_savefh_maxsz + \
625 encode_create_maxsz + \
626 encode_getfh_maxsz + \
627 encode_getattr_maxsz + \
628 encode_restorefh_maxsz + \
629 encode_getattr_maxsz)
630 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
631 decode_sequence_maxsz + \
632 decode_putfh_maxsz + \
633 decode_savefh_maxsz + \
634 decode_create_maxsz + \
635 decode_getfh_maxsz + \
636 decode_getattr_maxsz + \
637 decode_restorefh_maxsz + \
638 decode_getattr_maxsz)
639 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
640 encode_sequence_maxsz + \
641 encode_putfh_maxsz + \
642 encode_getattr_maxsz)
643 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
644 decode_sequence_maxsz + \
645 decode_putfh_maxsz + \
646 decode_getattr_maxsz)
647 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
648 encode_sequence_maxsz + \
649 encode_putfh_maxsz + \
651 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
652 decode_sequence_maxsz + \
653 decode_putfh_maxsz + \
655 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
656 encode_sequence_maxsz + \
657 encode_putfh_maxsz + \
658 encode_getattr_maxsz)
659 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
660 decode_sequence_maxsz + \
661 decode_putfh_maxsz + \
662 decode_getattr_maxsz)
663 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
664 encode_sequence_maxsz + \
665 encode_putfh_maxsz + \
666 encode_delegreturn_maxsz + \
667 encode_getattr_maxsz)
668 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
669 decode_sequence_maxsz + \
670 decode_delegreturn_maxsz + \
671 decode_getattr_maxsz)
672 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
673 encode_sequence_maxsz + \
674 encode_putfh_maxsz + \
676 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
677 decode_sequence_maxsz + \
678 decode_putfh_maxsz + \
680 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
681 encode_sequence_maxsz + \
682 encode_putfh_maxsz + \
684 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
685 decode_sequence_maxsz + \
686 decode_putfh_maxsz + \
688 #define NFS4_enc_fs_locations_sz \
689 (compound_encode_hdr_maxsz + \
690 encode_sequence_maxsz + \
691 encode_putfh_maxsz + \
692 encode_lookup_maxsz + \
693 encode_fs_locations_maxsz)
694 #define NFS4_dec_fs_locations_sz \
695 (compound_decode_hdr_maxsz + \
696 decode_sequence_maxsz + \
697 decode_putfh_maxsz + \
698 decode_lookup_maxsz + \
699 decode_fs_locations_maxsz)
700 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
701 encode_sequence_maxsz + \
702 encode_putfh_maxsz + \
703 encode_secinfo_maxsz)
704 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
705 decode_sequence_maxsz + \
706 decode_putfh_maxsz + \
707 decode_secinfo_maxsz)
708 #if defined(CONFIG_NFS_V4_1)
709 #define NFS4_enc_exchange_id_sz \
710 (compound_encode_hdr_maxsz + \
711 encode_exchange_id_maxsz)
712 #define NFS4_dec_exchange_id_sz \
713 (compound_decode_hdr_maxsz + \
714 decode_exchange_id_maxsz)
715 #define NFS4_enc_create_session_sz \
716 (compound_encode_hdr_maxsz + \
717 encode_create_session_maxsz)
718 #define NFS4_dec_create_session_sz \
719 (compound_decode_hdr_maxsz + \
720 decode_create_session_maxsz)
721 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
722 encode_destroy_session_maxsz)
723 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
724 decode_destroy_session_maxsz)
725 #define NFS4_enc_sequence_sz \
726 (compound_decode_hdr_maxsz + \
727 encode_sequence_maxsz)
728 #define NFS4_dec_sequence_sz \
729 (compound_decode_hdr_maxsz + \
730 decode_sequence_maxsz)
731 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
732 encode_sequence_maxsz + \
733 encode_putrootfh_maxsz + \
735 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
736 decode_sequence_maxsz + \
737 decode_putrootfh_maxsz + \
739 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
740 encode_sequence_maxsz + \
741 encode_reclaim_complete_maxsz)
742 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
743 decode_sequence_maxsz + \
744 decode_reclaim_complete_maxsz)
745 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
746 encode_sequence_maxsz +\
747 encode_getdeviceinfo_maxsz)
748 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_getdeviceinfo_maxsz)
751 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
752 encode_sequence_maxsz + \
753 encode_putfh_maxsz + \
754 encode_layoutget_maxsz)
755 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
756 decode_sequence_maxsz + \
757 decode_putfh_maxsz + \
758 decode_layoutget_maxsz)
759 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
760 encode_sequence_maxsz +\
761 encode_putfh_maxsz + \
762 encode_layoutcommit_maxsz + \
763 encode_getattr_maxsz)
764 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
765 decode_sequence_maxsz + \
766 decode_putfh_maxsz + \
767 decode_layoutcommit_maxsz + \
768 decode_getattr_maxsz)
769 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
770 encode_sequence_maxsz + \
771 encode_putfh_maxsz + \
772 encode_layoutreturn_maxsz)
773 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_putfh_maxsz + \
776 decode_layoutreturn_maxsz)
777 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putrootfh_maxsz +\
780 encode_secinfo_no_name_maxsz)
781 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putrootfh_maxsz + \
784 decode_secinfo_no_name_maxsz)
786 const u32 nfs41_maxwrite_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
787 compound_encode_hdr_maxsz
+
788 encode_sequence_maxsz
+
790 encode_getattr_maxsz
) *
793 const u32 nfs41_maxread_overhead
= ((RPC_MAX_HEADER_WITH_AUTH
+
794 compound_decode_hdr_maxsz
+
795 decode_sequence_maxsz
+
796 decode_putfh_maxsz
) *
798 #endif /* CONFIG_NFS_V4_1 */
800 static const umode_t nfs_type2fmt
[] = {
807 [NF4SOCK
] = S_IFSOCK
,
813 struct compound_hdr
{
819 uint32_t replen
; /* expected reply words */
823 static __be32
*reserve_space(struct xdr_stream
*xdr
, size_t nbytes
)
825 __be32
*p
= xdr_reserve_space(xdr
, nbytes
);
830 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
834 p
= xdr_reserve_space(xdr
, 4 + len
);
836 xdr_encode_opaque(p
, str
, len
);
839 static void encode_compound_hdr(struct xdr_stream
*xdr
,
840 struct rpc_rqst
*req
,
841 struct compound_hdr
*hdr
)
844 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
846 /* initialize running count of expected bytes in reply.
847 * NOTE: the replied tag SHOULD be the same is the one sent,
848 * but this is not required as a MUST for the server to do so. */
849 hdr
->replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ 3 + hdr
->taglen
;
851 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
852 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
853 p
= reserve_space(xdr
, 4 + hdr
->taglen
+ 8);
854 p
= xdr_encode_opaque(p
, hdr
->tag
, hdr
->taglen
);
855 *p
++ = cpu_to_be32(hdr
->minorversion
);
857 *p
= cpu_to_be32(hdr
->nops
);
860 static void encode_nops(struct compound_hdr
*hdr
)
862 BUG_ON(hdr
->nops
> NFS4_MAX_OPS
);
863 *hdr
->nops_p
= htonl(hdr
->nops
);
866 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
870 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
872 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
875 static void encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
877 char owner_name
[IDMAP_NAMESZ
];
878 char owner_group
[IDMAP_NAMESZ
];
879 int owner_namelen
= 0;
880 int owner_grouplen
= 0;
888 * We reserve enough space to write the entire attribute buffer at once.
889 * In the worst-case, this would be
890 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
891 * = 36 bytes, plus any contribution from variable-length fields
892 * such as owner/group.
897 if (iap
->ia_valid
& ATTR_SIZE
)
899 if (iap
->ia_valid
& ATTR_MODE
)
901 if (iap
->ia_valid
& ATTR_UID
) {
902 owner_namelen
= nfs_map_uid_to_name(server
, iap
->ia_uid
, owner_name
, IDMAP_NAMESZ
);
903 if (owner_namelen
< 0) {
904 dprintk("nfs: couldn't resolve uid %d to string\n",
907 strcpy(owner_name
, "nobody");
908 owner_namelen
= sizeof("nobody") - 1;
911 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
913 if (iap
->ia_valid
& ATTR_GID
) {
914 owner_grouplen
= nfs_map_gid_to_group(server
, iap
->ia_gid
, owner_group
, IDMAP_NAMESZ
);
915 if (owner_grouplen
< 0) {
916 dprintk("nfs: couldn't resolve gid %d to string\n",
918 strcpy(owner_group
, "nobody");
919 owner_grouplen
= sizeof("nobody") - 1;
922 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
924 if (iap
->ia_valid
& ATTR_ATIME_SET
)
926 else if (iap
->ia_valid
& ATTR_ATIME
)
928 if (iap
->ia_valid
& ATTR_MTIME_SET
)
930 else if (iap
->ia_valid
& ATTR_MTIME
)
932 p
= reserve_space(xdr
, len
);
935 * We write the bitmap length now, but leave the bitmap and the attribute
936 * buffer length to be backfilled at the end of this routine.
938 *p
++ = cpu_to_be32(2);
942 if (iap
->ia_valid
& ATTR_SIZE
) {
943 bmval0
|= FATTR4_WORD0_SIZE
;
944 p
= xdr_encode_hyper(p
, iap
->ia_size
);
946 if (iap
->ia_valid
& ATTR_MODE
) {
947 bmval1
|= FATTR4_WORD1_MODE
;
948 *p
++ = cpu_to_be32(iap
->ia_mode
& S_IALLUGO
);
950 if (iap
->ia_valid
& ATTR_UID
) {
951 bmval1
|= FATTR4_WORD1_OWNER
;
952 p
= xdr_encode_opaque(p
, owner_name
, owner_namelen
);
954 if (iap
->ia_valid
& ATTR_GID
) {
955 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
956 p
= xdr_encode_opaque(p
, owner_group
, owner_grouplen
);
958 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
959 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
960 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
961 *p
++ = cpu_to_be32(0);
962 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_sec
);
963 *p
++ = cpu_to_be32(iap
->ia_atime
.tv_nsec
);
965 else if (iap
->ia_valid
& ATTR_ATIME
) {
966 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
967 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
969 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
970 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
971 *p
++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME
);
972 *p
++ = cpu_to_be32(0);
973 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_sec
);
974 *p
++ = cpu_to_be32(iap
->ia_mtime
.tv_nsec
);
976 else if (iap
->ia_valid
& ATTR_MTIME
) {
977 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
978 *p
++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME
);
982 * Now we backfill the bitmap and the attribute buffer length.
984 if (len
!= ((char *)p
- (char *)q
) + 4) {
985 printk(KERN_ERR
"nfs: Attr length error, %u != %Zu\n",
986 len
, ((char *)p
- (char *)q
) + 4);
989 len
= (char *)p
- (char *)q
- 12;
990 *q
++ = htonl(bmval0
);
991 *q
++ = htonl(bmval1
);
997 static void encode_access(struct xdr_stream
*xdr
, u32 access
, struct compound_hdr
*hdr
)
1001 p
= reserve_space(xdr
, 8);
1002 *p
++ = cpu_to_be32(OP_ACCESS
);
1003 *p
= cpu_to_be32(access
);
1005 hdr
->replen
+= decode_access_maxsz
;
1008 static void encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1012 p
= reserve_space(xdr
, 8+NFS4_STATEID_SIZE
);
1013 *p
++ = cpu_to_be32(OP_CLOSE
);
1014 *p
++ = cpu_to_be32(arg
->seqid
->sequence
->counter
);
1015 xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1017 hdr
->replen
+= decode_close_maxsz
;
1020 static void encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1024 p
= reserve_space(xdr
, 16);
1025 *p
++ = cpu_to_be32(OP_COMMIT
);
1026 p
= xdr_encode_hyper(p
, args
->offset
);
1027 *p
= cpu_to_be32(args
->count
);
1029 hdr
->replen
+= decode_commit_maxsz
;
1032 static void encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
, struct compound_hdr
*hdr
)
1036 p
= reserve_space(xdr
, 8);
1037 *p
++ = cpu_to_be32(OP_CREATE
);
1038 *p
= cpu_to_be32(create
->ftype
);
1040 switch (create
->ftype
) {
1042 p
= reserve_space(xdr
, 4);
1043 *p
= cpu_to_be32(create
->u
.symlink
.len
);
1044 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
1047 case NF4BLK
: case NF4CHR
:
1048 p
= reserve_space(xdr
, 8);
1049 *p
++ = cpu_to_be32(create
->u
.device
.specdata1
);
1050 *p
= cpu_to_be32(create
->u
.device
.specdata2
);
1057 encode_string(xdr
, create
->name
->len
, create
->name
->name
);
1059 hdr
->replen
+= decode_create_maxsz
;
1061 encode_attrs(xdr
, create
->attrs
, create
->server
);
1064 static void encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
, struct compound_hdr
*hdr
)
1068 p
= reserve_space(xdr
, 12);
1069 *p
++ = cpu_to_be32(OP_GETATTR
);
1070 *p
++ = cpu_to_be32(1);
1071 *p
= cpu_to_be32(bitmap
);
1073 hdr
->replen
+= decode_getattr_maxsz
;
1076 static void encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
, struct compound_hdr
*hdr
)
1080 p
= reserve_space(xdr
, 16);
1081 *p
++ = cpu_to_be32(OP_GETATTR
);
1082 *p
++ = cpu_to_be32(2);
1083 *p
++ = cpu_to_be32(bm0
);
1084 *p
= cpu_to_be32(bm1
);
1086 hdr
->replen
+= decode_getattr_maxsz
;
1089 static void encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1091 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fattr_bitmap
[0],
1092 bitmask
[1] & nfs4_fattr_bitmap
[1], hdr
);
1095 static void encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1097 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
1098 bitmask
[1] & nfs4_fsinfo_bitmap
[1], hdr
);
1101 static void encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
, struct compound_hdr
*hdr
)
1103 encode_getattr_two(xdr
, bitmask
[0] & nfs4_fs_locations_bitmap
[0],
1104 bitmask
[1] & nfs4_fs_locations_bitmap
[1], hdr
);
1107 static void encode_getfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1111 p
= reserve_space(xdr
, 4);
1112 *p
= cpu_to_be32(OP_GETFH
);
1114 hdr
->replen
+= decode_getfh_maxsz
;
1117 static void encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1121 p
= reserve_space(xdr
, 8 + name
->len
);
1122 *p
++ = cpu_to_be32(OP_LINK
);
1123 xdr_encode_opaque(p
, name
->name
, name
->len
);
1125 hdr
->replen
+= decode_link_maxsz
;
1128 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
1130 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
1131 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
1132 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
1135 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
1137 if (fl
->fl_end
== OFFSET_MAX
)
1138 return ~(uint64_t)0;
1139 return fl
->fl_end
- fl
->fl_start
+ 1;
1142 static void encode_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
)
1146 p
= reserve_space(xdr
, 32);
1147 p
= xdr_encode_hyper(p
, lowner
->clientid
);
1148 *p
++ = cpu_to_be32(20);
1149 p
= xdr_encode_opaque_fixed(p
, "lock id:", 8);
1150 *p
++ = cpu_to_be32(lowner
->s_dev
);
1151 xdr_encode_hyper(p
, lowner
->id
);
1155 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1156 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1158 static void encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
, struct compound_hdr
*hdr
)
1162 p
= reserve_space(xdr
, 32);
1163 *p
++ = cpu_to_be32(OP_LOCK
);
1164 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, args
->block
));
1165 *p
++ = cpu_to_be32(args
->reclaim
);
1166 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1167 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1168 *p
= cpu_to_be32(args
->new_lock_owner
);
1169 if (args
->new_lock_owner
){
1170 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1171 *p
++ = cpu_to_be32(args
->open_seqid
->sequence
->counter
);
1172 p
= xdr_encode_opaque_fixed(p
, args
->open_stateid
->data
, NFS4_STATEID_SIZE
);
1173 *p
++ = cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1174 encode_lockowner(xdr
, &args
->lock_owner
);
1177 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
+4);
1178 p
= xdr_encode_opaque_fixed(p
, args
->lock_stateid
->data
, NFS4_STATEID_SIZE
);
1179 *p
= cpu_to_be32(args
->lock_seqid
->sequence
->counter
);
1182 hdr
->replen
+= decode_lock_maxsz
;
1185 static void encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
, struct compound_hdr
*hdr
)
1189 p
= reserve_space(xdr
, 24);
1190 *p
++ = cpu_to_be32(OP_LOCKT
);
1191 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1192 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1193 p
= xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1194 encode_lockowner(xdr
, &args
->lock_owner
);
1196 hdr
->replen
+= decode_lockt_maxsz
;
1199 static void encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
, struct compound_hdr
*hdr
)
1203 p
= reserve_space(xdr
, 12+NFS4_STATEID_SIZE
+16);
1204 *p
++ = cpu_to_be32(OP_LOCKU
);
1205 *p
++ = cpu_to_be32(nfs4_lock_type(args
->fl
, 0));
1206 *p
++ = cpu_to_be32(args
->seqid
->sequence
->counter
);
1207 p
= xdr_encode_opaque_fixed(p
, args
->stateid
->data
, NFS4_STATEID_SIZE
);
1208 p
= xdr_encode_hyper(p
, args
->fl
->fl_start
);
1209 xdr_encode_hyper(p
, nfs4_lock_length(args
->fl
));
1211 hdr
->replen
+= decode_locku_maxsz
;
1214 static void encode_release_lockowner(struct xdr_stream
*xdr
, const struct nfs_lowner
*lowner
, struct compound_hdr
*hdr
)
1218 p
= reserve_space(xdr
, 4);
1219 *p
= cpu_to_be32(OP_RELEASE_LOCKOWNER
);
1220 encode_lockowner(xdr
, lowner
);
1222 hdr
->replen
+= decode_release_lockowner_maxsz
;
1225 static void encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1227 int len
= name
->len
;
1230 p
= reserve_space(xdr
, 8 + len
);
1231 *p
++ = cpu_to_be32(OP_LOOKUP
);
1232 xdr_encode_opaque(p
, name
->name
, len
);
1234 hdr
->replen
+= decode_lookup_maxsz
;
1237 static void encode_share_access(struct xdr_stream
*xdr
, fmode_t fmode
)
1241 p
= reserve_space(xdr
, 8);
1242 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1244 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ
);
1247 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE
);
1249 case FMODE_READ
|FMODE_WRITE
:
1250 *p
++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH
);
1253 *p
++ = cpu_to_be32(0);
1255 *p
= cpu_to_be32(0); /* for linux, share_deny = 0 always */
1258 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1262 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1265 p
= reserve_space(xdr
, 8);
1266 *p
++ = cpu_to_be32(OP_OPEN
);
1267 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1268 encode_share_access(xdr
, arg
->fmode
);
1269 p
= reserve_space(xdr
, 32);
1270 p
= xdr_encode_hyper(p
, arg
->clientid
);
1271 *p
++ = cpu_to_be32(20);
1272 p
= xdr_encode_opaque_fixed(p
, "open id:", 8);
1273 *p
++ = cpu_to_be32(arg
->server
->s_dev
);
1274 xdr_encode_hyper(p
, arg
->id
);
1277 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1280 struct nfs_client
*clp
;
1282 p
= reserve_space(xdr
, 4);
1283 switch(arg
->open_flags
& O_EXCL
) {
1285 *p
= cpu_to_be32(NFS4_CREATE_UNCHECKED
);
1286 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1289 clp
= arg
->server
->nfs_client
;
1290 if (clp
->cl_mvops
->minor_version
> 0) {
1291 if (nfs4_has_persistent_session(clp
)) {
1292 *p
= cpu_to_be32(NFS4_CREATE_GUARDED
);
1293 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
1297 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1
);
1298 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1300 encode_attrs(xdr
, &dummy
, arg
->server
);
1303 *p
= cpu_to_be32(NFS4_CREATE_EXCLUSIVE
);
1304 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
1309 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
1313 p
= reserve_space(xdr
, 4);
1314 switch (arg
->open_flags
& O_CREAT
) {
1316 *p
= cpu_to_be32(NFS4_OPEN_NOCREATE
);
1319 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
1320 *p
= cpu_to_be32(NFS4_OPEN_CREATE
);
1321 encode_createmode(xdr
, arg
);
1325 static inline void encode_delegation_type(struct xdr_stream
*xdr
, fmode_t delegation_type
)
1329 p
= reserve_space(xdr
, 4);
1330 switch (delegation_type
) {
1332 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_NONE
);
1335 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_READ
);
1337 case FMODE_WRITE
|FMODE_READ
:
1338 *p
= cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE
);
1345 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
1349 p
= reserve_space(xdr
, 4);
1350 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_NULL
);
1351 encode_string(xdr
, name
->len
, name
->name
);
1354 static inline void encode_claim_previous(struct xdr_stream
*xdr
, fmode_t type
)
1358 p
= reserve_space(xdr
, 4);
1359 *p
= cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS
);
1360 encode_delegation_type(xdr
, type
);
1363 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
1367 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1368 *p
++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
1369 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1370 encode_string(xdr
, name
->len
, name
->name
);
1373 static void encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
, struct compound_hdr
*hdr
)
1375 encode_openhdr(xdr
, arg
);
1376 encode_opentype(xdr
, arg
);
1377 switch (arg
->claim
) {
1378 case NFS4_OPEN_CLAIM_NULL
:
1379 encode_claim_null(xdr
, arg
->name
);
1381 case NFS4_OPEN_CLAIM_PREVIOUS
:
1382 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
1384 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1385 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
1391 hdr
->replen
+= decode_open_maxsz
;
1394 static void encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
, struct compound_hdr
*hdr
)
1398 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1399 *p
++ = cpu_to_be32(OP_OPEN_CONFIRM
);
1400 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1401 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1403 hdr
->replen
+= decode_open_confirm_maxsz
;
1406 static void encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
, struct compound_hdr
*hdr
)
1410 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
+4);
1411 *p
++ = cpu_to_be32(OP_OPEN_DOWNGRADE
);
1412 p
= xdr_encode_opaque_fixed(p
, arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1413 *p
= cpu_to_be32(arg
->seqid
->sequence
->counter
);
1414 encode_share_access(xdr
, arg
->fmode
);
1416 hdr
->replen
+= decode_open_downgrade_maxsz
;
1420 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
, struct compound_hdr
*hdr
)
1425 p
= reserve_space(xdr
, 8 + len
);
1426 *p
++ = cpu_to_be32(OP_PUTFH
);
1427 xdr_encode_opaque(p
, fh
->data
, len
);
1429 hdr
->replen
+= decode_putfh_maxsz
;
1432 static void encode_putrootfh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1436 p
= reserve_space(xdr
, 4);
1437 *p
= cpu_to_be32(OP_PUTROOTFH
);
1439 hdr
->replen
+= decode_putrootfh_maxsz
;
1442 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
, const struct nfs_lock_context
*l_ctx
, int zero_seqid
)
1444 nfs4_stateid stateid
;
1447 p
= reserve_space(xdr
, NFS4_STATEID_SIZE
);
1448 if (ctx
->state
!= NULL
) {
1449 nfs4_copy_stateid(&stateid
, ctx
->state
, l_ctx
->lockowner
, l_ctx
->pid
);
1451 stateid
.stateid
.seqid
= 0;
1452 xdr_encode_opaque_fixed(p
, stateid
.data
, NFS4_STATEID_SIZE
);
1454 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1457 static void encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
, struct compound_hdr
*hdr
)
1461 p
= reserve_space(xdr
, 4);
1462 *p
= cpu_to_be32(OP_READ
);
1464 encode_stateid(xdr
, args
->context
, args
->lock_context
,
1467 p
= reserve_space(xdr
, 12);
1468 p
= xdr_encode_hyper(p
, args
->offset
);
1469 *p
= cpu_to_be32(args
->count
);
1471 hdr
->replen
+= decode_read_maxsz
;
1474 static void encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1476 uint32_t attrs
[2] = {
1477 FATTR4_WORD0_RDATTR_ERROR
,
1478 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1480 uint32_t dircount
= readdir
->count
>> 1;
1483 if (readdir
->plus
) {
1484 attrs
[0] |= FATTR4_WORD0_TYPE
|FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
|
1485 FATTR4_WORD0_FSID
|FATTR4_WORD0_FILEHANDLE
|FATTR4_WORD0_FILEID
;
1486 attrs
[1] |= FATTR4_WORD1_MODE
|FATTR4_WORD1_NUMLINKS
|FATTR4_WORD1_OWNER
|
1487 FATTR4_WORD1_OWNER_GROUP
|FATTR4_WORD1_RAWDEV
|
1488 FATTR4_WORD1_SPACE_USED
|FATTR4_WORD1_TIME_ACCESS
|
1489 FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
1492 /* Use mounted_on_fileid only if the server supports it */
1493 if (!(readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
))
1494 attrs
[0] |= FATTR4_WORD0_FILEID
;
1496 p
= reserve_space(xdr
, 12+NFS4_VERIFIER_SIZE
+20);
1497 *p
++ = cpu_to_be32(OP_READDIR
);
1498 p
= xdr_encode_hyper(p
, readdir
->cookie
);
1499 p
= xdr_encode_opaque_fixed(p
, readdir
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1500 *p
++ = cpu_to_be32(dircount
);
1501 *p
++ = cpu_to_be32(readdir
->count
);
1502 *p
++ = cpu_to_be32(2);
1504 *p
++ = cpu_to_be32(attrs
[0] & readdir
->bitmask
[0]);
1505 *p
= cpu_to_be32(attrs
[1] & readdir
->bitmask
[1]);
1507 hdr
->replen
+= decode_readdir_maxsz
;
1508 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1510 (unsigned long long)readdir
->cookie
,
1511 ((u32
*)readdir
->verifier
.data
)[0],
1512 ((u32
*)readdir
->verifier
.data
)[1],
1513 attrs
[0] & readdir
->bitmask
[0],
1514 attrs
[1] & readdir
->bitmask
[1]);
1517 static void encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
, struct compound_hdr
*hdr
)
1521 p
= reserve_space(xdr
, 4);
1522 *p
= cpu_to_be32(OP_READLINK
);
1524 hdr
->replen
+= decode_readlink_maxsz
;
1527 static void encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1531 p
= reserve_space(xdr
, 8 + name
->len
);
1532 *p
++ = cpu_to_be32(OP_REMOVE
);
1533 xdr_encode_opaque(p
, name
->name
, name
->len
);
1535 hdr
->replen
+= decode_remove_maxsz
;
1538 static void encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
, struct compound_hdr
*hdr
)
1542 p
= reserve_space(xdr
, 4);
1543 *p
= cpu_to_be32(OP_RENAME
);
1544 encode_string(xdr
, oldname
->len
, oldname
->name
);
1545 encode_string(xdr
, newname
->len
, newname
->name
);
1547 hdr
->replen
+= decode_rename_maxsz
;
1550 static void encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
, struct compound_hdr
*hdr
)
1554 p
= reserve_space(xdr
, 12);
1555 *p
++ = cpu_to_be32(OP_RENEW
);
1556 xdr_encode_hyper(p
, client_stateid
->cl_clientid
);
1558 hdr
->replen
+= decode_renew_maxsz
;
1562 encode_restorefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1566 p
= reserve_space(xdr
, 4);
1567 *p
= cpu_to_be32(OP_RESTOREFH
);
1569 hdr
->replen
+= decode_restorefh_maxsz
;
1573 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
, struct compound_hdr
*hdr
)
1577 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1578 *p
++ = cpu_to_be32(OP_SETATTR
);
1579 xdr_encode_opaque_fixed(p
, zero_stateid
.data
, NFS4_STATEID_SIZE
);
1580 p
= reserve_space(xdr
, 2*4);
1581 *p
++ = cpu_to_be32(1);
1582 *p
= cpu_to_be32(FATTR4_WORD0_ACL
);
1583 BUG_ON(arg
->acl_len
% 4);
1584 p
= reserve_space(xdr
, 4);
1585 *p
= cpu_to_be32(arg
->acl_len
);
1586 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1588 hdr
->replen
+= decode_setacl_maxsz
;
1592 encode_savefh(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
1596 p
= reserve_space(xdr
, 4);
1597 *p
= cpu_to_be32(OP_SAVEFH
);
1599 hdr
->replen
+= decode_savefh_maxsz
;
1602 static void encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
, struct compound_hdr
*hdr
)
1606 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1607 *p
++ = cpu_to_be32(OP_SETATTR
);
1608 xdr_encode_opaque_fixed(p
, arg
->stateid
.data
, NFS4_STATEID_SIZE
);
1610 hdr
->replen
+= decode_setattr_maxsz
;
1611 encode_attrs(xdr
, arg
->iap
, server
);
1614 static void encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
, struct compound_hdr
*hdr
)
1618 p
= reserve_space(xdr
, 4 + NFS4_VERIFIER_SIZE
);
1619 *p
++ = cpu_to_be32(OP_SETCLIENTID
);
1620 xdr_encode_opaque_fixed(p
, setclientid
->sc_verifier
->data
, NFS4_VERIFIER_SIZE
);
1622 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1623 p
= reserve_space(xdr
, 4);
1624 *p
= cpu_to_be32(setclientid
->sc_prog
);
1625 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1626 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1627 p
= reserve_space(xdr
, 4);
1628 *p
= cpu_to_be32(setclientid
->sc_cb_ident
);
1630 hdr
->replen
+= decode_setclientid_maxsz
;
1633 static void encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_setclientid_res
*arg
, struct compound_hdr
*hdr
)
1637 p
= reserve_space(xdr
, 12 + NFS4_VERIFIER_SIZE
);
1638 *p
++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM
);
1639 p
= xdr_encode_hyper(p
, arg
->clientid
);
1640 xdr_encode_opaque_fixed(p
, arg
->confirm
.data
, NFS4_VERIFIER_SIZE
);
1642 hdr
->replen
+= decode_setclientid_confirm_maxsz
;
1645 static void encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
, struct compound_hdr
*hdr
)
1649 p
= reserve_space(xdr
, 4);
1650 *p
= cpu_to_be32(OP_WRITE
);
1652 encode_stateid(xdr
, args
->context
, args
->lock_context
,
1655 p
= reserve_space(xdr
, 16);
1656 p
= xdr_encode_hyper(p
, args
->offset
);
1657 *p
++ = cpu_to_be32(args
->stable
);
1658 *p
= cpu_to_be32(args
->count
);
1660 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1662 hdr
->replen
+= decode_write_maxsz
;
1665 static void encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
, struct compound_hdr
*hdr
)
1669 p
= reserve_space(xdr
, 4+NFS4_STATEID_SIZE
);
1671 *p
++ = cpu_to_be32(OP_DELEGRETURN
);
1672 xdr_encode_opaque_fixed(p
, stateid
->data
, NFS4_STATEID_SIZE
);
1674 hdr
->replen
+= decode_delegreturn_maxsz
;
1677 static void encode_secinfo(struct xdr_stream
*xdr
, const struct qstr
*name
, struct compound_hdr
*hdr
)
1679 int len
= name
->len
;
1682 p
= reserve_space(xdr
, 8 + len
);
1683 *p
++ = cpu_to_be32(OP_SECINFO
);
1684 xdr_encode_opaque(p
, name
->name
, len
);
1686 hdr
->replen
+= decode_secinfo_maxsz
;
1689 #if defined(CONFIG_NFS_V4_1)
1690 /* NFSv4.1 operations */
1691 static void encode_exchange_id(struct xdr_stream
*xdr
,
1692 struct nfs41_exchange_id_args
*args
,
1693 struct compound_hdr
*hdr
)
1697 p
= reserve_space(xdr
, 4 + sizeof(args
->verifier
->data
));
1698 *p
++ = cpu_to_be32(OP_EXCHANGE_ID
);
1699 xdr_encode_opaque_fixed(p
, args
->verifier
->data
, sizeof(args
->verifier
->data
));
1701 encode_string(xdr
, args
->id_len
, args
->id
);
1703 p
= reserve_space(xdr
, 12);
1704 *p
++ = cpu_to_be32(args
->flags
);
1705 *p
++ = cpu_to_be32(0); /* zero length state_protect4_a */
1706 *p
= cpu_to_be32(0); /* zero length implementation id array */
1708 hdr
->replen
+= decode_exchange_id_maxsz
;
1711 static void encode_create_session(struct xdr_stream
*xdr
,
1712 struct nfs41_create_session_args
*args
,
1713 struct compound_hdr
*hdr
)
1716 char machine_name
[NFS4_MAX_MACHINE_NAME_LEN
];
1718 struct nfs_client
*clp
= args
->client
;
1719 u32 max_resp_sz_cached
;
1722 * Assumes OPEN is the biggest non-idempotent compound.
1723 * 2 is the verifier.
1725 max_resp_sz_cached
= (NFS4_dec_open_sz
+ RPC_REPHDRSIZE
+
1726 RPC_MAX_AUTH_SIZE
+ 2) * XDR_UNIT
;
1728 len
= scnprintf(machine_name
, sizeof(machine_name
), "%s",
1731 p
= reserve_space(xdr
, 20 + 2*28 + 20 + len
+ 12);
1732 *p
++ = cpu_to_be32(OP_CREATE_SESSION
);
1733 p
= xdr_encode_hyper(p
, clp
->cl_clientid
);
1734 *p
++ = cpu_to_be32(clp
->cl_seqid
); /*Sequence id */
1735 *p
++ = cpu_to_be32(args
->flags
); /*flags */
1738 *p
++ = cpu_to_be32(0); /* header padding size */
1739 *p
++ = cpu_to_be32(args
->fc_attrs
.max_rqst_sz
); /* max req size */
1740 *p
++ = cpu_to_be32(args
->fc_attrs
.max_resp_sz
); /* max resp size */
1741 *p
++ = cpu_to_be32(max_resp_sz_cached
); /* Max resp sz cached */
1742 *p
++ = cpu_to_be32(args
->fc_attrs
.max_ops
); /* max operations */
1743 *p
++ = cpu_to_be32(args
->fc_attrs
.max_reqs
); /* max requests */
1744 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1747 *p
++ = cpu_to_be32(0); /* header padding size */
1748 *p
++ = cpu_to_be32(args
->bc_attrs
.max_rqst_sz
); /* max req size */
1749 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz
); /* max resp size */
1750 *p
++ = cpu_to_be32(args
->bc_attrs
.max_resp_sz_cached
); /* Max resp sz cached */
1751 *p
++ = cpu_to_be32(args
->bc_attrs
.max_ops
); /* max operations */
1752 *p
++ = cpu_to_be32(args
->bc_attrs
.max_reqs
); /* max requests */
1753 *p
++ = cpu_to_be32(0); /* rdmachannel_attrs */
1755 *p
++ = cpu_to_be32(args
->cb_program
); /* cb_program */
1756 *p
++ = cpu_to_be32(1);
1757 *p
++ = cpu_to_be32(RPC_AUTH_UNIX
); /* auth_sys */
1759 /* authsys_parms rfc1831 */
1760 *p
++ = cpu_to_be32((u32
)clp
->cl_boot_time
.tv_nsec
); /* stamp */
1761 p
= xdr_encode_opaque(p
, machine_name
, len
);
1762 *p
++ = cpu_to_be32(0); /* UID */
1763 *p
++ = cpu_to_be32(0); /* GID */
1764 *p
= cpu_to_be32(0); /* No more gids */
1766 hdr
->replen
+= decode_create_session_maxsz
;
1769 static void encode_destroy_session(struct xdr_stream
*xdr
,
1770 struct nfs4_session
*session
,
1771 struct compound_hdr
*hdr
)
1774 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
);
1775 *p
++ = cpu_to_be32(OP_DESTROY_SESSION
);
1776 xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1778 hdr
->replen
+= decode_destroy_session_maxsz
;
1781 static void encode_reclaim_complete(struct xdr_stream
*xdr
,
1782 struct nfs41_reclaim_complete_args
*args
,
1783 struct compound_hdr
*hdr
)
1787 p
= reserve_space(xdr
, 8);
1788 *p
++ = cpu_to_be32(OP_RECLAIM_COMPLETE
);
1789 *p
++ = cpu_to_be32(args
->one_fs
);
1791 hdr
->replen
+= decode_reclaim_complete_maxsz
;
1793 #endif /* CONFIG_NFS_V4_1 */
1795 static void encode_sequence(struct xdr_stream
*xdr
,
1796 const struct nfs4_sequence_args
*args
,
1797 struct compound_hdr
*hdr
)
1799 #if defined(CONFIG_NFS_V4_1)
1800 struct nfs4_session
*session
= args
->sa_session
;
1801 struct nfs4_slot_table
*tp
;
1802 struct nfs4_slot
*slot
;
1808 tp
= &session
->fc_slot_table
;
1810 WARN_ON(args
->sa_slotid
== NFS4_MAX_SLOT_TABLE
);
1811 slot
= tp
->slots
+ args
->sa_slotid
;
1813 p
= reserve_space(xdr
, 4 + NFS4_MAX_SESSIONID_LEN
+ 16);
1814 *p
++ = cpu_to_be32(OP_SEQUENCE
);
1817 * Sessionid + seqid + slotid + max slotid + cache_this
1819 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1820 "max_slotid=%d cache_this=%d\n",
1822 ((u32
*)session
->sess_id
.data
)[0],
1823 ((u32
*)session
->sess_id
.data
)[1],
1824 ((u32
*)session
->sess_id
.data
)[2],
1825 ((u32
*)session
->sess_id
.data
)[3],
1826 slot
->seq_nr
, args
->sa_slotid
,
1827 tp
->highest_used_slotid
, args
->sa_cache_this
);
1828 p
= xdr_encode_opaque_fixed(p
, session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
);
1829 *p
++ = cpu_to_be32(slot
->seq_nr
);
1830 *p
++ = cpu_to_be32(args
->sa_slotid
);
1831 *p
++ = cpu_to_be32(tp
->highest_used_slotid
);
1832 *p
= cpu_to_be32(args
->sa_cache_this
);
1834 hdr
->replen
+= decode_sequence_maxsz
;
1835 #endif /* CONFIG_NFS_V4_1 */
1838 #ifdef CONFIG_NFS_V4_1
1840 encode_getdeviceinfo(struct xdr_stream
*xdr
,
1841 const struct nfs4_getdeviceinfo_args
*args
,
1842 struct compound_hdr
*hdr
)
1846 p
= reserve_space(xdr
, 16 + NFS4_DEVICEID4_SIZE
);
1847 *p
++ = cpu_to_be32(OP_GETDEVICEINFO
);
1848 p
= xdr_encode_opaque_fixed(p
, args
->pdev
->dev_id
.data
,
1849 NFS4_DEVICEID4_SIZE
);
1850 *p
++ = cpu_to_be32(args
->pdev
->layout_type
);
1851 *p
++ = cpu_to_be32(args
->pdev
->pglen
); /* gdia_maxcount */
1852 *p
++ = cpu_to_be32(0); /* bitmap length 0 */
1854 hdr
->replen
+= decode_getdeviceinfo_maxsz
;
1858 encode_layoutget(struct xdr_stream
*xdr
,
1859 const struct nfs4_layoutget_args
*args
,
1860 struct compound_hdr
*hdr
)
1864 p
= reserve_space(xdr
, 44 + NFS4_STATEID_SIZE
);
1865 *p
++ = cpu_to_be32(OP_LAYOUTGET
);
1866 *p
++ = cpu_to_be32(0); /* Signal layout available */
1867 *p
++ = cpu_to_be32(args
->type
);
1868 *p
++ = cpu_to_be32(args
->range
.iomode
);
1869 p
= xdr_encode_hyper(p
, args
->range
.offset
);
1870 p
= xdr_encode_hyper(p
, args
->range
.length
);
1871 p
= xdr_encode_hyper(p
, args
->minlength
);
1872 p
= xdr_encode_opaque_fixed(p
, &args
->stateid
.data
, NFS4_STATEID_SIZE
);
1873 *p
= cpu_to_be32(args
->maxcount
);
1875 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1879 (unsigned long)args
->range
.offset
,
1880 (unsigned long)args
->range
.length
,
1883 hdr
->replen
+= decode_layoutget_maxsz
;
1887 encode_layoutcommit(struct xdr_stream
*xdr
,
1888 struct inode
*inode
,
1889 const struct nfs4_layoutcommit_args
*args
,
1890 struct compound_hdr
*hdr
)
1894 dprintk("%s: lbw: %llu type: %d\n", __func__
, args
->lastbytewritten
,
1895 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);
1897 p
= reserve_space(xdr
, 44 + NFS4_STATEID_SIZE
);
1898 *p
++ = cpu_to_be32(OP_LAYOUTCOMMIT
);
1899 /* Only whole file layouts */
1900 p
= xdr_encode_hyper(p
, 0); /* offset */
1901 p
= xdr_encode_hyper(p
, NFS4_MAX_UINT64
); /* length */
1902 *p
++ = cpu_to_be32(0); /* reclaim */
1903 p
= xdr_encode_opaque_fixed(p
, args
->stateid
.data
, NFS4_STATEID_SIZE
);
1904 *p
++ = cpu_to_be32(1); /* newoffset = TRUE */
1905 p
= xdr_encode_hyper(p
, args
->lastbytewritten
);
1906 *p
++ = cpu_to_be32(0); /* Never send time_modify_changed */
1907 *p
++ = cpu_to_be32(NFS_SERVER(args
->inode
)->pnfs_curr_ld
->id
);/* type */
1909 if (NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit
)
1910 NFS_SERVER(inode
)->pnfs_curr_ld
->encode_layoutcommit(
1911 NFS_I(inode
)->layout
, xdr
, args
);
1913 p
= reserve_space(xdr
, 4);
1914 *p
= cpu_to_be32(0); /* no layout-type payload */
1918 hdr
->replen
+= decode_layoutcommit_maxsz
;
1923 encode_layoutreturn(struct xdr_stream
*xdr
,
1924 const struct nfs4_layoutreturn_args
*args
,
1925 struct compound_hdr
*hdr
)
1929 p
= reserve_space(xdr
, 20);
1930 *p
++ = cpu_to_be32(OP_LAYOUTRETURN
);
1931 *p
++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1932 *p
++ = cpu_to_be32(args
->layout_type
);
1933 *p
++ = cpu_to_be32(IOMODE_ANY
);
1934 *p
= cpu_to_be32(RETURN_FILE
);
1935 p
= reserve_space(xdr
, 16 + NFS4_STATEID_SIZE
);
1936 p
= xdr_encode_hyper(p
, 0);
1937 p
= xdr_encode_hyper(p
, NFS4_MAX_UINT64
);
1938 spin_lock(&args
->inode
->i_lock
);
1939 xdr_encode_opaque_fixed(p
, &args
->stateid
.data
, NFS4_STATEID_SIZE
);
1940 spin_unlock(&args
->inode
->i_lock
);
1941 if (NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn
) {
1942 NFS_SERVER(args
->inode
)->pnfs_curr_ld
->encode_layoutreturn(
1943 NFS_I(args
->inode
)->layout
, xdr
, args
);
1945 p
= reserve_space(xdr
, 4);
1946 *p
= cpu_to_be32(0);
1949 hdr
->replen
+= decode_layoutreturn_maxsz
;
1953 encode_secinfo_no_name(struct xdr_stream
*xdr
,
1954 const struct nfs41_secinfo_no_name_args
*args
,
1955 struct compound_hdr
*hdr
)
1958 p
= reserve_space(xdr
, 8);
1959 *p
++ = cpu_to_be32(OP_SECINFO_NO_NAME
);
1960 *p
++ = cpu_to_be32(args
->style
);
1962 hdr
->replen
+= decode_secinfo_no_name_maxsz
;
1965 #endif /* CONFIG_NFS_V4_1 */
1968 * END OF "GENERIC" ENCODE ROUTINES.
1971 static u32
nfs4_xdr_minorversion(const struct nfs4_sequence_args
*args
)
1973 #if defined(CONFIG_NFS_V4_1)
1974 if (args
->sa_session
)
1975 return args
->sa_session
->clp
->cl_mvops
->minor_version
;
1976 #endif /* CONFIG_NFS_V4_1 */
1981 * Encode an ACCESS request
1983 static void nfs4_xdr_enc_access(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1984 const struct nfs4_accessargs
*args
)
1986 struct compound_hdr hdr
= {
1987 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
1990 encode_compound_hdr(xdr
, req
, &hdr
);
1991 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
1992 encode_putfh(xdr
, args
->fh
, &hdr
);
1993 encode_access(xdr
, args
->access
, &hdr
);
1994 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
1999 * Encode LOOKUP request
2001 static void nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2002 const struct nfs4_lookup_arg
*args
)
2004 struct compound_hdr hdr
= {
2005 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2008 encode_compound_hdr(xdr
, req
, &hdr
);
2009 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2010 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2011 encode_lookup(xdr
, args
->name
, &hdr
);
2012 encode_getfh(xdr
, &hdr
);
2013 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2018 * Encode LOOKUP_ROOT request
2020 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
,
2021 struct xdr_stream
*xdr
,
2022 const struct nfs4_lookup_root_arg
*args
)
2024 struct compound_hdr hdr
= {
2025 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2028 encode_compound_hdr(xdr
, req
, &hdr
);
2029 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2030 encode_putrootfh(xdr
, &hdr
);
2031 encode_getfh(xdr
, &hdr
);
2032 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2037 * Encode REMOVE request
2039 static void nfs4_xdr_enc_remove(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2040 const struct nfs_removeargs
*args
)
2042 struct compound_hdr hdr
= {
2043 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2046 encode_compound_hdr(xdr
, req
, &hdr
);
2047 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2048 encode_putfh(xdr
, args
->fh
, &hdr
);
2049 encode_remove(xdr
, &args
->name
, &hdr
);
2050 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2055 * Encode RENAME request
2057 static void nfs4_xdr_enc_rename(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2058 const struct nfs_renameargs
*args
)
2060 struct compound_hdr hdr
= {
2061 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2064 encode_compound_hdr(xdr
, req
, &hdr
);
2065 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2066 encode_putfh(xdr
, args
->old_dir
, &hdr
);
2067 encode_savefh(xdr
, &hdr
);
2068 encode_putfh(xdr
, args
->new_dir
, &hdr
);
2069 encode_rename(xdr
, args
->old_name
, args
->new_name
, &hdr
);
2070 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2071 encode_restorefh(xdr
, &hdr
);
2072 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2077 * Encode LINK request
2079 static void nfs4_xdr_enc_link(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2080 const struct nfs4_link_arg
*args
)
2082 struct compound_hdr hdr
= {
2083 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2086 encode_compound_hdr(xdr
, req
, &hdr
);
2087 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2088 encode_putfh(xdr
, args
->fh
, &hdr
);
2089 encode_savefh(xdr
, &hdr
);
2090 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2091 encode_link(xdr
, args
->name
, &hdr
);
2092 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2093 encode_restorefh(xdr
, &hdr
);
2094 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2099 * Encode CREATE request
2101 static void nfs4_xdr_enc_create(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2102 const struct nfs4_create_arg
*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
->dir_fh
, &hdr
);
2111 encode_savefh(xdr
, &hdr
);
2112 encode_create(xdr
, args
, &hdr
);
2113 encode_getfh(xdr
, &hdr
);
2114 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2115 encode_restorefh(xdr
, &hdr
);
2116 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2121 * Encode SYMLINK request
2123 static void nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2124 const struct nfs4_create_arg
*args
)
2126 nfs4_xdr_enc_create(req
, xdr
, args
);
2130 * Encode GETATTR request
2132 static void nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2133 const struct nfs4_getattr_arg
*args
)
2135 struct compound_hdr hdr
= {
2136 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2139 encode_compound_hdr(xdr
, req
, &hdr
);
2140 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2141 encode_putfh(xdr
, args
->fh
, &hdr
);
2142 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2147 * Encode a CLOSE request
2149 static void nfs4_xdr_enc_close(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2150 struct nfs_closeargs
*args
)
2152 struct compound_hdr hdr
= {
2153 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2156 encode_compound_hdr(xdr
, req
, &hdr
);
2157 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2158 encode_putfh(xdr
, args
->fh
, &hdr
);
2159 encode_close(xdr
, args
, &hdr
);
2160 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2165 * Encode an OPEN request
2167 static void nfs4_xdr_enc_open(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2168 struct nfs_openargs
*args
)
2170 struct compound_hdr hdr
= {
2171 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2174 encode_compound_hdr(xdr
, req
, &hdr
);
2175 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2176 encode_putfh(xdr
, args
->fh
, &hdr
);
2177 encode_savefh(xdr
, &hdr
);
2178 encode_open(xdr
, args
, &hdr
);
2179 encode_getfh(xdr
, &hdr
);
2180 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2181 encode_restorefh(xdr
, &hdr
);
2182 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2187 * Encode an OPEN_CONFIRM request
2189 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
,
2190 struct xdr_stream
*xdr
,
2191 struct nfs_open_confirmargs
*args
)
2193 struct compound_hdr hdr
= {
2197 encode_compound_hdr(xdr
, req
, &hdr
);
2198 encode_putfh(xdr
, args
->fh
, &hdr
);
2199 encode_open_confirm(xdr
, args
, &hdr
);
2204 * Encode an OPEN request with no attributes.
2206 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
,
2207 struct xdr_stream
*xdr
,
2208 struct nfs_openargs
*args
)
2210 struct compound_hdr hdr
= {
2211 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2214 encode_compound_hdr(xdr
, req
, &hdr
);
2215 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2216 encode_putfh(xdr
, args
->fh
, &hdr
);
2217 encode_open(xdr
, args
, &hdr
);
2218 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2223 * Encode an OPEN_DOWNGRADE request
2225 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
,
2226 struct xdr_stream
*xdr
,
2227 struct nfs_closeargs
*args
)
2229 struct compound_hdr hdr
= {
2230 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2233 encode_compound_hdr(xdr
, req
, &hdr
);
2234 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2235 encode_putfh(xdr
, args
->fh
, &hdr
);
2236 encode_open_downgrade(xdr
, args
, &hdr
);
2237 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2242 * Encode a LOCK request
2244 static void nfs4_xdr_enc_lock(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2245 struct nfs_lock_args
*args
)
2247 struct compound_hdr hdr
= {
2248 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2251 encode_compound_hdr(xdr
, req
, &hdr
);
2252 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2253 encode_putfh(xdr
, args
->fh
, &hdr
);
2254 encode_lock(xdr
, args
, &hdr
);
2259 * Encode a LOCKT request
2261 static void nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2262 struct nfs_lockt_args
*args
)
2264 struct compound_hdr hdr
= {
2265 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2268 encode_compound_hdr(xdr
, req
, &hdr
);
2269 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2270 encode_putfh(xdr
, args
->fh
, &hdr
);
2271 encode_lockt(xdr
, args
, &hdr
);
2276 * Encode a LOCKU request
2278 static void nfs4_xdr_enc_locku(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2279 struct nfs_locku_args
*args
)
2281 struct compound_hdr hdr
= {
2282 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2285 encode_compound_hdr(xdr
, req
, &hdr
);
2286 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2287 encode_putfh(xdr
, args
->fh
, &hdr
);
2288 encode_locku(xdr
, args
, &hdr
);
2292 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst
*req
,
2293 struct xdr_stream
*xdr
,
2294 struct nfs_release_lockowner_args
*args
)
2296 struct compound_hdr hdr
= {
2300 encode_compound_hdr(xdr
, req
, &hdr
);
2301 encode_release_lockowner(xdr
, &args
->lock_owner
, &hdr
);
2306 * Encode a READLINK request
2308 static void nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2309 const struct nfs4_readlink
*args
)
2311 struct compound_hdr hdr
= {
2312 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2315 encode_compound_hdr(xdr
, req
, &hdr
);
2316 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2317 encode_putfh(xdr
, args
->fh
, &hdr
);
2318 encode_readlink(xdr
, args
, req
, &hdr
);
2320 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2321 args
->pgbase
, args
->pglen
);
2326 * Encode a READDIR request
2328 static void nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2329 const struct nfs4_readdir_arg
*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_readdir(xdr
, args
, req
, &hdr
);
2340 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2, args
->pages
,
2341 args
->pgbase
, args
->count
);
2342 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2343 __func__
, hdr
.replen
<< 2, args
->pages
,
2344 args
->pgbase
, args
->count
);
2349 * Encode a READ request
2351 static void nfs4_xdr_enc_read(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2352 struct nfs_readargs
*args
)
2354 struct compound_hdr hdr
= {
2355 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2358 encode_compound_hdr(xdr
, req
, &hdr
);
2359 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2360 encode_putfh(xdr
, args
->fh
, &hdr
);
2361 encode_read(xdr
, args
, &hdr
);
2363 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2364 args
->pages
, args
->pgbase
, args
->count
);
2365 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
2370 * Encode an SETATTR request
2372 static void nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2373 struct nfs_setattrargs
*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_setattr(xdr
, args
, args
->server
, &hdr
);
2383 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2388 * Encode a GETACL request
2390 static void nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2391 struct nfs_getaclargs
*args
)
2393 struct compound_hdr hdr
= {
2394 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2398 encode_compound_hdr(xdr
, req
, &hdr
);
2399 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2400 encode_putfh(xdr
, args
->fh
, &hdr
);
2401 replen
= hdr
.replen
+ op_decode_hdr_maxsz
+ nfs4_fattr_bitmap_maxsz
+ 1;
2402 encode_getattr_two(xdr
, FATTR4_WORD0_ACL
, 0, &hdr
);
2404 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2,
2405 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
2410 * Encode a WRITE request
2412 static void nfs4_xdr_enc_write(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2413 struct nfs_writeargs
*args
)
2415 struct compound_hdr hdr
= {
2416 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2419 encode_compound_hdr(xdr
, req
, &hdr
);
2420 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2421 encode_putfh(xdr
, args
->fh
, &hdr
);
2422 encode_write(xdr
, args
, &hdr
);
2423 req
->rq_snd_buf
.flags
|= XDRBUF_WRITE
;
2425 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2432 static void nfs4_xdr_enc_commit(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2433 struct nfs_writeargs
*args
)
2435 struct compound_hdr hdr
= {
2436 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2439 encode_compound_hdr(xdr
, req
, &hdr
);
2440 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2441 encode_putfh(xdr
, args
->fh
, &hdr
);
2442 encode_commit(xdr
, args
, &hdr
);
2444 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2451 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2452 struct nfs4_fsinfo_arg
*args
)
2454 struct compound_hdr hdr
= {
2455 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2458 encode_compound_hdr(xdr
, req
, &hdr
);
2459 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2460 encode_putfh(xdr
, args
->fh
, &hdr
);
2461 encode_fsinfo(xdr
, args
->bitmask
, &hdr
);
2466 * a PATHCONF request
2468 static void nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2469 const struct nfs4_pathconf_arg
*args
)
2471 struct compound_hdr hdr
= {
2472 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2475 encode_compound_hdr(xdr
, req
, &hdr
);
2476 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2477 encode_putfh(xdr
, args
->fh
, &hdr
);
2478 encode_getattr_one(xdr
, args
->bitmask
[0] & nfs4_pathconf_bitmap
[0],
2486 static void nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2487 const struct nfs4_statfs_arg
*args
)
2489 struct compound_hdr hdr
= {
2490 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2493 encode_compound_hdr(xdr
, req
, &hdr
);
2494 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2495 encode_putfh(xdr
, args
->fh
, &hdr
);
2496 encode_getattr_two(xdr
, args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
2497 args
->bitmask
[1] & nfs4_statfs_bitmap
[1], &hdr
);
2502 * GETATTR_BITMAP request
2504 static void nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
,
2505 struct xdr_stream
*xdr
,
2506 struct nfs4_server_caps_arg
*args
)
2508 struct compound_hdr hdr
= {
2509 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2512 encode_compound_hdr(xdr
, req
, &hdr
);
2513 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2514 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2515 encode_getattr_one(xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
2516 FATTR4_WORD0_LINK_SUPPORT
|
2517 FATTR4_WORD0_SYMLINK_SUPPORT
|
2518 FATTR4_WORD0_ACLSUPPORT
, &hdr
);
2525 static void nfs4_xdr_enc_renew(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2526 struct nfs_client
*clp
)
2528 struct compound_hdr hdr
= {
2532 encode_compound_hdr(xdr
, req
, &hdr
);
2533 encode_renew(xdr
, clp
, &hdr
);
2538 * a SETCLIENTID request
2540 static void nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
,
2541 struct xdr_stream
*xdr
,
2542 struct nfs4_setclientid
*sc
)
2544 struct compound_hdr hdr
= {
2548 encode_compound_hdr(xdr
, req
, &hdr
);
2549 encode_setclientid(xdr
, sc
, &hdr
);
2554 * a SETCLIENTID_CONFIRM request
2556 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
,
2557 struct xdr_stream
*xdr
,
2558 struct nfs4_setclientid_res
*arg
)
2560 struct compound_hdr hdr
= {
2563 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2565 encode_compound_hdr(xdr
, req
, &hdr
);
2566 encode_setclientid_confirm(xdr
, arg
, &hdr
);
2567 encode_putrootfh(xdr
, &hdr
);
2568 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2573 * DELEGRETURN request
2575 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
,
2576 struct xdr_stream
*xdr
,
2577 const struct nfs4_delegreturnargs
*args
)
2579 struct compound_hdr hdr
= {
2580 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2583 encode_compound_hdr(xdr
, req
, &hdr
);
2584 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2585 encode_putfh(xdr
, args
->fhandle
, &hdr
);
2586 encode_delegreturn(xdr
, args
->stateid
, &hdr
);
2587 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2592 * Encode FS_LOCATIONS request
2594 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
,
2595 struct xdr_stream
*xdr
,
2596 struct nfs4_fs_locations_arg
*args
)
2598 struct compound_hdr hdr
= {
2599 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2603 encode_compound_hdr(xdr
, req
, &hdr
);
2604 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2605 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2606 encode_lookup(xdr
, args
->name
, &hdr
);
2607 replen
= hdr
.replen
; /* get the attribute into args->page */
2608 encode_fs_locations(xdr
, args
->bitmask
, &hdr
);
2610 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, &args
->page
,
2616 * Encode SECINFO request
2618 static void nfs4_xdr_enc_secinfo(struct rpc_rqst
*req
,
2619 struct xdr_stream
*xdr
,
2620 struct nfs4_secinfo_arg
*args
)
2622 struct compound_hdr hdr
= {
2623 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2626 encode_compound_hdr(xdr
, req
, &hdr
);
2627 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2628 encode_putfh(xdr
, args
->dir_fh
, &hdr
);
2629 encode_secinfo(xdr
, args
->name
, &hdr
);
2633 #if defined(CONFIG_NFS_V4_1)
2635 * EXCHANGE_ID request
2637 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst
*req
,
2638 struct xdr_stream
*xdr
,
2639 struct nfs41_exchange_id_args
*args
)
2641 struct compound_hdr hdr
= {
2642 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2645 encode_compound_hdr(xdr
, req
, &hdr
);
2646 encode_exchange_id(xdr
, args
, &hdr
);
2651 * a CREATE_SESSION request
2653 static void nfs4_xdr_enc_create_session(struct rpc_rqst
*req
,
2654 struct xdr_stream
*xdr
,
2655 struct nfs41_create_session_args
*args
)
2657 struct compound_hdr hdr
= {
2658 .minorversion
= args
->client
->cl_mvops
->minor_version
,
2661 encode_compound_hdr(xdr
, req
, &hdr
);
2662 encode_create_session(xdr
, args
, &hdr
);
2667 * a DESTROY_SESSION request
2669 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst
*req
,
2670 struct xdr_stream
*xdr
,
2671 struct nfs4_session
*session
)
2673 struct compound_hdr hdr
= {
2674 .minorversion
= session
->clp
->cl_mvops
->minor_version
,
2677 encode_compound_hdr(xdr
, req
, &hdr
);
2678 encode_destroy_session(xdr
, session
, &hdr
);
2683 * a SEQUENCE request
2685 static void nfs4_xdr_enc_sequence(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
2686 struct nfs4_sequence_args
*args
)
2688 struct compound_hdr hdr
= {
2689 .minorversion
= nfs4_xdr_minorversion(args
),
2692 encode_compound_hdr(xdr
, req
, &hdr
);
2693 encode_sequence(xdr
, args
, &hdr
);
2698 * a GET_LEASE_TIME request
2700 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst
*req
,
2701 struct xdr_stream
*xdr
,
2702 struct nfs4_get_lease_time_args
*args
)
2704 struct compound_hdr hdr
= {
2705 .minorversion
= nfs4_xdr_minorversion(&args
->la_seq_args
),
2707 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
2709 encode_compound_hdr(xdr
, req
, &hdr
);
2710 encode_sequence(xdr
, &args
->la_seq_args
, &hdr
);
2711 encode_putrootfh(xdr
, &hdr
);
2712 encode_fsinfo(xdr
, lease_bitmap
, &hdr
);
2717 * a RECLAIM_COMPLETE request
2719 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst
*req
,
2720 struct xdr_stream
*xdr
,
2721 struct nfs41_reclaim_complete_args
*args
)
2723 struct compound_hdr hdr
= {
2724 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
)
2727 encode_compound_hdr(xdr
, req
, &hdr
);
2728 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2729 encode_reclaim_complete(xdr
, args
, &hdr
);
2734 * Encode GETDEVICEINFO request
2736 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst
*req
,
2737 struct xdr_stream
*xdr
,
2738 struct nfs4_getdeviceinfo_args
*args
)
2740 struct compound_hdr hdr
= {
2741 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2744 encode_compound_hdr(xdr
, req
, &hdr
);
2745 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2746 encode_getdeviceinfo(xdr
, args
, &hdr
);
2748 /* set up reply kvec. Subtract notification bitmap max size (2)
2749 * so that notification bitmap is put in xdr_buf tail */
2750 xdr_inline_pages(&req
->rq_rcv_buf
, (hdr
.replen
- 2) << 2,
2751 args
->pdev
->pages
, args
->pdev
->pgbase
,
2758 * Encode LAYOUTGET request
2760 static void nfs4_xdr_enc_layoutget(struct rpc_rqst
*req
,
2761 struct xdr_stream
*xdr
,
2762 struct nfs4_layoutget_args
*args
)
2764 struct compound_hdr hdr
= {
2765 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2768 encode_compound_hdr(xdr
, req
, &hdr
);
2769 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2770 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2771 encode_layoutget(xdr
, args
, &hdr
);
2773 xdr_inline_pages(&req
->rq_rcv_buf
, hdr
.replen
<< 2,
2774 args
->layout
.pages
, 0, args
->layout
.pglen
);
2780 * Encode LAYOUTCOMMIT request
2782 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst
*req
,
2783 struct xdr_stream
*xdr
,
2784 struct nfs4_layoutcommit_args
*args
)
2786 struct nfs4_layoutcommit_data
*data
=
2787 container_of(args
, struct nfs4_layoutcommit_data
, args
);
2788 struct compound_hdr hdr
= {
2789 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2792 encode_compound_hdr(xdr
, req
, &hdr
);
2793 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2794 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2795 encode_layoutcommit(xdr
, data
->args
.inode
, args
, &hdr
);
2796 encode_getfattr(xdr
, args
->bitmask
, &hdr
);
2801 * Encode LAYOUTRETURN request
2803 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst
*req
,
2804 struct xdr_stream
*xdr
,
2805 struct nfs4_layoutreturn_args
*args
)
2807 struct compound_hdr hdr
= {
2808 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2811 encode_compound_hdr(xdr
, req
, &hdr
);
2812 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2813 encode_putfh(xdr
, NFS_FH(args
->inode
), &hdr
);
2814 encode_layoutreturn(xdr
, args
, &hdr
);
2819 * Encode SECINFO_NO_NAME request
2821 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst
*req
,
2822 struct xdr_stream
*xdr
,
2823 struct nfs41_secinfo_no_name_args
*args
)
2825 struct compound_hdr hdr
= {
2826 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
2829 encode_compound_hdr(xdr
, req
, &hdr
);
2830 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
2831 encode_putrootfh(xdr
, &hdr
);
2832 encode_secinfo_no_name(xdr
, args
, &hdr
);
2836 #endif /* CONFIG_NFS_V4_1 */
2838 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
2840 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2841 "Remaining buffer length is %tu words.\n",
2842 func
, xdr
->end
- xdr
->p
);
2845 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2849 p
= xdr_inline_decode(xdr
, 4);
2852 *len
= be32_to_cpup(p
);
2853 p
= xdr_inline_decode(xdr
, *len
);
2856 *string
= (char *)p
;
2859 print_overflow_msg(__func__
, xdr
);
2863 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2867 p
= xdr_inline_decode(xdr
, 8);
2870 hdr
->status
= be32_to_cpup(p
++);
2871 hdr
->taglen
= be32_to_cpup(p
);
2873 p
= xdr_inline_decode(xdr
, hdr
->taglen
+ 4);
2876 hdr
->tag
= (char *)p
;
2877 p
+= XDR_QUADLEN(hdr
->taglen
);
2878 hdr
->nops
= be32_to_cpup(p
);
2879 if (unlikely(hdr
->nops
< 1))
2880 return nfs4_stat_to_errno(hdr
->status
);
2883 print_overflow_msg(__func__
, xdr
);
2887 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2893 p
= xdr_inline_decode(xdr
, 8);
2896 opnum
= be32_to_cpup(p
++);
2897 if (opnum
!= expected
) {
2898 dprintk("nfs: Server returned operation"
2899 " %d but we issued a request for %d\n",
2903 nfserr
= be32_to_cpup(p
);
2904 if (nfserr
!= NFS_OK
)
2905 return nfs4_stat_to_errno(nfserr
);
2908 print_overflow_msg(__func__
, xdr
);
2913 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2916 unsigned int strlen
;
2919 p
= xdr_inline_decode(xdr
, 12);
2921 return decode_opaque_inline(xdr
, &strlen
, &str
);
2922 print_overflow_msg(__func__
, xdr
);
2926 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2931 p
= xdr_inline_decode(xdr
, 4);
2934 bmlen
= be32_to_cpup(p
);
2936 bitmap
[0] = bitmap
[1] = 0;
2937 p
= xdr_inline_decode(xdr
, (bmlen
<< 2));
2941 bitmap
[0] = be32_to_cpup(p
++);
2943 bitmap
[1] = be32_to_cpup(p
);
2947 print_overflow_msg(__func__
, xdr
);
2951 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
2955 p
= xdr_inline_decode(xdr
, 4);
2958 *attrlen
= be32_to_cpup(p
);
2962 print_overflow_msg(__func__
, xdr
);
2966 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2968 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2970 ret
= decode_attr_bitmap(xdr
, bitmask
);
2971 if (unlikely(ret
< 0))
2973 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2975 bitmask
[0] = bitmask
[1] = 0;
2976 dprintk("%s: bitmask=%08x:%08x\n", __func__
, bitmask
[0], bitmask
[1]);
2980 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2986 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2988 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2989 p
= xdr_inline_decode(xdr
, 4);
2992 *type
= be32_to_cpup(p
);
2993 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2994 dprintk("%s: bad type %d\n", __func__
, *type
);
2997 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2998 ret
= NFS_ATTR_FATTR_TYPE
;
3000 dprintk("%s: type=0%o\n", __func__
, nfs_type2fmt
[*type
]);
3003 print_overflow_msg(__func__
, xdr
);
3007 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
3013 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
3015 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
3016 p
= xdr_inline_decode(xdr
, 8);
3019 xdr_decode_hyper(p
, change
);
3020 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
3021 ret
= NFS_ATTR_FATTR_CHANGE
;
3023 dprintk("%s: change attribute=%Lu\n", __func__
,
3024 (unsigned long long)*change
);
3027 print_overflow_msg(__func__
, xdr
);
3031 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
3037 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
3039 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
3040 p
= xdr_inline_decode(xdr
, 8);
3043 xdr_decode_hyper(p
, size
);
3044 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
3045 ret
= NFS_ATTR_FATTR_SIZE
;
3047 dprintk("%s: file size=%Lu\n", __func__
, (unsigned long long)*size
);
3050 print_overflow_msg(__func__
, xdr
);
3054 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3059 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
3061 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
3062 p
= xdr_inline_decode(xdr
, 4);
3065 *res
= be32_to_cpup(p
);
3066 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
3068 dprintk("%s: link support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3071 print_overflow_msg(__func__
, xdr
);
3075 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3080 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
3082 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
3083 p
= xdr_inline_decode(xdr
, 4);
3086 *res
= be32_to_cpup(p
);
3087 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
3089 dprintk("%s: symlink support=%s\n", __func__
, *res
== 0 ? "false" : "true");
3092 print_overflow_msg(__func__
, xdr
);
3096 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
3103 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
3105 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
3106 p
= xdr_inline_decode(xdr
, 16);
3109 p
= xdr_decode_hyper(p
, &fsid
->major
);
3110 xdr_decode_hyper(p
, &fsid
->minor
);
3111 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
3112 ret
= NFS_ATTR_FATTR_FSID
;
3114 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__
,
3115 (unsigned long long)fsid
->major
,
3116 (unsigned long long)fsid
->minor
);
3119 print_overflow_msg(__func__
, xdr
);
3123 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3128 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
3130 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
3131 p
= xdr_inline_decode(xdr
, 4);
3134 *res
= be32_to_cpup(p
);
3135 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
3137 dprintk("%s: file size=%u\n", __func__
, (unsigned int)*res
);
3140 print_overflow_msg(__func__
, xdr
);
3144 static int decode_attr_error(struct xdr_stream
*xdr
, uint32_t *bitmap
, int32_t *res
)
3148 if (unlikely(bitmap
[0] & (FATTR4_WORD0_RDATTR_ERROR
- 1U)))
3150 if (likely(bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
)) {
3151 p
= xdr_inline_decode(xdr
, 4);
3154 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
3155 *res
= -be32_to_cpup(p
);
3159 print_overflow_msg(__func__
, xdr
);
3163 static int decode_attr_filehandle(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fh
*fh
)
3169 memset(fh
, 0, sizeof(*fh
));
3171 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEHANDLE
- 1U)))
3173 if (likely(bitmap
[0] & FATTR4_WORD0_FILEHANDLE
)) {
3174 p
= xdr_inline_decode(xdr
, 4);
3177 len
= be32_to_cpup(p
);
3178 if (len
> NFS4_FHSIZE
)
3180 p
= xdr_inline_decode(xdr
, len
);
3184 memcpy(fh
->data
, p
, len
);
3187 bitmap
[0] &= ~FATTR4_WORD0_FILEHANDLE
;
3191 print_overflow_msg(__func__
, xdr
);
3195 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3199 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
3200 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
3202 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
3203 p
= xdr_inline_decode(xdr
, 4);
3206 *res
= be32_to_cpup(p
);
3207 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
3209 dprintk("%s: ACLs supported=%u\n", __func__
, (unsigned int)*res
);
3212 print_overflow_msg(__func__
, xdr
);
3216 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3222 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
3224 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
3225 p
= xdr_inline_decode(xdr
, 8);
3228 xdr_decode_hyper(p
, fileid
);
3229 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
3230 ret
= NFS_ATTR_FATTR_FILEID
;
3232 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3235 print_overflow_msg(__func__
, xdr
);
3239 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
3245 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
3247 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
3248 p
= xdr_inline_decode(xdr
, 8);
3251 xdr_decode_hyper(p
, fileid
);
3252 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
3253 ret
= NFS_ATTR_FATTR_MOUNTED_ON_FILEID
;
3255 dprintk("%s: fileid=%Lu\n", __func__
, (unsigned long long)*fileid
);
3258 print_overflow_msg(__func__
, xdr
);
3262 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3268 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
3270 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
3271 p
= xdr_inline_decode(xdr
, 8);
3274 xdr_decode_hyper(p
, res
);
3275 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
3277 dprintk("%s: files avail=%Lu\n", __func__
, (unsigned long long)*res
);
3280 print_overflow_msg(__func__
, xdr
);
3284 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3290 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
3292 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
3293 p
= xdr_inline_decode(xdr
, 8);
3296 xdr_decode_hyper(p
, res
);
3297 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
3299 dprintk("%s: files free=%Lu\n", __func__
, (unsigned long long)*res
);
3302 print_overflow_msg(__func__
, xdr
);
3306 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3312 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
3314 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
3315 p
= xdr_inline_decode(xdr
, 8);
3318 xdr_decode_hyper(p
, res
);
3319 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
3321 dprintk("%s: files total=%Lu\n", __func__
, (unsigned long long)*res
);
3324 print_overflow_msg(__func__
, xdr
);
3328 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
3334 p
= xdr_inline_decode(xdr
, 4);
3337 n
= be32_to_cpup(p
);
3341 path
->ncomponents
= 0;
3342 while (path
->ncomponents
< n
) {
3343 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
3344 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
3345 if (unlikely(status
!= 0))
3347 if (path
->ncomponents
!= n
)
3349 dprintk("%s", component
->data
);
3350 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
3351 path
->ncomponents
++;
3353 dprintk("cannot parse %d components in path\n", n
);
3361 /* a root pathname is sent as a zero component4 */
3362 path
->ncomponents
= 1;
3363 path
->components
[0].len
=0;
3364 path
->components
[0].data
=NULL
;
3365 dprintk("path /\n");
3368 dprintk(" status %d", status
);
3372 print_overflow_msg(__func__
, xdr
);
3376 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
3382 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
3385 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
3387 dprintk("%s: fsroot ", __func__
);
3388 status
= decode_pathname(xdr
, &res
->fs_path
);
3389 if (unlikely(status
!= 0))
3391 p
= xdr_inline_decode(xdr
, 4);
3394 n
= be32_to_cpup(p
);
3397 res
->nlocations
= 0;
3398 while (res
->nlocations
< n
) {
3400 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
3402 p
= xdr_inline_decode(xdr
, 4);
3405 m
= be32_to_cpup(p
);
3408 dprintk("%s: servers ", __func__
);
3409 while (loc
->nservers
< m
) {
3410 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
3411 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
3412 if (unlikely(status
!= 0))
3414 dprintk("%s ", server
->data
);
3415 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
3419 dprintk("%s: using first %u of %u servers "
3420 "returned for location %u\n",
3422 NFS4_FS_LOCATION_MAXSERVERS
,
3423 m
, res
->nlocations
);
3424 for (i
= loc
->nservers
; i
< m
; i
++) {
3427 status
= decode_opaque_inline(xdr
, &len
, &data
);
3428 if (unlikely(status
!= 0))
3433 status
= decode_pathname(xdr
, &loc
->rootpath
);
3434 if (unlikely(status
!= 0))
3436 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
3439 if (res
->nlocations
!= 0)
3440 status
= NFS_ATTR_FATTR_V4_REFERRAL
;
3442 dprintk("%s: fs_locations done, error = %d\n", __func__
, status
);
3445 print_overflow_msg(__func__
, xdr
);
3451 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3457 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
3459 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
3460 p
= xdr_inline_decode(xdr
, 8);
3463 xdr_decode_hyper(p
, res
);
3464 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
3466 dprintk("%s: maxfilesize=%Lu\n", __func__
, (unsigned long long)*res
);
3469 print_overflow_msg(__func__
, xdr
);
3473 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
3479 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
3481 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
3482 p
= xdr_inline_decode(xdr
, 4);
3485 *maxlink
= be32_to_cpup(p
);
3486 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
3488 dprintk("%s: maxlink=%u\n", __func__
, *maxlink
);
3491 print_overflow_msg(__func__
, xdr
);
3495 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
3501 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
3503 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
3504 p
= xdr_inline_decode(xdr
, 4);
3507 *maxname
= be32_to_cpup(p
);
3508 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
3510 dprintk("%s: maxname=%u\n", __func__
, *maxname
);
3513 print_overflow_msg(__func__
, xdr
);
3517 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3523 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
3525 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
3527 p
= xdr_inline_decode(xdr
, 8);
3530 xdr_decode_hyper(p
, &maxread
);
3531 if (maxread
> 0x7FFFFFFF)
3532 maxread
= 0x7FFFFFFF;
3533 *res
= (uint32_t)maxread
;
3534 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
3536 dprintk("%s: maxread=%lu\n", __func__
, (unsigned long)*res
);
3539 print_overflow_msg(__func__
, xdr
);
3543 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
3549 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
3551 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
3553 p
= xdr_inline_decode(xdr
, 8);
3556 xdr_decode_hyper(p
, &maxwrite
);
3557 if (maxwrite
> 0x7FFFFFFF)
3558 maxwrite
= 0x7FFFFFFF;
3559 *res
= (uint32_t)maxwrite
;
3560 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
3562 dprintk("%s: maxwrite=%lu\n", __func__
, (unsigned long)*res
);
3565 print_overflow_msg(__func__
, xdr
);
3569 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, umode_t
*mode
)
3576 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
3578 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
3579 p
= xdr_inline_decode(xdr
, 4);
3582 tmp
= be32_to_cpup(p
);
3583 *mode
= tmp
& ~S_IFMT
;
3584 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
3585 ret
= NFS_ATTR_FATTR_MODE
;
3587 dprintk("%s: file mode=0%o\n", __func__
, (unsigned int)*mode
);
3590 print_overflow_msg(__func__
, xdr
);
3594 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
3600 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
3602 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
3603 p
= xdr_inline_decode(xdr
, 4);
3606 *nlink
= be32_to_cpup(p
);
3607 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
3608 ret
= NFS_ATTR_FATTR_NLINK
;
3610 dprintk("%s: nlink=%u\n", __func__
, (unsigned int)*nlink
);
3613 print_overflow_msg(__func__
, xdr
);
3617 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3618 const struct nfs_server
*server
, uint32_t *uid
, int may_sleep
)
3625 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
3627 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
3628 p
= xdr_inline_decode(xdr
, 4);
3631 len
= be32_to_cpup(p
);
3632 p
= xdr_inline_decode(xdr
, len
);
3637 } else if (len
< XDR_MAX_NETOBJ
) {
3638 if (nfs_map_name_to_uid(server
, (char *)p
, len
, uid
) == 0)
3639 ret
= NFS_ATTR_FATTR_OWNER
;
3641 dprintk("%s: nfs_map_name_to_uid failed!\n",
3644 dprintk("%s: name too long (%u)!\n",
3646 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
3648 dprintk("%s: uid=%d\n", __func__
, (int)*uid
);
3651 print_overflow_msg(__func__
, xdr
);
3655 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3656 const struct nfs_server
*server
, uint32_t *gid
, int may_sleep
)
3663 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
3665 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
3666 p
= xdr_inline_decode(xdr
, 4);
3669 len
= be32_to_cpup(p
);
3670 p
= xdr_inline_decode(xdr
, len
);
3675 } else if (len
< XDR_MAX_NETOBJ
) {
3676 if (nfs_map_group_to_gid(server
, (char *)p
, len
, gid
) == 0)
3677 ret
= NFS_ATTR_FATTR_GROUP
;
3679 dprintk("%s: nfs_map_group_to_gid failed!\n",
3682 dprintk("%s: name too long (%u)!\n",
3684 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
3686 dprintk("%s: gid=%d\n", __func__
, (int)*gid
);
3689 print_overflow_msg(__func__
, xdr
);
3693 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
3695 uint32_t major
= 0, minor
= 0;
3700 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
3702 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
3705 p
= xdr_inline_decode(xdr
, 8);
3708 major
= be32_to_cpup(p
++);
3709 minor
= be32_to_cpup(p
);
3710 tmp
= MKDEV(major
, minor
);
3711 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
3713 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
3714 ret
= NFS_ATTR_FATTR_RDEV
;
3716 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__
, major
, minor
);
3719 print_overflow_msg(__func__
, xdr
);
3723 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3729 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
3731 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
3732 p
= xdr_inline_decode(xdr
, 8);
3735 xdr_decode_hyper(p
, res
);
3736 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
3738 dprintk("%s: space avail=%Lu\n", __func__
, (unsigned long long)*res
);
3741 print_overflow_msg(__func__
, xdr
);
3745 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3751 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
3753 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
3754 p
= xdr_inline_decode(xdr
, 8);
3757 xdr_decode_hyper(p
, res
);
3758 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
3760 dprintk("%s: space free=%Lu\n", __func__
, (unsigned long long)*res
);
3763 print_overflow_msg(__func__
, xdr
);
3767 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
3773 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
3775 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
3776 p
= xdr_inline_decode(xdr
, 8);
3779 xdr_decode_hyper(p
, res
);
3780 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
3782 dprintk("%s: space total=%Lu\n", __func__
, (unsigned long long)*res
);
3785 print_overflow_msg(__func__
, xdr
);
3789 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
3795 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
3797 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
3798 p
= xdr_inline_decode(xdr
, 8);
3801 xdr_decode_hyper(p
, used
);
3802 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
3803 ret
= NFS_ATTR_FATTR_SPACE_USED
;
3805 dprintk("%s: space used=%Lu\n", __func__
,
3806 (unsigned long long)*used
);
3809 print_overflow_msg(__func__
, xdr
);
3813 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
3819 p
= xdr_inline_decode(xdr
, 12);
3822 p
= xdr_decode_hyper(p
, &sec
);
3823 nsec
= be32_to_cpup(p
);
3824 time
->tv_sec
= (time_t)sec
;
3825 time
->tv_nsec
= (long)nsec
;
3828 print_overflow_msg(__func__
, xdr
);
3832 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3838 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
3840 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
3841 status
= decode_attr_time(xdr
, time
);
3843 status
= NFS_ATTR_FATTR_ATIME
;
3844 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
3846 dprintk("%s: atime=%ld\n", __func__
, (long)time
->tv_sec
);
3850 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3856 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
3858 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
3859 status
= decode_attr_time(xdr
, time
);
3861 status
= NFS_ATTR_FATTR_CTIME
;
3862 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
3864 dprintk("%s: ctime=%ld\n", __func__
, (long)time
->tv_sec
);
3868 static int decode_attr_time_delta(struct xdr_stream
*xdr
, uint32_t *bitmap
,
3869 struct timespec
*time
)
3875 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_DELTA
- 1U)))
3877 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_DELTA
)) {
3878 status
= decode_attr_time(xdr
, time
);
3879 bitmap
[1] &= ~FATTR4_WORD1_TIME_DELTA
;
3881 dprintk("%s: time_delta=%ld %ld\n", __func__
, (long)time
->tv_sec
,
3882 (long)time
->tv_nsec
);
3886 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
3892 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
3894 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
3895 status
= decode_attr_time(xdr
, time
);
3897 status
= NFS_ATTR_FATTR_MTIME
;
3898 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
3900 dprintk("%s: mtime=%ld\n", __func__
, (long)time
->tv_sec
);
3904 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
3906 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
3907 unsigned int nwords
= xdr
->p
- savep
;
3909 if (unlikely(attrwords
!= nwords
)) {
3910 dprintk("%s: server returned incorrect attribute length: "
3914 (attrwords
< nwords
) ? '<' : '>',
3921 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3925 p
= xdr_inline_decode(xdr
, 20);
3928 cinfo
->atomic
= be32_to_cpup(p
++);
3929 p
= xdr_decode_hyper(p
, &cinfo
->before
);
3930 xdr_decode_hyper(p
, &cinfo
->after
);
3933 print_overflow_msg(__func__
, xdr
);
3937 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
3943 status
= decode_op_hdr(xdr
, OP_ACCESS
);
3946 p
= xdr_inline_decode(xdr
, 8);
3949 supp
= be32_to_cpup(p
++);
3950 acc
= be32_to_cpup(p
);
3951 access
->supported
= supp
;
3952 access
->access
= acc
;
3955 print_overflow_msg(__func__
, xdr
);
3959 static int decode_opaque_fixed(struct xdr_stream
*xdr
, void *buf
, size_t len
)
3963 p
= xdr_inline_decode(xdr
, len
);
3965 memcpy(buf
, p
, len
);
3968 print_overflow_msg(__func__
, xdr
);
3972 static int decode_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
3974 return decode_opaque_fixed(xdr
, stateid
->data
, NFS4_STATEID_SIZE
);
3977 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3981 status
= decode_op_hdr(xdr
, OP_CLOSE
);
3983 nfs_increment_open_seqid(status
, res
->seqid
);
3985 status
= decode_stateid(xdr
, &res
->stateid
);
3989 static int decode_verifier(struct xdr_stream
*xdr
, void *verifier
)
3991 return decode_opaque_fixed(xdr
, verifier
, 8);
3994 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3998 status
= decode_op_hdr(xdr
, OP_COMMIT
);
4000 status
= decode_verifier(xdr
, res
->verf
->verifier
);
4004 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4010 status
= decode_op_hdr(xdr
, OP_CREATE
);
4013 if ((status
= decode_change_info(xdr
, cinfo
)))
4015 p
= xdr_inline_decode(xdr
, 4);
4018 bmlen
= be32_to_cpup(p
);
4019 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4023 print_overflow_msg(__func__
, xdr
);
4027 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
4030 uint32_t attrlen
, bitmap
[2] = {0};
4033 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4035 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4037 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4039 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
4041 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
4043 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
4045 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
4047 status
= verify_attr_len(xdr
, savep
, attrlen
);
4049 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4053 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
4056 uint32_t attrlen
, bitmap
[2] = {0};
4059 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4061 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4063 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4066 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
4068 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
4070 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
4072 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
4074 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
4076 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
4079 status
= verify_attr_len(xdr
, savep
, attrlen
);
4081 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4085 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
4088 uint32_t attrlen
, bitmap
[2] = {0};
4091 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4093 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4095 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4098 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
4100 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
4103 status
= verify_attr_len(xdr
, savep
, attrlen
);
4105 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4109 static int decode_getfattr_attrs(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4110 struct nfs_fattr
*fattr
, struct nfs_fh
*fh
,
4111 const struct nfs_server
*server
, int may_sleep
)
4118 status
= decode_attr_type(xdr
, bitmap
, &type
);
4123 fattr
->mode
|= nfs_type2fmt
[type
];
4124 fattr
->valid
|= status
;
4127 status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
);
4130 fattr
->valid
|= status
;
4132 status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
);
4135 fattr
->valid
|= status
;
4137 status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
);
4140 fattr
->valid
|= status
;
4143 status
= decode_attr_error(xdr
, bitmap
, &err
);
4146 if (err
== -NFS4ERR_WRONGSEC
)
4147 nfs_fixup_secinfo_attributes(fattr
, fh
);
4149 status
= decode_attr_filehandle(xdr
, bitmap
, fh
);
4153 status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
);
4156 fattr
->valid
|= status
;
4158 status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
4159 struct nfs4_fs_locations
,
4163 fattr
->valid
|= status
;
4165 status
= decode_attr_mode(xdr
, bitmap
, &fmode
);
4169 fattr
->mode
|= fmode
;
4170 fattr
->valid
|= status
;
4173 status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
);
4176 fattr
->valid
|= status
;
4178 status
= decode_attr_owner(xdr
, bitmap
, server
, &fattr
->uid
, may_sleep
);
4181 fattr
->valid
|= status
;
4183 status
= decode_attr_group(xdr
, bitmap
, server
, &fattr
->gid
, may_sleep
);
4186 fattr
->valid
|= status
;
4188 status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
);
4191 fattr
->valid
|= status
;
4193 status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
);
4196 fattr
->valid
|= status
;
4198 status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
);
4201 fattr
->valid
|= status
;
4203 status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
);
4206 fattr
->valid
|= status
;
4208 status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
);
4211 fattr
->valid
|= status
;
4213 status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fattr
->mounted_on_fileid
);
4216 fattr
->valid
|= status
;
4219 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4223 static int decode_getfattr_generic(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4224 struct nfs_fh
*fh
, const struct nfs_server
*server
, int may_sleep
)
4231 status
= decode_op_hdr(xdr
, OP_GETATTR
);
4235 status
= decode_attr_bitmap(xdr
, bitmap
);
4239 status
= decode_attr_length(xdr
, &attrlen
, &savep
);
4243 status
= decode_getfattr_attrs(xdr
, bitmap
, fattr
, fh
, server
, may_sleep
);
4247 status
= verify_attr_len(xdr
, savep
, attrlen
);
4249 dprintk("%s: xdr returned %d\n", __func__
, -status
);
4253 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
4254 const struct nfs_server
*server
, int may_sleep
)
4256 return decode_getfattr_generic(xdr
, fattr
, NULL
, server
, may_sleep
);
4260 * Decode potentially multiple layout types. Currently we only support
4261 * one layout driver per file system.
4263 static int decode_first_pnfs_layout_type(struct xdr_stream
*xdr
,
4264 uint32_t *layouttype
)
4269 p
= xdr_inline_decode(xdr
, 4);
4272 num
= be32_to_cpup(p
);
4274 /* pNFS is not supported by the underlying file system */
4280 printk(KERN_INFO
"%s: Warning: Multiple pNFS layout drivers "
4281 "per filesystem not supported\n", __func__
);
4283 /* Decode and set first layout type, move xdr->p past unused types */
4284 p
= xdr_inline_decode(xdr
, num
* 4);
4287 *layouttype
= be32_to_cpup(p
);
4290 print_overflow_msg(__func__
, xdr
);
4295 * The type of file system exported.
4296 * Note we must ensure that layouttype is set in any non-error case.
4298 static int decode_attr_pnfstype(struct xdr_stream
*xdr
, uint32_t *bitmap
,
4299 uint32_t *layouttype
)
4303 dprintk("%s: bitmap is %x\n", __func__
, bitmap
[1]);
4304 if (unlikely(bitmap
[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES
- 1U)))
4306 if (bitmap
[1] & FATTR4_WORD1_FS_LAYOUT_TYPES
) {
4307 status
= decode_first_pnfs_layout_type(xdr
, layouttype
);
4308 bitmap
[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES
;
4314 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
4317 uint32_t attrlen
, bitmap
[2];
4320 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4322 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4324 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4327 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
4329 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
4331 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
4333 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
4335 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
4336 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
4338 fsinfo
->wtpref
= fsinfo
->wtmax
;
4339 status
= decode_attr_time_delta(xdr
, bitmap
, &fsinfo
->time_delta
);
4342 status
= decode_attr_pnfstype(xdr
, bitmap
, &fsinfo
->layouttype
);
4346 status
= verify_attr_len(xdr
, savep
, attrlen
);
4348 dprintk("%s: xdr returned %d!\n", __func__
, -status
);
4352 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
4358 /* Zero handle first to allow comparisons */
4359 memset(fh
, 0, sizeof(*fh
));
4361 status
= decode_op_hdr(xdr
, OP_GETFH
);
4365 p
= xdr_inline_decode(xdr
, 4);
4368 len
= be32_to_cpup(p
);
4369 if (len
> NFS4_FHSIZE
)
4372 p
= xdr_inline_decode(xdr
, len
);
4375 memcpy(fh
->data
, p
, len
);
4378 print_overflow_msg(__func__
, xdr
);
4382 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4386 status
= decode_op_hdr(xdr
, OP_LINK
);
4389 return decode_change_info(xdr
, cinfo
);
4393 * We create the owner, so we know a proper owner.id length is 4.
4395 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
4397 uint64_t offset
, length
, clientid
;
4399 uint32_t namelen
, type
;
4401 p
= xdr_inline_decode(xdr
, 32); /* read 32 bytes */
4404 p
= xdr_decode_hyper(p
, &offset
); /* read 2 8-byte long words */
4405 p
= xdr_decode_hyper(p
, &length
);
4406 type
= be32_to_cpup(p
++); /* 4 byte read */
4407 if (fl
!= NULL
) { /* manipulate file lock */
4408 fl
->fl_start
= (loff_t
)offset
;
4409 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
4410 if (length
== ~(uint64_t)0)
4411 fl
->fl_end
= OFFSET_MAX
;
4412 fl
->fl_type
= F_WRLCK
;
4414 fl
->fl_type
= F_RDLCK
;
4417 p
= xdr_decode_hyper(p
, &clientid
); /* read 8 bytes */
4418 namelen
= be32_to_cpup(p
); /* read 4 bytes */ /* have read all 32 bytes now */
4419 p
= xdr_inline_decode(xdr
, namelen
); /* variable size field */
4421 return -NFS4ERR_DENIED
;
4423 print_overflow_msg(__func__
, xdr
);
4427 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
4431 status
= decode_op_hdr(xdr
, OP_LOCK
);
4435 status
= decode_stateid(xdr
, &res
->stateid
);
4436 if (unlikely(status
))
4438 } else if (status
== -NFS4ERR_DENIED
)
4439 status
= decode_lock_denied(xdr
, NULL
);
4440 if (res
->open_seqid
!= NULL
)
4441 nfs_increment_open_seqid(status
, res
->open_seqid
);
4442 nfs_increment_lock_seqid(status
, res
->lock_seqid
);
4447 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
4450 status
= decode_op_hdr(xdr
, OP_LOCKT
);
4451 if (status
== -NFS4ERR_DENIED
)
4452 return decode_lock_denied(xdr
, res
->denied
);
4456 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
4460 status
= decode_op_hdr(xdr
, OP_LOCKU
);
4462 nfs_increment_lock_seqid(status
, res
->seqid
);
4464 status
= decode_stateid(xdr
, &res
->stateid
);
4468 static int decode_release_lockowner(struct xdr_stream
*xdr
)
4470 return decode_op_hdr(xdr
, OP_RELEASE_LOCKOWNER
);
4473 static int decode_lookup(struct xdr_stream
*xdr
)
4475 return decode_op_hdr(xdr
, OP_LOOKUP
);
4478 /* This is too sick! */
4479 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
4482 uint32_t limit_type
, nblocks
, blocksize
;
4484 p
= xdr_inline_decode(xdr
, 12);
4487 limit_type
= be32_to_cpup(p
++);
4488 switch (limit_type
) {
4490 xdr_decode_hyper(p
, maxsize
);
4493 nblocks
= be32_to_cpup(p
++);
4494 blocksize
= be32_to_cpup(p
);
4495 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
4499 print_overflow_msg(__func__
, xdr
);
4503 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4506 uint32_t delegation_type
;
4509 p
= xdr_inline_decode(xdr
, 4);
4512 delegation_type
= be32_to_cpup(p
);
4513 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
4514 res
->delegation_type
= 0;
4517 status
= decode_stateid(xdr
, &res
->delegation
);
4518 if (unlikely(status
))
4520 p
= xdr_inline_decode(xdr
, 4);
4523 res
->do_recall
= be32_to_cpup(p
);
4525 switch (delegation_type
) {
4526 case NFS4_OPEN_DELEGATE_READ
:
4527 res
->delegation_type
= FMODE_READ
;
4529 case NFS4_OPEN_DELEGATE_WRITE
:
4530 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
4531 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
4534 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
4536 print_overflow_msg(__func__
, xdr
);
4540 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
4543 uint32_t savewords
, bmlen
, i
;
4546 status
= decode_op_hdr(xdr
, OP_OPEN
);
4548 nfs_increment_open_seqid(status
, res
->seqid
);
4550 status
= decode_stateid(xdr
, &res
->stateid
);
4551 if (unlikely(status
))
4554 decode_change_info(xdr
, &res
->cinfo
);
4556 p
= xdr_inline_decode(xdr
, 8);
4559 res
->rflags
= be32_to_cpup(p
++);
4560 bmlen
= be32_to_cpup(p
);
4564 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4567 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
4568 for (i
= 0; i
< savewords
; ++i
)
4569 res
->attrset
[i
] = be32_to_cpup(p
++);
4570 for (; i
< NFS4_BITMAP_SIZE
; i
++)
4571 res
->attrset
[i
] = 0;
4573 return decode_delegation(xdr
, res
);
4575 dprintk("%s: Bitmap too large! Length = %u\n", __func__
, bmlen
);
4578 print_overflow_msg(__func__
, xdr
);
4582 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
4586 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
4588 nfs_increment_open_seqid(status
, res
->seqid
);
4590 status
= decode_stateid(xdr
, &res
->stateid
);
4594 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
4598 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
4600 nfs_increment_open_seqid(status
, res
->seqid
);
4602 status
= decode_stateid(xdr
, &res
->stateid
);
4606 static int decode_putfh(struct xdr_stream
*xdr
)
4608 return decode_op_hdr(xdr
, OP_PUTFH
);
4611 static int decode_putrootfh(struct xdr_stream
*xdr
)
4613 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
4616 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
4618 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4620 uint32_t count
, eof
, recvd
, hdrlen
;
4623 status
= decode_op_hdr(xdr
, OP_READ
);
4626 p
= xdr_inline_decode(xdr
, 8);
4629 eof
= be32_to_cpup(p
++);
4630 count
= be32_to_cpup(p
);
4631 hdrlen
= (u8
*) xdr
->p
- (u8
*) iov
->iov_base
;
4632 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4633 if (count
> recvd
) {
4634 dprintk("NFS: server cheating in read reply: "
4635 "count %u > recvd %u\n", count
, recvd
);
4639 xdr_read_pages(xdr
, count
);
4644 print_overflow_msg(__func__
, xdr
);
4648 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
4650 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4651 struct kvec
*iov
= rcvbuf
->head
;
4653 u32 recvd
, pglen
= rcvbuf
->page_len
;
4656 status
= decode_op_hdr(xdr
, OP_READDIR
);
4658 status
= decode_verifier(xdr
, readdir
->verifier
.data
);
4659 if (unlikely(status
))
4661 dprintk("%s: verifier = %08x:%08x\n",
4663 ((u32
*)readdir
->verifier
.data
)[0],
4664 ((u32
*)readdir
->verifier
.data
)[1]);
4667 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4668 recvd
= rcvbuf
->len
- hdrlen
;
4671 xdr_read_pages(xdr
, pglen
);
4677 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
4679 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
4680 struct kvec
*iov
= rcvbuf
->head
;
4686 status
= decode_op_hdr(xdr
, OP_READLINK
);
4690 /* Convert length of symlink */
4691 p
= xdr_inline_decode(xdr
, 4);
4694 len
= be32_to_cpup(p
);
4695 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
4696 dprintk("nfs: server returned giant symlink!\n");
4697 return -ENAMETOOLONG
;
4699 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
4700 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4702 dprintk("NFS: server cheating in readlink reply: "
4703 "count %u > recvd %u\n", len
, recvd
);
4706 xdr_read_pages(xdr
, len
);
4708 * The XDR encode routine has set things up so that
4709 * the link text will be copied directly into the
4710 * buffer. We just have to do overflow-checking,
4711 * and and null-terminate the text (the VFS expects
4712 * null-termination).
4714 xdr_terminate_string(rcvbuf
, len
);
4717 print_overflow_msg(__func__
, xdr
);
4721 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
4725 status
= decode_op_hdr(xdr
, OP_REMOVE
);
4728 status
= decode_change_info(xdr
, cinfo
);
4733 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
4734 struct nfs4_change_info
*new_cinfo
)
4738 status
= decode_op_hdr(xdr
, OP_RENAME
);
4741 if ((status
= decode_change_info(xdr
, old_cinfo
)))
4743 status
= decode_change_info(xdr
, new_cinfo
);
4748 static int decode_renew(struct xdr_stream
*xdr
)
4750 return decode_op_hdr(xdr
, OP_RENEW
);
4754 decode_restorefh(struct xdr_stream
*xdr
)
4756 return decode_op_hdr(xdr
, OP_RESTOREFH
);
4759 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
4765 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
4769 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
4771 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
4773 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
4776 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
4778 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
4782 /* We ignore &savep and don't do consistency checks on
4783 * the attr length. Let userspace figure it out.... */
4784 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
4785 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
4786 if (attrlen
> recvd
) {
4787 dprintk("NFS: server cheating in getattr"
4788 " acl reply: attrlen %u > recvd %u\n",
4792 xdr_read_pages(xdr
, attrlen
);
4795 status
= -EOPNOTSUPP
;
4802 decode_savefh(struct xdr_stream
*xdr
)
4804 return decode_op_hdr(xdr
, OP_SAVEFH
);
4807 static int decode_setattr(struct xdr_stream
*xdr
)
4813 status
= decode_op_hdr(xdr
, OP_SETATTR
);
4816 p
= xdr_inline_decode(xdr
, 4);
4819 bmlen
= be32_to_cpup(p
);
4820 p
= xdr_inline_decode(xdr
, bmlen
<< 2);
4824 print_overflow_msg(__func__
, xdr
);
4828 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_setclientid_res
*res
)
4834 p
= xdr_inline_decode(xdr
, 8);
4837 opnum
= be32_to_cpup(p
++);
4838 if (opnum
!= OP_SETCLIENTID
) {
4839 dprintk("nfs: decode_setclientid: Server returned operation"
4843 nfserr
= be32_to_cpup(p
);
4844 if (nfserr
== NFS_OK
) {
4845 p
= xdr_inline_decode(xdr
, 8 + NFS4_VERIFIER_SIZE
);
4848 p
= xdr_decode_hyper(p
, &res
->clientid
);
4849 memcpy(res
->confirm
.data
, p
, NFS4_VERIFIER_SIZE
);
4850 } else if (nfserr
== NFSERR_CLID_INUSE
) {
4853 /* skip netid string */
4854 p
= xdr_inline_decode(xdr
, 4);
4857 len
= be32_to_cpup(p
);
4858 p
= xdr_inline_decode(xdr
, len
);
4862 /* skip uaddr string */
4863 p
= xdr_inline_decode(xdr
, 4);
4866 len
= be32_to_cpup(p
);
4867 p
= xdr_inline_decode(xdr
, len
);
4870 return -NFSERR_CLID_INUSE
;
4872 return nfs4_stat_to_errno(nfserr
);
4876 print_overflow_msg(__func__
, xdr
);
4880 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
4882 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
4885 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
4890 status
= decode_op_hdr(xdr
, OP_WRITE
);
4894 p
= xdr_inline_decode(xdr
, 16);
4897 res
->count
= be32_to_cpup(p
++);
4898 res
->verf
->committed
= be32_to_cpup(p
++);
4899 memcpy(res
->verf
->verifier
, p
, 8);
4902 print_overflow_msg(__func__
, xdr
);
4906 static int decode_delegreturn(struct xdr_stream
*xdr
)
4908 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
4911 static int decode_secinfo_gss(struct xdr_stream
*xdr
, struct nfs4_secinfo_flavor
*flavor
)
4915 p
= xdr_inline_decode(xdr
, 4);
4918 flavor
->gss
.sec_oid4
.len
= be32_to_cpup(p
);
4919 if (flavor
->gss
.sec_oid4
.len
> GSS_OID_MAX_LEN
)
4922 p
= xdr_inline_decode(xdr
, flavor
->gss
.sec_oid4
.len
);
4925 memcpy(flavor
->gss
.sec_oid4
.data
, p
, flavor
->gss
.sec_oid4
.len
);
4927 p
= xdr_inline_decode(xdr
, 8);
4930 flavor
->gss
.qop4
= be32_to_cpup(p
++);
4931 flavor
->gss
.service
= be32_to_cpup(p
);
4936 print_overflow_msg(__func__
, xdr
);
4942 static int decode_secinfo(struct xdr_stream
*xdr
, struct nfs4_secinfo_res
*res
)
4944 struct nfs4_secinfo_flavor
*sec_flavor
;
4949 status
= decode_op_hdr(xdr
, OP_SECINFO
);
4952 p
= xdr_inline_decode(xdr
, 4);
4956 res
->flavors
->num_flavors
= 0;
4957 num_flavors
= be32_to_cpup(p
);
4959 for (i
= 0; i
< num_flavors
; i
++) {
4960 sec_flavor
= &res
->flavors
->flavors
[i
];
4961 if ((char *)&sec_flavor
[1] - (char *)res
->flavors
> PAGE_SIZE
)
4964 p
= xdr_inline_decode(xdr
, 4);
4967 sec_flavor
->flavor
= be32_to_cpup(p
);
4969 if (sec_flavor
->flavor
== RPC_AUTH_GSS
) {
4970 status
= decode_secinfo_gss(xdr
, sec_flavor
);
4974 res
->flavors
->num_flavors
++;
4980 print_overflow_msg(__func__
, xdr
);
4984 #if defined(CONFIG_NFS_V4_1)
4985 static int decode_exchange_id(struct xdr_stream
*xdr
,
4986 struct nfs41_exchange_id_res
*res
)
4992 struct nfs_client
*clp
= res
->client
;
4994 status
= decode_op_hdr(xdr
, OP_EXCHANGE_ID
);
4998 p
= xdr_inline_decode(xdr
, 8);
5001 xdr_decode_hyper(p
, &clp
->cl_clientid
);
5002 p
= xdr_inline_decode(xdr
, 12);
5005 clp
->cl_seqid
= be32_to_cpup(p
++);
5006 clp
->cl_exchange_flags
= be32_to_cpup(p
++);
5008 /* We ask for SP4_NONE */
5009 dummy
= be32_to_cpup(p
);
5010 if (dummy
!= SP4_NONE
)
5013 /* Throw away minor_id */
5014 p
= xdr_inline_decode(xdr
, 8);
5018 /* Throw away Major id */
5019 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5020 if (unlikely(status
))
5023 /* Save server_scope */
5024 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5025 if (unlikely(status
))
5028 if (unlikely(dummy
> NFS4_OPAQUE_LIMIT
))
5031 memcpy(res
->server_scope
->server_scope
, dummy_str
, dummy
);
5032 res
->server_scope
->server_scope_sz
= dummy
;
5034 /* Throw away Implementation id array */
5035 status
= decode_opaque_inline(xdr
, &dummy
, &dummy_str
);
5036 if (unlikely(status
))
5041 print_overflow_msg(__func__
, xdr
);
5045 static int decode_chan_attrs(struct xdr_stream
*xdr
,
5046 struct nfs4_channel_attrs
*attrs
)
5051 p
= xdr_inline_decode(xdr
, 28);
5054 val
= be32_to_cpup(p
++); /* headerpadsz */
5056 return -EINVAL
; /* no support for header padding yet */
5057 attrs
->max_rqst_sz
= be32_to_cpup(p
++);
5058 attrs
->max_resp_sz
= be32_to_cpup(p
++);
5059 attrs
->max_resp_sz_cached
= be32_to_cpup(p
++);
5060 attrs
->max_ops
= be32_to_cpup(p
++);
5061 attrs
->max_reqs
= be32_to_cpup(p
++);
5062 nr_attrs
= be32_to_cpup(p
);
5063 if (unlikely(nr_attrs
> 1)) {
5064 printk(KERN_WARNING
"%s: Invalid rdma channel attrs count %u\n",
5065 __func__
, nr_attrs
);
5068 if (nr_attrs
== 1) {
5069 p
= xdr_inline_decode(xdr
, 4); /* skip rdma_attrs */
5075 print_overflow_msg(__func__
, xdr
);
5079 static int decode_sessionid(struct xdr_stream
*xdr
, struct nfs4_sessionid
*sid
)
5081 return decode_opaque_fixed(xdr
, sid
->data
, NFS4_MAX_SESSIONID_LEN
);
5084 static int decode_create_session(struct xdr_stream
*xdr
,
5085 struct nfs41_create_session_res
*res
)
5089 struct nfs_client
*clp
= res
->client
;
5090 struct nfs4_session
*session
= clp
->cl_session
;
5092 status
= decode_op_hdr(xdr
, OP_CREATE_SESSION
);
5094 status
= decode_sessionid(xdr
, &session
->sess_id
);
5095 if (unlikely(status
))
5099 p
= xdr_inline_decode(xdr
, 8);
5102 clp
->cl_seqid
= be32_to_cpup(p
++);
5103 session
->flags
= be32_to_cpup(p
);
5105 /* Channel attributes */
5106 status
= decode_chan_attrs(xdr
, &session
->fc_attrs
);
5108 status
= decode_chan_attrs(xdr
, &session
->bc_attrs
);
5111 print_overflow_msg(__func__
, xdr
);
5115 static int decode_destroy_session(struct xdr_stream
*xdr
, void *dummy
)
5117 return decode_op_hdr(xdr
, OP_DESTROY_SESSION
);
5120 static int decode_reclaim_complete(struct xdr_stream
*xdr
, void *dummy
)
5122 return decode_op_hdr(xdr
, OP_RECLAIM_COMPLETE
);
5124 #endif /* CONFIG_NFS_V4_1 */
5126 static int decode_sequence(struct xdr_stream
*xdr
,
5127 struct nfs4_sequence_res
*res
,
5128 struct rpc_rqst
*rqstp
)
5130 #if defined(CONFIG_NFS_V4_1)
5131 struct nfs4_sessionid id
;
5136 if (!res
->sr_session
)
5139 status
= decode_op_hdr(xdr
, OP_SEQUENCE
);
5141 status
= decode_sessionid(xdr
, &id
);
5142 if (unlikely(status
))
5146 * If the server returns different values for sessionID, slotID or
5147 * sequence number, the server is looney tunes.
5149 status
= -EREMOTEIO
;
5151 if (memcmp(id
.data
, res
->sr_session
->sess_id
.data
,
5152 NFS4_MAX_SESSIONID_LEN
)) {
5153 dprintk("%s Invalid session id\n", __func__
);
5157 p
= xdr_inline_decode(xdr
, 20);
5162 dummy
= be32_to_cpup(p
++);
5163 if (dummy
!= res
->sr_slot
->seq_nr
) {
5164 dprintk("%s Invalid sequence number\n", __func__
);
5168 dummy
= be32_to_cpup(p
++);
5169 if (dummy
!= res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
) {
5170 dprintk("%s Invalid slot id\n", __func__
);
5173 /* highest slot id - currently not processed */
5174 dummy
= be32_to_cpup(p
++);
5175 /* target highest slot id - currently not processed */
5176 dummy
= be32_to_cpup(p
++);
5178 res
->sr_status_flags
= be32_to_cpup(p
);
5181 res
->sr_status
= status
;
5184 print_overflow_msg(__func__
, xdr
);
5187 #else /* CONFIG_NFS_V4_1 */
5189 #endif /* CONFIG_NFS_V4_1 */
5192 #if defined(CONFIG_NFS_V4_1)
5194 static int decode_getdeviceinfo(struct xdr_stream
*xdr
,
5195 struct pnfs_device
*pdev
)
5201 status
= decode_op_hdr(xdr
, OP_GETDEVICEINFO
);
5203 if (status
== -ETOOSMALL
) {
5204 p
= xdr_inline_decode(xdr
, 4);
5207 pdev
->mincount
= be32_to_cpup(p
);
5208 dprintk("%s: Min count too small. mincnt = %u\n",
5209 __func__
, pdev
->mincount
);
5214 p
= xdr_inline_decode(xdr
, 8);
5217 type
= be32_to_cpup(p
++);
5218 if (type
!= pdev
->layout_type
) {
5219 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5220 __func__
, pdev
->layout_type
, type
);
5224 * Get the length of the opaque device_addr4. xdr_read_pages places
5225 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5226 * and places the remaining xdr data in xdr_buf->tail
5228 pdev
->mincount
= be32_to_cpup(p
);
5229 xdr_read_pages(xdr
, pdev
->mincount
); /* include space for the length */
5231 /* Parse notification bitmap, verifying that it is zero. */
5232 p
= xdr_inline_decode(xdr
, 4);
5235 len
= be32_to_cpup(p
);
5239 p
= xdr_inline_decode(xdr
, 4 * len
);
5242 for (i
= 0; i
< len
; i
++, p
++) {
5243 if (be32_to_cpup(p
)) {
5244 dprintk("%s: notifications not supported\n",
5252 print_overflow_msg(__func__
, xdr
);
5256 static int decode_layoutget(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
5257 struct nfs4_layoutget_res
*res
)
5262 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
5263 struct kvec
*iov
= rcvbuf
->head
;
5266 status
= decode_op_hdr(xdr
, OP_LAYOUTGET
);
5269 p
= xdr_inline_decode(xdr
, 8 + NFS4_STATEID_SIZE
);
5272 res
->return_on_close
= be32_to_cpup(p
++);
5273 p
= xdr_decode_opaque_fixed(p
, res
->stateid
.data
, NFS4_STATEID_SIZE
);
5274 layout_count
= be32_to_cpup(p
);
5275 if (!layout_count
) {
5276 dprintk("%s: server responded with empty layout array\n",
5281 p
= xdr_inline_decode(xdr
, 28);
5284 p
= xdr_decode_hyper(p
, &res
->range
.offset
);
5285 p
= xdr_decode_hyper(p
, &res
->range
.length
);
5286 res
->range
.iomode
= be32_to_cpup(p
++);
5287 res
->type
= be32_to_cpup(p
++);
5288 res
->layoutp
->len
= be32_to_cpup(p
);
5290 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5292 (unsigned long)res
->range
.offset
,
5293 (unsigned long)res
->range
.length
,
5298 hdrlen
= (u8
*) xdr
->p
- (u8
*) iov
->iov_base
;
5299 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
5300 if (res
->layoutp
->len
> recvd
) {
5301 dprintk("NFS: server cheating in layoutget reply: "
5302 "layout len %u > recvd %u\n",
5303 res
->layoutp
->len
, recvd
);
5307 xdr_read_pages(xdr
, res
->layoutp
->len
);
5309 if (layout_count
> 1) {
5310 /* We only handle a length one array at the moment. Any
5311 * further entries are just ignored. Note that this means
5312 * the client may see a response that is less than the
5313 * minimum it requested.
5315 dprintk("%s: server responded with %d layouts, dropping tail\n",
5316 __func__
, layout_count
);
5321 print_overflow_msg(__func__
, xdr
);
5325 static int decode_layoutreturn(struct xdr_stream
*xdr
,
5326 struct nfs4_layoutreturn_res
*res
)
5331 status
= decode_op_hdr(xdr
, OP_LAYOUTRETURN
);
5334 p
= xdr_inline_decode(xdr
, 4);
5337 res
->lrs_present
= be32_to_cpup(p
);
5338 if (res
->lrs_present
)
5339 status
= decode_stateid(xdr
, &res
->stateid
);
5342 print_overflow_msg(__func__
, xdr
);
5346 static int decode_layoutcommit(struct xdr_stream
*xdr
,
5347 struct rpc_rqst
*req
,
5348 struct nfs4_layoutcommit_res
*res
)
5354 status
= decode_op_hdr(xdr
, OP_LAYOUTCOMMIT
);
5358 p
= xdr_inline_decode(xdr
, 4);
5361 sizechanged
= be32_to_cpup(p
);
5364 /* throw away new size */
5365 p
= xdr_inline_decode(xdr
, 8);
5371 print_overflow_msg(__func__
, xdr
);
5374 #endif /* CONFIG_NFS_V4_1 */
5377 * END OF "GENERIC" DECODE ROUTINES.
5381 * Decode OPEN_DOWNGRADE response
5383 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
,
5384 struct xdr_stream
*xdr
,
5385 struct nfs_closeres
*res
)
5387 struct compound_hdr hdr
;
5390 status
= decode_compound_hdr(xdr
, &hdr
);
5393 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5396 status
= decode_putfh(xdr
);
5399 status
= decode_open_downgrade(xdr
, res
);
5402 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5403 !RPC_IS_ASYNC(rqstp
->rq_task
));
5409 * Decode ACCESS response
5411 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5412 struct nfs4_accessres
*res
)
5414 struct compound_hdr hdr
;
5417 status
= decode_compound_hdr(xdr
, &hdr
);
5420 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5423 status
= decode_putfh(xdr
);
5426 status
= decode_access(xdr
, res
);
5429 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5430 !RPC_IS_ASYNC(rqstp
->rq_task
));
5436 * Decode LOOKUP response
5438 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5439 struct nfs4_lookup_res
*res
)
5441 struct compound_hdr hdr
;
5444 status
= decode_compound_hdr(xdr
, &hdr
);
5447 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5450 status
= decode_putfh(xdr
);
5453 status
= decode_lookup(xdr
);
5456 status
= decode_getfh(xdr
, res
->fh
);
5459 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
5460 ,!RPC_IS_ASYNC(rqstp
->rq_task
));
5466 * Decode LOOKUP_ROOT response
5468 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
,
5469 struct xdr_stream
*xdr
,
5470 struct nfs4_lookup_res
*res
)
5472 struct compound_hdr hdr
;
5475 status
= decode_compound_hdr(xdr
, &hdr
);
5478 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5481 status
= decode_putrootfh(xdr
);
5484 status
= decode_getfh(xdr
, res
->fh
);
5486 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
,
5487 !RPC_IS_ASYNC(rqstp
->rq_task
));
5493 * Decode REMOVE response
5495 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5496 struct nfs_removeres
*res
)
5498 struct compound_hdr hdr
;
5501 status
= decode_compound_hdr(xdr
, &hdr
);
5504 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5507 status
= decode_putfh(xdr
);
5510 status
= decode_remove(xdr
, &res
->cinfo
);
5513 decode_getfattr(xdr
, res
->dir_attr
, res
->server
,
5514 !RPC_IS_ASYNC(rqstp
->rq_task
));
5520 * Decode RENAME response
5522 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5523 struct nfs_renameres
*res
)
5525 struct compound_hdr hdr
;
5528 status
= decode_compound_hdr(xdr
, &hdr
);
5531 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5534 status
= decode_putfh(xdr
);
5537 status
= decode_savefh(xdr
);
5540 status
= decode_putfh(xdr
);
5543 status
= decode_rename(xdr
, &res
->old_cinfo
, &res
->new_cinfo
);
5546 /* Current FH is target directory */
5547 if (decode_getfattr(xdr
, res
->new_fattr
, res
->server
,
5548 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5550 status
= decode_restorefh(xdr
);
5553 decode_getfattr(xdr
, res
->old_fattr
, res
->server
,
5554 !RPC_IS_ASYNC(rqstp
->rq_task
));
5560 * Decode LINK response
5562 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5563 struct nfs4_link_res
*res
)
5565 struct compound_hdr hdr
;
5568 status
= decode_compound_hdr(xdr
, &hdr
);
5571 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5574 status
= decode_putfh(xdr
);
5577 status
= decode_savefh(xdr
);
5580 status
= decode_putfh(xdr
);
5583 status
= decode_link(xdr
, &res
->cinfo
);
5587 * Note order: OP_LINK leaves the directory as the current
5590 if (decode_getfattr(xdr
, res
->dir_attr
, res
->server
,
5591 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5593 status
= decode_restorefh(xdr
);
5596 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5597 !RPC_IS_ASYNC(rqstp
->rq_task
));
5603 * Decode CREATE response
5605 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5606 struct nfs4_create_res
*res
)
5608 struct compound_hdr hdr
;
5611 status
= decode_compound_hdr(xdr
, &hdr
);
5614 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5617 status
= decode_putfh(xdr
);
5620 status
= decode_savefh(xdr
);
5623 status
= decode_create(xdr
, &res
->dir_cinfo
);
5626 status
= decode_getfh(xdr
, res
->fh
);
5629 if (decode_getfattr(xdr
, res
->fattr
, res
->server
,
5630 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5632 status
= decode_restorefh(xdr
);
5635 decode_getfattr(xdr
, res
->dir_fattr
, res
->server
,
5636 !RPC_IS_ASYNC(rqstp
->rq_task
));
5642 * Decode SYMLINK response
5644 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5645 struct nfs4_create_res
*res
)
5647 return nfs4_xdr_dec_create(rqstp
, xdr
, res
);
5651 * Decode GETATTR response
5653 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5654 struct nfs4_getattr_res
*res
)
5656 struct compound_hdr hdr
;
5659 status
= decode_compound_hdr(xdr
, &hdr
);
5662 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5665 status
= decode_putfh(xdr
);
5668 status
= decode_getfattr(xdr
, res
->fattr
, res
->server
,
5669 !RPC_IS_ASYNC(rqstp
->rq_task
));
5675 * Encode an SETACL request
5677 static void nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
5678 struct nfs_setaclargs
*args
)
5680 struct compound_hdr hdr
= {
5681 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
5684 encode_compound_hdr(xdr
, req
, &hdr
);
5685 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
5686 encode_putfh(xdr
, args
->fh
, &hdr
);
5687 encode_setacl(xdr
, args
, &hdr
);
5692 * Decode SETACL response
5695 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5696 struct nfs_setaclres
*res
)
5698 struct compound_hdr hdr
;
5701 status
= decode_compound_hdr(xdr
, &hdr
);
5704 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5707 status
= decode_putfh(xdr
);
5710 status
= decode_setattr(xdr
);
5716 * Decode GETACL response
5719 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5720 struct nfs_getaclres
*res
)
5722 struct compound_hdr hdr
;
5725 status
= decode_compound_hdr(xdr
, &hdr
);
5728 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5731 status
= decode_putfh(xdr
);
5734 status
= decode_getacl(xdr
, rqstp
, &res
->acl_len
);
5741 * Decode CLOSE response
5743 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5744 struct nfs_closeres
*res
)
5746 struct compound_hdr hdr
;
5749 status
= decode_compound_hdr(xdr
, &hdr
);
5752 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5755 status
= decode_putfh(xdr
);
5758 status
= decode_close(xdr
, res
);
5762 * Note: Server may do delete on close for this file
5763 * in which case the getattr call will fail with
5764 * an ESTALE error. Shouldn't be a problem,
5765 * though, since fattr->valid will remain unset.
5767 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5768 !RPC_IS_ASYNC(rqstp
->rq_task
));
5774 * Decode OPEN response
5776 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5777 struct nfs_openres
*res
)
5779 struct compound_hdr hdr
;
5782 status
= decode_compound_hdr(xdr
, &hdr
);
5785 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5788 status
= decode_putfh(xdr
);
5791 status
= decode_savefh(xdr
);
5794 status
= decode_open(xdr
, res
);
5797 if (decode_getfh(xdr
, &res
->fh
) != 0)
5799 if (decode_getfattr(xdr
, res
->f_attr
, res
->server
,
5800 !RPC_IS_ASYNC(rqstp
->rq_task
)) != 0)
5802 if (decode_restorefh(xdr
) != 0)
5804 decode_getfattr(xdr
, res
->dir_attr
, res
->server
,
5805 !RPC_IS_ASYNC(rqstp
->rq_task
));
5811 * Decode OPEN_CONFIRM response
5813 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
,
5814 struct xdr_stream
*xdr
,
5815 struct nfs_open_confirmres
*res
)
5817 struct compound_hdr hdr
;
5820 status
= decode_compound_hdr(xdr
, &hdr
);
5823 status
= decode_putfh(xdr
);
5826 status
= decode_open_confirm(xdr
, res
);
5832 * Decode OPEN response
5834 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
,
5835 struct xdr_stream
*xdr
,
5836 struct nfs_openres
*res
)
5838 struct compound_hdr hdr
;
5841 status
= decode_compound_hdr(xdr
, &hdr
);
5844 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5847 status
= decode_putfh(xdr
);
5850 status
= decode_open(xdr
, res
);
5853 decode_getfattr(xdr
, res
->f_attr
, res
->server
,
5854 !RPC_IS_ASYNC(rqstp
->rq_task
));
5860 * Decode SETATTR response
5862 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
,
5863 struct xdr_stream
*xdr
,
5864 struct nfs_setattrres
*res
)
5866 struct compound_hdr hdr
;
5869 status
= decode_compound_hdr(xdr
, &hdr
);
5872 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5875 status
= decode_putfh(xdr
);
5878 status
= decode_setattr(xdr
);
5881 decode_getfattr(xdr
, res
->fattr
, res
->server
,
5882 !RPC_IS_ASYNC(rqstp
->rq_task
));
5888 * Decode LOCK response
5890 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5891 struct nfs_lock_res
*res
)
5893 struct compound_hdr hdr
;
5896 status
= decode_compound_hdr(xdr
, &hdr
);
5899 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5902 status
= decode_putfh(xdr
);
5905 status
= decode_lock(xdr
, res
);
5911 * Decode LOCKT response
5913 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5914 struct nfs_lockt_res
*res
)
5916 struct compound_hdr hdr
;
5919 status
= decode_compound_hdr(xdr
, &hdr
);
5922 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5925 status
= decode_putfh(xdr
);
5928 status
= decode_lockt(xdr
, res
);
5934 * Decode LOCKU response
5936 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5937 struct nfs_locku_res
*res
)
5939 struct compound_hdr hdr
;
5942 status
= decode_compound_hdr(xdr
, &hdr
);
5945 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5948 status
= decode_putfh(xdr
);
5951 status
= decode_locku(xdr
, res
);
5956 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst
*rqstp
,
5957 struct xdr_stream
*xdr
, void *dummy
)
5959 struct compound_hdr hdr
;
5962 status
= decode_compound_hdr(xdr
, &hdr
);
5964 status
= decode_release_lockowner(xdr
);
5969 * Decode READLINK response
5971 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
,
5972 struct xdr_stream
*xdr
,
5973 struct nfs4_readlink_res
*res
)
5975 struct compound_hdr hdr
;
5978 status
= decode_compound_hdr(xdr
, &hdr
);
5981 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
5984 status
= decode_putfh(xdr
);
5987 status
= decode_readlink(xdr
, rqstp
);
5993 * Decode READDIR response
5995 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
5996 struct nfs4_readdir_res
*res
)
5998 struct compound_hdr hdr
;
6001 status
= decode_compound_hdr(xdr
, &hdr
);
6004 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6007 status
= decode_putfh(xdr
);
6010 status
= decode_readdir(xdr
, rqstp
, res
);
6016 * Decode Read response
6018 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6019 struct nfs_readres
*res
)
6021 struct compound_hdr hdr
;
6024 status
= decode_compound_hdr(xdr
, &hdr
);
6027 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6030 status
= decode_putfh(xdr
);
6033 status
= decode_read(xdr
, rqstp
, res
);
6035 status
= res
->count
;
6041 * Decode WRITE response
6043 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6044 struct nfs_writeres
*res
)
6046 struct compound_hdr hdr
;
6049 status
= decode_compound_hdr(xdr
, &hdr
);
6052 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6055 status
= decode_putfh(xdr
);
6058 status
= decode_write(xdr
, res
);
6062 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6063 !RPC_IS_ASYNC(rqstp
->rq_task
));
6065 status
= res
->count
;
6071 * Decode COMMIT response
6073 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6074 struct nfs_writeres
*res
)
6076 struct compound_hdr hdr
;
6079 status
= decode_compound_hdr(xdr
, &hdr
);
6082 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6085 status
= decode_putfh(xdr
);
6088 status
= decode_commit(xdr
, res
);
6092 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6093 !RPC_IS_ASYNC(rqstp
->rq_task
));
6099 * Decode FSINFO response
6101 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6102 struct nfs4_fsinfo_res
*res
)
6104 struct compound_hdr hdr
;
6107 status
= decode_compound_hdr(xdr
, &hdr
);
6109 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6111 status
= decode_putfh(xdr
);
6113 status
= decode_fsinfo(xdr
, res
->fsinfo
);
6118 * Decode PATHCONF response
6120 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6121 struct nfs4_pathconf_res
*res
)
6123 struct compound_hdr hdr
;
6126 status
= decode_compound_hdr(xdr
, &hdr
);
6128 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6130 status
= decode_putfh(xdr
);
6132 status
= decode_pathconf(xdr
, res
->pathconf
);
6137 * Decode STATFS response
6139 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
6140 struct nfs4_statfs_res
*res
)
6142 struct compound_hdr hdr
;
6145 status
= decode_compound_hdr(xdr
, &hdr
);
6147 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6149 status
= decode_putfh(xdr
);
6151 status
= decode_statfs(xdr
, res
->fsstat
);
6156 * Decode GETATTR_BITMAP response
6158 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
,
6159 struct xdr_stream
*xdr
,
6160 struct nfs4_server_caps_res
*res
)
6162 struct compound_hdr hdr
;
6165 status
= decode_compound_hdr(xdr
, &hdr
);
6168 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6171 status
= decode_putfh(xdr
);
6174 status
= decode_server_caps(xdr
, res
);
6180 * Decode RENEW response
6182 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, struct xdr_stream
*xdr
,
6185 struct compound_hdr hdr
;
6188 status
= decode_compound_hdr(xdr
, &hdr
);
6190 status
= decode_renew(xdr
);
6195 * Decode SETCLIENTID response
6197 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
,
6198 struct xdr_stream
*xdr
,
6199 struct nfs4_setclientid_res
*res
)
6201 struct compound_hdr hdr
;
6204 status
= decode_compound_hdr(xdr
, &hdr
);
6206 status
= decode_setclientid(xdr
, res
);
6211 * Decode SETCLIENTID_CONFIRM response
6213 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
,
6214 struct xdr_stream
*xdr
,
6215 struct nfs_fsinfo
*fsinfo
)
6217 struct compound_hdr hdr
;
6220 status
= decode_compound_hdr(xdr
, &hdr
);
6222 status
= decode_setclientid_confirm(xdr
);
6224 status
= decode_putrootfh(xdr
);
6226 status
= decode_fsinfo(xdr
, fsinfo
);
6231 * Decode DELEGRETURN response
6233 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
,
6234 struct xdr_stream
*xdr
,
6235 struct nfs4_delegreturnres
*res
)
6237 struct compound_hdr hdr
;
6240 status
= decode_compound_hdr(xdr
, &hdr
);
6243 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6246 status
= decode_putfh(xdr
);
6249 status
= decode_delegreturn(xdr
);
6252 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6253 !RPC_IS_ASYNC(rqstp
->rq_task
));
6259 * Decode FS_LOCATIONS response
6261 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
,
6262 struct xdr_stream
*xdr
,
6263 struct nfs4_fs_locations_res
*res
)
6265 struct compound_hdr hdr
;
6268 status
= decode_compound_hdr(xdr
, &hdr
);
6271 status
= decode_sequence(xdr
, &res
->seq_res
, req
);
6274 status
= decode_putfh(xdr
);
6277 status
= decode_lookup(xdr
);
6280 xdr_enter_page(xdr
, PAGE_SIZE
);
6281 status
= decode_getfattr(xdr
, &res
->fs_locations
->fattr
,
6282 res
->fs_locations
->server
,
6283 !RPC_IS_ASYNC(req
->rq_task
));
6289 * Decode SECINFO response
6291 static int nfs4_xdr_dec_secinfo(struct rpc_rqst
*rqstp
,
6292 struct xdr_stream
*xdr
,
6293 struct nfs4_secinfo_res
*res
)
6295 struct compound_hdr hdr
;
6298 status
= decode_compound_hdr(xdr
, &hdr
);
6301 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6304 status
= decode_putfh(xdr
);
6307 status
= decode_secinfo(xdr
, res
);
6314 #if defined(CONFIG_NFS_V4_1)
6316 * Decode EXCHANGE_ID response
6318 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst
*rqstp
,
6319 struct xdr_stream
*xdr
,
6322 struct compound_hdr hdr
;
6325 status
= decode_compound_hdr(xdr
, &hdr
);
6327 status
= decode_exchange_id(xdr
, res
);
6332 * Decode CREATE_SESSION response
6334 static int nfs4_xdr_dec_create_session(struct rpc_rqst
*rqstp
,
6335 struct xdr_stream
*xdr
,
6336 struct nfs41_create_session_res
*res
)
6338 struct compound_hdr hdr
;
6341 status
= decode_compound_hdr(xdr
, &hdr
);
6343 status
= decode_create_session(xdr
, res
);
6348 * Decode DESTROY_SESSION response
6350 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst
*rqstp
,
6351 struct xdr_stream
*xdr
,
6354 struct compound_hdr hdr
;
6357 status
= decode_compound_hdr(xdr
, &hdr
);
6359 status
= decode_destroy_session(xdr
, res
);
6364 * Decode SEQUENCE response
6366 static int nfs4_xdr_dec_sequence(struct rpc_rqst
*rqstp
,
6367 struct xdr_stream
*xdr
,
6368 struct nfs4_sequence_res
*res
)
6370 struct compound_hdr hdr
;
6373 status
= decode_compound_hdr(xdr
, &hdr
);
6375 status
= decode_sequence(xdr
, res
, rqstp
);
6380 * Decode GET_LEASE_TIME response
6382 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst
*rqstp
,
6383 struct xdr_stream
*xdr
,
6384 struct nfs4_get_lease_time_res
*res
)
6386 struct compound_hdr hdr
;
6389 status
= decode_compound_hdr(xdr
, &hdr
);
6391 status
= decode_sequence(xdr
, &res
->lr_seq_res
, rqstp
);
6393 status
= decode_putrootfh(xdr
);
6395 status
= decode_fsinfo(xdr
, res
->lr_fsinfo
);
6400 * Decode RECLAIM_COMPLETE response
6402 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst
*rqstp
,
6403 struct xdr_stream
*xdr
,
6404 struct nfs41_reclaim_complete_res
*res
)
6406 struct compound_hdr hdr
;
6409 status
= decode_compound_hdr(xdr
, &hdr
);
6411 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6413 status
= decode_reclaim_complete(xdr
, (void *)NULL
);
6418 * Decode GETDEVINFO response
6420 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst
*rqstp
,
6421 struct xdr_stream
*xdr
,
6422 struct nfs4_getdeviceinfo_res
*res
)
6424 struct compound_hdr hdr
;
6427 status
= decode_compound_hdr(xdr
, &hdr
);
6430 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6433 status
= decode_getdeviceinfo(xdr
, res
->pdev
);
6439 * Decode LAYOUTGET response
6441 static int nfs4_xdr_dec_layoutget(struct rpc_rqst
*rqstp
,
6442 struct xdr_stream
*xdr
,
6443 struct nfs4_layoutget_res
*res
)
6445 struct compound_hdr hdr
;
6448 status
= decode_compound_hdr(xdr
, &hdr
);
6451 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6454 status
= decode_putfh(xdr
);
6457 status
= decode_layoutget(xdr
, rqstp
, res
);
6463 * Decode LAYOUTRETURN response
6465 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst
*rqstp
,
6466 struct xdr_stream
*xdr
,
6467 struct nfs4_layoutreturn_res
*res
)
6469 struct compound_hdr hdr
;
6472 status
= decode_compound_hdr(xdr
, &hdr
);
6475 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6478 status
= decode_putfh(xdr
);
6481 status
= decode_layoutreturn(xdr
, res
);
6487 * Decode LAYOUTCOMMIT response
6489 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst
*rqstp
,
6490 struct xdr_stream
*xdr
,
6491 struct nfs4_layoutcommit_res
*res
)
6493 struct compound_hdr hdr
;
6496 status
= decode_compound_hdr(xdr
, &hdr
);
6499 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6502 status
= decode_putfh(xdr
);
6505 status
= decode_layoutcommit(xdr
, rqstp
, res
);
6508 decode_getfattr(xdr
, res
->fattr
, res
->server
,
6509 !RPC_IS_ASYNC(rqstp
->rq_task
));
6515 * Decode SECINFO_NO_NAME response
6517 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst
*rqstp
,
6518 struct xdr_stream
*xdr
,
6519 struct nfs4_secinfo_res
*res
)
6521 struct compound_hdr hdr
;
6524 status
= decode_compound_hdr(xdr
, &hdr
);
6527 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
6530 status
= decode_putrootfh(xdr
);
6533 status
= decode_secinfo(xdr
, res
);
6537 #endif /* CONFIG_NFS_V4_1 */
6540 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6541 * the local page cache.
6542 * @xdr: XDR stream where entry resides
6543 * @entry: buffer to fill in with entry data
6544 * @plus: boolean indicating whether this should be a readdirplus entry
6546 * Returns zero if successful, otherwise a negative errno value is
6549 * This function is not invoked during READDIR reply decoding, but
6550 * rather whenever an application invokes the getdents(2) system call
6551 * on a directory already in our cache.
6553 int nfs4_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
6556 uint32_t bitmap
[2] = {0};
6558 __be32
*p
= xdr_inline_decode(xdr
, 4);
6561 if (*p
== xdr_zero
) {
6562 p
= xdr_inline_decode(xdr
, 4);
6571 p
= xdr_inline_decode(xdr
, 12);
6574 entry
->prev_cookie
= entry
->cookie
;
6575 p
= xdr_decode_hyper(p
, &entry
->cookie
);
6576 entry
->len
= be32_to_cpup(p
);
6578 p
= xdr_inline_decode(xdr
, entry
->len
);
6581 entry
->name
= (const char *) p
;
6584 * In case the server doesn't return an inode number,
6585 * we fake one here. (We don't use inode number 0,
6586 * since glibc seems to choke on it...)
6589 entry
->fattr
->valid
= 0;
6591 if (decode_attr_bitmap(xdr
, bitmap
) < 0)
6594 if (decode_attr_length(xdr
, &len
, &p
) < 0)
6597 if (decode_getfattr_attrs(xdr
, bitmap
, entry
->fattr
, entry
->fh
,
6598 entry
->server
, 1) < 0)
6600 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
)
6601 entry
->ino
= entry
->fattr
->mounted_on_fileid
;
6602 else if (entry
->fattr
->valid
& NFS_ATTR_FATTR_FILEID
)
6603 entry
->ino
= entry
->fattr
->fileid
;
6605 entry
->d_type
= DT_UNKNOWN
;
6606 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_TYPE
)
6607 entry
->d_type
= nfs_umode_to_dtype(entry
->fattr
->mode
);
6612 print_overflow_msg(__func__
, xdr
);
6617 * We need to translate between nfs status return values and
6618 * the local errno values which may not be the same.
6625 { NFS4ERR_PERM
, -EPERM
},
6626 { NFS4ERR_NOENT
, -ENOENT
},
6627 { NFS4ERR_IO
, -errno_NFSERR_IO
},
6628 { NFS4ERR_NXIO
, -ENXIO
},
6629 { NFS4ERR_ACCESS
, -EACCES
},
6630 { NFS4ERR_EXIST
, -EEXIST
},
6631 { NFS4ERR_XDEV
, -EXDEV
},
6632 { NFS4ERR_NOTDIR
, -ENOTDIR
},
6633 { NFS4ERR_ISDIR
, -EISDIR
},
6634 { NFS4ERR_INVAL
, -EINVAL
},
6635 { NFS4ERR_FBIG
, -EFBIG
},
6636 { NFS4ERR_NOSPC
, -ENOSPC
},
6637 { NFS4ERR_ROFS
, -EROFS
},
6638 { NFS4ERR_MLINK
, -EMLINK
},
6639 { NFS4ERR_NAMETOOLONG
, -ENAMETOOLONG
},
6640 { NFS4ERR_NOTEMPTY
, -ENOTEMPTY
},
6641 { NFS4ERR_DQUOT
, -EDQUOT
},
6642 { NFS4ERR_STALE
, -ESTALE
},
6643 { NFS4ERR_BADHANDLE
, -EBADHANDLE
},
6644 { NFS4ERR_BAD_COOKIE
, -EBADCOOKIE
},
6645 { NFS4ERR_NOTSUPP
, -ENOTSUPP
},
6646 { NFS4ERR_TOOSMALL
, -ETOOSMALL
},
6647 { NFS4ERR_SERVERFAULT
, -EREMOTEIO
},
6648 { NFS4ERR_BADTYPE
, -EBADTYPE
},
6649 { NFS4ERR_LOCKED
, -EAGAIN
},
6650 { NFS4ERR_SYMLINK
, -ELOOP
},
6651 { NFS4ERR_OP_ILLEGAL
, -EOPNOTSUPP
},
6652 { NFS4ERR_DEADLOCK
, -EDEADLK
},
6657 * Convert an NFS error code to a local one.
6658 * This one is used jointly by NFSv2 and NFSv3.
6661 nfs4_stat_to_errno(int stat
)
6664 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
6665 if (nfs_errtbl
[i
].stat
== stat
)
6666 return nfs_errtbl
[i
].errno
;
6668 if (stat
<= 10000 || stat
> 10100) {
6669 /* The server is looney tunes. */
6672 /* If we cannot translate the error, the recovery routines should
6674 * Note: remaining NFSv4 error codes have values > 10000, so should
6675 * not conflict with native Linux error codes.
6680 #define PROC(proc, argtype, restype) \
6681 [NFSPROC4_CLNT_##proc] = { \
6682 .p_proc = NFSPROC4_COMPOUND, \
6683 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6684 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6685 .p_arglen = NFS4_##argtype##_sz, \
6686 .p_replen = NFS4_##restype##_sz, \
6687 .p_statidx = NFSPROC4_CLNT_##proc, \
6691 struct rpc_procinfo nfs4_procedures
[] = {
6692 PROC(READ
, enc_read
, dec_read
),
6693 PROC(WRITE
, enc_write
, dec_write
),
6694 PROC(COMMIT
, enc_commit
, dec_commit
),
6695 PROC(OPEN
, enc_open
, dec_open
),
6696 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
6697 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
6698 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
6699 PROC(CLOSE
, enc_close
, dec_close
),
6700 PROC(SETATTR
, enc_setattr
, dec_setattr
),
6701 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
6702 PROC(RENEW
, enc_renew
, dec_renew
),
6703 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
6704 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
6705 PROC(LOCK
, enc_lock
, dec_lock
),
6706 PROC(LOCKT
, enc_lockt
, dec_lockt
),
6707 PROC(LOCKU
, enc_locku
, dec_locku
),
6708 PROC(ACCESS
, enc_access
, dec_access
),
6709 PROC(GETATTR
, enc_getattr
, dec_getattr
),
6710 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
6711 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
6712 PROC(REMOVE
, enc_remove
, dec_remove
),
6713 PROC(RENAME
, enc_rename
, dec_rename
),
6714 PROC(LINK
, enc_link
, dec_link
),
6715 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
6716 PROC(CREATE
, enc_create
, dec_create
),
6717 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
6718 PROC(STATFS
, enc_statfs
, dec_statfs
),
6719 PROC(READLINK
, enc_readlink
, dec_readlink
),
6720 PROC(READDIR
, enc_readdir
, dec_readdir
),
6721 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
6722 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
6723 PROC(GETACL
, enc_getacl
, dec_getacl
),
6724 PROC(SETACL
, enc_setacl
, dec_setacl
),
6725 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
6726 PROC(RELEASE_LOCKOWNER
, enc_release_lockowner
, dec_release_lockowner
),
6727 PROC(SECINFO
, enc_secinfo
, dec_secinfo
),
6728 #if defined(CONFIG_NFS_V4_1)
6729 PROC(EXCHANGE_ID
, enc_exchange_id
, dec_exchange_id
),
6730 PROC(CREATE_SESSION
, enc_create_session
, dec_create_session
),
6731 PROC(DESTROY_SESSION
, enc_destroy_session
, dec_destroy_session
),
6732 PROC(SEQUENCE
, enc_sequence
, dec_sequence
),
6733 PROC(GET_LEASE_TIME
, enc_get_lease_time
, dec_get_lease_time
),
6734 PROC(RECLAIM_COMPLETE
, enc_reclaim_complete
, dec_reclaim_complete
),
6735 PROC(GETDEVICEINFO
, enc_getdeviceinfo
, dec_getdeviceinfo
),
6736 PROC(LAYOUTGET
, enc_layoutget
, dec_layoutget
),
6737 PROC(LAYOUTCOMMIT
, enc_layoutcommit
, dec_layoutcommit
),
6738 PROC(LAYOUTRETURN
, enc_layoutreturn
, dec_layoutreturn
),
6739 PROC(SECINFO_NO_NAME
, enc_secinfo_no_name
, dec_secinfo_no_name
),
6740 #endif /* CONFIG_NFS_V4_1 */
6743 struct rpc_version nfs_version4
= {
6745 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
6746 .procs
= nfs4_procedures