Branch data Line data Source code
1 : : /*
2 : : * fs/nfs/nfs4xdr.c
3 : : *
4 : : * Client-side XDR for NFSv4.
5 : : *
6 : : * Copyright (c) 2002 The Regents of the University of Michigan.
7 : : * All rights reserved.
8 : : *
9 : : * Kendrick Smith <kmsmith@umich.edu>
10 : : * Andy Adamson <andros@umich.edu>
11 : : *
12 : : * Redistribution and use in source and binary forms, with or without
13 : : * modification, are permitted provided that the following conditions
14 : : * are met:
15 : : *
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.
24 : : *
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.
36 : : */
37 : :
38 : : #include <linux/param.h>
39 : : #include <linux/time.h>
40 : : #include <linux/mm.h>
41 : : #include <linux/errno.h>
42 : : #include <linux/string.h>
43 : : #include <linux/in.h>
44 : : #include <linux/pagemap.h>
45 : : #include <linux/proc_fs.h>
46 : : #include <linux/kdev_t.h>
47 : : #include <linux/module.h>
48 : : #include <linux/utsname.h>
49 : : #include <linux/sunrpc/clnt.h>
50 : : #include <linux/sunrpc/msg_prot.h>
51 : : #include <linux/sunrpc/gss_api.h>
52 : : #include <linux/nfs.h>
53 : : #include <linux/nfs4.h>
54 : : #include <linux/nfs_fs.h>
55 : : #include <linux/nfs_idmap.h>
56 : :
57 : : #include "nfs4_fs.h"
58 : : #include "internal.h"
59 : : #include "nfs4session.h"
60 : : #include "pnfs.h"
61 : : #include "netns.h"
62 : :
63 : : #define NFSDBG_FACILITY NFSDBG_XDR
64 : :
65 : : /* Mapping from NFS error code to "errno" error code. */
66 : : #define errno_NFSERR_IO EIO
67 : :
68 : : static int nfs4_stat_to_errno(int);
69 : :
70 : : /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71 : : #ifdef DEBUG
72 : : #define NFS4_MAXTAGLEN 20
73 : : #else
74 : : #define NFS4_MAXTAGLEN 0
75 : : #endif
76 : :
77 : : /* lock,open owner id:
78 : : * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
79 : : */
80 : : #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
81 : : #define lock_owner_id_maxsz (1 + 1 + 4)
82 : : #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
83 : : #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84 : : #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85 : : #define op_encode_hdr_maxsz (1)
86 : : #define op_decode_hdr_maxsz (2)
87 : : #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88 : : #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89 : : #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90 : : #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91 : : #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 : : (NFS4_FHSIZE >> 2))
93 : : #define decode_putfh_maxsz (op_decode_hdr_maxsz)
94 : : #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95 : : #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96 : : #define encode_getfh_maxsz (op_encode_hdr_maxsz)
97 : : #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 : : ((3+NFS4_FHSIZE) >> 2))
99 : : #define nfs4_fattr_bitmap_maxsz 4
100 : : #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
101 : : #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102 : : #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
103 : : #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104 : : #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105 : : #ifdef CONFIG_NFS_V4_SECURITY_LABEL
106 : : /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107 : : #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
108 : : #else
109 : : #define nfs4_label_maxsz 0
110 : : #endif
111 : : /* We support only one layout type per file system */
112 : : #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
113 : : /* This is based on getfattr, which uses the most attributes: */
114 : : #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
115 : : 3 + 3 + 3 + nfs4_owner_maxsz + \
116 : : nfs4_group_maxsz + nfs4_label_maxsz + \
117 : : decode_mdsthreshold_maxsz))
118 : : #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 : : nfs4_fattr_value_maxsz)
120 : : #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
121 : : #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 : : 1 + 2 + 1 + \
123 : : nfs4_owner_maxsz + \
124 : : nfs4_group_maxsz + \
125 : : nfs4_label_maxsz + \
126 : : 4 + 4)
127 : : #define encode_savefh_maxsz (op_encode_hdr_maxsz)
128 : : #define decode_savefh_maxsz (op_decode_hdr_maxsz)
129 : : #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130 : : #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
131 : : #define encode_fsinfo_maxsz (encode_getattr_maxsz)
132 : : /* The 5 accounts for the PNFS attributes, and assumes that at most three
133 : : * layout types will be returned.
134 : : */
135 : : #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 : : nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
137 : : #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138 : : #define decode_renew_maxsz (op_decode_hdr_maxsz)
139 : : #define encode_setclientid_maxsz \
140 : : (op_encode_hdr_maxsz + \
141 : : XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142 : : XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
143 : : 1 /* sc_prog */ + \
144 : : XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 : : XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
146 : : 1) /* sc_cb_ident */
147 : : #define decode_setclientid_maxsz \
148 : : (op_decode_hdr_maxsz + \
149 : : 2 + \
150 : : 1024) /* large value for CLID_INUSE */
151 : : #define encode_setclientid_confirm_maxsz \
152 : : (op_encode_hdr_maxsz + \
153 : : 3 + (NFS4_VERIFIER_SIZE >> 2))
154 : : #define decode_setclientid_confirm_maxsz \
155 : : (op_decode_hdr_maxsz)
156 : : #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
157 : : #define decode_lookup_maxsz (op_decode_hdr_maxsz)
158 : : #define encode_share_access_maxsz \
159 : : (2)
160 : : #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
161 : : #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
162 : : #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
163 : : #define encode_open_maxsz (op_encode_hdr_maxsz + \
164 : : 2 + encode_share_access_maxsz + 2 + \
165 : : open_owner_id_maxsz + \
166 : : encode_opentype_maxsz + \
167 : : encode_claim_null_maxsz)
168 : : #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
169 : : #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
170 : : decode_ace_maxsz)
171 : : #define decode_change_info_maxsz (5)
172 : : #define decode_open_maxsz (op_decode_hdr_maxsz + \
173 : : decode_stateid_maxsz + \
174 : : decode_change_info_maxsz + 1 + \
175 : : nfs4_fattr_bitmap_maxsz + \
176 : : decode_delegation_maxsz)
177 : : #define encode_open_confirm_maxsz \
178 : : (op_encode_hdr_maxsz + \
179 : : encode_stateid_maxsz + 1)
180 : : #define decode_open_confirm_maxsz \
181 : : (op_decode_hdr_maxsz + \
182 : : decode_stateid_maxsz)
183 : : #define encode_open_downgrade_maxsz \
184 : : (op_encode_hdr_maxsz + \
185 : : encode_stateid_maxsz + 1 + \
186 : : encode_share_access_maxsz)
187 : : #define decode_open_downgrade_maxsz \
188 : : (op_decode_hdr_maxsz + \
189 : : decode_stateid_maxsz)
190 : : #define encode_close_maxsz (op_encode_hdr_maxsz + \
191 : : 1 + encode_stateid_maxsz)
192 : : #define decode_close_maxsz (op_decode_hdr_maxsz + \
193 : : decode_stateid_maxsz)
194 : : #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
195 : : encode_stateid_maxsz + \
196 : : encode_attrs_maxsz)
197 : : #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
198 : : nfs4_fattr_bitmap_maxsz)
199 : : #define encode_read_maxsz (op_encode_hdr_maxsz + \
200 : : encode_stateid_maxsz + 3)
201 : : #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
202 : : #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
203 : : 2 + encode_verifier_maxsz + 5 + \
204 : : nfs4_label_maxsz)
205 : : #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
206 : : decode_verifier_maxsz + \
207 : : nfs4_label_maxsz + nfs4_fattr_maxsz)
208 : : #define encode_readlink_maxsz (op_encode_hdr_maxsz)
209 : : #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
210 : : #define encode_write_maxsz (op_encode_hdr_maxsz + \
211 : : encode_stateid_maxsz + 4)
212 : : #define decode_write_maxsz (op_decode_hdr_maxsz + \
213 : : 2 + decode_verifier_maxsz)
214 : : #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
215 : : #define decode_commit_maxsz (op_decode_hdr_maxsz + \
216 : : decode_verifier_maxsz)
217 : : #define encode_remove_maxsz (op_encode_hdr_maxsz + \
218 : : nfs4_name_maxsz)
219 : : #define decode_remove_maxsz (op_decode_hdr_maxsz + \
220 : : decode_change_info_maxsz)
221 : : #define encode_rename_maxsz (op_encode_hdr_maxsz + \
222 : : 2 * nfs4_name_maxsz)
223 : : #define decode_rename_maxsz (op_decode_hdr_maxsz + \
224 : : decode_change_info_maxsz + \
225 : : decode_change_info_maxsz)
226 : : #define encode_link_maxsz (op_encode_hdr_maxsz + \
227 : : nfs4_name_maxsz)
228 : : #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
229 : : #define encode_lockowner_maxsz (7)
230 : : #define encode_lock_maxsz (op_encode_hdr_maxsz + \
231 : : 7 + \
232 : : 1 + encode_stateid_maxsz + 1 + \
233 : : encode_lockowner_maxsz)
234 : : #define decode_lock_denied_maxsz \
235 : : (8 + decode_lockowner_maxsz)
236 : : #define decode_lock_maxsz (op_decode_hdr_maxsz + \
237 : : decode_lock_denied_maxsz)
238 : : #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
239 : : encode_lockowner_maxsz)
240 : : #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
241 : : decode_lock_denied_maxsz)
242 : : #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
243 : : encode_stateid_maxsz + \
244 : : 4)
245 : : #define decode_locku_maxsz (op_decode_hdr_maxsz + \
246 : : decode_stateid_maxsz)
247 : : #define encode_release_lockowner_maxsz \
248 : : (op_encode_hdr_maxsz + \
249 : : encode_lockowner_maxsz)
250 : : #define decode_release_lockowner_maxsz \
251 : : (op_decode_hdr_maxsz)
252 : : #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
253 : : #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
254 : : #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
255 : : 1 + nfs4_name_maxsz + \
256 : : 1 + \
257 : : nfs4_fattr_maxsz)
258 : : #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
259 : : #define encode_create_maxsz (op_encode_hdr_maxsz + \
260 : : 1 + 2 + nfs4_name_maxsz + \
261 : : encode_attrs_maxsz)
262 : : #define decode_create_maxsz (op_decode_hdr_maxsz + \
263 : : decode_change_info_maxsz + \
264 : : nfs4_fattr_bitmap_maxsz)
265 : : #define encode_statfs_maxsz (encode_getattr_maxsz)
266 : : #define decode_statfs_maxsz (decode_getattr_maxsz)
267 : : #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
268 : : #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
269 : : #define encode_getacl_maxsz (encode_getattr_maxsz)
270 : : #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
271 : : nfs4_fattr_bitmap_maxsz + 1)
272 : : #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
273 : : encode_stateid_maxsz + 3)
274 : : #define decode_setacl_maxsz (decode_setattr_maxsz)
275 : : #define encode_fs_locations_maxsz \
276 : : (encode_getattr_maxsz)
277 : : #define decode_fs_locations_maxsz \
278 : : (0)
279 : : #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
280 : : #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
281 : :
282 : : #if defined(CONFIG_NFS_V4_1)
283 : : #define NFS4_MAX_MACHINE_NAME_LEN (64)
284 : : #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
285 : : sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
286 : :
287 : : #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
288 : : encode_verifier_maxsz + \
289 : : 1 /* co_ownerid.len */ + \
290 : : XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
291 : : 1 /* flags */ + \
292 : : 1 /* spa_how */ + \
293 : : /* max is SP4_MACH_CRED (for now) */ + \
294 : : 1 + NFS4_OP_MAP_NUM_WORDS + \
295 : : 1 + NFS4_OP_MAP_NUM_WORDS + \
296 : : 1 /* implementation id array of size 1 */ + \
297 : : 1 /* nii_domain */ + \
298 : : XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
299 : : 1 /* nii_name */ + \
300 : : XDR_QUADLEN(IMPL_NAME_LIMIT) + \
301 : : 3 /* nii_date */)
302 : : #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
303 : : 2 /* eir_clientid */ + \
304 : : 1 /* eir_sequenceid */ + \
305 : : 1 /* eir_flags */ + \
306 : : 1 /* spr_how */ + \
307 : : /* max is SP4_MACH_CRED (for now) */ + \
308 : : 1 + NFS4_OP_MAP_NUM_WORDS + \
309 : : 1 + NFS4_OP_MAP_NUM_WORDS + \
310 : : 2 /* eir_server_owner.so_minor_id */ + \
311 : : /* eir_server_owner.so_major_id<> */ \
312 : : XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
313 : : /* eir_server_scope<> */ \
314 : : XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
315 : : 1 /* eir_server_impl_id array length */ + \
316 : : 1 /* nii_domain */ + \
317 : : XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
318 : : 1 /* nii_name */ + \
319 : : XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 : : 3 /* nii_date */)
321 : : #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
322 : : #define decode_channel_attrs_maxsz (6 + \
323 : : 1 /* ca_rdma_ird.len */ + \
324 : : 1 /* ca_rdma_ird */)
325 : : #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
326 : : 2 /* csa_clientid */ + \
327 : : 1 /* csa_sequence */ + \
328 : : 1 /* csa_flags */ + \
329 : : encode_channel_attrs_maxsz + \
330 : : encode_channel_attrs_maxsz + \
331 : : 1 /* csa_cb_program */ + \
332 : : 1 /* csa_sec_parms.len (1) */ + \
333 : : 1 /* cb_secflavor (AUTH_SYS) */ + \
334 : : 1 /* stamp */ + \
335 : : 1 /* machinename.len */ + \
336 : : XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
337 : : 1 /* uid */ + \
338 : : 1 /* gid */ + \
339 : : 1 /* gids.len (0) */)
340 : : #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
341 : : XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
342 : : 1 /* csr_sequence */ + \
343 : : 1 /* csr_flags */ + \
344 : : decode_channel_attrs_maxsz + \
345 : : decode_channel_attrs_maxsz)
346 : : #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
347 : : /* bctsa_sessid */ \
348 : : XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
349 : : 1 /* bctsa_dir */ + \
350 : : 1 /* bctsa_use_conn_in_rdma_mode */)
351 : : #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
352 : : /* bctsr_sessid */ \
353 : : XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
354 : : 1 /* bctsr_dir */ + \
355 : : 1 /* bctsr_use_conn_in_rdma_mode */)
356 : : #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
357 : : #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
358 : : #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
359 : : #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
360 : : #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
361 : : XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
362 : : #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
363 : : XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
364 : : #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
365 : : #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
366 : : #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
367 : : encode_verifier_maxsz)
368 : : #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
369 : : 2 /* nfs_cookie4 gdlr_cookie */ + \
370 : : decode_verifier_maxsz \
371 : : /* verifier4 gdlr_verifier */ + \
372 : : 1 /* gdlr_deviceid_list count */ + \
373 : : XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
374 : : NFS4_DEVICEID4_SIZE) \
375 : : /* gdlr_deviceid_list */ + \
376 : : 1 /* bool gdlr_eof */)
377 : : #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
378 : : XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
379 : : #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380 : : 1 /* layout type */ + \
381 : : 1 /* opaque devaddr4 length */ + \
382 : : /* devaddr4 payload is read into page */ \
383 : : 1 /* notification bitmap length */ + \
384 : : 1 /* notification bitmap */)
385 : : #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
386 : : encode_stateid_maxsz)
387 : : #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
388 : : decode_stateid_maxsz + \
389 : : XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
390 : : #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
391 : : 2 /* offset */ + \
392 : : 2 /* length */ + \
393 : : 1 /* reclaim */ + \
394 : : encode_stateid_maxsz + \
395 : : 1 /* new offset (true) */ + \
396 : : 2 /* last byte written */ + \
397 : : 1 /* nt_timechanged (false) */ + \
398 : : 1 /* layoutupdate4 layout type */ + \
399 : : 1 /* NULL filelayout layoutupdate4 payload */)
400 : : #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
401 : : #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 : : encode_stateid_maxsz + \
403 : : 1 /* FIXME: opaque lrf_body always empty at the moment */)
404 : : #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
405 : : 1 + decode_stateid_maxsz)
406 : : #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
407 : : #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
408 : : #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
409 : : XDR_QUADLEN(NFS4_STATEID_SIZE))
410 : : #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
411 : : #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
412 : : XDR_QUADLEN(NFS4_STATEID_SIZE))
413 : : #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
414 : : #else /* CONFIG_NFS_V4_1 */
415 : : #define encode_sequence_maxsz 0
416 : : #define decode_sequence_maxsz 0
417 : : #endif /* CONFIG_NFS_V4_1 */
418 : :
419 : : #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
420 : : #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
421 : : #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
422 : : encode_sequence_maxsz + \
423 : : encode_putfh_maxsz + \
424 : : encode_read_maxsz)
425 : : #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
426 : : decode_sequence_maxsz + \
427 : : decode_putfh_maxsz + \
428 : : decode_read_maxsz)
429 : : #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
430 : : encode_sequence_maxsz + \
431 : : encode_putfh_maxsz + \
432 : : encode_readlink_maxsz)
433 : : #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
434 : : decode_sequence_maxsz + \
435 : : decode_putfh_maxsz + \
436 : : decode_readlink_maxsz)
437 : : #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
438 : : encode_sequence_maxsz + \
439 : : encode_putfh_maxsz + \
440 : : encode_readdir_maxsz)
441 : : #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
442 : : decode_sequence_maxsz + \
443 : : decode_putfh_maxsz + \
444 : : decode_readdir_maxsz)
445 : : #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
446 : : encode_sequence_maxsz + \
447 : : encode_putfh_maxsz + \
448 : : encode_write_maxsz + \
449 : : encode_getattr_maxsz)
450 : : #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
451 : : decode_sequence_maxsz + \
452 : : decode_putfh_maxsz + \
453 : : decode_write_maxsz + \
454 : : decode_getattr_maxsz)
455 : : #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
456 : : encode_sequence_maxsz + \
457 : : encode_putfh_maxsz + \
458 : : encode_commit_maxsz)
459 : : #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
460 : : decode_sequence_maxsz + \
461 : : decode_putfh_maxsz + \
462 : : decode_commit_maxsz)
463 : : #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
464 : : encode_sequence_maxsz + \
465 : : encode_putfh_maxsz + \
466 : : encode_open_maxsz + \
467 : : encode_access_maxsz + \
468 : : encode_getfh_maxsz + \
469 : : encode_getattr_maxsz)
470 : : #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
471 : : decode_sequence_maxsz + \
472 : : decode_putfh_maxsz + \
473 : : decode_open_maxsz + \
474 : : decode_access_maxsz + \
475 : : decode_getfh_maxsz + \
476 : : decode_getattr_maxsz)
477 : : #define NFS4_enc_open_confirm_sz \
478 : : (compound_encode_hdr_maxsz + \
479 : : encode_putfh_maxsz + \
480 : : encode_open_confirm_maxsz)
481 : : #define NFS4_dec_open_confirm_sz \
482 : : (compound_decode_hdr_maxsz + \
483 : : decode_putfh_maxsz + \
484 : : decode_open_confirm_maxsz)
485 : : #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
486 : : encode_sequence_maxsz + \
487 : : encode_putfh_maxsz + \
488 : : encode_open_maxsz + \
489 : : encode_access_maxsz + \
490 : : encode_getattr_maxsz)
491 : : #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
492 : : decode_sequence_maxsz + \
493 : : decode_putfh_maxsz + \
494 : : decode_open_maxsz + \
495 : : decode_access_maxsz + \
496 : : decode_getattr_maxsz)
497 : : #define NFS4_enc_open_downgrade_sz \
498 : : (compound_encode_hdr_maxsz + \
499 : : encode_sequence_maxsz + \
500 : : encode_putfh_maxsz + \
501 : : encode_open_downgrade_maxsz + \
502 : : encode_getattr_maxsz)
503 : : #define NFS4_dec_open_downgrade_sz \
504 : : (compound_decode_hdr_maxsz + \
505 : : decode_sequence_maxsz + \
506 : : decode_putfh_maxsz + \
507 : : decode_open_downgrade_maxsz + \
508 : : decode_getattr_maxsz)
509 : : #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
510 : : encode_sequence_maxsz + \
511 : : encode_putfh_maxsz + \
512 : : encode_close_maxsz + \
513 : : encode_getattr_maxsz)
514 : : #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
515 : : decode_sequence_maxsz + \
516 : : decode_putfh_maxsz + \
517 : : decode_close_maxsz + \
518 : : decode_getattr_maxsz)
519 : : #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
520 : : encode_sequence_maxsz + \
521 : : encode_putfh_maxsz + \
522 : : encode_setattr_maxsz + \
523 : : encode_getattr_maxsz)
524 : : #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
525 : : decode_sequence_maxsz + \
526 : : decode_putfh_maxsz + \
527 : : decode_setattr_maxsz + \
528 : : decode_getattr_maxsz)
529 : : #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
530 : : encode_sequence_maxsz + \
531 : : encode_putfh_maxsz + \
532 : : encode_fsinfo_maxsz)
533 : : #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
534 : : decode_sequence_maxsz + \
535 : : decode_putfh_maxsz + \
536 : : decode_fsinfo_maxsz)
537 : : #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
538 : : encode_renew_maxsz)
539 : : #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
540 : : decode_renew_maxsz)
541 : : #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
542 : : encode_setclientid_maxsz)
543 : : #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
544 : : decode_setclientid_maxsz)
545 : : #define NFS4_enc_setclientid_confirm_sz \
546 : : (compound_encode_hdr_maxsz + \
547 : : encode_setclientid_confirm_maxsz)
548 : : #define NFS4_dec_setclientid_confirm_sz \
549 : : (compound_decode_hdr_maxsz + \
550 : : decode_setclientid_confirm_maxsz)
551 : : #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
552 : : encode_sequence_maxsz + \
553 : : encode_putfh_maxsz + \
554 : : encode_lock_maxsz)
555 : : #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
556 : : decode_sequence_maxsz + \
557 : : decode_putfh_maxsz + \
558 : : decode_lock_maxsz)
559 : : #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
560 : : encode_sequence_maxsz + \
561 : : encode_putfh_maxsz + \
562 : : encode_lockt_maxsz)
563 : : #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
564 : : decode_sequence_maxsz + \
565 : : decode_putfh_maxsz + \
566 : : decode_lockt_maxsz)
567 : : #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
568 : : encode_sequence_maxsz + \
569 : : encode_putfh_maxsz + \
570 : : encode_locku_maxsz)
571 : : #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
572 : : decode_sequence_maxsz + \
573 : : decode_putfh_maxsz + \
574 : : decode_locku_maxsz)
575 : : #define NFS4_enc_release_lockowner_sz \
576 : : (compound_encode_hdr_maxsz + \
577 : : encode_lockowner_maxsz)
578 : : #define NFS4_dec_release_lockowner_sz \
579 : : (compound_decode_hdr_maxsz + \
580 : : decode_lockowner_maxsz)
581 : : #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
582 : : encode_sequence_maxsz + \
583 : : encode_putfh_maxsz + \
584 : : encode_access_maxsz + \
585 : : encode_getattr_maxsz)
586 : : #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
587 : : decode_sequence_maxsz + \
588 : : decode_putfh_maxsz + \
589 : : decode_access_maxsz + \
590 : : decode_getattr_maxsz)
591 : : #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
592 : : encode_sequence_maxsz + \
593 : : encode_putfh_maxsz + \
594 : : encode_getattr_maxsz + \
595 : : encode_renew_maxsz)
596 : : #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
597 : : decode_sequence_maxsz + \
598 : : decode_putfh_maxsz + \
599 : : decode_getattr_maxsz + \
600 : : decode_renew_maxsz)
601 : : #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
602 : : encode_sequence_maxsz + \
603 : : encode_putfh_maxsz + \
604 : : encode_lookup_maxsz + \
605 : : encode_getattr_maxsz + \
606 : : encode_getfh_maxsz)
607 : : #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
608 : : decode_sequence_maxsz + \
609 : : decode_putfh_maxsz + \
610 : : decode_lookup_maxsz + \
611 : : decode_getattr_maxsz + \
612 : : decode_getfh_maxsz)
613 : : #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
614 : : encode_sequence_maxsz + \
615 : : encode_putrootfh_maxsz + \
616 : : encode_getattr_maxsz + \
617 : : encode_getfh_maxsz)
618 : : #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
619 : : decode_sequence_maxsz + \
620 : : decode_putrootfh_maxsz + \
621 : : decode_getattr_maxsz + \
622 : : decode_getfh_maxsz)
623 : : #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
624 : : encode_sequence_maxsz + \
625 : : encode_putfh_maxsz + \
626 : : encode_remove_maxsz)
627 : : #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
628 : : decode_sequence_maxsz + \
629 : : decode_putfh_maxsz + \
630 : : decode_remove_maxsz)
631 : : #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
632 : : encode_sequence_maxsz + \
633 : : encode_putfh_maxsz + \
634 : : encode_savefh_maxsz + \
635 : : encode_putfh_maxsz + \
636 : : encode_rename_maxsz)
637 : : #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
638 : : decode_sequence_maxsz + \
639 : : decode_putfh_maxsz + \
640 : : decode_savefh_maxsz + \
641 : : decode_putfh_maxsz + \
642 : : decode_rename_maxsz)
643 : : #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
644 : : encode_sequence_maxsz + \
645 : : encode_putfh_maxsz + \
646 : : encode_savefh_maxsz + \
647 : : encode_putfh_maxsz + \
648 : : encode_link_maxsz + \
649 : : encode_restorefh_maxsz + \
650 : : encode_getattr_maxsz)
651 : : #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
652 : : decode_sequence_maxsz + \
653 : : decode_putfh_maxsz + \
654 : : decode_savefh_maxsz + \
655 : : decode_putfh_maxsz + \
656 : : decode_link_maxsz + \
657 : : decode_restorefh_maxsz + \
658 : : decode_getattr_maxsz)
659 : : #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
660 : : encode_sequence_maxsz + \
661 : : encode_putfh_maxsz + \
662 : : encode_symlink_maxsz + \
663 : : encode_getattr_maxsz + \
664 : : encode_getfh_maxsz)
665 : : #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
666 : : decode_sequence_maxsz + \
667 : : decode_putfh_maxsz + \
668 : : decode_symlink_maxsz + \
669 : : decode_getattr_maxsz + \
670 : : decode_getfh_maxsz)
671 : : #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
672 : : encode_sequence_maxsz + \
673 : : encode_putfh_maxsz + \
674 : : encode_create_maxsz + \
675 : : encode_getfh_maxsz + \
676 : : encode_getattr_maxsz)
677 : : #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
678 : : decode_sequence_maxsz + \
679 : : decode_putfh_maxsz + \
680 : : decode_create_maxsz + \
681 : : decode_getfh_maxsz + \
682 : : decode_getattr_maxsz)
683 : : #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
684 : : encode_sequence_maxsz + \
685 : : encode_putfh_maxsz + \
686 : : encode_getattr_maxsz)
687 : : #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
688 : : decode_sequence_maxsz + \
689 : : decode_putfh_maxsz + \
690 : : decode_getattr_maxsz)
691 : : #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
692 : : encode_sequence_maxsz + \
693 : : encode_putfh_maxsz + \
694 : : encode_statfs_maxsz)
695 : : #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
696 : : decode_sequence_maxsz + \
697 : : decode_putfh_maxsz + \
698 : : decode_statfs_maxsz)
699 : : #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
700 : : encode_sequence_maxsz + \
701 : : encode_putfh_maxsz + \
702 : : encode_getattr_maxsz)
703 : : #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
704 : : decode_sequence_maxsz + \
705 : : decode_putfh_maxsz + \
706 : : decode_getattr_maxsz)
707 : : #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
708 : : encode_sequence_maxsz + \
709 : : encode_putfh_maxsz + \
710 : : encode_delegreturn_maxsz + \
711 : : encode_getattr_maxsz)
712 : : #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
713 : : decode_sequence_maxsz + \
714 : : decode_delegreturn_maxsz + \
715 : : decode_getattr_maxsz)
716 : : #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
717 : : encode_sequence_maxsz + \
718 : : encode_putfh_maxsz + \
719 : : encode_getacl_maxsz)
720 : : #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
721 : : decode_sequence_maxsz + \
722 : : decode_putfh_maxsz + \
723 : : decode_getacl_maxsz)
724 : : #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
725 : : encode_sequence_maxsz + \
726 : : encode_putfh_maxsz + \
727 : : encode_setacl_maxsz)
728 : : #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
729 : : decode_sequence_maxsz + \
730 : : decode_putfh_maxsz + \
731 : : decode_setacl_maxsz)
732 : : #define NFS4_enc_fs_locations_sz \
733 : : (compound_encode_hdr_maxsz + \
734 : : encode_sequence_maxsz + \
735 : : encode_putfh_maxsz + \
736 : : encode_lookup_maxsz + \
737 : : encode_fs_locations_maxsz + \
738 : : encode_renew_maxsz)
739 : : #define NFS4_dec_fs_locations_sz \
740 : : (compound_decode_hdr_maxsz + \
741 : : decode_sequence_maxsz + \
742 : : decode_putfh_maxsz + \
743 : : decode_lookup_maxsz + \
744 : : decode_fs_locations_maxsz + \
745 : : decode_renew_maxsz)
746 : : #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
747 : : encode_sequence_maxsz + \
748 : : encode_putfh_maxsz + \
749 : : encode_secinfo_maxsz)
750 : : #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
751 : : decode_sequence_maxsz + \
752 : : decode_putfh_maxsz + \
753 : : decode_secinfo_maxsz)
754 : : #define NFS4_enc_fsid_present_sz \
755 : : (compound_encode_hdr_maxsz + \
756 : : encode_sequence_maxsz + \
757 : : encode_putfh_maxsz + \
758 : : encode_getfh_maxsz + \
759 : : encode_renew_maxsz)
760 : : #define NFS4_dec_fsid_present_sz \
761 : : (compound_decode_hdr_maxsz + \
762 : : decode_sequence_maxsz + \
763 : : decode_putfh_maxsz + \
764 : : decode_getfh_maxsz + \
765 : : decode_renew_maxsz)
766 : : #if defined(CONFIG_NFS_V4_1)
767 : : #define NFS4_enc_bind_conn_to_session_sz \
768 : : (compound_encode_hdr_maxsz + \
769 : : encode_bind_conn_to_session_maxsz)
770 : : #define NFS4_dec_bind_conn_to_session_sz \
771 : : (compound_decode_hdr_maxsz + \
772 : : decode_bind_conn_to_session_maxsz)
773 : : #define NFS4_enc_exchange_id_sz \
774 : : (compound_encode_hdr_maxsz + \
775 : : encode_exchange_id_maxsz)
776 : : #define NFS4_dec_exchange_id_sz \
777 : : (compound_decode_hdr_maxsz + \
778 : : decode_exchange_id_maxsz)
779 : : #define NFS4_enc_create_session_sz \
780 : : (compound_encode_hdr_maxsz + \
781 : : encode_create_session_maxsz)
782 : : #define NFS4_dec_create_session_sz \
783 : : (compound_decode_hdr_maxsz + \
784 : : decode_create_session_maxsz)
785 : : #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
786 : : encode_destroy_session_maxsz)
787 : : #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
788 : : decode_destroy_session_maxsz)
789 : : #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
790 : : encode_destroy_clientid_maxsz)
791 : : #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
792 : : decode_destroy_clientid_maxsz)
793 : : #define NFS4_enc_sequence_sz \
794 : : (compound_decode_hdr_maxsz + \
795 : : encode_sequence_maxsz)
796 : : #define NFS4_dec_sequence_sz \
797 : : (compound_decode_hdr_maxsz + \
798 : : decode_sequence_maxsz)
799 : : #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
800 : : encode_sequence_maxsz + \
801 : : encode_putrootfh_maxsz + \
802 : : encode_fsinfo_maxsz)
803 : : #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
804 : : decode_sequence_maxsz + \
805 : : decode_putrootfh_maxsz + \
806 : : decode_fsinfo_maxsz)
807 : : #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
808 : : encode_sequence_maxsz + \
809 : : encode_reclaim_complete_maxsz)
810 : : #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
811 : : decode_sequence_maxsz + \
812 : : decode_reclaim_complete_maxsz)
813 : : #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
814 : : encode_sequence_maxsz + \
815 : : encode_putfh_maxsz + \
816 : : encode_getdevicelist_maxsz)
817 : : #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
818 : : decode_sequence_maxsz + \
819 : : decode_putfh_maxsz + \
820 : : decode_getdevicelist_maxsz)
821 : : #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
822 : : encode_sequence_maxsz +\
823 : : encode_getdeviceinfo_maxsz)
824 : : #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
825 : : decode_sequence_maxsz + \
826 : : decode_getdeviceinfo_maxsz)
827 : : #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
828 : : encode_sequence_maxsz + \
829 : : encode_putfh_maxsz + \
830 : : encode_layoutget_maxsz)
831 : : #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
832 : : decode_sequence_maxsz + \
833 : : decode_putfh_maxsz + \
834 : : decode_layoutget_maxsz)
835 : : #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
836 : : encode_sequence_maxsz +\
837 : : encode_putfh_maxsz + \
838 : : encode_layoutcommit_maxsz + \
839 : : encode_getattr_maxsz)
840 : : #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
841 : : decode_sequence_maxsz + \
842 : : decode_putfh_maxsz + \
843 : : decode_layoutcommit_maxsz + \
844 : : decode_getattr_maxsz)
845 : : #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
846 : : encode_sequence_maxsz + \
847 : : encode_putfh_maxsz + \
848 : : encode_layoutreturn_maxsz)
849 : : #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
850 : : decode_sequence_maxsz + \
851 : : decode_putfh_maxsz + \
852 : : decode_layoutreturn_maxsz)
853 : : #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
854 : : encode_sequence_maxsz + \
855 : : encode_putrootfh_maxsz +\
856 : : encode_secinfo_no_name_maxsz)
857 : : #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
858 : : decode_sequence_maxsz + \
859 : : decode_putrootfh_maxsz + \
860 : : decode_secinfo_no_name_maxsz)
861 : : #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
862 : : encode_sequence_maxsz + \
863 : : encode_test_stateid_maxsz)
864 : : #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
865 : : decode_sequence_maxsz + \
866 : : decode_test_stateid_maxsz)
867 : : #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
868 : : encode_sequence_maxsz + \
869 : : encode_free_stateid_maxsz)
870 : : #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
871 : : decode_sequence_maxsz + \
872 : : decode_free_stateid_maxsz)
873 : :
874 : : const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
875 : : compound_encode_hdr_maxsz +
876 : : encode_sequence_maxsz +
877 : : encode_putfh_maxsz +
878 : : encode_getattr_maxsz) *
879 : : XDR_UNIT);
880 : :
881 : : const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
882 : : compound_decode_hdr_maxsz +
883 : : decode_sequence_maxsz +
884 : : decode_putfh_maxsz) *
885 : : XDR_UNIT);
886 : :
887 : : const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
888 : : compound_decode_hdr_maxsz +
889 : : decode_sequence_maxsz) *
890 : : XDR_UNIT);
891 : : EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
892 : : #endif /* CONFIG_NFS_V4_1 */
893 : :
894 : : static const umode_t nfs_type2fmt[] = {
895 : : [NF4BAD] = 0,
896 : : [NF4REG] = S_IFREG,
897 : : [NF4DIR] = S_IFDIR,
898 : : [NF4BLK] = S_IFBLK,
899 : : [NF4CHR] = S_IFCHR,
900 : : [NF4LNK] = S_IFLNK,
901 : : [NF4SOCK] = S_IFSOCK,
902 : : [NF4FIFO] = S_IFIFO,
903 : : [NF4ATTRDIR] = 0,
904 : : [NF4NAMEDATTR] = 0,
905 : : };
906 : :
907 : : struct compound_hdr {
908 : : int32_t status;
909 : : uint32_t nops;
910 : : __be32 * nops_p;
911 : : uint32_t taglen;
912 : : char * tag;
913 : : uint32_t replen; /* expected reply words */
914 : : u32 minorversion;
915 : : };
916 : :
917 : 0 : static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
918 : : {
919 : 0 : __be32 *p = xdr_reserve_space(xdr, nbytes);
920 [ # # ]: 0 : BUG_ON(!p);
921 : 0 : return p;
922 : : }
923 : :
924 : 0 : static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
925 : : {
926 : : __be32 *p;
927 : :
928 : 0 : p = xdr_reserve_space(xdr, len);
929 : 0 : xdr_encode_opaque_fixed(p, buf, len);
930 : 0 : }
931 : :
932 : 0 : static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
933 : : {
934 : : __be32 *p;
935 : :
936 : 0 : p = reserve_space(xdr, 4 + len);
937 : 0 : xdr_encode_opaque(p, str, len);
938 : 0 : }
939 : :
940 : 0 : static void encode_uint32(struct xdr_stream *xdr, u32 n)
941 : : {
942 : : __be32 *p;
943 : :
944 : 0 : p = reserve_space(xdr, 4);
945 [ # # ]: 0 : *p = cpu_to_be32(n);
946 : 0 : }
947 : :
948 : 0 : static void encode_uint64(struct xdr_stream *xdr, u64 n)
949 : : {
950 : : __be32 *p;
951 : :
952 : 0 : p = reserve_space(xdr, 8);
953 : : xdr_encode_hyper(p, n);
954 : 0 : }
955 : :
956 : 0 : static void encode_nfs4_seqid(struct xdr_stream *xdr,
957 : : const struct nfs_seqid *seqid)
958 : : {
959 : 0 : encode_uint32(xdr, seqid->sequence->counter);
960 : 0 : }
961 : :
962 : 0 : static void encode_compound_hdr(struct xdr_stream *xdr,
963 : : struct rpc_rqst *req,
964 : : struct compound_hdr *hdr)
965 : : {
966 : : __be32 *p;
967 : 0 : struct rpc_auth *auth = req->rq_cred->cr_auth;
968 : :
969 : : /* initialize running count of expected bytes in reply.
970 : : * NOTE: the replied tag SHOULD be the same is the one sent,
971 : : * but this is not required as a MUST for the server to do so. */
972 : 0 : hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
973 : :
974 [ # # ][ # # ]: 0 : WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
[ # # ]
975 : 0 : encode_string(xdr, hdr->taglen, hdr->tag);
976 : 0 : p = reserve_space(xdr, 8);
977 [ # # ]: 0 : *p++ = cpu_to_be32(hdr->minorversion);
978 : 0 : hdr->nops_p = p;
979 [ # # ]: 0 : *p = cpu_to_be32(hdr->nops);
980 : 0 : }
981 : :
982 : : static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
983 : : uint32_t replen,
984 : : struct compound_hdr *hdr)
985 : : {
986 : 0 : encode_uint32(xdr, op);
987 : 0 : hdr->nops++;
988 : 0 : hdr->replen += replen;
989 : : }
990 : :
991 : 0 : static void encode_nops(struct compound_hdr *hdr)
992 : : {
993 [ # # ][ # # ]: 0 : WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
[ # # ]
994 [ # # ]: 0 : *hdr->nops_p = htonl(hdr->nops);
995 : 0 : }
996 : :
997 : 0 : static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
998 : : {
999 : 0 : encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1000 : 0 : }
1001 : :
1002 : 0 : static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1003 : : {
1004 : 0 : encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1005 : 0 : }
1006 : :
1007 : 0 : static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1008 : : const struct nfs4_label *label,
1009 : : const struct nfs_server *server)
1010 : : {
1011 : : char owner_name[IDMAP_NAMESZ];
1012 : : char owner_group[IDMAP_NAMESZ];
1013 : : int owner_namelen = 0;
1014 : : int owner_grouplen = 0;
1015 : : __be32 *p;
1016 : : unsigned i;
1017 : : uint32_t len = 0;
1018 : : uint32_t bmval_len;
1019 : 0 : uint32_t bmval[3] = { 0 };
1020 : :
1021 : : /*
1022 : : * We reserve enough space to write the entire attribute buffer at once.
1023 : : * In the worst-case, this would be
1024 : : * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1025 : : * = 40 bytes, plus any contribution from variable-length fields
1026 : : * such as owner/group.
1027 : : */
1028 [ # # ]: 0 : if (iap->ia_valid & ATTR_SIZE) {
1029 : 0 : bmval[0] |= FATTR4_WORD0_SIZE;
1030 : : len += 8;
1031 : : }
1032 [ # # ]: 0 : if (iap->ia_valid & ATTR_MODE) {
1033 : 0 : bmval[1] |= FATTR4_WORD1_MODE;
1034 : 0 : len += 4;
1035 : : }
1036 [ # # ]: 0 : if (iap->ia_valid & ATTR_UID) {
1037 : 0 : owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1038 [ # # ]: 0 : if (owner_namelen < 0) {
1039 : : dprintk("nfs: couldn't resolve uid %d to string\n",
1040 : : from_kuid(&init_user_ns, iap->ia_uid));
1041 : : /* XXX */
1042 : 0 : strcpy(owner_name, "nobody");
1043 : : owner_namelen = sizeof("nobody") - 1;
1044 : : /* goto out; */
1045 : : }
1046 : 0 : bmval[1] |= FATTR4_WORD1_OWNER;
1047 : 0 : len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1048 : : }
1049 [ # # ]: 0 : if (iap->ia_valid & ATTR_GID) {
1050 : 0 : owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1051 [ # # ]: 0 : if (owner_grouplen < 0) {
1052 : : dprintk("nfs: couldn't resolve gid %d to string\n",
1053 : : from_kgid(&init_user_ns, iap->ia_gid));
1054 : 0 : strcpy(owner_group, "nobody");
1055 : : owner_grouplen = sizeof("nobody") - 1;
1056 : : /* goto out; */
1057 : : }
1058 : 0 : bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1059 : 0 : len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1060 : : }
1061 [ # # ]: 0 : if (iap->ia_valid & ATTR_ATIME_SET) {
1062 : 0 : bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1063 : 0 : len += 16;
1064 [ # # ]: 0 : } else if (iap->ia_valid & ATTR_ATIME) {
1065 : 0 : bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1066 : 0 : len += 4;
1067 : : }
1068 [ # # ]: 0 : if (iap->ia_valid & ATTR_MTIME_SET) {
1069 : 0 : bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1070 : 0 : len += 16;
1071 [ # # ]: 0 : } else if (iap->ia_valid & ATTR_MTIME) {
1072 : 0 : bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1073 : 0 : len += 4;
1074 : : }
1075 [ # # ]: 0 : if (label) {
1076 : 0 : len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1077 : 0 : bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1078 : : }
1079 : :
1080 [ # # ]: 0 : if (bmval[2] != 0)
1081 : : bmval_len = 3;
1082 [ # # ]: 0 : else if (bmval[1] != 0)
1083 : : bmval_len = 2;
1084 : : else
1085 : : bmval_len = 1;
1086 : :
1087 : 0 : p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1088 : :
1089 [ # # ]: 0 : *p++ = cpu_to_be32(bmval_len);
1090 [ # # ]: 0 : for (i = 0; i < bmval_len; i++)
1091 [ # # ]: 0 : *p++ = cpu_to_be32(bmval[i]);
1092 [ # # ]: 0 : *p++ = cpu_to_be32(len);
1093 : :
1094 [ # # ]: 0 : if (bmval[0] & FATTR4_WORD0_SIZE)
1095 : 0 : p = xdr_encode_hyper(p, iap->ia_size);
1096 [ # # ]: 0 : if (bmval[1] & FATTR4_WORD1_MODE)
1097 [ # # ]: 0 : *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1098 [ # # ]: 0 : if (bmval[1] & FATTR4_WORD1_OWNER)
1099 : 0 : p = xdr_encode_opaque(p, owner_name, owner_namelen);
1100 [ # # ]: 0 : if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1101 : 0 : p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1102 [ # # ]: 0 : if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1103 [ # # ]: 0 : if (iap->ia_valid & ATTR_ATIME_SET) {
1104 : 0 : *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1105 : 0 : p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1106 [ # # ]: 0 : *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1107 : : } else
1108 : 0 : *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1109 : : }
1110 [ # # ]: 0 : if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1111 [ # # ]: 0 : if (iap->ia_valid & ATTR_MTIME_SET) {
1112 : 0 : *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1113 : 0 : p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1114 [ # # ]: 0 : *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1115 : : } else
1116 : 0 : *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1117 : : }
1118 [ # # ]: 0 : if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1119 [ # # ]: 0 : *p++ = cpu_to_be32(label->lfs);
1120 [ # # ]: 0 : *p++ = cpu_to_be32(label->pi);
1121 [ # # ]: 0 : *p++ = cpu_to_be32(label->len);
1122 : 0 : p = xdr_encode_opaque_fixed(p, label->label, label->len);
1123 : : }
1124 : :
1125 : : /* out: */
1126 : 0 : }
1127 : :
1128 : 0 : static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1129 : : {
1130 : : encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1131 : 0 : encode_uint32(xdr, access);
1132 : 0 : }
1133 : :
1134 : 0 : static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1135 : : {
1136 : : encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1137 : 0 : encode_nfs4_seqid(xdr, arg->seqid);
1138 : 0 : encode_nfs4_stateid(xdr, arg->stateid);
1139 : 0 : }
1140 : :
1141 : 0 : static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1142 : : {
1143 : : __be32 *p;
1144 : :
1145 : : encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1146 : 0 : p = reserve_space(xdr, 12);
1147 : 0 : p = xdr_encode_hyper(p, args->offset);
1148 [ # # ]: 0 : *p = cpu_to_be32(args->count);
1149 : 0 : }
1150 : :
1151 : 0 : static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1152 : : {
1153 : : __be32 *p;
1154 : :
1155 : : encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1156 : 0 : encode_uint32(xdr, create->ftype);
1157 : :
1158 [ # # # ]: 0 : switch (create->ftype) {
1159 : : case NF4LNK:
1160 : 0 : p = reserve_space(xdr, 4);
1161 [ # # ]: 0 : *p = cpu_to_be32(create->u.symlink.len);
1162 : 0 : xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1163 : 0 : break;
1164 : :
1165 : : case NF4BLK: case NF4CHR:
1166 : 0 : p = reserve_space(xdr, 8);
1167 [ # # ]: 0 : *p++ = cpu_to_be32(create->u.device.specdata1);
1168 [ # # ]: 0 : *p = cpu_to_be32(create->u.device.specdata2);
1169 : 0 : break;
1170 : :
1171 : : default:
1172 : : break;
1173 : : }
1174 : :
1175 : 0 : encode_string(xdr, create->name->len, create->name->name);
1176 : 0 : encode_attrs(xdr, create->attrs, create->label, create->server);
1177 : 0 : }
1178 : :
1179 : 0 : static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1180 : : {
1181 : : __be32 *p;
1182 : :
1183 : : encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1184 : 0 : p = reserve_space(xdr, 8);
1185 : 0 : *p++ = cpu_to_be32(1);
1186 [ # # ]: 0 : *p = cpu_to_be32(bitmap);
1187 : 0 : }
1188 : :
1189 : 0 : static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1190 : : {
1191 : : __be32 *p;
1192 : :
1193 : : encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1194 : 0 : p = reserve_space(xdr, 12);
1195 : 0 : *p++ = cpu_to_be32(2);
1196 [ # # ]: 0 : *p++ = cpu_to_be32(bm0);
1197 [ # # ]: 0 : *p = cpu_to_be32(bm1);
1198 : 0 : }
1199 : :
1200 : : static void
1201 : 0 : encode_getattr_three(struct xdr_stream *xdr,
1202 : : uint32_t bm0, uint32_t bm1, uint32_t bm2,
1203 : : struct compound_hdr *hdr)
1204 : : {
1205 : : __be32 *p;
1206 : :
1207 : : encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1208 [ # # ]: 0 : if (bm2) {
1209 : 0 : p = reserve_space(xdr, 16);
1210 : 0 : *p++ = cpu_to_be32(3);
1211 [ # # ]: 0 : *p++ = cpu_to_be32(bm0);
1212 [ # # ]: 0 : *p++ = cpu_to_be32(bm1);
1213 [ # # ]: 0 : *p = cpu_to_be32(bm2);
1214 [ # # ]: 0 : } else if (bm1) {
1215 : 0 : p = reserve_space(xdr, 12);
1216 : 0 : *p++ = cpu_to_be32(2);
1217 [ # # ]: 0 : *p++ = cpu_to_be32(bm0);
1218 [ # # ]: 0 : *p = cpu_to_be32(bm1);
1219 : : } else {
1220 : 0 : p = reserve_space(xdr, 8);
1221 : 0 : *p++ = cpu_to_be32(1);
1222 [ # # ]: 0 : *p = cpu_to_be32(bm0);
1223 : : }
1224 : 0 : }
1225 : :
1226 : 0 : static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1227 : : {
1228 : 0 : encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1229 : 0 : bitmask[1] & nfs4_fattr_bitmap[1],
1230 : 0 : bitmask[2] & nfs4_fattr_bitmap[2],
1231 : : hdr);
1232 : 0 : }
1233 : :
1234 : 0 : static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1235 : : const u32 *open_bitmap,
1236 : : struct compound_hdr *hdr)
1237 : : {
1238 : 0 : encode_getattr_three(xdr,
1239 : 0 : bitmask[0] & open_bitmap[0],
1240 : 0 : bitmask[1] & open_bitmap[1],
1241 : 0 : bitmask[2] & open_bitmap[2],
1242 : : hdr);
1243 : 0 : }
1244 : :
1245 : 0 : static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1246 : : {
1247 : 0 : encode_getattr_three(xdr,
1248 : 0 : bitmask[0] & nfs4_fsinfo_bitmap[0],
1249 : 0 : bitmask[1] & nfs4_fsinfo_bitmap[1],
1250 : 0 : bitmask[2] & nfs4_fsinfo_bitmap[2],
1251 : : hdr);
1252 : 0 : }
1253 : :
1254 : 0 : static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1255 : : {
1256 : 0 : encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1257 : 0 : bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1258 : 0 : }
1259 : :
1260 : : static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1261 : : {
1262 : : encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1263 : : }
1264 : :
1265 : 0 : static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1266 : : {
1267 : : encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1268 : 0 : encode_string(xdr, name->len, name->name);
1269 : 0 : }
1270 : :
1271 : : static inline int nfs4_lock_type(struct file_lock *fl, int block)
1272 : : {
1273 [ # # ][ # # ]: 0 : if (fl->fl_type == F_RDLCK)
[ # # ]
1274 [ # # ]: 0 : return block ? NFS4_READW_LT : NFS4_READ_LT;
1275 [ # # ]: 0 : return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1276 : : }
1277 : :
1278 : : static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1279 : : {
1280 [ # # ][ # # ]: 0 : if (fl->fl_end == OFFSET_MAX)
[ # # ]
1281 : : return ~(uint64_t)0;
1282 : 0 : return fl->fl_end - fl->fl_start + 1;
1283 : : }
1284 : :
1285 : 0 : static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1286 : : {
1287 : : __be32 *p;
1288 : :
1289 : 0 : p = reserve_space(xdr, 32);
1290 : 0 : p = xdr_encode_hyper(p, lowner->clientid);
1291 : 0 : *p++ = cpu_to_be32(20);
1292 : 0 : p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1293 [ # # ]: 0 : *p++ = cpu_to_be32(lowner->s_dev);
1294 : 0 : xdr_encode_hyper(p, lowner->id);
1295 : 0 : }
1296 : :
1297 : : /*
1298 : : * opcode,type,reclaim,offset,length,new_lock_owner = 32
1299 : : * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1300 : : */
1301 : 0 : static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1302 : : {
1303 : : __be32 *p;
1304 : :
1305 : : encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1306 : 0 : p = reserve_space(xdr, 28);
1307 : 0 : *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1308 [ # # ]: 0 : *p++ = cpu_to_be32(args->reclaim);
1309 : 0 : p = xdr_encode_hyper(p, args->fl->fl_start);
1310 : 0 : p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1311 [ # # ]: 0 : *p = cpu_to_be32(args->new_lock_owner);
1312 [ # # ]: 0 : if (args->new_lock_owner){
1313 : 0 : encode_nfs4_seqid(xdr, args->open_seqid);
1314 : 0 : encode_nfs4_stateid(xdr, args->open_stateid);
1315 : 0 : encode_nfs4_seqid(xdr, args->lock_seqid);
1316 : 0 : encode_lockowner(xdr, &args->lock_owner);
1317 : : }
1318 : : else {
1319 : 0 : encode_nfs4_stateid(xdr, args->lock_stateid);
1320 : 0 : encode_nfs4_seqid(xdr, args->lock_seqid);
1321 : : }
1322 : 0 : }
1323 : :
1324 : 0 : static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1325 : : {
1326 : : __be32 *p;
1327 : :
1328 : : encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1329 : 0 : p = reserve_space(xdr, 20);
1330 : 0 : *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1331 : 0 : p = xdr_encode_hyper(p, args->fl->fl_start);
1332 : 0 : p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1333 : 0 : encode_lockowner(xdr, &args->lock_owner);
1334 : 0 : }
1335 : :
1336 : 0 : static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1337 : : {
1338 : : __be32 *p;
1339 : :
1340 : : encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1341 : 0 : encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1342 : 0 : encode_nfs4_seqid(xdr, args->seqid);
1343 : 0 : encode_nfs4_stateid(xdr, args->stateid);
1344 : 0 : p = reserve_space(xdr, 16);
1345 : 0 : p = xdr_encode_hyper(p, args->fl->fl_start);
1346 : 0 : xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1347 : 0 : }
1348 : :
1349 : 0 : static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1350 : : {
1351 : : encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1352 : 0 : encode_lockowner(xdr, lowner);
1353 : 0 : }
1354 : :
1355 : 0 : static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1356 : : {
1357 : : encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1358 : 0 : encode_string(xdr, name->len, name->name);
1359 : 0 : }
1360 : :
1361 : 0 : static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1362 : : {
1363 : : __be32 *p;
1364 : :
1365 : 0 : p = reserve_space(xdr, 8);
1366 [ # # # # ]: 0 : switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1367 : : case FMODE_READ:
1368 : 0 : *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1369 : 0 : break;
1370 : : case FMODE_WRITE:
1371 : 0 : *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1372 : 0 : break;
1373 : : case FMODE_READ|FMODE_WRITE:
1374 : 0 : *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1375 : 0 : break;
1376 : : default:
1377 : 0 : *p++ = cpu_to_be32(0);
1378 : : }
1379 : 0 : *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1380 : 0 : }
1381 : :
1382 : : static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1383 : : {
1384 : : __be32 *p;
1385 : : /*
1386 : : * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1387 : : * owner 4 = 32
1388 : : */
1389 : 0 : encode_nfs4_seqid(xdr, arg->seqid);
1390 : 0 : encode_share_access(xdr, arg->fmode);
1391 : 0 : p = reserve_space(xdr, 36);
1392 : 0 : p = xdr_encode_hyper(p, arg->clientid);
1393 : 0 : *p++ = cpu_to_be32(24);
1394 : 0 : p = xdr_encode_opaque_fixed(p, "open id:", 8);
1395 [ # # ]: 0 : *p++ = cpu_to_be32(arg->server->s_dev);
1396 [ # # ]: 0 : *p++ = cpu_to_be32(arg->id.uniquifier);
1397 : 0 : xdr_encode_hyper(p, arg->id.create_time);
1398 : : }
1399 : :
1400 : : static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1401 : : {
1402 : : struct iattr dummy;
1403 : : __be32 *p;
1404 : :
1405 : 0 : p = reserve_space(xdr, 4);
1406 [ # # # # : 0 : switch(arg->createmode) {
# ]
1407 : : case NFS4_CREATE_UNCHECKED:
1408 : 0 : *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1409 : 0 : encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1410 : : break;
1411 : : case NFS4_CREATE_GUARDED:
1412 : 0 : *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1413 : 0 : encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1414 : : break;
1415 : : case NFS4_CREATE_EXCLUSIVE:
1416 : 0 : *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1417 : 0 : encode_nfs4_verifier(xdr, &arg->u.verifier);
1418 : : break;
1419 : : case NFS4_CREATE_EXCLUSIVE4_1:
1420 : 0 : *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1421 : 0 : encode_nfs4_verifier(xdr, &arg->u.verifier);
1422 : 0 : dummy.ia_valid = 0;
1423 : 0 : encode_attrs(xdr, &dummy, arg->label, arg->server);
1424 : : }
1425 : : }
1426 : :
1427 : 0 : static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1428 : : {
1429 : : __be32 *p;
1430 : :
1431 : 0 : p = reserve_space(xdr, 4);
1432 [ # # ]: 0 : switch (arg->open_flags & O_CREAT) {
1433 : : case 0:
1434 : 0 : *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1435 : 0 : break;
1436 : : default:
1437 : 0 : *p = cpu_to_be32(NFS4_OPEN_CREATE);
1438 : : encode_createmode(xdr, arg);
1439 : : }
1440 : 0 : }
1441 : :
1442 : : static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1443 : : {
1444 : : __be32 *p;
1445 : :
1446 : 0 : p = reserve_space(xdr, 4);
1447 [ # # # # ]: 0 : switch (delegation_type) {
1448 : : case 0:
1449 : 0 : *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1450 : : break;
1451 : : case FMODE_READ:
1452 : 0 : *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1453 : : break;
1454 : : case FMODE_WRITE|FMODE_READ:
1455 : 0 : *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1456 : : break;
1457 : : default:
1458 : 0 : BUG();
1459 : : }
1460 : : }
1461 : :
1462 : : static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1463 : : {
1464 : : __be32 *p;
1465 : :
1466 : 0 : p = reserve_space(xdr, 4);
1467 : 0 : *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1468 : 0 : encode_string(xdr, name->len, name->name);
1469 : : }
1470 : :
1471 : : static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1472 : : {
1473 : : __be32 *p;
1474 : :
1475 : 0 : p = reserve_space(xdr, 4);
1476 : 0 : *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1477 : : encode_delegation_type(xdr, type);
1478 : : }
1479 : :
1480 : : static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1481 : : {
1482 : : __be32 *p;
1483 : :
1484 : 0 : p = reserve_space(xdr, 4);
1485 : 0 : *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1486 : 0 : encode_nfs4_stateid(xdr, stateid);
1487 : 0 : encode_string(xdr, name->len, name->name);
1488 : : }
1489 : :
1490 : : static inline void encode_claim_fh(struct xdr_stream *xdr)
1491 : : {
1492 : : __be32 *p;
1493 : :
1494 : 0 : p = reserve_space(xdr, 4);
1495 : 0 : *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1496 : : }
1497 : :
1498 : : static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1499 : : {
1500 : : __be32 *p;
1501 : :
1502 : 0 : p = reserve_space(xdr, 4);
1503 : 0 : *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1504 : 0 : encode_nfs4_stateid(xdr, stateid);
1505 : : }
1506 : :
1507 : 0 : static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1508 : : {
1509 : : encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1510 : : encode_openhdr(xdr, arg);
1511 : 0 : encode_opentype(xdr, arg);
1512 [ # # # # : 0 : switch (arg->claim) {
# # ]
1513 : : case NFS4_OPEN_CLAIM_NULL:
1514 : 0 : encode_claim_null(xdr, arg->name);
1515 : : break;
1516 : : case NFS4_OPEN_CLAIM_PREVIOUS:
1517 : 0 : encode_claim_previous(xdr, arg->u.delegation_type);
1518 : : break;
1519 : : case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1520 : 0 : encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1521 : : break;
1522 : : case NFS4_OPEN_CLAIM_FH:
1523 : : encode_claim_fh(xdr);
1524 : : break;
1525 : : case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1526 : 0 : encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1527 : : break;
1528 : : default:
1529 : 0 : BUG();
1530 : : }
1531 : 0 : }
1532 : :
1533 : 0 : static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1534 : : {
1535 : : encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1536 : 0 : encode_nfs4_stateid(xdr, arg->stateid);
1537 : 0 : encode_nfs4_seqid(xdr, arg->seqid);
1538 : 0 : }
1539 : :
1540 : 0 : static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1541 : : {
1542 : : encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1543 : 0 : encode_nfs4_stateid(xdr, arg->stateid);
1544 : 0 : encode_nfs4_seqid(xdr, arg->seqid);
1545 : 0 : encode_share_access(xdr, arg->fmode);
1546 : 0 : }
1547 : :
1548 : : static void
1549 : 0 : encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1550 : : {
1551 : : encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1552 : 0 : encode_string(xdr, fh->size, fh->data);
1553 : 0 : }
1554 : :
1555 : : static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1556 : : {
1557 : : encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1558 : : }
1559 : :
1560 : 0 : static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1561 : : {
1562 : : __be32 *p;
1563 : :
1564 : : encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1565 : 0 : encode_nfs4_stateid(xdr, &args->stateid);
1566 : :
1567 : 0 : p = reserve_space(xdr, 12);
1568 : 0 : p = xdr_encode_hyper(p, args->offset);
1569 [ # # ]: 0 : *p = cpu_to_be32(args->count);
1570 : 0 : }
1571 : :
1572 : 0 : static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1573 : : {
1574 : 0 : uint32_t attrs[3] = {
1575 : : FATTR4_WORD0_RDATTR_ERROR,
1576 : : FATTR4_WORD1_MOUNTED_ON_FILEID,
1577 : : };
1578 : 0 : uint32_t dircount = readdir->count >> 1;
1579 : : __be32 *p, verf[2];
1580 : : uint32_t attrlen = 0;
1581 : : unsigned int i;
1582 : :
1583 [ # # ]: 0 : if (readdir->plus) {
1584 : 0 : attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1585 : : FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1586 : 0 : attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1587 : : FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1588 : : FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1589 : : FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1590 : 0 : attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1591 : 0 : dircount >>= 1;
1592 : : }
1593 : : /* Use mounted_on_fileid only if the server supports it */
1594 [ # # ]: 0 : if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1595 : 0 : attrs[0] |= FATTR4_WORD0_FILEID;
1596 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1597 : 0 : attrs[i] &= readdir->bitmask[i];
1598 [ # # ]: 0 : if (attrs[i] != 0)
1599 : 0 : attrlen = i+1;
1600 : : }
1601 : :
1602 : : encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1603 : 0 : encode_uint64(xdr, readdir->cookie);
1604 : : encode_nfs4_verifier(xdr, &readdir->verifier);
1605 : 0 : p = reserve_space(xdr, 12 + (attrlen << 2));
1606 [ # # ]: 0 : *p++ = cpu_to_be32(dircount);
1607 [ # # ]: 0 : *p++ = cpu_to_be32(readdir->count);
1608 [ # # ]: 0 : *p++ = cpu_to_be32(attrlen);
1609 [ # # ]: 0 : for (i = 0; i < attrlen; i++)
1610 [ # # ]: 0 : *p++ = cpu_to_be32(attrs[i]);
1611 : 0 : memcpy(verf, readdir->verifier.data, sizeof(verf));
1612 : :
1613 : : dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1614 : : __func__,
1615 : : (unsigned long long)readdir->cookie,
1616 : : verf[0], verf[1],
1617 : : attrs[0] & readdir->bitmask[0],
1618 : : attrs[1] & readdir->bitmask[1],
1619 : : attrs[2] & readdir->bitmask[2]);
1620 : 0 : }
1621 : :
1622 : : static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1623 : : {
1624 : : encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1625 : : }
1626 : :
1627 : 0 : static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1628 : : {
1629 : : encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1630 : 0 : encode_string(xdr, name->len, name->name);
1631 : 0 : }
1632 : :
1633 : 0 : static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1634 : : {
1635 : : encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1636 : 0 : encode_string(xdr, oldname->len, oldname->name);
1637 : 0 : encode_string(xdr, newname->len, newname->name);
1638 : 0 : }
1639 : :
1640 : 0 : static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641 : : struct compound_hdr *hdr)
1642 : : {
1643 : : encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1644 : 0 : encode_uint64(xdr, clid);
1645 : 0 : }
1646 : :
1647 : : static void
1648 : : encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1649 : : {
1650 : : encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1651 : : }
1652 : :
1653 : : static void
1654 : 0 : encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1655 : : {
1656 : : __be32 *p;
1657 : :
1658 : : encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1659 : : encode_nfs4_stateid(xdr, &zero_stateid);
1660 : 0 : p = reserve_space(xdr, 2*4);
1661 : 0 : *p++ = cpu_to_be32(1);
1662 : 0 : *p = cpu_to_be32(FATTR4_WORD0_ACL);
1663 : 0 : p = reserve_space(xdr, 4);
1664 [ # # ]: 0 : *p = cpu_to_be32(arg->acl_len);
1665 : 0 : xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1666 : 0 : }
1667 : :
1668 : : static void
1669 : : encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1670 : : {
1671 : : encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1672 : : }
1673 : :
1674 : 0 : static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1675 : : {
1676 : : encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1677 : 0 : encode_nfs4_stateid(xdr, &arg->stateid);
1678 : 0 : encode_attrs(xdr, arg->iap, arg->label, server);
1679 : 0 : }
1680 : :
1681 : 0 : static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1682 : : {
1683 : : __be32 *p;
1684 : :
1685 : : encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1686 : 0 : encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1687 : :
1688 : 0 : encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1689 : 0 : p = reserve_space(xdr, 4);
1690 [ # # ]: 0 : *p = cpu_to_be32(setclientid->sc_prog);
1691 : 0 : encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1692 : 0 : encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1693 : 0 : p = reserve_space(xdr, 4);
1694 [ # # ]: 0 : *p = cpu_to_be32(setclientid->sc_cb_ident);
1695 : 0 : }
1696 : :
1697 : 0 : static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1698 : : {
1699 : : encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1700 : : decode_setclientid_confirm_maxsz, hdr);
1701 : 0 : encode_uint64(xdr, arg->clientid);
1702 : : encode_nfs4_verifier(xdr, &arg->confirm);
1703 : 0 : }
1704 : :
1705 : 0 : static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1706 : : {
1707 : : __be32 *p;
1708 : :
1709 : : encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1710 : 0 : encode_nfs4_stateid(xdr, &args->stateid);
1711 : :
1712 : 0 : p = reserve_space(xdr, 16);
1713 : 0 : p = xdr_encode_hyper(p, args->offset);
1714 [ # # ]: 0 : *p++ = cpu_to_be32(args->stable);
1715 [ # # ]: 0 : *p = cpu_to_be32(args->count);
1716 : :
1717 : 0 : xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1718 : 0 : }
1719 : :
1720 : 0 : static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1721 : : {
1722 : : encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1723 : : encode_nfs4_stateid(xdr, stateid);
1724 : 0 : }
1725 : :
1726 : 0 : static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1727 : : {
1728 : : encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1729 : 0 : encode_string(xdr, name->len, name->name);
1730 : 0 : }
1731 : :
1732 : : #if defined(CONFIG_NFS_V4_1)
1733 : : /* NFSv4.1 operations */
1734 : : static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1735 : : struct nfs4_session *session,
1736 : : struct compound_hdr *hdr)
1737 : : {
1738 : : __be32 *p;
1739 : :
1740 : : encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1741 : : decode_bind_conn_to_session_maxsz, hdr);
1742 : : encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1743 : : p = xdr_reserve_space(xdr, 8);
1744 : : *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1745 : : *p = 0; /* use_conn_in_rdma_mode = False */
1746 : : }
1747 : :
1748 : : static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1749 : : {
1750 : : unsigned int i;
1751 : : encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1752 : : for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1753 : : encode_uint32(xdr, op_map->u.words[i]);
1754 : : }
1755 : :
1756 : : static void encode_exchange_id(struct xdr_stream *xdr,
1757 : : struct nfs41_exchange_id_args *args,
1758 : : struct compound_hdr *hdr)
1759 : : {
1760 : : __be32 *p;
1761 : : char impl_name[IMPL_NAME_LIMIT];
1762 : : int len = 0;
1763 : :
1764 : : encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1765 : : encode_nfs4_verifier(xdr, args->verifier);
1766 : :
1767 : : encode_string(xdr, args->id_len, args->id);
1768 : :
1769 : : encode_uint32(xdr, args->flags);
1770 : : encode_uint32(xdr, args->state_protect.how);
1771 : :
1772 : : switch (args->state_protect.how) {
1773 : : case SP4_NONE:
1774 : : break;
1775 : : case SP4_MACH_CRED:
1776 : : encode_op_map(xdr, &args->state_protect.enforce);
1777 : : encode_op_map(xdr, &args->state_protect.allow);
1778 : : break;
1779 : : default:
1780 : : WARN_ON_ONCE(1);
1781 : : break;
1782 : : }
1783 : :
1784 : : if (send_implementation_id &&
1785 : : sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1786 : : sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1787 : : <= sizeof(impl_name) + 1)
1788 : : len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1789 : : utsname()->sysname, utsname()->release,
1790 : : utsname()->version, utsname()->machine);
1791 : :
1792 : : if (len > 0) {
1793 : : encode_uint32(xdr, 1); /* implementation id array length=1 */
1794 : :
1795 : : encode_string(xdr,
1796 : : sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1797 : : CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1798 : : encode_string(xdr, len, impl_name);
1799 : : /* just send zeros for nii_date - the date is in nii_name */
1800 : : p = reserve_space(xdr, 12);
1801 : : p = xdr_encode_hyper(p, 0);
1802 : : *p = cpu_to_be32(0);
1803 : : } else
1804 : : encode_uint32(xdr, 0); /* implementation id array length=0 */
1805 : : }
1806 : :
1807 : : static void encode_create_session(struct xdr_stream *xdr,
1808 : : struct nfs41_create_session_args *args,
1809 : : struct compound_hdr *hdr)
1810 : : {
1811 : : __be32 *p;
1812 : : char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1813 : : uint32_t len;
1814 : : struct nfs_client *clp = args->client;
1815 : : struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1816 : : u32 max_resp_sz_cached;
1817 : :
1818 : : /*
1819 : : * Assumes OPEN is the biggest non-idempotent compound.
1820 : : * 2 is the verifier.
1821 : : */
1822 : : max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1823 : : RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1824 : :
1825 : : len = scnprintf(machine_name, sizeof(machine_name), "%s",
1826 : : clp->cl_ipaddr);
1827 : :
1828 : : encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1829 : : p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1830 : : p = xdr_encode_hyper(p, clp->cl_clientid);
1831 : : *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1832 : : *p++ = cpu_to_be32(args->flags); /*flags */
1833 : :
1834 : : /* Fore Channel */
1835 : : *p++ = cpu_to_be32(0); /* header padding size */
1836 : : *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1837 : : *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1838 : : *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1839 : : *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1840 : : *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1841 : : *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1842 : :
1843 : : /* Back Channel */
1844 : : *p++ = cpu_to_be32(0); /* header padding size */
1845 : : *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1846 : : *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1847 : : *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1848 : : *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1849 : : *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1850 : : *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1851 : :
1852 : : *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1853 : : *p++ = cpu_to_be32(1);
1854 : : *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1855 : :
1856 : : /* authsys_parms rfc1831 */
1857 : : *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
1858 : : p = xdr_encode_opaque(p, machine_name, len);
1859 : : *p++ = cpu_to_be32(0); /* UID */
1860 : : *p++ = cpu_to_be32(0); /* GID */
1861 : : *p = cpu_to_be32(0); /* No more gids */
1862 : : }
1863 : :
1864 : : static void encode_destroy_session(struct xdr_stream *xdr,
1865 : : struct nfs4_session *session,
1866 : : struct compound_hdr *hdr)
1867 : : {
1868 : : encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1869 : : encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1870 : : }
1871 : :
1872 : : static void encode_destroy_clientid(struct xdr_stream *xdr,
1873 : : uint64_t clientid,
1874 : : struct compound_hdr *hdr)
1875 : : {
1876 : : encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1877 : : encode_uint64(xdr, clientid);
1878 : : }
1879 : :
1880 : : static void encode_reclaim_complete(struct xdr_stream *xdr,
1881 : : struct nfs41_reclaim_complete_args *args,
1882 : : struct compound_hdr *hdr)
1883 : : {
1884 : : encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1885 : : encode_uint32(xdr, args->one_fs);
1886 : : }
1887 : : #endif /* CONFIG_NFS_V4_1 */
1888 : :
1889 : : static void encode_sequence(struct xdr_stream *xdr,
1890 : : const struct nfs4_sequence_args *args,
1891 : : struct compound_hdr *hdr)
1892 : : {
1893 : : #if defined(CONFIG_NFS_V4_1)
1894 : : struct nfs4_session *session;
1895 : : struct nfs4_slot_table *tp;
1896 : : struct nfs4_slot *slot = args->sa_slot;
1897 : : __be32 *p;
1898 : :
1899 : : tp = slot->table;
1900 : : session = tp->session;
1901 : : if (!session)
1902 : : return;
1903 : :
1904 : : encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1905 : :
1906 : : /*
1907 : : * Sessionid + seqid + slotid + max slotid + cache_this
1908 : : */
1909 : : dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1910 : : "max_slotid=%d cache_this=%d\n",
1911 : : __func__,
1912 : : ((u32 *)session->sess_id.data)[0],
1913 : : ((u32 *)session->sess_id.data)[1],
1914 : : ((u32 *)session->sess_id.data)[2],
1915 : : ((u32 *)session->sess_id.data)[3],
1916 : : slot->seq_nr, slot->slot_nr,
1917 : : tp->highest_used_slotid, args->sa_cache_this);
1918 : : p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1919 : : p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1920 : : *p++ = cpu_to_be32(slot->seq_nr);
1921 : : *p++ = cpu_to_be32(slot->slot_nr);
1922 : : *p++ = cpu_to_be32(tp->highest_used_slotid);
1923 : : *p = cpu_to_be32(args->sa_cache_this);
1924 : : #endif /* CONFIG_NFS_V4_1 */
1925 : : }
1926 : :
1927 : : #ifdef CONFIG_NFS_V4_1
1928 : : static void
1929 : : encode_getdevicelist(struct xdr_stream *xdr,
1930 : : const struct nfs4_getdevicelist_args *args,
1931 : : struct compound_hdr *hdr)
1932 : : {
1933 : : __be32 *p;
1934 : : nfs4_verifier dummy = {
1935 : : .data = "dummmmmy",
1936 : : };
1937 : :
1938 : : encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1939 : : p = reserve_space(xdr, 16);
1940 : : *p++ = cpu_to_be32(args->layoutclass);
1941 : : *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1942 : : xdr_encode_hyper(p, 0ULL); /* cookie */
1943 : : encode_nfs4_verifier(xdr, &dummy);
1944 : : }
1945 : :
1946 : : static void
1947 : : encode_getdeviceinfo(struct xdr_stream *xdr,
1948 : : const struct nfs4_getdeviceinfo_args *args,
1949 : : struct compound_hdr *hdr)
1950 : : {
1951 : : __be32 *p;
1952 : :
1953 : : encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1954 : : p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1955 : : p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1956 : : NFS4_DEVICEID4_SIZE);
1957 : : *p++ = cpu_to_be32(args->pdev->layout_type);
1958 : : *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
1959 : : *p++ = cpu_to_be32(0); /* bitmap length 0 */
1960 : : }
1961 : :
1962 : : static void
1963 : : encode_layoutget(struct xdr_stream *xdr,
1964 : : const struct nfs4_layoutget_args *args,
1965 : : struct compound_hdr *hdr)
1966 : : {
1967 : : __be32 *p;
1968 : :
1969 : : encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1970 : : p = reserve_space(xdr, 36);
1971 : : *p++ = cpu_to_be32(0); /* Signal layout available */
1972 : : *p++ = cpu_to_be32(args->type);
1973 : : *p++ = cpu_to_be32(args->range.iomode);
1974 : : p = xdr_encode_hyper(p, args->range.offset);
1975 : : p = xdr_encode_hyper(p, args->range.length);
1976 : : p = xdr_encode_hyper(p, args->minlength);
1977 : : encode_nfs4_stateid(xdr, &args->stateid);
1978 : : encode_uint32(xdr, args->maxcount);
1979 : :
1980 : : dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1981 : : __func__,
1982 : : args->type,
1983 : : args->range.iomode,
1984 : : (unsigned long)args->range.offset,
1985 : : (unsigned long)args->range.length,
1986 : : args->maxcount);
1987 : : }
1988 : :
1989 : : static int
1990 : : encode_layoutcommit(struct xdr_stream *xdr,
1991 : : struct inode *inode,
1992 : : const struct nfs4_layoutcommit_args *args,
1993 : : struct compound_hdr *hdr)
1994 : : {
1995 : : __be32 *p;
1996 : :
1997 : : dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1998 : : NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1999 : :
2000 : : encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2001 : : p = reserve_space(xdr, 20);
2002 : : /* Only whole file layouts */
2003 : : p = xdr_encode_hyper(p, 0); /* offset */
2004 : : p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
2005 : : *p = cpu_to_be32(0); /* reclaim */
2006 : : encode_nfs4_stateid(xdr, &args->stateid);
2007 : : p = reserve_space(xdr, 20);
2008 : : *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2009 : : p = xdr_encode_hyper(p, args->lastbytewritten);
2010 : : *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2011 : : *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2012 : :
2013 : : if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2014 : : NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2015 : : NFS_I(inode)->layout, xdr, args);
2016 : : else
2017 : : encode_uint32(xdr, 0); /* no layout-type payload */
2018 : :
2019 : : return 0;
2020 : : }
2021 : :
2022 : : static void
2023 : : encode_layoutreturn(struct xdr_stream *xdr,
2024 : : const struct nfs4_layoutreturn_args *args,
2025 : : struct compound_hdr *hdr)
2026 : : {
2027 : : __be32 *p;
2028 : :
2029 : : encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2030 : : p = reserve_space(xdr, 16);
2031 : : *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2032 : : *p++ = cpu_to_be32(args->layout_type);
2033 : : *p++ = cpu_to_be32(IOMODE_ANY);
2034 : : *p = cpu_to_be32(RETURN_FILE);
2035 : : p = reserve_space(xdr, 16);
2036 : : p = xdr_encode_hyper(p, 0);
2037 : : p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2038 : : spin_lock(&args->inode->i_lock);
2039 : : encode_nfs4_stateid(xdr, &args->stateid);
2040 : : spin_unlock(&args->inode->i_lock);
2041 : : if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2042 : : NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2043 : : NFS_I(args->inode)->layout, xdr, args);
2044 : : } else
2045 : : encode_uint32(xdr, 0);
2046 : : }
2047 : :
2048 : : static int
2049 : : encode_secinfo_no_name(struct xdr_stream *xdr,
2050 : : const struct nfs41_secinfo_no_name_args *args,
2051 : : struct compound_hdr *hdr)
2052 : : {
2053 : : encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2054 : : encode_uint32(xdr, args->style);
2055 : : return 0;
2056 : : }
2057 : :
2058 : : static void encode_test_stateid(struct xdr_stream *xdr,
2059 : : struct nfs41_test_stateid_args *args,
2060 : : struct compound_hdr *hdr)
2061 : : {
2062 : : encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2063 : : encode_uint32(xdr, 1);
2064 : : encode_nfs4_stateid(xdr, args->stateid);
2065 : : }
2066 : :
2067 : : static void encode_free_stateid(struct xdr_stream *xdr,
2068 : : struct nfs41_free_stateid_args *args,
2069 : : struct compound_hdr *hdr)
2070 : : {
2071 : : encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2072 : : encode_nfs4_stateid(xdr, &args->stateid);
2073 : : }
2074 : : #endif /* CONFIG_NFS_V4_1 */
2075 : :
2076 : : /*
2077 : : * END OF "GENERIC" ENCODE ROUTINES.
2078 : : */
2079 : :
2080 : : static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2081 : : {
2082 : : #if defined(CONFIG_NFS_V4_1)
2083 : : struct nfs4_session *session = args->sa_slot->table->session;
2084 : : if (session)
2085 : : return session->clp->cl_mvops->minor_version;
2086 : : #endif /* CONFIG_NFS_V4_1 */
2087 : : return 0;
2088 : : }
2089 : :
2090 : : /*
2091 : : * Encode an ACCESS request
2092 : : */
2093 : 0 : static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2094 : : const struct nfs4_accessargs *args)
2095 : : {
2096 : 0 : struct compound_hdr hdr = {
2097 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2098 : : };
2099 : :
2100 : 0 : encode_compound_hdr(xdr, req, &hdr);
2101 : : encode_sequence(xdr, &args->seq_args, &hdr);
2102 : 0 : encode_putfh(xdr, args->fh, &hdr);
2103 : 0 : encode_access(xdr, args->access, &hdr);
2104 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2105 : 0 : encode_nops(&hdr);
2106 : 0 : }
2107 : :
2108 : : /*
2109 : : * Encode LOOKUP request
2110 : : */
2111 : 0 : static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 : : const struct nfs4_lookup_arg *args)
2113 : : {
2114 : 0 : struct compound_hdr hdr = {
2115 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2116 : : };
2117 : :
2118 : 0 : encode_compound_hdr(xdr, req, &hdr);
2119 : : encode_sequence(xdr, &args->seq_args, &hdr);
2120 : 0 : encode_putfh(xdr, args->dir_fh, &hdr);
2121 : 0 : encode_lookup(xdr, args->name, &hdr);
2122 : : encode_getfh(xdr, &hdr);
2123 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2124 : 0 : encode_nops(&hdr);
2125 : 0 : }
2126 : :
2127 : : /*
2128 : : * Encode LOOKUP_ROOT request
2129 : : */
2130 : 0 : static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2131 : : struct xdr_stream *xdr,
2132 : : const struct nfs4_lookup_root_arg *args)
2133 : : {
2134 : 0 : struct compound_hdr hdr = {
2135 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2136 : : };
2137 : :
2138 : 0 : encode_compound_hdr(xdr, req, &hdr);
2139 : : encode_sequence(xdr, &args->seq_args, &hdr);
2140 : : encode_putrootfh(xdr, &hdr);
2141 : : encode_getfh(xdr, &hdr);
2142 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2143 : 0 : encode_nops(&hdr);
2144 : 0 : }
2145 : :
2146 : : /*
2147 : : * Encode REMOVE request
2148 : : */
2149 : 0 : static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2150 : : const struct nfs_removeargs *args)
2151 : : {
2152 : 0 : struct compound_hdr hdr = {
2153 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2154 : : };
2155 : :
2156 : 0 : encode_compound_hdr(xdr, req, &hdr);
2157 : : encode_sequence(xdr, &args->seq_args, &hdr);
2158 : 0 : encode_putfh(xdr, args->fh, &hdr);
2159 : 0 : encode_remove(xdr, &args->name, &hdr);
2160 : 0 : encode_nops(&hdr);
2161 : 0 : }
2162 : :
2163 : : /*
2164 : : * Encode RENAME request
2165 : : */
2166 : 0 : static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 : : const struct nfs_renameargs *args)
2168 : : {
2169 : 0 : struct compound_hdr hdr = {
2170 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2171 : : };
2172 : :
2173 : 0 : encode_compound_hdr(xdr, req, &hdr);
2174 : : encode_sequence(xdr, &args->seq_args, &hdr);
2175 : 0 : encode_putfh(xdr, args->old_dir, &hdr);
2176 : : encode_savefh(xdr, &hdr);
2177 : 0 : encode_putfh(xdr, args->new_dir, &hdr);
2178 : 0 : encode_rename(xdr, args->old_name, args->new_name, &hdr);
2179 : 0 : encode_nops(&hdr);
2180 : 0 : }
2181 : :
2182 : : /*
2183 : : * Encode LINK request
2184 : : */
2185 : 0 : static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2186 : : const struct nfs4_link_arg *args)
2187 : : {
2188 : 0 : struct compound_hdr hdr = {
2189 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2190 : : };
2191 : :
2192 : 0 : encode_compound_hdr(xdr, req, &hdr);
2193 : : encode_sequence(xdr, &args->seq_args, &hdr);
2194 : 0 : encode_putfh(xdr, args->fh, &hdr);
2195 : : encode_savefh(xdr, &hdr);
2196 : 0 : encode_putfh(xdr, args->dir_fh, &hdr);
2197 : 0 : encode_link(xdr, args->name, &hdr);
2198 : : encode_restorefh(xdr, &hdr);
2199 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2200 : 0 : encode_nops(&hdr);
2201 : 0 : }
2202 : :
2203 : : /*
2204 : : * Encode CREATE request
2205 : : */
2206 : 0 : static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 : : const struct nfs4_create_arg *args)
2208 : : {
2209 : 0 : struct compound_hdr hdr = {
2210 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2211 : : };
2212 : :
2213 : 0 : encode_compound_hdr(xdr, req, &hdr);
2214 : : encode_sequence(xdr, &args->seq_args, &hdr);
2215 : 0 : encode_putfh(xdr, args->dir_fh, &hdr);
2216 : 0 : encode_create(xdr, args, &hdr);
2217 : : encode_getfh(xdr, &hdr);
2218 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2219 : 0 : encode_nops(&hdr);
2220 : 0 : }
2221 : :
2222 : : /*
2223 : : * Encode SYMLINK request
2224 : : */
2225 : 0 : static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2226 : : const struct nfs4_create_arg *args)
2227 : : {
2228 : 0 : nfs4_xdr_enc_create(req, xdr, args);
2229 : 0 : }
2230 : :
2231 : : /*
2232 : : * Encode GETATTR request
2233 : : */
2234 : 0 : static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2235 : : const struct nfs4_getattr_arg *args)
2236 : : {
2237 : 0 : struct compound_hdr hdr = {
2238 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2239 : : };
2240 : :
2241 : 0 : encode_compound_hdr(xdr, req, &hdr);
2242 : : encode_sequence(xdr, &args->seq_args, &hdr);
2243 : 0 : encode_putfh(xdr, args->fh, &hdr);
2244 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2245 : 0 : encode_nops(&hdr);
2246 : 0 : }
2247 : :
2248 : : /*
2249 : : * Encode a CLOSE request
2250 : : */
2251 : 0 : static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 : : struct nfs_closeargs *args)
2253 : : {
2254 : 0 : struct compound_hdr hdr = {
2255 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2256 : : };
2257 : :
2258 : 0 : encode_compound_hdr(xdr, req, &hdr);
2259 : : encode_sequence(xdr, &args->seq_args, &hdr);
2260 : 0 : encode_putfh(xdr, args->fh, &hdr);
2261 : 0 : encode_close(xdr, args, &hdr);
2262 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2263 : 0 : encode_nops(&hdr);
2264 : 0 : }
2265 : :
2266 : : /*
2267 : : * Encode an OPEN request
2268 : : */
2269 : 0 : static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2270 : : struct nfs_openargs *args)
2271 : : {
2272 : 0 : struct compound_hdr hdr = {
2273 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2274 : : };
2275 : :
2276 : 0 : encode_compound_hdr(xdr, req, &hdr);
2277 : : encode_sequence(xdr, &args->seq_args, &hdr);
2278 : 0 : encode_putfh(xdr, args->fh, &hdr);
2279 : 0 : encode_open(xdr, args, &hdr);
2280 : : encode_getfh(xdr, &hdr);
2281 [ # # ]: 0 : if (args->access)
2282 : 0 : encode_access(xdr, args->access, &hdr);
2283 : 0 : encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2284 : 0 : encode_nops(&hdr);
2285 : 0 : }
2286 : :
2287 : : /*
2288 : : * Encode an OPEN_CONFIRM request
2289 : : */
2290 : 0 : static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2291 : : struct xdr_stream *xdr,
2292 : : struct nfs_open_confirmargs *args)
2293 : : {
2294 : 0 : struct compound_hdr hdr = {
2295 : : .nops = 0,
2296 : : };
2297 : :
2298 : 0 : encode_compound_hdr(xdr, req, &hdr);
2299 : 0 : encode_putfh(xdr, args->fh, &hdr);
2300 : 0 : encode_open_confirm(xdr, args, &hdr);
2301 : 0 : encode_nops(&hdr);
2302 : 0 : }
2303 : :
2304 : : /*
2305 : : * Encode an OPEN request with no attributes.
2306 : : */
2307 : 0 : static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2308 : : struct xdr_stream *xdr,
2309 : : struct nfs_openargs *args)
2310 : : {
2311 : 0 : struct compound_hdr hdr = {
2312 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2313 : : };
2314 : :
2315 : 0 : encode_compound_hdr(xdr, req, &hdr);
2316 : : encode_sequence(xdr, &args->seq_args, &hdr);
2317 : 0 : encode_putfh(xdr, args->fh, &hdr);
2318 : 0 : encode_open(xdr, args, &hdr);
2319 [ # # ]: 0 : if (args->access)
2320 : 0 : encode_access(xdr, args->access, &hdr);
2321 : 0 : encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2322 : 0 : encode_nops(&hdr);
2323 : 0 : }
2324 : :
2325 : : /*
2326 : : * Encode an OPEN_DOWNGRADE request
2327 : : */
2328 : 0 : static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2329 : : struct xdr_stream *xdr,
2330 : : struct nfs_closeargs *args)
2331 : : {
2332 : 0 : struct compound_hdr hdr = {
2333 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2334 : : };
2335 : :
2336 : 0 : encode_compound_hdr(xdr, req, &hdr);
2337 : : encode_sequence(xdr, &args->seq_args, &hdr);
2338 : 0 : encode_putfh(xdr, args->fh, &hdr);
2339 : 0 : encode_open_downgrade(xdr, args, &hdr);
2340 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2341 : 0 : encode_nops(&hdr);
2342 : 0 : }
2343 : :
2344 : : /*
2345 : : * Encode a LOCK request
2346 : : */
2347 : 0 : static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2348 : : struct nfs_lock_args *args)
2349 : : {
2350 : 0 : struct compound_hdr hdr = {
2351 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2352 : : };
2353 : :
2354 : 0 : encode_compound_hdr(xdr, req, &hdr);
2355 : : encode_sequence(xdr, &args->seq_args, &hdr);
2356 : 0 : encode_putfh(xdr, args->fh, &hdr);
2357 : 0 : encode_lock(xdr, args, &hdr);
2358 : 0 : encode_nops(&hdr);
2359 : 0 : }
2360 : :
2361 : : /*
2362 : : * Encode a LOCKT request
2363 : : */
2364 : 0 : static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2365 : : struct nfs_lockt_args *args)
2366 : : {
2367 : 0 : struct compound_hdr hdr = {
2368 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2369 : : };
2370 : :
2371 : 0 : encode_compound_hdr(xdr, req, &hdr);
2372 : : encode_sequence(xdr, &args->seq_args, &hdr);
2373 : 0 : encode_putfh(xdr, args->fh, &hdr);
2374 : 0 : encode_lockt(xdr, args, &hdr);
2375 : 0 : encode_nops(&hdr);
2376 : 0 : }
2377 : :
2378 : : /*
2379 : : * Encode a LOCKU request
2380 : : */
2381 : 0 : static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2382 : : struct nfs_locku_args *args)
2383 : : {
2384 : 0 : struct compound_hdr hdr = {
2385 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2386 : : };
2387 : :
2388 : 0 : encode_compound_hdr(xdr, req, &hdr);
2389 : : encode_sequence(xdr, &args->seq_args, &hdr);
2390 : 0 : encode_putfh(xdr, args->fh, &hdr);
2391 : 0 : encode_locku(xdr, args, &hdr);
2392 : 0 : encode_nops(&hdr);
2393 : 0 : }
2394 : :
2395 : 0 : static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2396 : : struct xdr_stream *xdr,
2397 : : struct nfs_release_lockowner_args *args)
2398 : : {
2399 : 0 : struct compound_hdr hdr = {
2400 : : .minorversion = 0,
2401 : : };
2402 : :
2403 : 0 : encode_compound_hdr(xdr, req, &hdr);
2404 : 0 : encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2405 : 0 : encode_nops(&hdr);
2406 : 0 : }
2407 : :
2408 : : /*
2409 : : * Encode a READLINK request
2410 : : */
2411 : 0 : static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 : : const struct nfs4_readlink *args)
2413 : : {
2414 : 0 : struct compound_hdr hdr = {
2415 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2416 : : };
2417 : :
2418 : 0 : encode_compound_hdr(xdr, req, &hdr);
2419 : : encode_sequence(xdr, &args->seq_args, &hdr);
2420 : 0 : encode_putfh(xdr, args->fh, &hdr);
2421 : : encode_readlink(xdr, args, req, &hdr);
2422 : :
2423 : 0 : xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2424 : : args->pgbase, args->pglen);
2425 : 0 : encode_nops(&hdr);
2426 : 0 : }
2427 : :
2428 : : /*
2429 : : * Encode a READDIR request
2430 : : */
2431 : 0 : static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2432 : : const struct nfs4_readdir_arg *args)
2433 : : {
2434 : 0 : struct compound_hdr hdr = {
2435 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2436 : : };
2437 : :
2438 : 0 : encode_compound_hdr(xdr, req, &hdr);
2439 : : encode_sequence(xdr, &args->seq_args, &hdr);
2440 : 0 : encode_putfh(xdr, args->fh, &hdr);
2441 : 0 : encode_readdir(xdr, args, req, &hdr);
2442 : :
2443 : 0 : xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2444 : : args->pgbase, args->count);
2445 : : dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2446 : : __func__, hdr.replen << 2, args->pages,
2447 : : args->pgbase, args->count);
2448 : 0 : encode_nops(&hdr);
2449 : 0 : }
2450 : :
2451 : : /*
2452 : : * Encode a READ request
2453 : : */
2454 : 0 : static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2455 : : struct nfs_readargs *args)
2456 : : {
2457 : 0 : struct compound_hdr hdr = {
2458 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2459 : : };
2460 : :
2461 : 0 : encode_compound_hdr(xdr, req, &hdr);
2462 : : encode_sequence(xdr, &args->seq_args, &hdr);
2463 : 0 : encode_putfh(xdr, args->fh, &hdr);
2464 : 0 : encode_read(xdr, args, &hdr);
2465 : :
2466 : 0 : xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2467 : : args->pages, args->pgbase, args->count);
2468 : 0 : req->rq_rcv_buf.flags |= XDRBUF_READ;
2469 : 0 : encode_nops(&hdr);
2470 : 0 : }
2471 : :
2472 : : /*
2473 : : * Encode an SETATTR request
2474 : : */
2475 : 0 : static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2476 : : struct nfs_setattrargs *args)
2477 : : {
2478 : 0 : struct compound_hdr hdr = {
2479 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2480 : : };
2481 : :
2482 : 0 : encode_compound_hdr(xdr, req, &hdr);
2483 : : encode_sequence(xdr, &args->seq_args, &hdr);
2484 : 0 : encode_putfh(xdr, args->fh, &hdr);
2485 : 0 : encode_setattr(xdr, args, args->server, &hdr);
2486 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2487 : 0 : encode_nops(&hdr);
2488 : 0 : }
2489 : :
2490 : : /*
2491 : : * Encode a GETACL request
2492 : : */
2493 : 0 : static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2494 : : struct nfs_getaclargs *args)
2495 : : {
2496 : 0 : struct compound_hdr hdr = {
2497 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2498 : : };
2499 : : uint32_t replen;
2500 : :
2501 : 0 : encode_compound_hdr(xdr, req, &hdr);
2502 : : encode_sequence(xdr, &args->seq_args, &hdr);
2503 : 0 : encode_putfh(xdr, args->fh, &hdr);
2504 : 0 : replen = hdr.replen + op_decode_hdr_maxsz + 1;
2505 : 0 : encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2506 : :
2507 : 0 : xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2508 : : args->acl_pages, args->acl_pgbase, args->acl_len);
2509 : :
2510 : 0 : encode_nops(&hdr);
2511 : 0 : }
2512 : :
2513 : : /*
2514 : : * Encode a WRITE request
2515 : : */
2516 : 0 : static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2517 : : struct nfs_writeargs *args)
2518 : : {
2519 : 0 : struct compound_hdr hdr = {
2520 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2521 : : };
2522 : :
2523 : 0 : encode_compound_hdr(xdr, req, &hdr);
2524 : : encode_sequence(xdr, &args->seq_args, &hdr);
2525 : 0 : encode_putfh(xdr, args->fh, &hdr);
2526 : 0 : encode_write(xdr, args, &hdr);
2527 : 0 : req->rq_snd_buf.flags |= XDRBUF_WRITE;
2528 [ # # ]: 0 : if (args->bitmask)
2529 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2530 : 0 : encode_nops(&hdr);
2531 : 0 : }
2532 : :
2533 : : /*
2534 : : * a COMMIT request
2535 : : */
2536 : 0 : static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2537 : : struct nfs_commitargs *args)
2538 : : {
2539 : 0 : struct compound_hdr hdr = {
2540 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2541 : : };
2542 : :
2543 : 0 : encode_compound_hdr(xdr, req, &hdr);
2544 : : encode_sequence(xdr, &args->seq_args, &hdr);
2545 : 0 : encode_putfh(xdr, args->fh, &hdr);
2546 : 0 : encode_commit(xdr, args, &hdr);
2547 : 0 : encode_nops(&hdr);
2548 : 0 : }
2549 : :
2550 : : /*
2551 : : * FSINFO request
2552 : : */
2553 : 0 : static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2554 : : struct nfs4_fsinfo_arg *args)
2555 : : {
2556 : 0 : struct compound_hdr hdr = {
2557 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2558 : : };
2559 : :
2560 : 0 : encode_compound_hdr(xdr, req, &hdr);
2561 : : encode_sequence(xdr, &args->seq_args, &hdr);
2562 : 0 : encode_putfh(xdr, args->fh, &hdr);
2563 : 0 : encode_fsinfo(xdr, args->bitmask, &hdr);
2564 : 0 : encode_nops(&hdr);
2565 : 0 : }
2566 : :
2567 : : /*
2568 : : * a PATHCONF request
2569 : : */
2570 : 0 : static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2571 : : const struct nfs4_pathconf_arg *args)
2572 : : {
2573 : 0 : struct compound_hdr hdr = {
2574 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2575 : : };
2576 : :
2577 : 0 : encode_compound_hdr(xdr, req, &hdr);
2578 : : encode_sequence(xdr, &args->seq_args, &hdr);
2579 : 0 : encode_putfh(xdr, args->fh, &hdr);
2580 : 0 : encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2581 : : &hdr);
2582 : 0 : encode_nops(&hdr);
2583 : 0 : }
2584 : :
2585 : : /*
2586 : : * a STATFS request
2587 : : */
2588 : 0 : static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2589 : : const struct nfs4_statfs_arg *args)
2590 : : {
2591 : 0 : struct compound_hdr hdr = {
2592 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2593 : : };
2594 : :
2595 : 0 : encode_compound_hdr(xdr, req, &hdr);
2596 : : encode_sequence(xdr, &args->seq_args, &hdr);
2597 : 0 : encode_putfh(xdr, args->fh, &hdr);
2598 : 0 : encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2599 : 0 : args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2600 : 0 : encode_nops(&hdr);
2601 : 0 : }
2602 : :
2603 : : /*
2604 : : * GETATTR_BITMAP request
2605 : : */
2606 : 0 : static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2607 : : struct xdr_stream *xdr,
2608 : : struct nfs4_server_caps_arg *args)
2609 : : {
2610 : 0 : struct compound_hdr hdr = {
2611 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2612 : : };
2613 : :
2614 : 0 : encode_compound_hdr(xdr, req, &hdr);
2615 : : encode_sequence(xdr, &args->seq_args, &hdr);
2616 : 0 : encode_putfh(xdr, args->fhandle, &hdr);
2617 : 0 : encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2618 : : FATTR4_WORD0_FH_EXPIRE_TYPE|
2619 : : FATTR4_WORD0_LINK_SUPPORT|
2620 : : FATTR4_WORD0_SYMLINK_SUPPORT|
2621 : : FATTR4_WORD0_ACLSUPPORT, &hdr);
2622 : 0 : encode_nops(&hdr);
2623 : 0 : }
2624 : :
2625 : : /*
2626 : : * a RENEW request
2627 : : */
2628 : 0 : static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2629 : : struct nfs_client *clp)
2630 : : {
2631 : 0 : struct compound_hdr hdr = {
2632 : : .nops = 0,
2633 : : };
2634 : :
2635 : 0 : encode_compound_hdr(xdr, req, &hdr);
2636 : 0 : encode_renew(xdr, clp->cl_clientid, &hdr);
2637 : 0 : encode_nops(&hdr);
2638 : 0 : }
2639 : :
2640 : : /*
2641 : : * a SETCLIENTID request
2642 : : */
2643 : 0 : static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2644 : : struct xdr_stream *xdr,
2645 : : struct nfs4_setclientid *sc)
2646 : : {
2647 : 0 : struct compound_hdr hdr = {
2648 : : .nops = 0,
2649 : : };
2650 : :
2651 : 0 : encode_compound_hdr(xdr, req, &hdr);
2652 : 0 : encode_setclientid(xdr, sc, &hdr);
2653 : 0 : encode_nops(&hdr);
2654 : 0 : }
2655 : :
2656 : : /*
2657 : : * a SETCLIENTID_CONFIRM request
2658 : : */
2659 : 0 : static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2660 : : struct xdr_stream *xdr,
2661 : : struct nfs4_setclientid_res *arg)
2662 : : {
2663 : 0 : struct compound_hdr hdr = {
2664 : : .nops = 0,
2665 : : };
2666 : :
2667 : 0 : encode_compound_hdr(xdr, req, &hdr);
2668 : 0 : encode_setclientid_confirm(xdr, arg, &hdr);
2669 : 0 : encode_nops(&hdr);
2670 : 0 : }
2671 : :
2672 : : /*
2673 : : * DELEGRETURN request
2674 : : */
2675 : 0 : static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2676 : : struct xdr_stream *xdr,
2677 : : const struct nfs4_delegreturnargs *args)
2678 : : {
2679 : 0 : struct compound_hdr hdr = {
2680 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2681 : : };
2682 : :
2683 : 0 : encode_compound_hdr(xdr, req, &hdr);
2684 : : encode_sequence(xdr, &args->seq_args, &hdr);
2685 : 0 : encode_putfh(xdr, args->fhandle, &hdr);
2686 : 0 : encode_getfattr(xdr, args->bitmask, &hdr);
2687 : 0 : encode_delegreturn(xdr, args->stateid, &hdr);
2688 : 0 : encode_nops(&hdr);
2689 : 0 : }
2690 : :
2691 : : /*
2692 : : * Encode FS_LOCATIONS request
2693 : : */
2694 : 0 : static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2695 : : struct xdr_stream *xdr,
2696 : : struct nfs4_fs_locations_arg *args)
2697 : : {
2698 : 0 : struct compound_hdr hdr = {
2699 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2700 : : };
2701 : : uint32_t replen;
2702 : :
2703 : 0 : encode_compound_hdr(xdr, req, &hdr);
2704 : : encode_sequence(xdr, &args->seq_args, &hdr);
2705 [ # # ]: 0 : if (args->migration) {
2706 : 0 : encode_putfh(xdr, args->fh, &hdr);
2707 : 0 : replen = hdr.replen;
2708 : 0 : encode_fs_locations(xdr, args->bitmask, &hdr);
2709 [ # # ]: 0 : if (args->renew)
2710 : 0 : encode_renew(xdr, args->clientid, &hdr);
2711 : : } else {
2712 : 0 : encode_putfh(xdr, args->dir_fh, &hdr);
2713 : 0 : encode_lookup(xdr, args->name, &hdr);
2714 : 0 : replen = hdr.replen;
2715 : 0 : encode_fs_locations(xdr, args->bitmask, &hdr);
2716 : : }
2717 : :
2718 : : /* Set up reply kvec to capture returned fs_locations array. */
2719 : 0 : xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2720 : : 0, PAGE_SIZE);
2721 : 0 : encode_nops(&hdr);
2722 : 0 : }
2723 : :
2724 : : /*
2725 : : * Encode SECINFO request
2726 : : */
2727 : 0 : static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2728 : : struct xdr_stream *xdr,
2729 : : struct nfs4_secinfo_arg *args)
2730 : : {
2731 : 0 : struct compound_hdr hdr = {
2732 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2733 : : };
2734 : :
2735 : 0 : encode_compound_hdr(xdr, req, &hdr);
2736 : : encode_sequence(xdr, &args->seq_args, &hdr);
2737 : 0 : encode_putfh(xdr, args->dir_fh, &hdr);
2738 : 0 : encode_secinfo(xdr, args->name, &hdr);
2739 : 0 : encode_nops(&hdr);
2740 : 0 : }
2741 : :
2742 : : /*
2743 : : * Encode FSID_PRESENT request
2744 : : */
2745 : 0 : static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2746 : : struct xdr_stream *xdr,
2747 : : struct nfs4_fsid_present_arg *args)
2748 : : {
2749 : 0 : struct compound_hdr hdr = {
2750 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2751 : : };
2752 : :
2753 : 0 : encode_compound_hdr(xdr, req, &hdr);
2754 : : encode_sequence(xdr, &args->seq_args, &hdr);
2755 : 0 : encode_putfh(xdr, args->fh, &hdr);
2756 : : encode_getfh(xdr, &hdr);
2757 [ # # ]: 0 : if (args->renew)
2758 : 0 : encode_renew(xdr, args->clientid, &hdr);
2759 : 0 : encode_nops(&hdr);
2760 : 0 : }
2761 : :
2762 : : #if defined(CONFIG_NFS_V4_1)
2763 : : /*
2764 : : * BIND_CONN_TO_SESSION request
2765 : : */
2766 : : static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2767 : : struct xdr_stream *xdr,
2768 : : struct nfs_client *clp)
2769 : : {
2770 : : struct compound_hdr hdr = {
2771 : : .minorversion = clp->cl_mvops->minor_version,
2772 : : };
2773 : :
2774 : : encode_compound_hdr(xdr, req, &hdr);
2775 : : encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2776 : : encode_nops(&hdr);
2777 : : }
2778 : :
2779 : : /*
2780 : : * EXCHANGE_ID request
2781 : : */
2782 : : static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2783 : : struct xdr_stream *xdr,
2784 : : struct nfs41_exchange_id_args *args)
2785 : : {
2786 : : struct compound_hdr hdr = {
2787 : : .minorversion = args->client->cl_mvops->minor_version,
2788 : : };
2789 : :
2790 : : encode_compound_hdr(xdr, req, &hdr);
2791 : : encode_exchange_id(xdr, args, &hdr);
2792 : : encode_nops(&hdr);
2793 : : }
2794 : :
2795 : : /*
2796 : : * a CREATE_SESSION request
2797 : : */
2798 : : static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2799 : : struct xdr_stream *xdr,
2800 : : struct nfs41_create_session_args *args)
2801 : : {
2802 : : struct compound_hdr hdr = {
2803 : : .minorversion = args->client->cl_mvops->minor_version,
2804 : : };
2805 : :
2806 : : encode_compound_hdr(xdr, req, &hdr);
2807 : : encode_create_session(xdr, args, &hdr);
2808 : : encode_nops(&hdr);
2809 : : }
2810 : :
2811 : : /*
2812 : : * a DESTROY_SESSION request
2813 : : */
2814 : : static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2815 : : struct xdr_stream *xdr,
2816 : : struct nfs4_session *session)
2817 : : {
2818 : : struct compound_hdr hdr = {
2819 : : .minorversion = session->clp->cl_mvops->minor_version,
2820 : : };
2821 : :
2822 : : encode_compound_hdr(xdr, req, &hdr);
2823 : : encode_destroy_session(xdr, session, &hdr);
2824 : : encode_nops(&hdr);
2825 : : }
2826 : :
2827 : : /*
2828 : : * a DESTROY_CLIENTID request
2829 : : */
2830 : : static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2831 : : struct xdr_stream *xdr,
2832 : : struct nfs_client *clp)
2833 : : {
2834 : : struct compound_hdr hdr = {
2835 : : .minorversion = clp->cl_mvops->minor_version,
2836 : : };
2837 : :
2838 : : encode_compound_hdr(xdr, req, &hdr);
2839 : : encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2840 : : encode_nops(&hdr);
2841 : : }
2842 : :
2843 : : /*
2844 : : * a SEQUENCE request
2845 : : */
2846 : : static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2847 : : struct nfs4_sequence_args *args)
2848 : : {
2849 : : struct compound_hdr hdr = {
2850 : : .minorversion = nfs4_xdr_minorversion(args),
2851 : : };
2852 : :
2853 : : encode_compound_hdr(xdr, req, &hdr);
2854 : : encode_sequence(xdr, args, &hdr);
2855 : : encode_nops(&hdr);
2856 : : }
2857 : :
2858 : : /*
2859 : : * a GET_LEASE_TIME request
2860 : : */
2861 : : static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2862 : : struct xdr_stream *xdr,
2863 : : struct nfs4_get_lease_time_args *args)
2864 : : {
2865 : : struct compound_hdr hdr = {
2866 : : .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2867 : : };
2868 : : const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2869 : :
2870 : : encode_compound_hdr(xdr, req, &hdr);
2871 : : encode_sequence(xdr, &args->la_seq_args, &hdr);
2872 : : encode_putrootfh(xdr, &hdr);
2873 : : encode_fsinfo(xdr, lease_bitmap, &hdr);
2874 : : encode_nops(&hdr);
2875 : : }
2876 : :
2877 : : /*
2878 : : * a RECLAIM_COMPLETE request
2879 : : */
2880 : : static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2881 : : struct xdr_stream *xdr,
2882 : : struct nfs41_reclaim_complete_args *args)
2883 : : {
2884 : : struct compound_hdr hdr = {
2885 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2886 : : };
2887 : :
2888 : : encode_compound_hdr(xdr, req, &hdr);
2889 : : encode_sequence(xdr, &args->seq_args, &hdr);
2890 : : encode_reclaim_complete(xdr, args, &hdr);
2891 : : encode_nops(&hdr);
2892 : : }
2893 : :
2894 : : /*
2895 : : * Encode GETDEVICELIST request
2896 : : */
2897 : : static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2898 : : struct xdr_stream *xdr,
2899 : : struct nfs4_getdevicelist_args *args)
2900 : : {
2901 : : struct compound_hdr hdr = {
2902 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2903 : : };
2904 : :
2905 : : encode_compound_hdr(xdr, req, &hdr);
2906 : : encode_sequence(xdr, &args->seq_args, &hdr);
2907 : : encode_putfh(xdr, args->fh, &hdr);
2908 : : encode_getdevicelist(xdr, args, &hdr);
2909 : : encode_nops(&hdr);
2910 : : }
2911 : :
2912 : : /*
2913 : : * Encode GETDEVICEINFO request
2914 : : */
2915 : : static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2916 : : struct xdr_stream *xdr,
2917 : : struct nfs4_getdeviceinfo_args *args)
2918 : : {
2919 : : struct compound_hdr hdr = {
2920 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2921 : : };
2922 : :
2923 : : encode_compound_hdr(xdr, req, &hdr);
2924 : : encode_sequence(xdr, &args->seq_args, &hdr);
2925 : : encode_getdeviceinfo(xdr, args, &hdr);
2926 : :
2927 : : /* set up reply kvec. Subtract notification bitmap max size (2)
2928 : : * so that notification bitmap is put in xdr_buf tail */
2929 : : xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2930 : : args->pdev->pages, args->pdev->pgbase,
2931 : : args->pdev->pglen);
2932 : :
2933 : : encode_nops(&hdr);
2934 : : }
2935 : :
2936 : : /*
2937 : : * Encode LAYOUTGET request
2938 : : */
2939 : : static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2940 : : struct xdr_stream *xdr,
2941 : : struct nfs4_layoutget_args *args)
2942 : : {
2943 : : struct compound_hdr hdr = {
2944 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2945 : : };
2946 : :
2947 : : encode_compound_hdr(xdr, req, &hdr);
2948 : : encode_sequence(xdr, &args->seq_args, &hdr);
2949 : : encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2950 : : encode_layoutget(xdr, args, &hdr);
2951 : :
2952 : : xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2953 : : args->layout.pages, 0, args->layout.pglen);
2954 : :
2955 : : encode_nops(&hdr);
2956 : : }
2957 : :
2958 : : /*
2959 : : * Encode LAYOUTCOMMIT request
2960 : : */
2961 : : static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2962 : : struct xdr_stream *xdr,
2963 : : struct nfs4_layoutcommit_args *args)
2964 : : {
2965 : : struct nfs4_layoutcommit_data *data =
2966 : : container_of(args, struct nfs4_layoutcommit_data, args);
2967 : : struct compound_hdr hdr = {
2968 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2969 : : };
2970 : :
2971 : : encode_compound_hdr(xdr, req, &hdr);
2972 : : encode_sequence(xdr, &args->seq_args, &hdr);
2973 : : encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2974 : : encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2975 : : encode_getfattr(xdr, args->bitmask, &hdr);
2976 : : encode_nops(&hdr);
2977 : : }
2978 : :
2979 : : /*
2980 : : * Encode LAYOUTRETURN request
2981 : : */
2982 : : static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2983 : : struct xdr_stream *xdr,
2984 : : struct nfs4_layoutreturn_args *args)
2985 : : {
2986 : : struct compound_hdr hdr = {
2987 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2988 : : };
2989 : :
2990 : : encode_compound_hdr(xdr, req, &hdr);
2991 : : encode_sequence(xdr, &args->seq_args, &hdr);
2992 : : encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2993 : : encode_layoutreturn(xdr, args, &hdr);
2994 : : encode_nops(&hdr);
2995 : : }
2996 : :
2997 : : /*
2998 : : * Encode SECINFO_NO_NAME request
2999 : : */
3000 : : static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3001 : : struct xdr_stream *xdr,
3002 : : struct nfs41_secinfo_no_name_args *args)
3003 : : {
3004 : : struct compound_hdr hdr = {
3005 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3006 : : };
3007 : :
3008 : : encode_compound_hdr(xdr, req, &hdr);
3009 : : encode_sequence(xdr, &args->seq_args, &hdr);
3010 : : encode_putrootfh(xdr, &hdr);
3011 : : encode_secinfo_no_name(xdr, args, &hdr);
3012 : : encode_nops(&hdr);
3013 : : return 0;
3014 : : }
3015 : :
3016 : : /*
3017 : : * Encode TEST_STATEID request
3018 : : */
3019 : : static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3020 : : struct xdr_stream *xdr,
3021 : : struct nfs41_test_stateid_args *args)
3022 : : {
3023 : : struct compound_hdr hdr = {
3024 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3025 : : };
3026 : :
3027 : : encode_compound_hdr(xdr, req, &hdr);
3028 : : encode_sequence(xdr, &args->seq_args, &hdr);
3029 : : encode_test_stateid(xdr, args, &hdr);
3030 : : encode_nops(&hdr);
3031 : : }
3032 : :
3033 : : /*
3034 : : * Encode FREE_STATEID request
3035 : : */
3036 : : static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3037 : : struct xdr_stream *xdr,
3038 : : struct nfs41_free_stateid_args *args)
3039 : : {
3040 : : struct compound_hdr hdr = {
3041 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3042 : : };
3043 : :
3044 : : encode_compound_hdr(xdr, req, &hdr);
3045 : : encode_sequence(xdr, &args->seq_args, &hdr);
3046 : : encode_free_stateid(xdr, args, &hdr);
3047 : : encode_nops(&hdr);
3048 : : }
3049 : : #endif /* CONFIG_NFS_V4_1 */
3050 : :
3051 : : static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3052 : : {
3053 : : dprintk("nfs: %s: prematurely hit end of receive buffer. "
3054 : : "Remaining buffer length is %tu words.\n",
3055 : : func, xdr->end - xdr->p);
3056 : : }
3057 : :
3058 : 0 : static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3059 : : {
3060 : 0 : __be32 *p;
3061 : :
3062 : 0 : p = xdr_inline_decode(xdr, 4);
3063 [ # # ]: 0 : if (unlikely(!p))
3064 : : goto out_overflow;
3065 : 0 : *len = be32_to_cpup(p);
3066 : 0 : p = xdr_inline_decode(xdr, *len);
3067 [ # # ]: 0 : if (unlikely(!p))
3068 : : goto out_overflow;
3069 : 0 : *string = (char *)p;
3070 : 0 : return 0;
3071 : : out_overflow:
3072 : : print_overflow_msg(__func__, xdr);
3073 : : return -EIO;
3074 : : }
3075 : :
3076 : 0 : static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3077 : : {
3078 : 0 : __be32 *p;
3079 : :
3080 : 0 : p = xdr_inline_decode(xdr, 8);
3081 [ # # ]: 0 : if (unlikely(!p))
3082 : : goto out_overflow;
3083 : 0 : hdr->status = be32_to_cpup(p++);
3084 : 0 : hdr->taglen = be32_to_cpup(p);
3085 : :
3086 : 0 : p = xdr_inline_decode(xdr, hdr->taglen + 4);
3087 [ # # ]: 0 : if (unlikely(!p))
3088 : : goto out_overflow;
3089 : 0 : hdr->tag = (char *)p;
3090 : 0 : p += XDR_QUADLEN(hdr->taglen);
3091 : 0 : hdr->nops = be32_to_cpup(p);
3092 [ # # ]: 0 : if (unlikely(hdr->nops < 1))
3093 : 0 : return nfs4_stat_to_errno(hdr->status);
3094 : : return 0;
3095 : : out_overflow:
3096 : : print_overflow_msg(__func__, xdr);
3097 : : return -EIO;
3098 : : }
3099 : :
3100 : 0 : static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3101 : : int *nfs_retval)
3102 : : {
3103 : 0 : __be32 *p;
3104 : : uint32_t opnum;
3105 : : int32_t nfserr;
3106 : :
3107 : 0 : p = xdr_inline_decode(xdr, 8);
3108 [ # # ]: 0 : if (unlikely(!p))
3109 : : goto out_overflow;
3110 : 0 : opnum = be32_to_cpup(p++);
3111 [ # # ]: 0 : if (unlikely(opnum != expected))
3112 : : goto out_bad_operation;
3113 : 0 : nfserr = be32_to_cpup(p);
3114 [ # # ]: 0 : if (nfserr == NFS_OK)
3115 : 0 : *nfs_retval = 0;
3116 : : else
3117 : 0 : *nfs_retval = nfs4_stat_to_errno(nfserr);
3118 : : return true;
3119 : : out_bad_operation:
3120 : : dprintk("nfs: Server returned operation"
3121 : : " %d but we issued a request for %d\n",
3122 : : opnum, expected);
3123 : 0 : *nfs_retval = -EREMOTEIO;
3124 : 0 : return false;
3125 : : out_overflow:
3126 : : print_overflow_msg(__func__, xdr);
3127 : 0 : *nfs_retval = -EIO;
3128 : 0 : return false;
3129 : : }
3130 : :
3131 : : static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3132 : : {
3133 : : int retval;
3134 : :
3135 : 0 : __decode_op_hdr(xdr, expected, &retval);
3136 : 0 : return retval;
3137 : : }
3138 : :
3139 : : /* Dummy routine */
3140 : 0 : static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3141 : : {
3142 : : __be32 *p;
3143 : : unsigned int strlen;
3144 : : char *str;
3145 : :
3146 : 0 : p = xdr_inline_decode(xdr, 12);
3147 [ # # ]: 0 : if (likely(p))
3148 : 0 : return decode_opaque_inline(xdr, &strlen, &str);
3149 : : print_overflow_msg(__func__, xdr);
3150 : : return -EIO;
3151 : : }
3152 : :
3153 : 0 : static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3154 : : {
3155 : : uint32_t bmlen;
3156 : 0 : __be32 *p;
3157 : :
3158 : 0 : p = xdr_inline_decode(xdr, 4);
3159 [ # # ]: 0 : if (unlikely(!p))
3160 : : goto out_overflow;
3161 : : bmlen = be32_to_cpup(p);
3162 : :
3163 : 0 : bitmap[0] = bitmap[1] = bitmap[2] = 0;
3164 : 0 : p = xdr_inline_decode(xdr, (bmlen << 2));
3165 [ # # ]: 0 : if (unlikely(!p))
3166 : : goto out_overflow;
3167 [ # # ]: 0 : if (bmlen > 0) {
3168 : 0 : bitmap[0] = be32_to_cpup(p++);
3169 [ # # ]: 0 : if (bmlen > 1) {
3170 : 0 : bitmap[1] = be32_to_cpup(p++);
3171 [ # # ]: 0 : if (bmlen > 2)
3172 : 0 : bitmap[2] = be32_to_cpup(p);
3173 : : }
3174 : : }
3175 : : return 0;
3176 : : out_overflow:
3177 : : print_overflow_msg(__func__, xdr);
3178 : : return -EIO;
3179 : : }
3180 : :
3181 : 0 : static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3182 : : {
3183 : 0 : __be32 *p;
3184 : :
3185 : 0 : p = xdr_inline_decode(xdr, 4);
3186 [ # # ]: 0 : if (unlikely(!p))
3187 : : goto out_overflow;
3188 : 0 : *attrlen = be32_to_cpup(p);
3189 : 0 : *savep = xdr_stream_pos(xdr);
3190 : 0 : return 0;
3191 : : out_overflow:
3192 : : print_overflow_msg(__func__, xdr);
3193 : : return -EIO;
3194 : : }
3195 : :
3196 : 0 : static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3197 : : {
3198 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3199 : : int ret;
3200 : 0 : ret = decode_attr_bitmap(xdr, bitmask);
3201 [ # # ]: 0 : if (unlikely(ret < 0))
3202 : : return ret;
3203 : 0 : bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3204 : : } else
3205 : 0 : bitmask[0] = bitmask[1] = bitmask[2] = 0;
3206 : : dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3207 : : bitmask[0], bitmask[1], bitmask[2]);
3208 : : return 0;
3209 : : }
3210 : :
3211 : 0 : static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3212 : : {
3213 : 0 : __be32 *p;
3214 : : int ret = 0;
3215 : :
3216 : 0 : *type = 0;
3217 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3218 : : return -EIO;
3219 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3220 : 0 : p = xdr_inline_decode(xdr, 4);
3221 [ # # ]: 0 : if (unlikely(!p))
3222 : : goto out_overflow;
3223 : 0 : *type = be32_to_cpup(p);
3224 [ # # ]: 0 : if (*type < NF4REG || *type > NF4NAMEDATTR) {
3225 : : dprintk("%s: bad type %d\n", __func__, *type);
3226 : : return -EIO;
3227 : : }
3228 : 0 : bitmap[0] &= ~FATTR4_WORD0_TYPE;
3229 : : ret = NFS_ATTR_FATTR_TYPE;
3230 : : }
3231 : : dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3232 : 0 : return ret;
3233 : : out_overflow:
3234 : : print_overflow_msg(__func__, xdr);
3235 : : return -EIO;
3236 : : }
3237 : :
3238 : 0 : static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3239 : : uint32_t *bitmap, uint32_t *type)
3240 : : {
3241 : 0 : __be32 *p;
3242 : :
3243 : 0 : *type = 0;
3244 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3245 : : return -EIO;
3246 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3247 : 0 : p = xdr_inline_decode(xdr, 4);
3248 [ # # ]: 0 : if (unlikely(!p))
3249 : : goto out_overflow;
3250 : 0 : *type = be32_to_cpup(p);
3251 : 0 : bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3252 : : }
3253 : : dprintk("%s: expire type=0x%x\n", __func__, *type);
3254 : : return 0;
3255 : : out_overflow:
3256 : : print_overflow_msg(__func__, xdr);
3257 : : return -EIO;
3258 : : }
3259 : :
3260 : 0 : static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3261 : : {
3262 : : __be32 *p;
3263 : : int ret = 0;
3264 : :
3265 : 0 : *change = 0;
3266 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3267 : : return -EIO;
3268 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3269 : 0 : p = xdr_inline_decode(xdr, 8);
3270 [ # # ]: 0 : if (unlikely(!p))
3271 : : goto out_overflow;
3272 : : xdr_decode_hyper(p, change);
3273 : 0 : bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3274 : : ret = NFS_ATTR_FATTR_CHANGE;
3275 : : }
3276 : : dprintk("%s: change attribute=%Lu\n", __func__,
3277 : : (unsigned long long)*change);
3278 : 0 : return ret;
3279 : : out_overflow:
3280 : : print_overflow_msg(__func__, xdr);
3281 : : return -EIO;
3282 : : }
3283 : :
3284 : 0 : static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3285 : : {
3286 : : __be32 *p;
3287 : : int ret = 0;
3288 : :
3289 : 0 : *size = 0;
3290 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3291 : : return -EIO;
3292 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3293 : 0 : p = xdr_inline_decode(xdr, 8);
3294 [ # # ]: 0 : if (unlikely(!p))
3295 : : goto out_overflow;
3296 : : xdr_decode_hyper(p, size);
3297 : 0 : bitmap[0] &= ~FATTR4_WORD0_SIZE;
3298 : : ret = NFS_ATTR_FATTR_SIZE;
3299 : : }
3300 : : dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3301 : 0 : return ret;
3302 : : out_overflow:
3303 : : print_overflow_msg(__func__, xdr);
3304 : : return -EIO;
3305 : : }
3306 : :
3307 : 0 : static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3308 : : {
3309 : 0 : __be32 *p;
3310 : :
3311 : 0 : *res = 0;
3312 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3313 : : return -EIO;
3314 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3315 : 0 : p = xdr_inline_decode(xdr, 4);
3316 [ # # ]: 0 : if (unlikely(!p))
3317 : : goto out_overflow;
3318 : 0 : *res = be32_to_cpup(p);
3319 : 0 : bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3320 : : }
3321 : : dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3322 : : return 0;
3323 : : out_overflow:
3324 : : print_overflow_msg(__func__, xdr);
3325 : : return -EIO;
3326 : : }
3327 : :
3328 : 0 : static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3329 : : {
3330 : 0 : __be32 *p;
3331 : :
3332 : 0 : *res = 0;
3333 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3334 : : return -EIO;
3335 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3336 : 0 : p = xdr_inline_decode(xdr, 4);
3337 [ # # ]: 0 : if (unlikely(!p))
3338 : : goto out_overflow;
3339 : 0 : *res = be32_to_cpup(p);
3340 : 0 : bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3341 : : }
3342 : : dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3343 : : return 0;
3344 : : out_overflow:
3345 : : print_overflow_msg(__func__, xdr);
3346 : : return -EIO;
3347 : : }
3348 : :
3349 : 0 : static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3350 : : {
3351 : : __be32 *p;
3352 : : int ret = 0;
3353 : :
3354 : 0 : fsid->major = 0;
3355 : 0 : fsid->minor = 0;
3356 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3357 : : return -EIO;
3358 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3359 : 0 : p = xdr_inline_decode(xdr, 16);
3360 [ # # ]: 0 : if (unlikely(!p))
3361 : : goto out_overflow;
3362 : : p = xdr_decode_hyper(p, &fsid->major);
3363 : : xdr_decode_hyper(p, &fsid->minor);
3364 : 0 : bitmap[0] &= ~FATTR4_WORD0_FSID;
3365 : : ret = NFS_ATTR_FATTR_FSID;
3366 : : }
3367 : : dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3368 : : (unsigned long long)fsid->major,
3369 : : (unsigned long long)fsid->minor);
3370 : 0 : return ret;
3371 : : out_overflow:
3372 : : print_overflow_msg(__func__, xdr);
3373 : : return -EIO;
3374 : : }
3375 : :
3376 : 0 : static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3377 : : {
3378 : 0 : __be32 *p;
3379 : :
3380 : 0 : *res = 60;
3381 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3382 : : return -EIO;
3383 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3384 : 0 : p = xdr_inline_decode(xdr, 4);
3385 [ # # ]: 0 : if (unlikely(!p))
3386 : : goto out_overflow;
3387 : 0 : *res = be32_to_cpup(p);
3388 : 0 : bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3389 : : }
3390 : : dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3391 : : return 0;
3392 : : out_overflow:
3393 : : print_overflow_msg(__func__, xdr);
3394 : : return -EIO;
3395 : : }
3396 : :
3397 : 0 : static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3398 : : {
3399 : 0 : __be32 *p;
3400 : :
3401 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3402 : : return -EIO;
3403 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3404 : 0 : p = xdr_inline_decode(xdr, 4);
3405 [ # # ]: 0 : if (unlikely(!p))
3406 : : goto out_overflow;
3407 : 0 : bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3408 : 0 : *res = -be32_to_cpup(p);
3409 : : }
3410 : : return 0;
3411 : : out_overflow:
3412 : : print_overflow_msg(__func__, xdr);
3413 : : return -EIO;
3414 : : }
3415 : :
3416 : 0 : static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3417 : : {
3418 : 0 : __be32 *p;
3419 : : int len;
3420 : :
3421 [ # # ]: 0 : if (fh != NULL)
3422 : 0 : memset(fh, 0, sizeof(*fh));
3423 : :
3424 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3425 : : return -EIO;
3426 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3427 : 0 : p = xdr_inline_decode(xdr, 4);
3428 [ # # ]: 0 : if (unlikely(!p))
3429 : : goto out_overflow;
3430 : 0 : len = be32_to_cpup(p);
3431 [ # # ]: 0 : if (len > NFS4_FHSIZE)
3432 : : return -EIO;
3433 : 0 : p = xdr_inline_decode(xdr, len);
3434 [ # # ]: 0 : if (unlikely(!p))
3435 : : goto out_overflow;
3436 [ # # ]: 0 : if (fh != NULL) {
3437 : 0 : memcpy(fh->data, p, len);
3438 : 0 : fh->size = len;
3439 : : }
3440 : 0 : bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3441 : : }
3442 : : return 0;
3443 : : out_overflow:
3444 : : print_overflow_msg(__func__, xdr);
3445 : : return -EIO;
3446 : : }
3447 : :
3448 : 0 : static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3449 : : {
3450 : 0 : __be32 *p;
3451 : :
3452 : 0 : *res = 0;
3453 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3454 : : return -EIO;
3455 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3456 : 0 : p = xdr_inline_decode(xdr, 4);
3457 [ # # ]: 0 : if (unlikely(!p))
3458 : : goto out_overflow;
3459 : 0 : *res = be32_to_cpup(p);
3460 : 0 : bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3461 : : }
3462 : : dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3463 : : return 0;
3464 : : out_overflow:
3465 : : print_overflow_msg(__func__, xdr);
3466 : : return -EIO;
3467 : : }
3468 : :
3469 : 0 : static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3470 : : {
3471 : : __be32 *p;
3472 : : int ret = 0;
3473 : :
3474 : 0 : *fileid = 0;
3475 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3476 : : return -EIO;
3477 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3478 : 0 : p = xdr_inline_decode(xdr, 8);
3479 [ # # ]: 0 : if (unlikely(!p))
3480 : : goto out_overflow;
3481 : : xdr_decode_hyper(p, fileid);
3482 : 0 : bitmap[0] &= ~FATTR4_WORD0_FILEID;
3483 : : ret = NFS_ATTR_FATTR_FILEID;
3484 : : }
3485 : : dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3486 : 0 : return ret;
3487 : : out_overflow:
3488 : : print_overflow_msg(__func__, xdr);
3489 : : return -EIO;
3490 : : }
3491 : :
3492 : 0 : static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3493 : : {
3494 : : __be32 *p;
3495 : : int ret = 0;
3496 : :
3497 : 0 : *fileid = 0;
3498 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3499 : : return -EIO;
3500 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3501 : 0 : p = xdr_inline_decode(xdr, 8);
3502 [ # # ]: 0 : if (unlikely(!p))
3503 : : goto out_overflow;
3504 : : xdr_decode_hyper(p, fileid);
3505 : 0 : bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3506 : : ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3507 : : }
3508 : : dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3509 : 0 : return ret;
3510 : : out_overflow:
3511 : : print_overflow_msg(__func__, xdr);
3512 : : return -EIO;
3513 : : }
3514 : :
3515 : 0 : static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3516 : : {
3517 : : __be32 *p;
3518 : : int status = 0;
3519 : :
3520 : 0 : *res = 0;
3521 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3522 : : return -EIO;
3523 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3524 : 0 : p = xdr_inline_decode(xdr, 8);
3525 [ # # ]: 0 : if (unlikely(!p))
3526 : : goto out_overflow;
3527 : : xdr_decode_hyper(p, res);
3528 : 0 : bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3529 : : }
3530 : : dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3531 : : return status;
3532 : : out_overflow:
3533 : : print_overflow_msg(__func__, xdr);
3534 : : return -EIO;
3535 : : }
3536 : :
3537 : 0 : static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3538 : : {
3539 : : __be32 *p;
3540 : : int status = 0;
3541 : :
3542 : 0 : *res = 0;
3543 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3544 : : return -EIO;
3545 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3546 : 0 : p = xdr_inline_decode(xdr, 8);
3547 [ # # ]: 0 : if (unlikely(!p))
3548 : : goto out_overflow;
3549 : : xdr_decode_hyper(p, res);
3550 : 0 : bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3551 : : }
3552 : : dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3553 : : return status;
3554 : : out_overflow:
3555 : : print_overflow_msg(__func__, xdr);
3556 : : return -EIO;
3557 : : }
3558 : :
3559 : 0 : static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3560 : : {
3561 : : __be32 *p;
3562 : : int status = 0;
3563 : :
3564 : 0 : *res = 0;
3565 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3566 : : return -EIO;
3567 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3568 : 0 : p = xdr_inline_decode(xdr, 8);
3569 [ # # ]: 0 : if (unlikely(!p))
3570 : : goto out_overflow;
3571 : : xdr_decode_hyper(p, res);
3572 : 0 : bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3573 : : }
3574 : : dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3575 : : return status;
3576 : : out_overflow:
3577 : : print_overflow_msg(__func__, xdr);
3578 : : return -EIO;
3579 : : }
3580 : :
3581 : 0 : static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3582 : : {
3583 : : u32 n;
3584 : 0 : __be32 *p;
3585 : : int status = 0;
3586 : :
3587 : 0 : p = xdr_inline_decode(xdr, 4);
3588 [ # # ]: 0 : if (unlikely(!p))
3589 : : goto out_overflow;
3590 : : n = be32_to_cpup(p);
3591 [ # # ]: 0 : if (n == 0)
3592 : : goto root_path;
3593 : : dprintk("pathname4: ");
3594 [ # # ]: 0 : if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3595 : : dprintk("cannot parse %d components in path\n", n);
3596 : : goto out_eio;
3597 : : }
3598 [ # # ]: 0 : for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3599 : 0 : struct nfs4_string *component = &path->components[path->ncomponents];
3600 : 0 : status = decode_opaque_inline(xdr, &component->len, &component->data);
3601 [ # # ]: 0 : if (unlikely(status != 0))
3602 : : goto out_eio;
3603 : : ifdebug (XDR)
3604 : : pr_cont("%s%.*s ",
3605 : : (path->ncomponents != n ? "/ " : ""),
3606 : : component->len, component->data);
3607 : : }
3608 : : out:
3609 : 0 : return status;
3610 : : root_path:
3611 : : /* a root pathname is sent as a zero component4 */
3612 : 0 : path->ncomponents = 1;
3613 : 0 : path->components[0].len=0;
3614 : 0 : path->components[0].data=NULL;
3615 : : dprintk("pathname4: /\n");
3616 : 0 : goto out;
3617 : : out_eio:
3618 : : dprintk(" status %d", status);
3619 : : status = -EIO;
3620 : : goto out;
3621 : : out_overflow:
3622 : : print_overflow_msg(__func__, xdr);
3623 : : return -EIO;
3624 : : }
3625 : :
3626 : 0 : static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3627 : : {
3628 : : int n;
3629 : 0 : __be32 *p;
3630 : : int status = -EIO;
3631 : :
3632 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3633 : : goto out;
3634 : : status = 0;
3635 [ # # ]: 0 : if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3636 : : goto out;
3637 : : status = -EIO;
3638 : : /* Ignore borken servers that return unrequested attrs */
3639 [ # # ]: 0 : if (unlikely(res == NULL))
3640 : : goto out;
3641 : : dprintk("%s: fsroot:\n", __func__);
3642 : 0 : status = decode_pathname(xdr, &res->fs_path);
3643 [ # # ]: 0 : if (unlikely(status != 0))
3644 : : goto out;
3645 : 0 : p = xdr_inline_decode(xdr, 4);
3646 [ # # ]: 0 : if (unlikely(!p))
3647 : : goto out_overflow;
3648 : 0 : n = be32_to_cpup(p);
3649 [ # # ]: 0 : if (n <= 0)
3650 : : goto out_eio;
3651 [ # # ]: 0 : for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3652 : : u32 m;
3653 : : struct nfs4_fs_location *loc;
3654 : :
3655 [ # # ]: 0 : if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3656 : : break;
3657 : 0 : loc = &res->locations[res->nlocations];
3658 : 0 : p = xdr_inline_decode(xdr, 4);
3659 [ # # ]: 0 : if (unlikely(!p))
3660 : : goto out_overflow;
3661 : : m = be32_to_cpup(p);
3662 : :
3663 : : dprintk("%s: servers:\n", __func__);
3664 [ # # ]: 0 : for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3665 : : struct nfs4_string *server;
3666 : :
3667 [ # # ]: 0 : if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3668 : : unsigned int i;
3669 : : dprintk("%s: using first %u of %u servers "
3670 : : "returned for location %u\n",
3671 : : __func__,
3672 : : NFS4_FS_LOCATION_MAXSERVERS,
3673 : : m, res->nlocations);
3674 [ # # ]: 0 : for (i = loc->nservers; i < m; i++) {
3675 : : unsigned int len;
3676 : : char *data;
3677 : 0 : status = decode_opaque_inline(xdr, &len, &data);
3678 [ # # ]: 0 : if (unlikely(status != 0))
3679 : : goto out_eio;
3680 : : }
3681 : : break;
3682 : : }
3683 : 0 : server = &loc->servers[loc->nservers];
3684 : 0 : status = decode_opaque_inline(xdr, &server->len, &server->data);
3685 [ # # ]: 0 : if (unlikely(status != 0))
3686 : : goto out_eio;
3687 : : dprintk("%s ", server->data);
3688 : : }
3689 : 0 : status = decode_pathname(xdr, &loc->rootpath);
3690 [ # # ]: 0 : if (unlikely(status != 0))
3691 : : goto out_eio;
3692 : : }
3693 [ # # ]: 0 : if (res->nlocations != 0)
3694 : : status = NFS_ATTR_FATTR_V4_LOCATIONS;
3695 : : out:
3696 : : dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3697 : 0 : return status;
3698 : : out_overflow:
3699 : : print_overflow_msg(__func__, xdr);
3700 : : out_eio:
3701 : : status = -EIO;
3702 : : goto out;
3703 : : }
3704 : :
3705 : 0 : static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3706 : : {
3707 : : __be32 *p;
3708 : : int status = 0;
3709 : :
3710 : 0 : *res = 0;
3711 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3712 : : return -EIO;
3713 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3714 : 0 : p = xdr_inline_decode(xdr, 8);
3715 [ # # ]: 0 : if (unlikely(!p))
3716 : : goto out_overflow;
3717 : : xdr_decode_hyper(p, res);
3718 : 0 : bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3719 : : }
3720 : : dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3721 : : return status;
3722 : : out_overflow:
3723 : : print_overflow_msg(__func__, xdr);
3724 : : return -EIO;
3725 : : }
3726 : :
3727 : 0 : static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3728 : : {
3729 : 0 : __be32 *p;
3730 : : int status = 0;
3731 : :
3732 : 0 : *maxlink = 1;
3733 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3734 : : return -EIO;
3735 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3736 : 0 : p = xdr_inline_decode(xdr, 4);
3737 [ # # ]: 0 : if (unlikely(!p))
3738 : : goto out_overflow;
3739 : 0 : *maxlink = be32_to_cpup(p);
3740 : 0 : bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3741 : : }
3742 : : dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3743 : : return status;
3744 : : out_overflow:
3745 : : print_overflow_msg(__func__, xdr);
3746 : : return -EIO;
3747 : : }
3748 : :
3749 : 0 : static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3750 : : {
3751 : 0 : __be32 *p;
3752 : : int status = 0;
3753 : :
3754 : 0 : *maxname = 1024;
3755 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3756 : : return -EIO;
3757 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3758 : 0 : p = xdr_inline_decode(xdr, 4);
3759 [ # # ]: 0 : if (unlikely(!p))
3760 : : goto out_overflow;
3761 : 0 : *maxname = be32_to_cpup(p);
3762 : 0 : bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3763 : : }
3764 : : dprintk("%s: maxname=%u\n", __func__, *maxname);
3765 : : return status;
3766 : : out_overflow:
3767 : : print_overflow_msg(__func__, xdr);
3768 : : return -EIO;
3769 : : }
3770 : :
3771 : 0 : static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3772 : : {
3773 : : __be32 *p;
3774 : : int status = 0;
3775 : :
3776 : 0 : *res = 1024;
3777 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3778 : : return -EIO;
3779 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3780 : : uint64_t maxread;
3781 : 0 : p = xdr_inline_decode(xdr, 8);
3782 [ # # ]: 0 : if (unlikely(!p))
3783 : : goto out_overflow;
3784 : : xdr_decode_hyper(p, &maxread);
3785 [ # # ]: 0 : if (maxread > 0x7FFFFFFF)
3786 : : maxread = 0x7FFFFFFF;
3787 : 0 : *res = (uint32_t)maxread;
3788 : 0 : bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3789 : : }
3790 : : dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3791 : : return status;
3792 : : out_overflow:
3793 : : print_overflow_msg(__func__, xdr);
3794 : : return -EIO;
3795 : : }
3796 : :
3797 : 0 : static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3798 : : {
3799 : : __be32 *p;
3800 : : int status = 0;
3801 : :
3802 : 0 : *res = 1024;
3803 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3804 : : return -EIO;
3805 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3806 : : uint64_t maxwrite;
3807 : 0 : p = xdr_inline_decode(xdr, 8);
3808 [ # # ]: 0 : if (unlikely(!p))
3809 : : goto out_overflow;
3810 : : xdr_decode_hyper(p, &maxwrite);
3811 [ # # ]: 0 : if (maxwrite > 0x7FFFFFFF)
3812 : : maxwrite = 0x7FFFFFFF;
3813 : 0 : *res = (uint32_t)maxwrite;
3814 : 0 : bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3815 : : }
3816 : : dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3817 : : return status;
3818 : : out_overflow:
3819 : : print_overflow_msg(__func__, xdr);
3820 : : return -EIO;
3821 : : }
3822 : :
3823 : 0 : static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3824 : : {
3825 : : uint32_t tmp;
3826 : 0 : __be32 *p;
3827 : : int ret = 0;
3828 : :
3829 : 0 : *mode = 0;
3830 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3831 : : return -EIO;
3832 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3833 : 0 : p = xdr_inline_decode(xdr, 4);
3834 [ # # ]: 0 : if (unlikely(!p))
3835 : : goto out_overflow;
3836 : : tmp = be32_to_cpup(p);
3837 : 0 : *mode = tmp & ~S_IFMT;
3838 : 0 : bitmap[1] &= ~FATTR4_WORD1_MODE;
3839 : : ret = NFS_ATTR_FATTR_MODE;
3840 : : }
3841 : : dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3842 : 0 : return ret;
3843 : : out_overflow:
3844 : : print_overflow_msg(__func__, xdr);
3845 : : return -EIO;
3846 : : }
3847 : :
3848 : 0 : static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3849 : : {
3850 : 0 : __be32 *p;
3851 : : int ret = 0;
3852 : :
3853 : 0 : *nlink = 1;
3854 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3855 : : return -EIO;
3856 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3857 : 0 : p = xdr_inline_decode(xdr, 4);
3858 [ # # ]: 0 : if (unlikely(!p))
3859 : : goto out_overflow;
3860 : 0 : *nlink = be32_to_cpup(p);
3861 : 0 : bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3862 : : ret = NFS_ATTR_FATTR_NLINK;
3863 : : }
3864 : : dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3865 : 0 : return ret;
3866 : : out_overflow:
3867 : : print_overflow_msg(__func__, xdr);
3868 : : return -EIO;
3869 : : }
3870 : :
3871 : 0 : static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3872 : : const struct nfs_server *server, kuid_t *uid,
3873 : : struct nfs4_string *owner_name)
3874 : : {
3875 : : uint32_t len;
3876 : 0 : __be32 *p;
3877 : : int ret = 0;
3878 : :
3879 : 0 : *uid = make_kuid(&init_user_ns, -2);
3880 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3881 : : return -EIO;
3882 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3883 : 0 : p = xdr_inline_decode(xdr, 4);
3884 [ # # ]: 0 : if (unlikely(!p))
3885 : : goto out_overflow;
3886 : : len = be32_to_cpup(p);
3887 : 0 : p = xdr_inline_decode(xdr, len);
3888 [ # # ]: 0 : if (unlikely(!p))
3889 : : goto out_overflow;
3890 [ # # ]: 0 : if (owner_name != NULL) {
3891 : 0 : owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3892 [ # # ]: 0 : if (owner_name->data != NULL) {
3893 : 0 : owner_name->len = len;
3894 : : ret = NFS_ATTR_FATTR_OWNER_NAME;
3895 : : }
3896 [ # # ]: 0 : } else if (len < XDR_MAX_NETOBJ) {
3897 [ # # ]: 0 : if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3898 : : ret = NFS_ATTR_FATTR_OWNER;
3899 : : else
3900 : : dprintk("%s: nfs_map_name_to_uid failed!\n",
3901 : : __func__);
3902 : : } else
3903 : : dprintk("%s: name too long (%u)!\n",
3904 : : __func__, len);
3905 : 0 : bitmap[1] &= ~FATTR4_WORD1_OWNER;
3906 : : }
3907 : : dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3908 : 0 : return ret;
3909 : : out_overflow:
3910 : : print_overflow_msg(__func__, xdr);
3911 : : return -EIO;
3912 : : }
3913 : :
3914 : 0 : static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3915 : : const struct nfs_server *server, kgid_t *gid,
3916 : : struct nfs4_string *group_name)
3917 : : {
3918 : : uint32_t len;
3919 : 0 : __be32 *p;
3920 : : int ret = 0;
3921 : :
3922 : 0 : *gid = make_kgid(&init_user_ns, -2);
3923 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3924 : : return -EIO;
3925 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3926 : 0 : p = xdr_inline_decode(xdr, 4);
3927 [ # # ]: 0 : if (unlikely(!p))
3928 : : goto out_overflow;
3929 : : len = be32_to_cpup(p);
3930 : 0 : p = xdr_inline_decode(xdr, len);
3931 [ # # ]: 0 : if (unlikely(!p))
3932 : : goto out_overflow;
3933 [ # # ]: 0 : if (group_name != NULL) {
3934 : 0 : group_name->data = kmemdup(p, len, GFP_NOWAIT);
3935 [ # # ]: 0 : if (group_name->data != NULL) {
3936 : 0 : group_name->len = len;
3937 : : ret = NFS_ATTR_FATTR_GROUP_NAME;
3938 : : }
3939 [ # # ]: 0 : } else if (len < XDR_MAX_NETOBJ) {
3940 [ # # ]: 0 : if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3941 : : ret = NFS_ATTR_FATTR_GROUP;
3942 : : else
3943 : : dprintk("%s: nfs_map_group_to_gid failed!\n",
3944 : : __func__);
3945 : : } else
3946 : : dprintk("%s: name too long (%u)!\n",
3947 : : __func__, len);
3948 : 0 : bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3949 : : }
3950 : : dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3951 : 0 : return ret;
3952 : : out_overflow:
3953 : : print_overflow_msg(__func__, xdr);
3954 : : return -EIO;
3955 : : }
3956 : :
3957 : 0 : static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3958 : : {
3959 : : uint32_t major = 0, minor = 0;
3960 : 0 : __be32 *p;
3961 : : int ret = 0;
3962 : :
3963 : 0 : *rdev = MKDEV(0,0);
3964 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3965 : : return -EIO;
3966 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3967 : : dev_t tmp;
3968 : :
3969 : 0 : p = xdr_inline_decode(xdr, 8);
3970 [ # # ]: 0 : if (unlikely(!p))
3971 : : goto out_overflow;
3972 : 0 : major = be32_to_cpup(p++);
3973 : : minor = be32_to_cpup(p);
3974 : 0 : tmp = MKDEV(major, minor);
3975 [ # # ][ # # ]: 0 : if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3976 : 0 : *rdev = tmp;
3977 : 0 : bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3978 : : ret = NFS_ATTR_FATTR_RDEV;
3979 : : }
3980 : : dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3981 : 0 : return ret;
3982 : : out_overflow:
3983 : : print_overflow_msg(__func__, xdr);
3984 : : return -EIO;
3985 : : }
3986 : :
3987 : 0 : static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3988 : : {
3989 : : __be32 *p;
3990 : : int status = 0;
3991 : :
3992 : 0 : *res = 0;
3993 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3994 : : return -EIO;
3995 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3996 : 0 : p = xdr_inline_decode(xdr, 8);
3997 [ # # ]: 0 : if (unlikely(!p))
3998 : : goto out_overflow;
3999 : : xdr_decode_hyper(p, res);
4000 : 0 : bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4001 : : }
4002 : : dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
4003 : : return status;
4004 : : out_overflow:
4005 : : print_overflow_msg(__func__, xdr);
4006 : : return -EIO;
4007 : : }
4008 : :
4009 : 0 : static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4010 : : {
4011 : : __be32 *p;
4012 : : int status = 0;
4013 : :
4014 : 0 : *res = 0;
4015 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4016 : : return -EIO;
4017 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4018 : 0 : p = xdr_inline_decode(xdr, 8);
4019 [ # # ]: 0 : if (unlikely(!p))
4020 : : goto out_overflow;
4021 : : xdr_decode_hyper(p, res);
4022 : 0 : bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4023 : : }
4024 : : dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
4025 : : return status;
4026 : : out_overflow:
4027 : : print_overflow_msg(__func__, xdr);
4028 : : return -EIO;
4029 : : }
4030 : :
4031 : 0 : static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4032 : : {
4033 : : __be32 *p;
4034 : : int status = 0;
4035 : :
4036 : 0 : *res = 0;
4037 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4038 : : return -EIO;
4039 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4040 : 0 : p = xdr_inline_decode(xdr, 8);
4041 [ # # ]: 0 : if (unlikely(!p))
4042 : : goto out_overflow;
4043 : : xdr_decode_hyper(p, res);
4044 : 0 : bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4045 : : }
4046 : : dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4047 : : return status;
4048 : : out_overflow:
4049 : : print_overflow_msg(__func__, xdr);
4050 : : return -EIO;
4051 : : }
4052 : :
4053 : 0 : static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4054 : : {
4055 : : __be32 *p;
4056 : : int ret = 0;
4057 : :
4058 : 0 : *used = 0;
4059 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4060 : : return -EIO;
4061 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4062 : 0 : p = xdr_inline_decode(xdr, 8);
4063 [ # # ]: 0 : if (unlikely(!p))
4064 : : goto out_overflow;
4065 : : xdr_decode_hyper(p, used);
4066 : 0 : bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4067 : : ret = NFS_ATTR_FATTR_SPACE_USED;
4068 : : }
4069 : : dprintk("%s: space used=%Lu\n", __func__,
4070 : : (unsigned long long)*used);
4071 : 0 : return ret;
4072 : : out_overflow:
4073 : : print_overflow_msg(__func__, xdr);
4074 : : return -EIO;
4075 : : }
4076 : :
4077 : 0 : static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4078 : : {
4079 : 0 : __be32 *p;
4080 : : uint64_t sec;
4081 : : uint32_t nsec;
4082 : :
4083 : 0 : p = xdr_inline_decode(xdr, 12);
4084 [ # # ]: 0 : if (unlikely(!p))
4085 : : goto out_overflow;
4086 : : p = xdr_decode_hyper(p, &sec);
4087 : : nsec = be32_to_cpup(p);
4088 : 0 : time->tv_sec = (time_t)sec;
4089 : 0 : time->tv_nsec = (long)nsec;
4090 : 0 : return 0;
4091 : : out_overflow:
4092 : : print_overflow_msg(__func__, xdr);
4093 : : return -EIO;
4094 : : }
4095 : :
4096 : 0 : static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4097 : : {
4098 : : int status = 0;
4099 : :
4100 : 0 : time->tv_sec = 0;
4101 : 0 : time->tv_nsec = 0;
4102 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4103 : : return -EIO;
4104 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4105 : 0 : status = decode_attr_time(xdr, time);
4106 [ # # ]: 0 : if (status == 0)
4107 : : status = NFS_ATTR_FATTR_ATIME;
4108 : 0 : bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4109 : : }
4110 : : dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4111 : 0 : return status;
4112 : : }
4113 : :
4114 : 0 : static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4115 : : {
4116 : : int status = 0;
4117 : :
4118 : 0 : time->tv_sec = 0;
4119 : 0 : time->tv_nsec = 0;
4120 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4121 : : return -EIO;
4122 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4123 : 0 : status = decode_attr_time(xdr, time);
4124 [ # # ]: 0 : if (status == 0)
4125 : : status = NFS_ATTR_FATTR_CTIME;
4126 : 0 : bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4127 : : }
4128 : : dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4129 : 0 : return status;
4130 : : }
4131 : :
4132 : 0 : static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4133 : : struct timespec *time)
4134 : : {
4135 : : int status = 0;
4136 : :
4137 : 0 : time->tv_sec = 0;
4138 : 0 : time->tv_nsec = 0;
4139 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4140 : : return -EIO;
4141 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4142 : 0 : status = decode_attr_time(xdr, time);
4143 : 0 : bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4144 : : }
4145 : : dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4146 : : (long)time->tv_nsec);
4147 : 0 : return status;
4148 : : }
4149 : :
4150 : 0 : static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4151 : : struct nfs4_label *label)
4152 : : {
4153 : : uint32_t pi = 0;
4154 : : uint32_t lfs = 0;
4155 : : __u32 len;
4156 : : __be32 *p;
4157 : : int status = 0;
4158 : :
4159 [ # # ]: 0 : if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4160 : : return -EIO;
4161 [ # # ]: 0 : if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4162 : 0 : p = xdr_inline_decode(xdr, 4);
4163 [ # # ]: 0 : if (unlikely(!p))
4164 : : goto out_overflow;
4165 : 0 : lfs = be32_to_cpup(p++);
4166 : 0 : p = xdr_inline_decode(xdr, 4);
4167 [ # # ]: 0 : if (unlikely(!p))
4168 : : goto out_overflow;
4169 : 0 : pi = be32_to_cpup(p++);
4170 : 0 : p = xdr_inline_decode(xdr, 4);
4171 [ # # ]: 0 : if (unlikely(!p))
4172 : : goto out_overflow;
4173 : 0 : len = be32_to_cpup(p++);
4174 : 0 : p = xdr_inline_decode(xdr, len);
4175 [ # # ]: 0 : if (unlikely(!p))
4176 : : goto out_overflow;
4177 [ # # ]: 0 : if (len < NFS4_MAXLABELLEN) {
4178 [ # # ]: 0 : if (label) {
4179 : 0 : memcpy(label->label, p, len);
4180 : 0 : label->len = len;
4181 : 0 : label->pi = pi;
4182 : 0 : label->lfs = lfs;
4183 : : status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4184 : : }
4185 : 0 : bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4186 : : } else
4187 : 0 : printk(KERN_WARNING "%s: label too long (%u)!\n",
4188 : : __func__, len);
4189 : : }
4190 : : if (label && label->label)
4191 : : dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4192 : : (char *)label->label, label->len, label->pi, label->lfs);
4193 : 0 : return status;
4194 : :
4195 : : out_overflow:
4196 : : print_overflow_msg(__func__, xdr);
4197 : : return -EIO;
4198 : : }
4199 : :
4200 : 0 : static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4201 : : {
4202 : : int status = 0;
4203 : :
4204 : 0 : time->tv_sec = 0;
4205 : 0 : time->tv_nsec = 0;
4206 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4207 : : return -EIO;
4208 [ # # ]: 0 : if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4209 : 0 : status = decode_attr_time(xdr, time);
4210 [ # # ]: 0 : if (status == 0)
4211 : : status = NFS_ATTR_FATTR_MTIME;
4212 : 0 : bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4213 : : }
4214 : : dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4215 : 0 : return status;
4216 : : }
4217 : :
4218 : : static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4219 : : {
4220 : 0 : unsigned int attrwords = XDR_QUADLEN(attrlen);
4221 : 0 : unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4222 : :
4223 [ # # ][ # # ]: 0 : if (unlikely(attrwords != nwords)) {
[ # # ][ # # ]
[ # # ][ # # ]
4224 : : dprintk("%s: server returned incorrect attribute length: "
4225 : : "%u %c %u\n",
4226 : : __func__,
4227 : : attrwords << 2,
4228 : : (attrwords < nwords) ? '<' : '>',
4229 : : nwords << 2);
4230 : : return -EIO;
4231 : : }
4232 : : return 0;
4233 : : }
4234 : :
4235 : 0 : static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4236 : : {
4237 : : __be32 *p;
4238 : :
4239 : 0 : p = xdr_inline_decode(xdr, 20);
4240 [ # # ]: 0 : if (unlikely(!p))
4241 : : goto out_overflow;
4242 : 0 : cinfo->atomic = be32_to_cpup(p++);
4243 : : p = xdr_decode_hyper(p, &cinfo->before);
4244 : : xdr_decode_hyper(p, &cinfo->after);
4245 : 0 : return 0;
4246 : : out_overflow:
4247 : : print_overflow_msg(__func__, xdr);
4248 : : return -EIO;
4249 : : }
4250 : :
4251 : 0 : static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4252 : : {
4253 : 0 : __be32 *p;
4254 : : uint32_t supp, acc;
4255 : : int status;
4256 : :
4257 : : status = decode_op_hdr(xdr, OP_ACCESS);
4258 [ # # ]: 0 : if (status)
4259 : : return status;
4260 : 0 : p = xdr_inline_decode(xdr, 8);
4261 [ # # ]: 0 : if (unlikely(!p))
4262 : : goto out_overflow;
4263 : 0 : supp = be32_to_cpup(p++);
4264 : : acc = be32_to_cpup(p);
4265 : 0 : *supported = supp;
4266 : 0 : *access = acc;
4267 : 0 : return 0;
4268 : : out_overflow:
4269 : : print_overflow_msg(__func__, xdr);
4270 : : return -EIO;
4271 : : }
4272 : :
4273 : 0 : static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4274 : : {
4275 : : __be32 *p;
4276 : :
4277 : 0 : p = xdr_inline_decode(xdr, len);
4278 [ # # ]: 0 : if (likely(p)) {
4279 : 0 : memcpy(buf, p, len);
4280 : 0 : return 0;
4281 : : }
4282 : : print_overflow_msg(__func__, xdr);
4283 : : return -EIO;
4284 : : }
4285 : :
4286 : : static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4287 : : {
4288 : 0 : return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4289 : : }
4290 : :
4291 : 0 : static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4292 : : {
4293 : : int status;
4294 : :
4295 : : status = decode_op_hdr(xdr, OP_CLOSE);
4296 [ # # ]: 0 : if (status != -EIO)
4297 : 0 : nfs_increment_open_seqid(status, res->seqid);
4298 [ # # ]: 0 : if (!status)
4299 : 0 : status = decode_stateid(xdr, &res->stateid);
4300 : 0 : return status;
4301 : : }
4302 : :
4303 : : static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4304 : : {
4305 : 0 : return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4306 : : }
4307 : :
4308 : : static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4309 : : {
4310 : 0 : return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4311 : : }
4312 : :
4313 : 0 : static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4314 : : {
4315 : : int status;
4316 : :
4317 : : status = decode_op_hdr(xdr, OP_COMMIT);
4318 [ # # ]: 0 : if (!status)
4319 : 0 : status = decode_write_verifier(xdr, &res->verf->verifier);
4320 : 0 : return status;
4321 : : }
4322 : :
4323 : 0 : static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4324 : : {
4325 : 0 : __be32 *p;
4326 : : uint32_t bmlen;
4327 : : int status;
4328 : :
4329 : : status = decode_op_hdr(xdr, OP_CREATE);
4330 [ # # ]: 0 : if (status)
4331 : : return status;
4332 [ # # ]: 0 : if ((status = decode_change_info(xdr, cinfo)))
4333 : : return status;
4334 : 0 : p = xdr_inline_decode(xdr, 4);
4335 [ # # ]: 0 : if (unlikely(!p))
4336 : : goto out_overflow;
4337 : : bmlen = be32_to_cpup(p);
4338 : 0 : p = xdr_inline_decode(xdr, bmlen << 2);
4339 [ # # ]: 0 : if (likely(p))
4340 : : return 0;
4341 : : out_overflow:
4342 : : print_overflow_msg(__func__, xdr);
4343 : : return -EIO;
4344 : : }
4345 : :
4346 : 0 : static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4347 : : {
4348 : : unsigned int savep;
4349 : 0 : uint32_t attrlen, bitmap[3] = {0};
4350 : : int status;
4351 : :
4352 [ # # ]: 0 : if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4353 : : goto xdr_error;
4354 [ # # ]: 0 : if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4355 : : goto xdr_error;
4356 [ # # ]: 0 : if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4357 : : goto xdr_error;
4358 [ # # ]: 0 : if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4359 : : goto xdr_error;
4360 [ # # ]: 0 : if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4361 : 0 : &res->fh_expire_type)) != 0)
4362 : : goto xdr_error;
4363 [ # # ]: 0 : if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4364 : : goto xdr_error;
4365 [ # # ]: 0 : if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4366 : : goto xdr_error;
4367 [ # # ]: 0 : if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4368 : : goto xdr_error;
4369 : 0 : status = verify_attr_len(xdr, savep, attrlen);
4370 : : xdr_error:
4371 : : dprintk("%s: xdr returned %d!\n", __func__, -status);
4372 : 0 : return status;
4373 : : }
4374 : :
4375 : 0 : static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4376 : : {
4377 : : unsigned int savep;
4378 : 0 : uint32_t attrlen, bitmap[3] = {0};
4379 : : int status;
4380 : :
4381 [ # # ]: 0 : if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4382 : : goto xdr_error;
4383 [ # # ]: 0 : if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4384 : : goto xdr_error;
4385 [ # # ]: 0 : if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4386 : : goto xdr_error;
4387 : :
4388 [ # # ]: 0 : if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4389 : : goto xdr_error;
4390 [ # # ]: 0 : if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4391 : : goto xdr_error;
4392 [ # # ]: 0 : if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4393 : : goto xdr_error;
4394 [ # # ]: 0 : if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4395 : : goto xdr_error;
4396 [ # # ]: 0 : if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4397 : : goto xdr_error;
4398 [ # # ]: 0 : if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4399 : : goto xdr_error;
4400 : :
4401 : 0 : status = verify_attr_len(xdr, savep, attrlen);
4402 : : xdr_error:
4403 : : dprintk("%s: xdr returned %d!\n", __func__, -status);
4404 : 0 : return status;
4405 : : }
4406 : :
4407 : 0 : static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4408 : : {
4409 : : unsigned int savep;
4410 : 0 : uint32_t attrlen, bitmap[3] = {0};
4411 : : int status;
4412 : :
4413 [ # # ]: 0 : if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4414 : : goto xdr_error;
4415 [ # # ]: 0 : if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4416 : : goto xdr_error;
4417 [ # # ]: 0 : if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4418 : : goto xdr_error;
4419 : :
4420 [ # # ]: 0 : if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4421 : : goto xdr_error;
4422 [ # # ]: 0 : if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4423 : : goto xdr_error;
4424 : :
4425 : 0 : status = verify_attr_len(xdr, savep, attrlen);
4426 : : xdr_error:
4427 : : dprintk("%s: xdr returned %d!\n", __func__, -status);
4428 : 0 : return status;
4429 : : }
4430 : :
4431 : 0 : static int decode_threshold_hint(struct xdr_stream *xdr,
4432 : : uint32_t *bitmap,
4433 : : uint64_t *res,
4434 : : uint32_t hint_bit)
4435 : : {
4436 : : __be32 *p;
4437 : :
4438 : 0 : *res = 0;
4439 [ # # ]: 0 : if (likely(bitmap[0] & hint_bit)) {
4440 : 0 : p = xdr_inline_decode(xdr, 8);
4441 [ # # ]: 0 : if (unlikely(!p))
4442 : : goto out_overflow;
4443 : : xdr_decode_hyper(p, res);
4444 : : }
4445 : : return 0;
4446 : : out_overflow:
4447 : : print_overflow_msg(__func__, xdr);
4448 : : return -EIO;
4449 : : }
4450 : :
4451 : 0 : static int decode_first_threshold_item4(struct xdr_stream *xdr,
4452 : : struct nfs4_threshold *res)
4453 : : {
4454 : 0 : __be32 *p;
4455 : : unsigned int savep;
4456 : 0 : uint32_t bitmap[3] = {0,}, attrlen;
4457 : : int status;
4458 : :
4459 : : /* layout type */
4460 : 0 : p = xdr_inline_decode(xdr, 4);
4461 [ # # ]: 0 : if (unlikely(!p)) {
4462 : : print_overflow_msg(__func__, xdr);
4463 : : return -EIO;
4464 : : }
4465 : 0 : res->l_type = be32_to_cpup(p);
4466 : :
4467 : : /* thi_hintset bitmap */
4468 : 0 : status = decode_attr_bitmap(xdr, bitmap);
4469 [ # # ]: 0 : if (status < 0)
4470 : : goto xdr_error;
4471 : :
4472 : : /* thi_hintlist length */
4473 : 0 : status = decode_attr_length(xdr, &attrlen, &savep);
4474 [ # # ]: 0 : if (status < 0)
4475 : : goto xdr_error;
4476 : : /* thi_hintlist */
4477 : 0 : status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4478 [ # # ]: 0 : if (status < 0)
4479 : : goto xdr_error;
4480 : 0 : status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4481 [ # # ]: 0 : if (status < 0)
4482 : : goto xdr_error;
4483 : 0 : status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4484 : : THRESHOLD_RD_IO);
4485 [ # # ]: 0 : if (status < 0)
4486 : : goto xdr_error;
4487 : 0 : status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4488 : : THRESHOLD_WR_IO);
4489 [ # # ]: 0 : if (status < 0)
4490 : : goto xdr_error;
4491 : :
4492 : 0 : status = verify_attr_len(xdr, savep, attrlen);
4493 : 0 : res->bm = bitmap[0];
4494 : :
4495 : : dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4496 : : __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4497 : : res->wr_io_sz);
4498 : : xdr_error:
4499 : : dprintk("%s ret=%d!\n", __func__, status);
4500 : 0 : return status;
4501 : : }
4502 : :
4503 : : /*
4504 : : * Thresholds on pNFS direct I/O vrs MDS I/O
4505 : : */
4506 : 0 : static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4507 : : uint32_t *bitmap,
4508 : : struct nfs4_threshold *res)
4509 : : {
4510 : 0 : __be32 *p;
4511 : : int status = 0;
4512 : : uint32_t num;
4513 : :
4514 [ # # ]: 0 : if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4515 : : return -EIO;
4516 [ # # ]: 0 : if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4517 : : /* Did the server return an unrequested attribute? */
4518 [ # # ]: 0 : if (unlikely(res == NULL))
4519 : : return -EREMOTEIO;
4520 : 0 : p = xdr_inline_decode(xdr, 4);
4521 [ # # ]: 0 : if (unlikely(!p))
4522 : : goto out_overflow;
4523 : : num = be32_to_cpup(p);
4524 [ # # ]: 0 : if (num == 0)
4525 : : return 0;
4526 [ # # ]: 0 : if (num > 1)
4527 : 0 : printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4528 : : "drivers per filesystem not supported\n",
4529 : : __func__);
4530 : :
4531 : 0 : status = decode_first_threshold_item4(xdr, res);
4532 : 0 : bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4533 : : }
4534 : 0 : return status;
4535 : : out_overflow:
4536 : : print_overflow_msg(__func__, xdr);
4537 : : return -EIO;
4538 : : }
4539 : :
4540 : 0 : static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4541 : : struct nfs_fattr *fattr, struct nfs_fh *fh,
4542 : : struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4543 : : const struct nfs_server *server)
4544 : : {
4545 : : int status;
4546 : 0 : umode_t fmode = 0;
4547 : : uint32_t type;
4548 : : int32_t err;
4549 : :
4550 : 0 : status = decode_attr_type(xdr, bitmap, &type);
4551 [ # # ]: 0 : if (status < 0)
4552 : : goto xdr_error;
4553 : 0 : fattr->mode = 0;
4554 [ # # ]: 0 : if (status != 0) {
4555 : 0 : fattr->mode |= nfs_type2fmt[type];
4556 : 0 : fattr->valid |= status;
4557 : : }
4558 : :
4559 : 0 : status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4560 [ # # ]: 0 : if (status < 0)
4561 : : goto xdr_error;
4562 : 0 : fattr->valid |= status;
4563 : :
4564 : 0 : status = decode_attr_size(xdr, bitmap, &fattr->size);
4565 [ # # ]: 0 : if (status < 0)
4566 : : goto xdr_error;
4567 : 0 : fattr->valid |= status;
4568 : :
4569 : 0 : status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4570 [ # # ]: 0 : if (status < 0)
4571 : : goto xdr_error;
4572 : 0 : fattr->valid |= status;
4573 : :
4574 : 0 : err = 0;
4575 : 0 : status = decode_attr_error(xdr, bitmap, &err);
4576 [ # # ]: 0 : if (status < 0)
4577 : : goto xdr_error;
4578 : :
4579 : 0 : status = decode_attr_filehandle(xdr, bitmap, fh);
4580 [ # # ]: 0 : if (status < 0)
4581 : : goto xdr_error;
4582 : :
4583 : 0 : status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4584 [ # # ]: 0 : if (status < 0)
4585 : : goto xdr_error;
4586 : 0 : fattr->valid |= status;
4587 : :
4588 : 0 : status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4589 [ # # ]: 0 : if (status < 0)
4590 : : goto xdr_error;
4591 : 0 : fattr->valid |= status;
4592 : :
4593 : 0 : status = decode_attr_mode(xdr, bitmap, &fmode);
4594 [ # # ]: 0 : if (status < 0)
4595 : : goto xdr_error;
4596 [ # # ]: 0 : if (status != 0) {
4597 : 0 : fattr->mode |= fmode;
4598 : 0 : fattr->valid |= status;
4599 : : }
4600 : :
4601 : 0 : status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4602 [ # # ]: 0 : if (status < 0)
4603 : : goto xdr_error;
4604 : 0 : fattr->valid |= status;
4605 : :
4606 : 0 : status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4607 [ # # ]: 0 : if (status < 0)
4608 : : goto xdr_error;
4609 : 0 : fattr->valid |= status;
4610 : :
4611 : 0 : status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4612 [ # # ]: 0 : if (status < 0)
4613 : : goto xdr_error;
4614 : 0 : fattr->valid |= status;
4615 : :
4616 : 0 : status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4617 [ # # ]: 0 : if (status < 0)
4618 : : goto xdr_error;
4619 : 0 : fattr->valid |= status;
4620 : :
4621 : 0 : status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4622 [ # # ]: 0 : if (status < 0)
4623 : : goto xdr_error;
4624 : 0 : fattr->valid |= status;
4625 : :
4626 : 0 : status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4627 [ # # ]: 0 : if (status < 0)
4628 : : goto xdr_error;
4629 : 0 : fattr->valid |= status;
4630 : :
4631 : 0 : status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4632 [ # # ]: 0 : if (status < 0)
4633 : : goto xdr_error;
4634 : 0 : fattr->valid |= status;
4635 : :
4636 : 0 : status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4637 [ # # ]: 0 : if (status < 0)
4638 : : goto xdr_error;
4639 : 0 : fattr->valid |= status;
4640 : :
4641 : 0 : status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4642 [ # # ]: 0 : if (status < 0)
4643 : : goto xdr_error;
4644 : 0 : fattr->valid |= status;
4645 : :
4646 : 0 : status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4647 [ # # ]: 0 : if (status < 0)
4648 : : goto xdr_error;
4649 : :
4650 [ # # ]: 0 : if (label) {
4651 : 0 : status = decode_attr_security_label(xdr, bitmap, label);
4652 [ # # ]: 0 : if (status < 0)
4653 : : goto xdr_error;
4654 : 0 : fattr->valid |= status;
4655 : : }
4656 : :
4657 : : xdr_error:
4658 : : dprintk("%s: xdr returned %d\n", __func__, -status);
4659 : 0 : return status;
4660 : : }
4661 : :
4662 : 0 : static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4663 : : struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4664 : : struct nfs4_label *label, const struct nfs_server *server)
4665 : : {
4666 : : unsigned int savep;
4667 : : uint32_t attrlen,
4668 : 0 : bitmap[3] = {0};
4669 : : int status;
4670 : :
4671 : : status = decode_op_hdr(xdr, OP_GETATTR);
4672 [ # # ]: 0 : if (status < 0)
4673 : : goto xdr_error;
4674 : :
4675 : 0 : status = decode_attr_bitmap(xdr, bitmap);
4676 [ # # ]: 0 : if (status < 0)
4677 : : goto xdr_error;
4678 : :
4679 : 0 : status = decode_attr_length(xdr, &attrlen, &savep);
4680 [ # # ]: 0 : if (status < 0)
4681 : : goto xdr_error;
4682 : :
4683 : 0 : status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4684 : : label, server);
4685 [ # # ]: 0 : if (status < 0)
4686 : : goto xdr_error;
4687 : :
4688 : 0 : status = verify_attr_len(xdr, savep, attrlen);
4689 : : xdr_error:
4690 : : dprintk("%s: xdr returned %d\n", __func__, -status);
4691 : 0 : return status;
4692 : : }
4693 : :
4694 : : static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4695 : : struct nfs4_label *label, const struct nfs_server *server)
4696 : : {
4697 : 0 : return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4698 : : }
4699 : :
4700 : : static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4701 : : const struct nfs_server *server)
4702 : : {
4703 : 0 : return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4704 : : }
4705 : :
4706 : : /*
4707 : : * Decode potentially multiple layout types. Currently we only support
4708 : : * one layout driver per file system.
4709 : : */
4710 : 0 : static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4711 : : uint32_t *layouttype)
4712 : : {
4713 : 0 : __be32 *p;
4714 : : int num;
4715 : :
4716 : 0 : p = xdr_inline_decode(xdr, 4);
4717 [ # # ]: 0 : if (unlikely(!p))
4718 : : goto out_overflow;
4719 : 0 : num = be32_to_cpup(p);
4720 : :
4721 : : /* pNFS is not supported by the underlying file system */
4722 [ # # ]: 0 : if (num == 0) {
4723 : 0 : *layouttype = 0;
4724 : 0 : return 0;
4725 : : }
4726 [ # # ]: 0 : if (num > 1)
4727 : 0 : printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4728 : : "drivers per filesystem not supported\n", __func__);
4729 : :
4730 : : /* Decode and set first layout type, move xdr->p past unused types */
4731 : 0 : p = xdr_inline_decode(xdr, num * 4);
4732 [ # # ]: 0 : if (unlikely(!p))
4733 : : goto out_overflow;
4734 : 0 : *layouttype = be32_to_cpup(p);
4735 : 0 : return 0;
4736 : : out_overflow:
4737 : : print_overflow_msg(__func__, xdr);
4738 : : return -EIO;
4739 : : }
4740 : :
4741 : : /*
4742 : : * The type of file system exported.
4743 : : * Note we must ensure that layouttype is set in any non-error case.
4744 : : */
4745 : 0 : static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4746 : : uint32_t *layouttype)
4747 : : {
4748 : : int status = 0;
4749 : :
4750 : : dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4751 [ # # ]: 0 : if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4752 : : return -EIO;
4753 [ # # ]: 0 : if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4754 : 0 : status = decode_first_pnfs_layout_type(xdr, layouttype);
4755 : 0 : bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4756 : : } else
4757 : 0 : *layouttype = 0;
4758 : 0 : return status;
4759 : : }
4760 : :
4761 : : /*
4762 : : * The prefered block size for layout directed io
4763 : : */
4764 : 0 : static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4765 : : uint32_t *res)
4766 : : {
4767 : 0 : __be32 *p;
4768 : :
4769 : : dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4770 : 0 : *res = 0;
4771 [ # # ]: 0 : if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4772 : 0 : p = xdr_inline_decode(xdr, 4);
4773 [ # # ]: 0 : if (unlikely(!p)) {
4774 : : print_overflow_msg(__func__, xdr);
4775 : : return -EIO;
4776 : : }
4777 : 0 : *res = be32_to_cpup(p);
4778 : 0 : bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4779 : : }
4780 : : return 0;
4781 : : }
4782 : :
4783 : 0 : static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4784 : : {
4785 : : unsigned int savep;
4786 : : uint32_t attrlen, bitmap[3];
4787 : : int status;
4788 : :
4789 [ # # ]: 0 : if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4790 : : goto xdr_error;
4791 [ # # ]: 0 : if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4792 : : goto xdr_error;
4793 [ # # ]: 0 : if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4794 : : goto xdr_error;
4795 : :
4796 : 0 : fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4797 : :
4798 [ # # ]: 0 : if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4799 : : goto xdr_error;
4800 [ # # ]: 0 : if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4801 : : goto xdr_error;
4802 [ # # ]: 0 : if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4803 : : goto xdr_error;
4804 : 0 : fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4805 [ # # ]: 0 : if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4806 : : goto xdr_error;
4807 : 0 : fsinfo->wtpref = fsinfo->wtmax;
4808 : 0 : status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4809 [ # # ]: 0 : if (status != 0)
4810 : : goto xdr_error;
4811 : 0 : status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4812 [ # # ]: 0 : if (status != 0)
4813 : : goto xdr_error;
4814 : 0 : status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4815 [ # # ]: 0 : if (status)
4816 : : goto xdr_error;
4817 : :
4818 : 0 : status = verify_attr_len(xdr, savep, attrlen);
4819 : : xdr_error:
4820 : : dprintk("%s: xdr returned %d!\n", __func__, -status);
4821 : 0 : return status;
4822 : : }
4823 : :
4824 : 0 : static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4825 : : {
4826 : 0 : __be32 *p;
4827 : : uint32_t len;
4828 : : int status;
4829 : :
4830 : : /* Zero handle first to allow comparisons */
4831 : 0 : memset(fh, 0, sizeof(*fh));
4832 : :
4833 : : status = decode_op_hdr(xdr, OP_GETFH);
4834 [ # # ]: 0 : if (status)
4835 : : return status;
4836 : :
4837 : 0 : p = xdr_inline_decode(xdr, 4);
4838 [ # # ]: 0 : if (unlikely(!p))
4839 : : goto out_overflow;
4840 : : len = be32_to_cpup(p);
4841 [ # # ]: 0 : if (len > NFS4_FHSIZE)
4842 : : return -EIO;
4843 : 0 : fh->size = len;
4844 : 0 : p = xdr_inline_decode(xdr, len);
4845 [ # # ]: 0 : if (unlikely(!p))
4846 : : goto out_overflow;
4847 : 0 : memcpy(fh->data, p, len);
4848 : 0 : return 0;
4849 : : out_overflow:
4850 : : print_overflow_msg(__func__, xdr);
4851 : : return -EIO;
4852 : : }
4853 : :
4854 : 0 : static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4855 : : {
4856 : : int status;
4857 : :
4858 : : status = decode_op_hdr(xdr, OP_LINK);
4859 [ # # ]: 0 : if (status)
4860 : : return status;
4861 : 0 : return decode_change_info(xdr, cinfo);
4862 : : }
4863 : :
4864 : : /*
4865 : : * We create the owner, so we know a proper owner.id length is 4.
4866 : : */
4867 : 0 : static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4868 : : {
4869 : : uint64_t offset, length, clientid;
4870 : 0 : __be32 *p;
4871 : : uint32_t namelen, type;
4872 : :
4873 : 0 : p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4874 [ # # ]: 0 : if (unlikely(!p))
4875 : : goto out_overflow;
4876 : : p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4877 : : p = xdr_decode_hyper(p, &length);
4878 : 0 : type = be32_to_cpup(p++); /* 4 byte read */
4879 [ # # ]: 0 : if (fl != NULL) { /* manipulate file lock */
4880 : 0 : fl->fl_start = (loff_t)offset;
4881 : 0 : fl->fl_end = fl->fl_start + (loff_t)length - 1;
4882 [ # # ]: 0 : if (length == ~(uint64_t)0)
4883 : 0 : fl->fl_end = OFFSET_MAX;
4884 : 0 : fl->fl_type = F_WRLCK;
4885 [ # # ]: 0 : if (type & 1)
4886 : 0 : fl->fl_type = F_RDLCK;
4887 : 0 : fl->fl_pid = 0;
4888 : : }
4889 : : p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4890 : : namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4891 : 0 : p = xdr_inline_decode(xdr, namelen); /* variable size field */
4892 [ # # ]: 0 : if (likely(p))
4893 : : return -NFS4ERR_DENIED;
4894 : : out_overflow:
4895 : : print_overflow_msg(__func__, xdr);
4896 : : return -EIO;
4897 : : }
4898 : :
4899 : 0 : static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4900 : : {
4901 : : int status;
4902 : :
4903 : : status = decode_op_hdr(xdr, OP_LOCK);
4904 [ # # ]: 0 : if (status == -EIO)
4905 : : goto out;
4906 [ # # ]: 0 : if (status == 0) {
4907 : 0 : status = decode_stateid(xdr, &res->stateid);
4908 [ # # ]: 0 : if (unlikely(status))
4909 : : goto out;
4910 [ # # ]: 0 : } else if (status == -NFS4ERR_DENIED)
4911 : 0 : status = decode_lock_denied(xdr, NULL);
4912 [ # # ]: 0 : if (res->open_seqid != NULL)
4913 : 0 : nfs_increment_open_seqid(status, res->open_seqid);
4914 : 0 : nfs_increment_lock_seqid(status, res->lock_seqid);
4915 : : out:
4916 : 0 : return status;
4917 : : }
4918 : :
4919 : 0 : static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4920 : : {
4921 : : int status;
4922 : : status = decode_op_hdr(xdr, OP_LOCKT);
4923 [ # # ]: 0 : if (status == -NFS4ERR_DENIED)
4924 : 0 : return decode_lock_denied(xdr, res->denied);
4925 : : return status;
4926 : : }
4927 : :
4928 : 0 : static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4929 : : {
4930 : : int status;
4931 : :
4932 : : status = decode_op_hdr(xdr, OP_LOCKU);
4933 [ # # ]: 0 : if (status != -EIO)
4934 : 0 : nfs_increment_lock_seqid(status, res->seqid);
4935 [ # # ]: 0 : if (status == 0)
4936 : 0 : status = decode_stateid(xdr, &res->stateid);
4937 : 0 : return status;
4938 : : }
4939 : :
4940 : : static int decode_release_lockowner(struct xdr_stream *xdr)
4941 : : {
4942 : : return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4943 : : }
4944 : :
4945 : : static int decode_lookup(struct xdr_stream *xdr)
4946 : : {
4947 : : return decode_op_hdr(xdr, OP_LOOKUP);
4948 : : }
4949 : :
4950 : : /* This is too sick! */
4951 : 0 : static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4952 : : {
4953 : 0 : __be32 *p;
4954 : : uint32_t limit_type, nblocks, blocksize;
4955 : :
4956 : 0 : p = xdr_inline_decode(xdr, 12);
4957 [ # # ]: 0 : if (unlikely(!p))
4958 : : goto out_overflow;
4959 : 0 : limit_type = be32_to_cpup(p++);
4960 [ # # # ]: 0 : switch (limit_type) {
4961 : : case 1:
4962 : : xdr_decode_hyper(p, maxsize);
4963 : : break;
4964 : : case 2:
4965 : 0 : nblocks = be32_to_cpup(p++);
4966 : : blocksize = be32_to_cpup(p);
4967 : 0 : *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4968 : : }
4969 : : return 0;
4970 : : out_overflow:
4971 : : print_overflow_msg(__func__, xdr);
4972 : : return -EIO;
4973 : : }
4974 : :
4975 : 0 : static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4976 : : {
4977 : 0 : __be32 *p;
4978 : : uint32_t delegation_type;
4979 : : int status;
4980 : :
4981 : 0 : p = xdr_inline_decode(xdr, 4);
4982 [ # # ]: 0 : if (unlikely(!p))
4983 : : goto out_overflow;
4984 : : delegation_type = be32_to_cpup(p);
4985 [ # # ]: 0 : if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4986 : 0 : res->delegation_type = 0;
4987 : 0 : return 0;
4988 : : }
4989 : 0 : status = decode_stateid(xdr, &res->delegation);
4990 [ # # ]: 0 : if (unlikely(status))
4991 : : return status;
4992 : 0 : p = xdr_inline_decode(xdr, 4);
4993 [ # # ]: 0 : if (unlikely(!p))
4994 : : goto out_overflow;
4995 : 0 : res->do_recall = be32_to_cpup(p);
4996 : :
4997 [ # # # ]: 0 : switch (delegation_type) {
4998 : : case NFS4_OPEN_DELEGATE_READ:
4999 : 0 : res->delegation_type = FMODE_READ;
5000 : 0 : break;
5001 : : case NFS4_OPEN_DELEGATE_WRITE:
5002 : 0 : res->delegation_type = FMODE_WRITE|FMODE_READ;
5003 [ # # ]: 0 : if (decode_space_limit(xdr, &res->maxsize) < 0)
5004 : : return -EIO;
5005 : : }
5006 : 0 : return decode_ace(xdr, NULL, res->server->nfs_client);
5007 : : out_overflow:
5008 : : print_overflow_msg(__func__, xdr);
5009 : : return -EIO;
5010 : : }
5011 : :
5012 : 0 : static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5013 : : {
5014 : 0 : __be32 *p;
5015 : : uint32_t savewords, bmlen, i;
5016 : : int status;
5017 : :
5018 [ # # ]: 0 : if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5019 : 0 : return status;
5020 : 0 : nfs_increment_open_seqid(status, res->seqid);
5021 [ # # ]: 0 : if (status)
5022 : : return status;
5023 : 0 : status = decode_stateid(xdr, &res->stateid);
5024 [ # # ]: 0 : if (unlikely(status))
5025 : : return status;
5026 : :
5027 : 0 : decode_change_info(xdr, &res->cinfo);
5028 : :
5029 : 0 : p = xdr_inline_decode(xdr, 8);
5030 [ # # ]: 0 : if (unlikely(!p))
5031 : : goto out_overflow;
5032 : 0 : res->rflags = be32_to_cpup(p++);
5033 : : bmlen = be32_to_cpup(p);
5034 [ # # ]: 0 : if (bmlen > 10)
5035 : : goto xdr_error;
5036 : :
5037 : 0 : p = xdr_inline_decode(xdr, bmlen << 2);
5038 [ # # ]: 0 : if (unlikely(!p))
5039 : : goto out_overflow;
5040 : 0 : savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5041 [ # # ]: 0 : for (i = 0; i < savewords; ++i)
5042 : 0 : res->attrset[i] = be32_to_cpup(p++);
5043 [ # # ]: 0 : for (; i < NFS4_BITMAP_SIZE; i++)
5044 : 0 : res->attrset[i] = 0;
5045 : :
5046 : 0 : return decode_delegation(xdr, res);
5047 : : xdr_error:
5048 : : dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5049 : : return -EIO;
5050 : : out_overflow:
5051 : : print_overflow_msg(__func__, xdr);
5052 : : return -EIO;
5053 : : }
5054 : :
5055 : 0 : static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5056 : : {
5057 : : int status;
5058 : :
5059 : : status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5060 [ # # ]: 0 : if (status != -EIO)
5061 : 0 : nfs_increment_open_seqid(status, res->seqid);
5062 [ # # ]: 0 : if (!status)
5063 : 0 : status = decode_stateid(xdr, &res->stateid);
5064 : 0 : return status;
5065 : : }
5066 : :
5067 : 0 : static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5068 : : {
5069 : : int status;
5070 : :
5071 : : status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5072 [ # # ]: 0 : if (status != -EIO)
5073 : 0 : nfs_increment_open_seqid(status, res->seqid);
5074 [ # # ]: 0 : if (!status)
5075 : 0 : status = decode_stateid(xdr, &res->stateid);
5076 : 0 : return status;
5077 : : }
5078 : :
5079 : : static int decode_putfh(struct xdr_stream *xdr)
5080 : : {
5081 : : return decode_op_hdr(xdr, OP_PUTFH);
5082 : : }
5083 : :
5084 : : static int decode_putrootfh(struct xdr_stream *xdr)
5085 : : {
5086 : : return decode_op_hdr(xdr, OP_PUTROOTFH);
5087 : : }
5088 : :
5089 : 0 : static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5090 : : {
5091 : 0 : __be32 *p;
5092 : : uint32_t count, eof, recvd;
5093 : : int status;
5094 : :
5095 : : status = decode_op_hdr(xdr, OP_READ);
5096 [ # # ]: 0 : if (status)
5097 : : return status;
5098 : 0 : p = xdr_inline_decode(xdr, 8);
5099 [ # # ]: 0 : if (unlikely(!p))
5100 : : goto out_overflow;
5101 : 0 : eof = be32_to_cpup(p++);
5102 : : count = be32_to_cpup(p);
5103 : 0 : recvd = xdr_read_pages(xdr, count);
5104 [ # # ]: 0 : if (count > recvd) {
5105 : : dprintk("NFS: server cheating in read reply: "
5106 : : "count %u > recvd %u\n", count, recvd);
5107 : : count = recvd;
5108 : : eof = 0;
5109 : : }
5110 : 0 : res->eof = eof;
5111 : 0 : res->count = count;
5112 : : return 0;
5113 : : out_overflow:
5114 : : print_overflow_msg(__func__, xdr);
5115 : : return -EIO;
5116 : : }
5117 : :
5118 : 0 : static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5119 : : {
5120 : : int status;
5121 : : __be32 verf[2];
5122 : :
5123 : : status = decode_op_hdr(xdr, OP_READDIR);
5124 [ # # ]: 0 : if (!status)
5125 : 0 : status = decode_verifier(xdr, readdir->verifier.data);
5126 [ # # ]: 0 : if (unlikely(status))
5127 : : return status;
5128 : 0 : memcpy(verf, readdir->verifier.data, sizeof(verf));
5129 : : dprintk("%s: verifier = %08x:%08x\n",
5130 : : __func__, verf[0], verf[1]);
5131 : 0 : return xdr_read_pages(xdr, xdr->buf->page_len);
5132 : : }
5133 : :
5134 : 0 : static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5135 : : {
5136 : 0 : struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5137 : : u32 len, recvd;
5138 : 0 : __be32 *p;
5139 : : int status;
5140 : :
5141 : : status = decode_op_hdr(xdr, OP_READLINK);
5142 [ # # ]: 0 : if (status)
5143 : : return status;
5144 : :
5145 : : /* Convert length of symlink */
5146 : 0 : p = xdr_inline_decode(xdr, 4);
5147 [ # # ]: 0 : if (unlikely(!p))
5148 : : goto out_overflow;
5149 : : len = be32_to_cpup(p);
5150 [ # # ][ # # ]: 0 : if (len >= rcvbuf->page_len || len <= 0) {
5151 : : dprintk("nfs: server returned giant symlink!\n");
5152 : : return -ENAMETOOLONG;
5153 : : }
5154 : 0 : recvd = xdr_read_pages(xdr, len);
5155 [ # # ]: 0 : if (recvd < len) {
5156 : : dprintk("NFS: server cheating in readlink reply: "
5157 : : "count %u > recvd %u\n", len, recvd);
5158 : : return -EIO;
5159 : : }
5160 : : /*
5161 : : * The XDR encode routine has set things up so that
5162 : : * the link text will be copied directly into the
5163 : : * buffer. We just have to do overflow-checking,
5164 : : * and and null-terminate the text (the VFS expects
5165 : : * null-termination).
5166 : : */
5167 : 0 : xdr_terminate_string(rcvbuf, len);
5168 : 0 : return 0;
5169 : : out_overflow:
5170 : : print_overflow_msg(__func__, xdr);
5171 : : return -EIO;
5172 : : }
5173 : :
5174 : 0 : static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5175 : : {
5176 : : int status;
5177 : :
5178 : : status = decode_op_hdr(xdr, OP_REMOVE);
5179 [ # # ]: 0 : if (status)
5180 : : goto out;
5181 : 0 : status = decode_change_info(xdr, cinfo);
5182 : : out:
5183 : 0 : return status;
5184 : : }
5185 : :
5186 : 0 : static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5187 : : struct nfs4_change_info *new_cinfo)
5188 : : {
5189 : : int status;
5190 : :
5191 : : status = decode_op_hdr(xdr, OP_RENAME);
5192 [ # # ]: 0 : if (status)
5193 : : goto out;
5194 [ # # ]: 0 : if ((status = decode_change_info(xdr, old_cinfo)))
5195 : : goto out;
5196 : 0 : status = decode_change_info(xdr, new_cinfo);
5197 : : out:
5198 : 0 : return status;
5199 : : }
5200 : :
5201 : : static int decode_renew(struct xdr_stream *xdr)
5202 : : {
5203 : : return decode_op_hdr(xdr, OP_RENEW);
5204 : : }
5205 : :
5206 : : static int
5207 : : decode_restorefh(struct xdr_stream *xdr)
5208 : : {
5209 : : return decode_op_hdr(xdr, OP_RESTOREFH);
5210 : : }
5211 : :
5212 : 0 : static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5213 : : struct nfs_getaclres *res)
5214 : : {
5215 : : unsigned int savep;
5216 : : uint32_t attrlen,
5217 : 0 : bitmap[3] = {0};
5218 : : int status;
5219 : : unsigned int pg_offset;
5220 : :
5221 : 0 : res->acl_len = 0;
5222 [ # # ]: 0 : if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5223 : : goto out;
5224 : :
5225 : 0 : xdr_enter_page(xdr, xdr->buf->page_len);
5226 : :
5227 : : /* Calculate the offset of the page data */
5228 : 0 : pg_offset = xdr->buf->head[0].iov_len;
5229 : :
5230 [ # # ]: 0 : if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5231 : : goto out;
5232 [ # # ]: 0 : if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5233 : : goto out;
5234 : :
5235 [ # # ]: 0 : if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5236 : : return -EIO;
5237 [ # # ]: 0 : if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5238 : :
5239 : : /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5240 : : * are stored with the acl data to handle the problem of
5241 : : * variable length bitmaps.*/
5242 : 0 : res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5243 : 0 : res->acl_len = attrlen;
5244 : :
5245 : : /* Check for receive buffer overflow */
5246 [ # # ][ # # ]: 0 : if (res->acl_len > (xdr->nwords << 2) ||
5247 : 0 : res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5248 : 0 : res->acl_flags |= NFS4_ACL_TRUNC;
5249 : : dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5250 : : attrlen, xdr->nwords << 2);
5251 : : }
5252 : : } else
5253 : : status = -EOPNOTSUPP;
5254 : :
5255 : : out:
5256 : : return status;
5257 : : }
5258 : :
5259 : : static int
5260 : : decode_savefh(struct xdr_stream *xdr)
5261 : : {
5262 : : return decode_op_hdr(xdr, OP_SAVEFH);
5263 : : }
5264 : :
5265 : 0 : static int decode_setattr(struct xdr_stream *xdr)
5266 : : {
5267 : 0 : __be32 *p;
5268 : : uint32_t bmlen;
5269 : : int status;
5270 : :
5271 : : status = decode_op_hdr(xdr, OP_SETATTR);
5272 [ # # ]: 0 : if (status)
5273 : : return status;
5274 : 0 : p = xdr_inline_decode(xdr, 4);
5275 [ # # ]: 0 : if (unlikely(!p))
5276 : : goto out_overflow;
5277 : : bmlen = be32_to_cpup(p);
5278 : 0 : p = xdr_inline_decode(xdr, bmlen << 2);
5279 [ # # ]: 0 : if (likely(p))
5280 : : return 0;
5281 : : out_overflow:
5282 : : print_overflow_msg(__func__, xdr);
5283 : : return -EIO;
5284 : : }
5285 : :
5286 : 0 : static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5287 : : {
5288 : 0 : __be32 *p;
5289 : : uint32_t opnum;
5290 : : int32_t nfserr;
5291 : :
5292 : 0 : p = xdr_inline_decode(xdr, 8);
5293 [ # # ]: 0 : if (unlikely(!p))
5294 : : goto out_overflow;
5295 : 0 : opnum = be32_to_cpup(p++);
5296 [ # # ]: 0 : if (opnum != OP_SETCLIENTID) {
5297 : : dprintk("nfs: decode_setclientid: Server returned operation"
5298 : : " %d\n", opnum);
5299 : : return -EIO;
5300 : : }
5301 : 0 : nfserr = be32_to_cpup(p);
5302 [ # # ]: 0 : if (nfserr == NFS_OK) {
5303 : 0 : p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5304 [ # # ]: 0 : if (unlikely(!p))
5305 : : goto out_overflow;
5306 : 0 : p = xdr_decode_hyper(p, &res->clientid);
5307 : 0 : memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5308 [ # # ]: 0 : } else if (nfserr == NFSERR_CLID_INUSE) {
5309 : : uint32_t len;
5310 : :
5311 : : /* skip netid string */
5312 : 0 : p = xdr_inline_decode(xdr, 4);
5313 [ # # ]: 0 : if (unlikely(!p))
5314 : : goto out_overflow;
5315 : : len = be32_to_cpup(p);
5316 : 0 : p = xdr_inline_decode(xdr, len);
5317 [ # # ]: 0 : if (unlikely(!p))
5318 : : goto out_overflow;
5319 : :
5320 : : /* skip uaddr string */
5321 : 0 : p = xdr_inline_decode(xdr, 4);
5322 [ # # ]: 0 : if (unlikely(!p))
5323 : : goto out_overflow;
5324 : : len = be32_to_cpup(p);
5325 : 0 : p = xdr_inline_decode(xdr, len);
5326 [ # # ]: 0 : if (unlikely(!p))
5327 : : goto out_overflow;
5328 : : return -NFSERR_CLID_INUSE;
5329 : : } else
5330 : 0 : return nfs4_stat_to_errno(nfserr);
5331 : :
5332 : 0 : return 0;
5333 : : out_overflow:
5334 : : print_overflow_msg(__func__, xdr);
5335 : : return -EIO;
5336 : : }
5337 : :
5338 : : static int decode_setclientid_confirm(struct xdr_stream *xdr)
5339 : : {
5340 : : return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5341 : : }
5342 : :
5343 : 0 : static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5344 : : {
5345 : : __be32 *p;
5346 : : int status;
5347 : :
5348 : : status = decode_op_hdr(xdr, OP_WRITE);
5349 [ # # ]: 0 : if (status)
5350 : : return status;
5351 : :
5352 : 0 : p = xdr_inline_decode(xdr, 8);
5353 [ # # ]: 0 : if (unlikely(!p))
5354 : : goto out_overflow;
5355 : 0 : res->count = be32_to_cpup(p++);
5356 : 0 : res->verf->committed = be32_to_cpup(p++);
5357 : 0 : return decode_write_verifier(xdr, &res->verf->verifier);
5358 : : out_overflow:
5359 : : print_overflow_msg(__func__, xdr);
5360 : : return -EIO;
5361 : : }
5362 : :
5363 : : static int decode_delegreturn(struct xdr_stream *xdr)
5364 : : {
5365 : : return decode_op_hdr(xdr, OP_DELEGRETURN);
5366 : : }
5367 : :
5368 : 0 : static int decode_secinfo_gss(struct xdr_stream *xdr,
5369 : : struct nfs4_secinfo4 *flavor)
5370 : : {
5371 : : u32 oid_len;
5372 : 0 : __be32 *p;
5373 : :
5374 : 0 : p = xdr_inline_decode(xdr, 4);
5375 [ # # ]: 0 : if (unlikely(!p))
5376 : : goto out_overflow;
5377 : : oid_len = be32_to_cpup(p);
5378 [ # # ]: 0 : if (oid_len > GSS_OID_MAX_LEN)
5379 : : goto out_err;
5380 : :
5381 : 0 : p = xdr_inline_decode(xdr, oid_len);
5382 [ # # ]: 0 : if (unlikely(!p))
5383 : : goto out_overflow;
5384 : 0 : memcpy(flavor->flavor_info.oid.data, p, oid_len);
5385 : 0 : flavor->flavor_info.oid.len = oid_len;
5386 : :
5387 : 0 : p = xdr_inline_decode(xdr, 8);
5388 [ # # ]: 0 : if (unlikely(!p))
5389 : : goto out_overflow;
5390 : 0 : flavor->flavor_info.qop = be32_to_cpup(p++);
5391 : 0 : flavor->flavor_info.service = be32_to_cpup(p);
5392 : :
5393 : 0 : return 0;
5394 : :
5395 : : out_overflow:
5396 : : print_overflow_msg(__func__, xdr);
5397 : : return -EIO;
5398 : : out_err:
5399 : : return -EINVAL;
5400 : : }
5401 : :
5402 : 0 : static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5403 : : {
5404 : : struct nfs4_secinfo4 *sec_flavor;
5405 : : unsigned int i, num_flavors;
5406 : : int status;
5407 : 0 : __be32 *p;
5408 : :
5409 : 0 : p = xdr_inline_decode(xdr, 4);
5410 [ # # ]: 0 : if (unlikely(!p))
5411 : : goto out_overflow;
5412 : :
5413 : 0 : res->flavors->num_flavors = 0;
5414 : : num_flavors = be32_to_cpup(p);
5415 : :
5416 [ # # ]: 0 : for (i = 0; i < num_flavors; i++) {
5417 : 0 : sec_flavor = &res->flavors->flavors[i];
5418 [ # # ]: 0 : if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5419 : : break;
5420 : :
5421 : 0 : p = xdr_inline_decode(xdr, 4);
5422 [ # # ]: 0 : if (unlikely(!p))
5423 : : goto out_overflow;
5424 : 0 : sec_flavor->flavor = be32_to_cpup(p);
5425 : :
5426 [ # # ]: 0 : if (sec_flavor->flavor == RPC_AUTH_GSS) {
5427 : 0 : status = decode_secinfo_gss(xdr, sec_flavor);
5428 [ # # ]: 0 : if (status)
5429 : : goto out;
5430 : : }
5431 : 0 : res->flavors->num_flavors++;
5432 : : }
5433 : :
5434 : : status = 0;
5435 : : out:
5436 : : return status;
5437 : : out_overflow:
5438 : : print_overflow_msg(__func__, xdr);
5439 : : return -EIO;
5440 : : }
5441 : :
5442 : 0 : static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5443 : : {
5444 : : int status = decode_op_hdr(xdr, OP_SECINFO);
5445 [ # # ]: 0 : if (status)
5446 : : return status;
5447 : 0 : return decode_secinfo_common(xdr, res);
5448 : : }
5449 : :
5450 : : #if defined(CONFIG_NFS_V4_1)
5451 : : static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5452 : : {
5453 : : int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5454 : : if (status)
5455 : : return status;
5456 : : return decode_secinfo_common(xdr, res);
5457 : : }
5458 : :
5459 : : static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5460 : : {
5461 : : __be32 *p;
5462 : : uint32_t bitmap_words;
5463 : : unsigned int i;
5464 : :
5465 : : p = xdr_inline_decode(xdr, 4);
5466 : : bitmap_words = be32_to_cpup(p++);
5467 : : if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5468 : : return -EIO;
5469 : : p = xdr_inline_decode(xdr, 4 * bitmap_words);
5470 : : for (i = 0; i < bitmap_words; i++)
5471 : : op_map->u.words[i] = be32_to_cpup(p++);
5472 : :
5473 : : return 0;
5474 : : }
5475 : :
5476 : : static int decode_exchange_id(struct xdr_stream *xdr,
5477 : : struct nfs41_exchange_id_res *res)
5478 : : {
5479 : : __be32 *p;
5480 : : uint32_t dummy;
5481 : : char *dummy_str;
5482 : : int status;
5483 : : uint32_t impl_id_count;
5484 : :
5485 : : status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5486 : : if (status)
5487 : : return status;
5488 : :
5489 : : p = xdr_inline_decode(xdr, 8);
5490 : : if (unlikely(!p))
5491 : : goto out_overflow;
5492 : : xdr_decode_hyper(p, &res->clientid);
5493 : : p = xdr_inline_decode(xdr, 12);
5494 : : if (unlikely(!p))
5495 : : goto out_overflow;
5496 : : res->seqid = be32_to_cpup(p++);
5497 : : res->flags = be32_to_cpup(p++);
5498 : :
5499 : : res->state_protect.how = be32_to_cpup(p);
5500 : : switch (res->state_protect.how) {
5501 : : case SP4_NONE:
5502 : : break;
5503 : : case SP4_MACH_CRED:
5504 : : status = decode_op_map(xdr, &res->state_protect.enforce);
5505 : : if (status)
5506 : : return status;
5507 : : status = decode_op_map(xdr, &res->state_protect.allow);
5508 : : if (status)
5509 : : return status;
5510 : : break;
5511 : : default:
5512 : : WARN_ON_ONCE(1);
5513 : : return -EIO;
5514 : : }
5515 : :
5516 : : /* server_owner4.so_minor_id */
5517 : : p = xdr_inline_decode(xdr, 8);
5518 : : if (unlikely(!p))
5519 : : goto out_overflow;
5520 : : p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5521 : :
5522 : : /* server_owner4.so_major_id */
5523 : : status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5524 : : if (unlikely(status))
5525 : : return status;
5526 : : if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5527 : : return -EIO;
5528 : : memcpy(res->server_owner->major_id, dummy_str, dummy);
5529 : : res->server_owner->major_id_sz = dummy;
5530 : :
5531 : : /* server_scope4 */
5532 : : status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5533 : : if (unlikely(status))
5534 : : return status;
5535 : : if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5536 : : return -EIO;
5537 : : memcpy(res->server_scope->server_scope, dummy_str, dummy);
5538 : : res->server_scope->server_scope_sz = dummy;
5539 : :
5540 : : /* Implementation Id */
5541 : : p = xdr_inline_decode(xdr, 4);
5542 : : if (unlikely(!p))
5543 : : goto out_overflow;
5544 : : impl_id_count = be32_to_cpup(p++);
5545 : :
5546 : : if (impl_id_count) {
5547 : : /* nii_domain */
5548 : : status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5549 : : if (unlikely(status))
5550 : : return status;
5551 : : if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5552 : : return -EIO;
5553 : : memcpy(res->impl_id->domain, dummy_str, dummy);
5554 : :
5555 : : /* nii_name */
5556 : : status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5557 : : if (unlikely(status))
5558 : : return status;
5559 : : if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5560 : : return -EIO;
5561 : : memcpy(res->impl_id->name, dummy_str, dummy);
5562 : :
5563 : : /* nii_date */
5564 : : p = xdr_inline_decode(xdr, 12);
5565 : : if (unlikely(!p))
5566 : : goto out_overflow;
5567 : : p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5568 : : res->impl_id->date.nseconds = be32_to_cpup(p);
5569 : :
5570 : : /* if there's more than one entry, ignore the rest */
5571 : : }
5572 : : return 0;
5573 : : out_overflow:
5574 : : print_overflow_msg(__func__, xdr);
5575 : : return -EIO;
5576 : : }
5577 : :
5578 : : static int decode_chan_attrs(struct xdr_stream *xdr,
5579 : : struct nfs4_channel_attrs *attrs)
5580 : : {
5581 : : __be32 *p;
5582 : : u32 nr_attrs, val;
5583 : :
5584 : : p = xdr_inline_decode(xdr, 28);
5585 : : if (unlikely(!p))
5586 : : goto out_overflow;
5587 : : val = be32_to_cpup(p++); /* headerpadsz */
5588 : : if (val)
5589 : : return -EINVAL; /* no support for header padding yet */
5590 : : attrs->max_rqst_sz = be32_to_cpup(p++);
5591 : : attrs->max_resp_sz = be32_to_cpup(p++);
5592 : : attrs->max_resp_sz_cached = be32_to_cpup(p++);
5593 : : attrs->max_ops = be32_to_cpup(p++);
5594 : : attrs->max_reqs = be32_to_cpup(p++);
5595 : : nr_attrs = be32_to_cpup(p);
5596 : : if (unlikely(nr_attrs > 1)) {
5597 : : printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5598 : : "count %u\n", __func__, nr_attrs);
5599 : : return -EINVAL;
5600 : : }
5601 : : if (nr_attrs == 1) {
5602 : : p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5603 : : if (unlikely(!p))
5604 : : goto out_overflow;
5605 : : }
5606 : : return 0;
5607 : : out_overflow:
5608 : : print_overflow_msg(__func__, xdr);
5609 : : return -EIO;
5610 : : }
5611 : :
5612 : : static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5613 : : {
5614 : : return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5615 : : }
5616 : :
5617 : : static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5618 : : struct nfs41_bind_conn_to_session_res *res)
5619 : : {
5620 : : __be32 *p;
5621 : : int status;
5622 : :
5623 : : status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5624 : : if (!status)
5625 : : status = decode_sessionid(xdr, &res->session->sess_id);
5626 : : if (unlikely(status))
5627 : : return status;
5628 : :
5629 : : /* dir flags, rdma mode bool */
5630 : : p = xdr_inline_decode(xdr, 8);
5631 : : if (unlikely(!p))
5632 : : goto out_overflow;
5633 : :
5634 : : res->dir = be32_to_cpup(p++);
5635 : : if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5636 : : return -EIO;
5637 : : if (be32_to_cpup(p) == 0)
5638 : : res->use_conn_in_rdma_mode = false;
5639 : : else
5640 : : res->use_conn_in_rdma_mode = true;
5641 : :
5642 : : return 0;
5643 : : out_overflow:
5644 : : print_overflow_msg(__func__, xdr);
5645 : : return -EIO;
5646 : : }
5647 : :
5648 : : static int decode_create_session(struct xdr_stream *xdr,
5649 : : struct nfs41_create_session_res *res)
5650 : : {
5651 : : __be32 *p;
5652 : : int status;
5653 : : struct nfs_client *clp = res->client;
5654 : : struct nfs4_session *session = clp->cl_session;
5655 : :
5656 : : status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5657 : : if (!status)
5658 : : status = decode_sessionid(xdr, &session->sess_id);
5659 : : if (unlikely(status))
5660 : : return status;
5661 : :
5662 : : /* seqid, flags */
5663 : : p = xdr_inline_decode(xdr, 8);
5664 : : if (unlikely(!p))
5665 : : goto out_overflow;
5666 : : clp->cl_seqid = be32_to_cpup(p++);
5667 : : session->flags = be32_to_cpup(p);
5668 : :
5669 : : /* Channel attributes */
5670 : : status = decode_chan_attrs(xdr, &session->fc_attrs);
5671 : : if (!status)
5672 : : status = decode_chan_attrs(xdr, &session->bc_attrs);
5673 : : return status;
5674 : : out_overflow:
5675 : : print_overflow_msg(__func__, xdr);
5676 : : return -EIO;
5677 : : }
5678 : :
5679 : : static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5680 : : {
5681 : : return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5682 : : }
5683 : :
5684 : : static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5685 : : {
5686 : : return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5687 : : }
5688 : :
5689 : : static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5690 : : {
5691 : : return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5692 : : }
5693 : : #endif /* CONFIG_NFS_V4_1 */
5694 : :
5695 : : static int decode_sequence(struct xdr_stream *xdr,
5696 : : struct nfs4_sequence_res *res,
5697 : : struct rpc_rqst *rqstp)
5698 : : {
5699 : : #if defined(CONFIG_NFS_V4_1)
5700 : : struct nfs4_session *session;
5701 : : struct nfs4_sessionid id;
5702 : : u32 dummy;
5703 : : int status;
5704 : : __be32 *p;
5705 : :
5706 : : if (res->sr_slot == NULL)
5707 : : return 0;
5708 : : if (!res->sr_slot->table->session)
5709 : : return 0;
5710 : :
5711 : : status = decode_op_hdr(xdr, OP_SEQUENCE);
5712 : : if (!status)
5713 : : status = decode_sessionid(xdr, &id);
5714 : : if (unlikely(status))
5715 : : goto out_err;
5716 : :
5717 : : /*
5718 : : * If the server returns different values for sessionID, slotID or
5719 : : * sequence number, the server is looney tunes.
5720 : : */
5721 : : status = -EREMOTEIO;
5722 : : session = res->sr_slot->table->session;
5723 : :
5724 : : if (memcmp(id.data, session->sess_id.data,
5725 : : NFS4_MAX_SESSIONID_LEN)) {
5726 : : dprintk("%s Invalid session id\n", __func__);
5727 : : goto out_err;
5728 : : }
5729 : :
5730 : : p = xdr_inline_decode(xdr, 20);
5731 : : if (unlikely(!p))
5732 : : goto out_overflow;
5733 : :
5734 : : /* seqid */
5735 : : dummy = be32_to_cpup(p++);
5736 : : if (dummy != res->sr_slot->seq_nr) {
5737 : : dprintk("%s Invalid sequence number\n", __func__);
5738 : : goto out_err;
5739 : : }
5740 : : /* slot id */
5741 : : dummy = be32_to_cpup(p++);
5742 : : if (dummy != res->sr_slot->slot_nr) {
5743 : : dprintk("%s Invalid slot id\n", __func__);
5744 : : goto out_err;
5745 : : }
5746 : : /* highest slot id */
5747 : : res->sr_highest_slotid = be32_to_cpup(p++);
5748 : : /* target highest slot id */
5749 : : res->sr_target_highest_slotid = be32_to_cpup(p++);
5750 : : /* result flags */
5751 : : res->sr_status_flags = be32_to_cpup(p);
5752 : : status = 0;
5753 : : out_err:
5754 : : res->sr_status = status;
5755 : : return status;
5756 : : out_overflow:
5757 : : print_overflow_msg(__func__, xdr);
5758 : : status = -EIO;
5759 : : goto out_err;
5760 : : #else /* CONFIG_NFS_V4_1 */
5761 : : return 0;
5762 : : #endif /* CONFIG_NFS_V4_1 */
5763 : : }
5764 : :
5765 : : #if defined(CONFIG_NFS_V4_1)
5766 : : /*
5767 : : * TODO: Need to handle case when EOF != true;
5768 : : */
5769 : : static int decode_getdevicelist(struct xdr_stream *xdr,
5770 : : struct pnfs_devicelist *res)
5771 : : {
5772 : : __be32 *p;
5773 : : int status, i;
5774 : : nfs4_verifier verftemp;
5775 : :
5776 : : status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5777 : : if (status)
5778 : : return status;
5779 : :
5780 : : p = xdr_inline_decode(xdr, 8 + 8 + 4);
5781 : : if (unlikely(!p))
5782 : : goto out_overflow;
5783 : :
5784 : : /* TODO: Skip cookie for now */
5785 : : p += 2;
5786 : :
5787 : : /* Read verifier */
5788 : : p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
5789 : :
5790 : : res->num_devs = be32_to_cpup(p);
5791 : :
5792 : : dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5793 : :
5794 : : if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5795 : : printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
5796 : : __func__, res->num_devs);
5797 : : return -EIO;
5798 : : }
5799 : :
5800 : : p = xdr_inline_decode(xdr,
5801 : : res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5802 : : if (unlikely(!p))
5803 : : goto out_overflow;
5804 : : for (i = 0; i < res->num_devs; i++)
5805 : : p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5806 : : NFS4_DEVICEID4_SIZE);
5807 : : res->eof = be32_to_cpup(p);
5808 : : return 0;
5809 : : out_overflow:
5810 : : print_overflow_msg(__func__, xdr);
5811 : : return -EIO;
5812 : : }
5813 : :
5814 : : static int decode_getdeviceinfo(struct xdr_stream *xdr,
5815 : : struct pnfs_device *pdev)
5816 : : {
5817 : : __be32 *p;
5818 : : uint32_t len, type;
5819 : : int status;
5820 : :
5821 : : status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5822 : : if (status) {
5823 : : if (status == -ETOOSMALL) {
5824 : : p = xdr_inline_decode(xdr, 4);
5825 : : if (unlikely(!p))
5826 : : goto out_overflow;
5827 : : pdev->mincount = be32_to_cpup(p);
5828 : : dprintk("%s: Min count too small. mincnt = %u\n",
5829 : : __func__, pdev->mincount);
5830 : : }
5831 : : return status;
5832 : : }
5833 : :
5834 : : p = xdr_inline_decode(xdr, 8);
5835 : : if (unlikely(!p))
5836 : : goto out_overflow;
5837 : : type = be32_to_cpup(p++);
5838 : : if (type != pdev->layout_type) {
5839 : : dprintk("%s: layout mismatch req: %u pdev: %u\n",
5840 : : __func__, pdev->layout_type, type);
5841 : : return -EINVAL;
5842 : : }
5843 : : /*
5844 : : * Get the length of the opaque device_addr4. xdr_read_pages places
5845 : : * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5846 : : * and places the remaining xdr data in xdr_buf->tail
5847 : : */
5848 : : pdev->mincount = be32_to_cpup(p);
5849 : : if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5850 : : goto out_overflow;
5851 : :
5852 : : /* Parse notification bitmap, verifying that it is zero. */
5853 : : p = xdr_inline_decode(xdr, 4);
5854 : : if (unlikely(!p))
5855 : : goto out_overflow;
5856 : : len = be32_to_cpup(p);
5857 : : if (len) {
5858 : : uint32_t i;
5859 : :
5860 : : p = xdr_inline_decode(xdr, 4 * len);
5861 : : if (unlikely(!p))
5862 : : goto out_overflow;
5863 : : for (i = 0; i < len; i++, p++) {
5864 : : if (be32_to_cpup(p)) {
5865 : : dprintk("%s: notifications not supported\n",
5866 : : __func__);
5867 : : return -EIO;
5868 : : }
5869 : : }
5870 : : }
5871 : : return 0;
5872 : : out_overflow:
5873 : : print_overflow_msg(__func__, xdr);
5874 : : return -EIO;
5875 : : }
5876 : :
5877 : : static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5878 : : struct nfs4_layoutget_res *res)
5879 : : {
5880 : : __be32 *p;
5881 : : int status;
5882 : : u32 layout_count;
5883 : : u32 recvd;
5884 : :
5885 : : status = decode_op_hdr(xdr, OP_LAYOUTGET);
5886 : : if (status)
5887 : : return status;
5888 : : p = xdr_inline_decode(xdr, 4);
5889 : : if (unlikely(!p))
5890 : : goto out_overflow;
5891 : : res->return_on_close = be32_to_cpup(p);
5892 : : decode_stateid(xdr, &res->stateid);
5893 : : p = xdr_inline_decode(xdr, 4);
5894 : : if (unlikely(!p))
5895 : : goto out_overflow;
5896 : : layout_count = be32_to_cpup(p);
5897 : : if (!layout_count) {
5898 : : dprintk("%s: server responded with empty layout array\n",
5899 : : __func__);
5900 : : return -EINVAL;
5901 : : }
5902 : :
5903 : : p = xdr_inline_decode(xdr, 28);
5904 : : if (unlikely(!p))
5905 : : goto out_overflow;
5906 : : p = xdr_decode_hyper(p, &res->range.offset);
5907 : : p = xdr_decode_hyper(p, &res->range.length);
5908 : : res->range.iomode = be32_to_cpup(p++);
5909 : : res->type = be32_to_cpup(p++);
5910 : : res->layoutp->len = be32_to_cpup(p);
5911 : :
5912 : : dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5913 : : __func__,
5914 : : (unsigned long)res->range.offset,
5915 : : (unsigned long)res->range.length,
5916 : : res->range.iomode,
5917 : : res->type,
5918 : : res->layoutp->len);
5919 : :
5920 : : recvd = xdr_read_pages(xdr, res->layoutp->len);
5921 : : if (res->layoutp->len > recvd) {
5922 : : dprintk("NFS: server cheating in layoutget reply: "
5923 : : "layout len %u > recvd %u\n",
5924 : : res->layoutp->len, recvd);
5925 : : return -EINVAL;
5926 : : }
5927 : :
5928 : : if (layout_count > 1) {
5929 : : /* We only handle a length one array at the moment. Any
5930 : : * further entries are just ignored. Note that this means
5931 : : * the client may see a response that is less than the
5932 : : * minimum it requested.
5933 : : */
5934 : : dprintk("%s: server responded with %d layouts, dropping tail\n",
5935 : : __func__, layout_count);
5936 : : }
5937 : :
5938 : : return 0;
5939 : : out_overflow:
5940 : : print_overflow_msg(__func__, xdr);
5941 : : return -EIO;
5942 : : }
5943 : :
5944 : : static int decode_layoutreturn(struct xdr_stream *xdr,
5945 : : struct nfs4_layoutreturn_res *res)
5946 : : {
5947 : : __be32 *p;
5948 : : int status;
5949 : :
5950 : : status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5951 : : if (status)
5952 : : return status;
5953 : : p = xdr_inline_decode(xdr, 4);
5954 : : if (unlikely(!p))
5955 : : goto out_overflow;
5956 : : res->lrs_present = be32_to_cpup(p);
5957 : : if (res->lrs_present)
5958 : : status = decode_stateid(xdr, &res->stateid);
5959 : : return status;
5960 : : out_overflow:
5961 : : print_overflow_msg(__func__, xdr);
5962 : : return -EIO;
5963 : : }
5964 : :
5965 : : static int decode_layoutcommit(struct xdr_stream *xdr,
5966 : : struct rpc_rqst *req,
5967 : : struct nfs4_layoutcommit_res *res)
5968 : : {
5969 : : __be32 *p;
5970 : : __u32 sizechanged;
5971 : : int status;
5972 : :
5973 : : status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5974 : : res->status = status;
5975 : : if (status)
5976 : : return status;
5977 : :
5978 : : p = xdr_inline_decode(xdr, 4);
5979 : : if (unlikely(!p))
5980 : : goto out_overflow;
5981 : : sizechanged = be32_to_cpup(p);
5982 : :
5983 : : if (sizechanged) {
5984 : : /* throw away new size */
5985 : : p = xdr_inline_decode(xdr, 8);
5986 : : if (unlikely(!p))
5987 : : goto out_overflow;
5988 : : }
5989 : : return 0;
5990 : : out_overflow:
5991 : : print_overflow_msg(__func__, xdr);
5992 : : return -EIO;
5993 : : }
5994 : :
5995 : : static int decode_test_stateid(struct xdr_stream *xdr,
5996 : : struct nfs41_test_stateid_res *res)
5997 : : {
5998 : : __be32 *p;
5999 : : int status;
6000 : : int num_res;
6001 : :
6002 : : status = decode_op_hdr(xdr, OP_TEST_STATEID);
6003 : : if (status)
6004 : : return status;
6005 : :
6006 : : p = xdr_inline_decode(xdr, 4);
6007 : : if (unlikely(!p))
6008 : : goto out_overflow;
6009 : : num_res = be32_to_cpup(p++);
6010 : : if (num_res != 1)
6011 : : goto out;
6012 : :
6013 : : p = xdr_inline_decode(xdr, 4);
6014 : : if (unlikely(!p))
6015 : : goto out_overflow;
6016 : : res->status = be32_to_cpup(p++);
6017 : :
6018 : : return status;
6019 : : out_overflow:
6020 : : print_overflow_msg(__func__, xdr);
6021 : : out:
6022 : : return -EIO;
6023 : : }
6024 : :
6025 : : static int decode_free_stateid(struct xdr_stream *xdr,
6026 : : struct nfs41_free_stateid_res *res)
6027 : : {
6028 : : res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
6029 : : return res->status;
6030 : : }
6031 : : #endif /* CONFIG_NFS_V4_1 */
6032 : :
6033 : : /*
6034 : : * END OF "GENERIC" DECODE ROUTINES.
6035 : : */
6036 : :
6037 : : /*
6038 : : * Decode OPEN_DOWNGRADE response
6039 : : */
6040 : 0 : static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6041 : : struct xdr_stream *xdr,
6042 : : struct nfs_closeres *res)
6043 : : {
6044 : : struct compound_hdr hdr;
6045 : : int status;
6046 : :
6047 : 0 : status = decode_compound_hdr(xdr, &hdr);
6048 [ # # ]: 0 : if (status)
6049 : : goto out;
6050 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6051 : : if (status)
6052 : : goto out;
6053 : : status = decode_putfh(xdr);
6054 [ # # ]: 0 : if (status)
6055 : : goto out;
6056 : 0 : status = decode_open_downgrade(xdr, res);
6057 [ # # ]: 0 : if (status != 0)
6058 : : goto out;
6059 : 0 : decode_getfattr(xdr, res->fattr, res->server);
6060 : : out:
6061 : 0 : return status;
6062 : : }
6063 : :
6064 : : /*
6065 : : * Decode ACCESS response
6066 : : */
6067 : 0 : static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6068 : : struct nfs4_accessres *res)
6069 : : {
6070 : : struct compound_hdr hdr;
6071 : : int status;
6072 : :
6073 : 0 : status = decode_compound_hdr(xdr, &hdr);
6074 [ # # ]: 0 : if (status)
6075 : : goto out;
6076 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6077 : : if (status)
6078 : : goto out;
6079 : : status = decode_putfh(xdr);
6080 [ # # ]: 0 : if (status != 0)
6081 : : goto out;
6082 : 0 : status = decode_access(xdr, &res->supported, &res->access);
6083 [ # # ]: 0 : if (status != 0)
6084 : : goto out;
6085 : 0 : decode_getfattr(xdr, res->fattr, res->server);
6086 : : out:
6087 : 0 : return status;
6088 : : }
6089 : :
6090 : : /*
6091 : : * Decode LOOKUP response
6092 : : */
6093 : 0 : static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6094 : : struct nfs4_lookup_res *res)
6095 : : {
6096 : : struct compound_hdr hdr;
6097 : : int status;
6098 : :
6099 : 0 : status = decode_compound_hdr(xdr, &hdr);
6100 [ # # ]: 0 : if (status)
6101 : : goto out;
6102 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6103 : : if (status)
6104 : : goto out;
6105 : : status = decode_putfh(xdr);
6106 [ # # ]: 0 : if (status)
6107 : : goto out;
6108 : : status = decode_lookup(xdr);
6109 [ # # ]: 0 : if (status)
6110 : : goto out;
6111 : 0 : status = decode_getfh(xdr, res->fh);
6112 [ # # ]: 0 : if (status)
6113 : : goto out;
6114 : 0 : status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6115 : : out:
6116 : 0 : return status;
6117 : : }
6118 : :
6119 : : /*
6120 : : * Decode LOOKUP_ROOT response
6121 : : */
6122 : 0 : static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6123 : : struct xdr_stream *xdr,
6124 : : struct nfs4_lookup_res *res)
6125 : : {
6126 : : struct compound_hdr hdr;
6127 : : int status;
6128 : :
6129 : 0 : status = decode_compound_hdr(xdr, &hdr);
6130 [ # # ]: 0 : if (status)
6131 : : goto out;
6132 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6133 : : if (status)
6134 : : goto out;
6135 : : status = decode_putrootfh(xdr);
6136 [ # # ]: 0 : if (status)
6137 : : goto out;
6138 : 0 : status = decode_getfh(xdr, res->fh);
6139 [ # # ]: 0 : if (status == 0)
6140 : 0 : status = decode_getfattr_label(xdr, res->fattr,
6141 : : res->label, res->server);
6142 : : out:
6143 : 0 : return status;
6144 : : }
6145 : :
6146 : : /*
6147 : : * Decode REMOVE response
6148 : : */
6149 : 0 : static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6150 : : struct nfs_removeres *res)
6151 : : {
6152 : : struct compound_hdr hdr;
6153 : : int status;
6154 : :
6155 : 0 : status = decode_compound_hdr(xdr, &hdr);
6156 [ # # ]: 0 : if (status)
6157 : : goto out;
6158 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6159 : : if (status)
6160 : : goto out;
6161 : : status = decode_putfh(xdr);
6162 [ # # ]: 0 : if (status)
6163 : : goto out;
6164 : 0 : status = decode_remove(xdr, &res->cinfo);
6165 : : out:
6166 : 0 : return status;
6167 : : }
6168 : :
6169 : : /*
6170 : : * Decode RENAME response
6171 : : */
6172 : 0 : static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6173 : : struct nfs_renameres *res)
6174 : : {
6175 : : struct compound_hdr hdr;
6176 : : int status;
6177 : :
6178 : 0 : status = decode_compound_hdr(xdr, &hdr);
6179 [ # # ]: 0 : if (status)
6180 : : goto out;
6181 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6182 : : if (status)
6183 : : goto out;
6184 : : status = decode_putfh(xdr);
6185 [ # # ]: 0 : if (status)
6186 : : goto out;
6187 : : status = decode_savefh(xdr);
6188 [ # # ]: 0 : if (status)
6189 : : goto out;
6190 : : status = decode_putfh(xdr);
6191 [ # # ]: 0 : if (status)
6192 : : goto out;
6193 : 0 : status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6194 : : out:
6195 : 0 : return status;
6196 : : }
6197 : :
6198 : : /*
6199 : : * Decode LINK response
6200 : : */
6201 : 0 : static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6202 : : struct nfs4_link_res *res)
6203 : : {
6204 : : struct compound_hdr hdr;
6205 : : int status;
6206 : :
6207 : 0 : status = decode_compound_hdr(xdr, &hdr);
6208 [ # # ]: 0 : if (status)
6209 : : goto out;
6210 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6211 : : if (status)
6212 : : goto out;
6213 : : status = decode_putfh(xdr);
6214 [ # # ]: 0 : if (status)
6215 : : goto out;
6216 : : status = decode_savefh(xdr);
6217 [ # # ]: 0 : if (status)
6218 : : goto out;
6219 : : status = decode_putfh(xdr);
6220 [ # # ]: 0 : if (status)
6221 : : goto out;
6222 : 0 : status = decode_link(xdr, &res->cinfo);
6223 [ # # ]: 0 : if (status)
6224 : : goto out;
6225 : : /*
6226 : : * Note order: OP_LINK leaves the directory as the current
6227 : : * filehandle.
6228 : : */
6229 : : status = decode_restorefh(xdr);
6230 [ # # ]: 0 : if (status)
6231 : : goto out;
6232 : 0 : decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6233 : : out:
6234 : 0 : return status;
6235 : : }
6236 : :
6237 : : /*
6238 : : * Decode CREATE response
6239 : : */
6240 : 0 : static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6241 : : struct nfs4_create_res *res)
6242 : : {
6243 : : struct compound_hdr hdr;
6244 : : int status;
6245 : :
6246 : 0 : status = decode_compound_hdr(xdr, &hdr);
6247 [ # # ]: 0 : if (status)
6248 : : goto out;
6249 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6250 : : if (status)
6251 : : goto out;
6252 : : status = decode_putfh(xdr);
6253 [ # # ]: 0 : if (status)
6254 : : goto out;
6255 : 0 : status = decode_create(xdr, &res->dir_cinfo);
6256 [ # # ]: 0 : if (status)
6257 : : goto out;
6258 : 0 : status = decode_getfh(xdr, res->fh);
6259 [ # # ]: 0 : if (status)
6260 : : goto out;
6261 : 0 : decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6262 : : out:
6263 : 0 : return status;
6264 : : }
6265 : :
6266 : : /*
6267 : : * Decode SYMLINK response
6268 : : */
6269 : 0 : static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6270 : : struct nfs4_create_res *res)
6271 : : {
6272 : 0 : return nfs4_xdr_dec_create(rqstp, xdr, res);
6273 : : }
6274 : :
6275 : : /*
6276 : : * Decode GETATTR response
6277 : : */
6278 : 0 : static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 : : struct nfs4_getattr_res *res)
6280 : : {
6281 : : struct compound_hdr hdr;
6282 : : int status;
6283 : :
6284 : 0 : status = decode_compound_hdr(xdr, &hdr);
6285 [ # # ]: 0 : if (status)
6286 : : goto out;
6287 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6288 : : if (status)
6289 : : goto out;
6290 : : status = decode_putfh(xdr);
6291 [ # # ]: 0 : if (status)
6292 : : goto out;
6293 : 0 : status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6294 : : out:
6295 : 0 : return status;
6296 : : }
6297 : :
6298 : : /*
6299 : : * Encode an SETACL request
6300 : : */
6301 : 0 : static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6302 : : struct nfs_setaclargs *args)
6303 : : {
6304 : 0 : struct compound_hdr hdr = {
6305 : : .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6306 : : };
6307 : :
6308 : 0 : encode_compound_hdr(xdr, req, &hdr);
6309 : : encode_sequence(xdr, &args->seq_args, &hdr);
6310 : 0 : encode_putfh(xdr, args->fh, &hdr);
6311 : 0 : encode_setacl(xdr, args, &hdr);
6312 : 0 : encode_nops(&hdr);
6313 : 0 : }
6314 : :
6315 : : /*
6316 : : * Decode SETACL response
6317 : : */
6318 : : static int
6319 : 0 : nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6320 : : struct nfs_setaclres *res)
6321 : : {
6322 : : struct compound_hdr hdr;
6323 : : int status;
6324 : :
6325 : 0 : status = decode_compound_hdr(xdr, &hdr);
6326 [ # # ]: 0 : if (status)
6327 : : goto out;
6328 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6329 : : if (status)
6330 : : goto out;
6331 : : status = decode_putfh(xdr);
6332 [ # # ]: 0 : if (status)
6333 : : goto out;
6334 : 0 : status = decode_setattr(xdr);
6335 : : out:
6336 : 0 : return status;
6337 : : }
6338 : :
6339 : : /*
6340 : : * Decode GETACL response
6341 : : */
6342 : : static int
6343 : 0 : nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6344 : : struct nfs_getaclres *res)
6345 : : {
6346 : : struct compound_hdr hdr;
6347 : : int status;
6348 : :
6349 [ # # ]: 0 : if (res->acl_scratch != NULL) {
6350 : 0 : void *p = page_address(res->acl_scratch);
6351 : 0 : xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6352 : : }
6353 : 0 : status = decode_compound_hdr(xdr, &hdr);
6354 [ # # ]: 0 : if (status)
6355 : : goto out;
6356 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6357 : : if (status)
6358 : : goto out;
6359 : : status = decode_putfh(xdr);
6360 [ # # ]: 0 : if (status)
6361 : : goto out;
6362 : 0 : status = decode_getacl(xdr, rqstp, res);
6363 : :
6364 : : out:
6365 : 0 : return status;
6366 : : }
6367 : :
6368 : : /*
6369 : : * Decode CLOSE response
6370 : : */
6371 : 0 : static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6372 : : struct nfs_closeres *res)
6373 : : {
6374 : : struct compound_hdr hdr;
6375 : : int status;
6376 : :
6377 : 0 : status = decode_compound_hdr(xdr, &hdr);
6378 [ # # ]: 0 : if (status)
6379 : : goto out;
6380 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6381 : : if (status)
6382 : : goto out;
6383 : : status = decode_putfh(xdr);
6384 [ # # ]: 0 : if (status)
6385 : : goto out;
6386 : 0 : status = decode_close(xdr, res);
6387 [ # # ]: 0 : if (status != 0)
6388 : : goto out;
6389 : : /*
6390 : : * Note: Server may do delete on close for this file
6391 : : * in which case the getattr call will fail with
6392 : : * an ESTALE error. Shouldn't be a problem,
6393 : : * though, since fattr->valid will remain unset.
6394 : : */
6395 : 0 : decode_getfattr(xdr, res->fattr, res->server);
6396 : : out:
6397 : 0 : return status;
6398 : : }
6399 : :
6400 : : /*
6401 : : * Decode OPEN response
6402 : : */
6403 : 0 : static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6404 : : struct nfs_openres *res)
6405 : : {
6406 : : struct compound_hdr hdr;
6407 : : int status;
6408 : :
6409 : 0 : status = decode_compound_hdr(xdr, &hdr);
6410 [ # # ]: 0 : if (status)
6411 : : goto out;
6412 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6413 : : if (status)
6414 : : goto out;
6415 : : status = decode_putfh(xdr);
6416 [ # # ]: 0 : if (status)
6417 : : goto out;
6418 : 0 : status = decode_open(xdr, res);
6419 [ # # ]: 0 : if (status)
6420 : : goto out;
6421 : 0 : status = decode_getfh(xdr, &res->fh);
6422 [ # # ]: 0 : if (status)
6423 : : goto out;
6424 [ # # ]: 0 : if (res->access_request)
6425 : 0 : decode_access(xdr, &res->access_supported, &res->access_result);
6426 : 0 : decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6427 : : out:
6428 : 0 : return status;
6429 : : }
6430 : :
6431 : : /*
6432 : : * Decode OPEN_CONFIRM response
6433 : : */
6434 : 0 : static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6435 : : struct xdr_stream *xdr,
6436 : : struct nfs_open_confirmres *res)
6437 : : {
6438 : : struct compound_hdr hdr;
6439 : : int status;
6440 : :
6441 : 0 : status = decode_compound_hdr(xdr, &hdr);
6442 [ # # ]: 0 : if (status)
6443 : : goto out;
6444 : : status = decode_putfh(xdr);
6445 [ # # ]: 0 : if (status)
6446 : : goto out;
6447 : 0 : status = decode_open_confirm(xdr, res);
6448 : : out:
6449 : 0 : return status;
6450 : : }
6451 : :
6452 : : /*
6453 : : * Decode OPEN response
6454 : : */
6455 : 0 : static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6456 : : struct xdr_stream *xdr,
6457 : : struct nfs_openres *res)
6458 : : {
6459 : : struct compound_hdr hdr;
6460 : : int status;
6461 : :
6462 : 0 : status = decode_compound_hdr(xdr, &hdr);
6463 [ # # ]: 0 : if (status)
6464 : : goto out;
6465 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6466 : : if (status)
6467 : : goto out;
6468 : : status = decode_putfh(xdr);
6469 [ # # ]: 0 : if (status)
6470 : : goto out;
6471 : 0 : status = decode_open(xdr, res);
6472 [ # # ]: 0 : if (status)
6473 : : goto out;
6474 [ # # ]: 0 : if (res->access_request)
6475 : 0 : decode_access(xdr, &res->access_supported, &res->access_result);
6476 : 0 : decode_getfattr(xdr, res->f_attr, res->server);
6477 : : out:
6478 : 0 : return status;
6479 : : }
6480 : :
6481 : : /*
6482 : : * Decode SETATTR response
6483 : : */
6484 : 0 : static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6485 : : struct xdr_stream *xdr,
6486 : : struct nfs_setattrres *res)
6487 : : {
6488 : : struct compound_hdr hdr;
6489 : : int status;
6490 : :
6491 : 0 : status = decode_compound_hdr(xdr, &hdr);
6492 [ # # ]: 0 : if (status)
6493 : : goto out;
6494 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6495 : : if (status)
6496 : : goto out;
6497 : : status = decode_putfh(xdr);
6498 [ # # ]: 0 : if (status)
6499 : : goto out;
6500 : 0 : status = decode_setattr(xdr);
6501 [ # # ]: 0 : if (status)
6502 : : goto out;
6503 : 0 : decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6504 : : out:
6505 : 0 : return status;
6506 : : }
6507 : :
6508 : : /*
6509 : : * Decode LOCK response
6510 : : */
6511 : 0 : static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6512 : : struct nfs_lock_res *res)
6513 : : {
6514 : : struct compound_hdr hdr;
6515 : : int status;
6516 : :
6517 : 0 : status = decode_compound_hdr(xdr, &hdr);
6518 [ # # ]: 0 : if (status)
6519 : : goto out;
6520 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6521 : : if (status)
6522 : : goto out;
6523 : : status = decode_putfh(xdr);
6524 [ # # ]: 0 : if (status)
6525 : : goto out;
6526 : 0 : status = decode_lock(xdr, res);
6527 : : out:
6528 : 0 : return status;
6529 : : }
6530 : :
6531 : : /*
6532 : : * Decode LOCKT response
6533 : : */
6534 : 0 : static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6535 : : struct nfs_lockt_res *res)
6536 : : {
6537 : : struct compound_hdr hdr;
6538 : : int status;
6539 : :
6540 : 0 : status = decode_compound_hdr(xdr, &hdr);
6541 [ # # ]: 0 : if (status)
6542 : : goto out;
6543 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6544 : : if (status)
6545 : : goto out;
6546 : : status = decode_putfh(xdr);
6547 [ # # ]: 0 : if (status)
6548 : : goto out;
6549 : 0 : status = decode_lockt(xdr, res);
6550 : : out:
6551 : 0 : return status;
6552 : : }
6553 : :
6554 : : /*
6555 : : * Decode LOCKU response
6556 : : */
6557 : 0 : static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6558 : : struct nfs_locku_res *res)
6559 : : {
6560 : : struct compound_hdr hdr;
6561 : : int status;
6562 : :
6563 : 0 : status = decode_compound_hdr(xdr, &hdr);
6564 [ # # ]: 0 : if (status)
6565 : : goto out;
6566 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6567 : : if (status)
6568 : : goto out;
6569 : : status = decode_putfh(xdr);
6570 [ # # ]: 0 : if (status)
6571 : : goto out;
6572 : 0 : status = decode_locku(xdr, res);
6573 : : out:
6574 : 0 : return status;
6575 : : }
6576 : :
6577 : 0 : static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6578 : : struct xdr_stream *xdr, void *dummy)
6579 : : {
6580 : : struct compound_hdr hdr;
6581 : : int status;
6582 : :
6583 : 0 : status = decode_compound_hdr(xdr, &hdr);
6584 [ # # ]: 0 : if (!status)
6585 : : status = decode_release_lockowner(xdr);
6586 : 0 : return status;
6587 : : }
6588 : :
6589 : : /*
6590 : : * Decode READLINK response
6591 : : */
6592 : 0 : static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6593 : : struct xdr_stream *xdr,
6594 : : struct nfs4_readlink_res *res)
6595 : : {
6596 : : struct compound_hdr hdr;
6597 : : int status;
6598 : :
6599 : 0 : status = decode_compound_hdr(xdr, &hdr);
6600 [ # # ]: 0 : if (status)
6601 : : goto out;
6602 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6603 : : if (status)
6604 : : goto out;
6605 : : status = decode_putfh(xdr);
6606 [ # # ]: 0 : if (status)
6607 : : goto out;
6608 : 0 : status = decode_readlink(xdr, rqstp);
6609 : : out:
6610 : 0 : return status;
6611 : : }
6612 : :
6613 : : /*
6614 : : * Decode READDIR response
6615 : : */
6616 : 0 : static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6617 : : struct nfs4_readdir_res *res)
6618 : : {
6619 : : struct compound_hdr hdr;
6620 : : int status;
6621 : :
6622 : 0 : status = decode_compound_hdr(xdr, &hdr);
6623 [ # # ]: 0 : if (status)
6624 : : goto out;
6625 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6626 : : if (status)
6627 : : goto out;
6628 : : status = decode_putfh(xdr);
6629 [ # # ]: 0 : if (status)
6630 : : goto out;
6631 : 0 : status = decode_readdir(xdr, rqstp, res);
6632 : : out:
6633 : 0 : return status;
6634 : : }
6635 : :
6636 : : /*
6637 : : * Decode Read response
6638 : : */
6639 : 0 : static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6640 : : struct nfs_readres *res)
6641 : : {
6642 : : struct compound_hdr hdr;
6643 : : int status;
6644 : :
6645 : 0 : status = decode_compound_hdr(xdr, &hdr);
6646 [ # # ]: 0 : if (status)
6647 : : goto out;
6648 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6649 : : if (status)
6650 : : goto out;
6651 : : status = decode_putfh(xdr);
6652 [ # # ]: 0 : if (status)
6653 : : goto out;
6654 : 0 : status = decode_read(xdr, rqstp, res);
6655 [ # # ]: 0 : if (!status)
6656 : 0 : status = res->count;
6657 : : out:
6658 : 0 : return status;
6659 : : }
6660 : :
6661 : : /*
6662 : : * Decode WRITE response
6663 : : */
6664 : 0 : static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6665 : : struct nfs_writeres *res)
6666 : : {
6667 : : struct compound_hdr hdr;
6668 : : int status;
6669 : :
6670 : 0 : status = decode_compound_hdr(xdr, &hdr);
6671 [ # # ]: 0 : if (status)
6672 : : goto out;
6673 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6674 : : if (status)
6675 : : goto out;
6676 : : status = decode_putfh(xdr);
6677 [ # # ]: 0 : if (status)
6678 : : goto out;
6679 : 0 : status = decode_write(xdr, res);
6680 [ # # ]: 0 : if (status)
6681 : : goto out;
6682 [ # # ]: 0 : if (res->fattr)
6683 : 0 : decode_getfattr(xdr, res->fattr, res->server);
6684 [ # # ]: 0 : if (!status)
6685 : 0 : status = res->count;
6686 : : out:
6687 : 0 : return status;
6688 : : }
6689 : :
6690 : : /*
6691 : : * Decode COMMIT response
6692 : : */
6693 : 0 : static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6694 : : struct nfs_commitres *res)
6695 : : {
6696 : : struct compound_hdr hdr;
6697 : : int status;
6698 : :
6699 : 0 : status = decode_compound_hdr(xdr, &hdr);
6700 [ # # ]: 0 : if (status)
6701 : : goto out;
6702 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6703 : : if (status)
6704 : : goto out;
6705 : : status = decode_putfh(xdr);
6706 [ # # ]: 0 : if (status)
6707 : : goto out;
6708 : 0 : status = decode_commit(xdr, res);
6709 : : out:
6710 : 0 : return status;
6711 : : }
6712 : :
6713 : : /*
6714 : : * Decode FSINFO response
6715 : : */
6716 : 0 : static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6717 : : struct nfs4_fsinfo_res *res)
6718 : : {
6719 : : struct compound_hdr hdr;
6720 : : int status;
6721 : :
6722 : 0 : status = decode_compound_hdr(xdr, &hdr);
6723 [ # # ]: 0 : if (!status)
6724 : : status = decode_sequence(xdr, &res->seq_res, req);
6725 [ # # ]: 0 : if (!status)
6726 : : status = decode_putfh(xdr);
6727 [ # # ]: 0 : if (!status)
6728 : 0 : status = decode_fsinfo(xdr, res->fsinfo);
6729 : 0 : return status;
6730 : : }
6731 : :
6732 : : /*
6733 : : * Decode PATHCONF response
6734 : : */
6735 : 0 : static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6736 : : struct nfs4_pathconf_res *res)
6737 : : {
6738 : : struct compound_hdr hdr;
6739 : : int status;
6740 : :
6741 : 0 : status = decode_compound_hdr(xdr, &hdr);
6742 [ # # ]: 0 : if (!status)
6743 : : status = decode_sequence(xdr, &res->seq_res, req);
6744 [ # # ]: 0 : if (!status)
6745 : : status = decode_putfh(xdr);
6746 [ # # ]: 0 : if (!status)
6747 : 0 : status = decode_pathconf(xdr, res->pathconf);
6748 : 0 : return status;
6749 : : }
6750 : :
6751 : : /*
6752 : : * Decode STATFS response
6753 : : */
6754 : 0 : static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6755 : : struct nfs4_statfs_res *res)
6756 : : {
6757 : : struct compound_hdr hdr;
6758 : : int status;
6759 : :
6760 : 0 : status = decode_compound_hdr(xdr, &hdr);
6761 [ # # ]: 0 : if (!status)
6762 : : status = decode_sequence(xdr, &res->seq_res, req);
6763 [ # # ]: 0 : if (!status)
6764 : : status = decode_putfh(xdr);
6765 [ # # ]: 0 : if (!status)
6766 : 0 : status = decode_statfs(xdr, res->fsstat);
6767 : 0 : return status;
6768 : : }
6769 : :
6770 : : /*
6771 : : * Decode GETATTR_BITMAP response
6772 : : */
6773 : 0 : static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6774 : : struct xdr_stream *xdr,
6775 : : struct nfs4_server_caps_res *res)
6776 : : {
6777 : : struct compound_hdr hdr;
6778 : : int status;
6779 : :
6780 : 0 : status = decode_compound_hdr(xdr, &hdr);
6781 [ # # ]: 0 : if (status)
6782 : : goto out;
6783 : : status = decode_sequence(xdr, &res->seq_res, req);
6784 : : if (status)
6785 : : goto out;
6786 : : status = decode_putfh(xdr);
6787 [ # # ]: 0 : if (status)
6788 : : goto out;
6789 : 0 : status = decode_server_caps(xdr, res);
6790 : : out:
6791 : 0 : return status;
6792 : : }
6793 : :
6794 : : /*
6795 : : * Decode RENEW response
6796 : : */
6797 : 0 : static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6798 : : void *__unused)
6799 : : {
6800 : : struct compound_hdr hdr;
6801 : : int status;
6802 : :
6803 : 0 : status = decode_compound_hdr(xdr, &hdr);
6804 [ # # ]: 0 : if (!status)
6805 : : status = decode_renew(xdr);
6806 : 0 : return status;
6807 : : }
6808 : :
6809 : : /*
6810 : : * Decode SETCLIENTID response
6811 : : */
6812 : 0 : static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6813 : : struct xdr_stream *xdr,
6814 : : struct nfs4_setclientid_res *res)
6815 : : {
6816 : : struct compound_hdr hdr;
6817 : : int status;
6818 : :
6819 : 0 : status = decode_compound_hdr(xdr, &hdr);
6820 [ # # ]: 0 : if (!status)
6821 : 0 : status = decode_setclientid(xdr, res);
6822 : 0 : return status;
6823 : : }
6824 : :
6825 : : /*
6826 : : * Decode SETCLIENTID_CONFIRM response
6827 : : */
6828 : 0 : static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6829 : : struct xdr_stream *xdr)
6830 : : {
6831 : : struct compound_hdr hdr;
6832 : : int status;
6833 : :
6834 : 0 : status = decode_compound_hdr(xdr, &hdr);
6835 [ # # ]: 0 : if (!status)
6836 : : status = decode_setclientid_confirm(xdr);
6837 : 0 : return status;
6838 : : }
6839 : :
6840 : : /*
6841 : : * Decode DELEGRETURN response
6842 : : */
6843 : 0 : static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6844 : : struct xdr_stream *xdr,
6845 : : struct nfs4_delegreturnres *res)
6846 : : {
6847 : : struct compound_hdr hdr;
6848 : : int status;
6849 : :
6850 : 0 : status = decode_compound_hdr(xdr, &hdr);
6851 [ # # ]: 0 : if (status)
6852 : : goto out;
6853 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6854 : : if (status)
6855 : : goto out;
6856 : : status = decode_putfh(xdr);
6857 [ # # ]: 0 : if (status != 0)
6858 : : goto out;
6859 : 0 : status = decode_getfattr(xdr, res->fattr, res->server);
6860 [ # # ]: 0 : if (status != 0)
6861 : : goto out;
6862 : : status = decode_delegreturn(xdr);
6863 : : out:
6864 : 0 : return status;
6865 : : }
6866 : :
6867 : : /*
6868 : : * Decode FS_LOCATIONS response
6869 : : */
6870 : 0 : static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6871 : : struct xdr_stream *xdr,
6872 : : struct nfs4_fs_locations_res *res)
6873 : : {
6874 : : struct compound_hdr hdr;
6875 : : int status;
6876 : :
6877 : 0 : status = decode_compound_hdr(xdr, &hdr);
6878 [ # # ]: 0 : if (status)
6879 : : goto out;
6880 : : status = decode_sequence(xdr, &res->seq_res, req);
6881 : : if (status)
6882 : : goto out;
6883 : : status = decode_putfh(xdr);
6884 [ # # ]: 0 : if (status)
6885 : : goto out;
6886 [ # # ]: 0 : if (res->migration) {
6887 : 0 : xdr_enter_page(xdr, PAGE_SIZE);
6888 : 0 : status = decode_getfattr_generic(xdr,
6889 : 0 : &res->fs_locations->fattr,
6890 : : NULL, res->fs_locations,
6891 : : NULL, res->fs_locations->server);
6892 [ # # ]: 0 : if (status)
6893 : : goto out;
6894 [ # # ]: 0 : if (res->renew)
6895 : : status = decode_renew(xdr);
6896 : : } else {
6897 : : status = decode_lookup(xdr);
6898 [ # # ]: 0 : if (status)
6899 : : goto out;
6900 : 0 : xdr_enter_page(xdr, PAGE_SIZE);
6901 : 0 : status = decode_getfattr_generic(xdr,
6902 : 0 : &res->fs_locations->fattr,
6903 : : NULL, res->fs_locations,
6904 : : NULL, res->fs_locations->server);
6905 : : }
6906 : : out:
6907 : 0 : return status;
6908 : : }
6909 : :
6910 : : /*
6911 : : * Decode SECINFO response
6912 : : */
6913 : 0 : static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6914 : : struct xdr_stream *xdr,
6915 : : struct nfs4_secinfo_res *res)
6916 : : {
6917 : : struct compound_hdr hdr;
6918 : : int status;
6919 : :
6920 : 0 : status = decode_compound_hdr(xdr, &hdr);
6921 [ # # ]: 0 : if (status)
6922 : : goto out;
6923 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6924 : : if (status)
6925 : : goto out;
6926 : : status = decode_putfh(xdr);
6927 [ # # ]: 0 : if (status)
6928 : : goto out;
6929 : 0 : status = decode_secinfo(xdr, res);
6930 : : out:
6931 : 0 : return status;
6932 : : }
6933 : :
6934 : : /*
6935 : : * Decode FSID_PRESENT response
6936 : : */
6937 : 0 : static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6938 : : struct xdr_stream *xdr,
6939 : : struct nfs4_fsid_present_res *res)
6940 : : {
6941 : : struct compound_hdr hdr;
6942 : : int status;
6943 : :
6944 : 0 : status = decode_compound_hdr(xdr, &hdr);
6945 [ # # ]: 0 : if (status)
6946 : : goto out;
6947 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
6948 : : if (status)
6949 : : goto out;
6950 : : status = decode_putfh(xdr);
6951 [ # # ]: 0 : if (status)
6952 : : goto out;
6953 : 0 : status = decode_getfh(xdr, res->fh);
6954 [ # # ]: 0 : if (status)
6955 : : goto out;
6956 [ # # ]: 0 : if (res->renew)
6957 : : status = decode_renew(xdr);
6958 : : out:
6959 : 0 : return status;
6960 : : }
6961 : :
6962 : : #if defined(CONFIG_NFS_V4_1)
6963 : : /*
6964 : : * Decode BIND_CONN_TO_SESSION response
6965 : : */
6966 : : static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6967 : : struct xdr_stream *xdr,
6968 : : void *res)
6969 : : {
6970 : : struct compound_hdr hdr;
6971 : : int status;
6972 : :
6973 : : status = decode_compound_hdr(xdr, &hdr);
6974 : : if (!status)
6975 : : status = decode_bind_conn_to_session(xdr, res);
6976 : : return status;
6977 : : }
6978 : :
6979 : : /*
6980 : : * Decode EXCHANGE_ID response
6981 : : */
6982 : : static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6983 : : struct xdr_stream *xdr,
6984 : : void *res)
6985 : : {
6986 : : struct compound_hdr hdr;
6987 : : int status;
6988 : :
6989 : : status = decode_compound_hdr(xdr, &hdr);
6990 : : if (!status)
6991 : : status = decode_exchange_id(xdr, res);
6992 : : return status;
6993 : : }
6994 : :
6995 : : /*
6996 : : * Decode CREATE_SESSION response
6997 : : */
6998 : : static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6999 : : struct xdr_stream *xdr,
7000 : : struct nfs41_create_session_res *res)
7001 : : {
7002 : : struct compound_hdr hdr;
7003 : : int status;
7004 : :
7005 : : status = decode_compound_hdr(xdr, &hdr);
7006 : : if (!status)
7007 : : status = decode_create_session(xdr, res);
7008 : : return status;
7009 : : }
7010 : :
7011 : : /*
7012 : : * Decode DESTROY_SESSION response
7013 : : */
7014 : : static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7015 : : struct xdr_stream *xdr,
7016 : : void *res)
7017 : : {
7018 : : struct compound_hdr hdr;
7019 : : int status;
7020 : :
7021 : : status = decode_compound_hdr(xdr, &hdr);
7022 : : if (!status)
7023 : : status = decode_destroy_session(xdr, res);
7024 : : return status;
7025 : : }
7026 : :
7027 : : /*
7028 : : * Decode DESTROY_CLIENTID response
7029 : : */
7030 : : static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7031 : : struct xdr_stream *xdr,
7032 : : void *res)
7033 : : {
7034 : : struct compound_hdr hdr;
7035 : : int status;
7036 : :
7037 : : status = decode_compound_hdr(xdr, &hdr);
7038 : : if (!status)
7039 : : status = decode_destroy_clientid(xdr, res);
7040 : : return status;
7041 : : }
7042 : :
7043 : : /*
7044 : : * Decode SEQUENCE response
7045 : : */
7046 : : static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7047 : : struct xdr_stream *xdr,
7048 : : struct nfs4_sequence_res *res)
7049 : : {
7050 : : struct compound_hdr hdr;
7051 : : int status;
7052 : :
7053 : : status = decode_compound_hdr(xdr, &hdr);
7054 : : if (!status)
7055 : : status = decode_sequence(xdr, res, rqstp);
7056 : : return status;
7057 : : }
7058 : :
7059 : : /*
7060 : : * Decode GET_LEASE_TIME response
7061 : : */
7062 : : static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7063 : : struct xdr_stream *xdr,
7064 : : struct nfs4_get_lease_time_res *res)
7065 : : {
7066 : : struct compound_hdr hdr;
7067 : : int status;
7068 : :
7069 : : status = decode_compound_hdr(xdr, &hdr);
7070 : : if (!status)
7071 : : status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
7072 : : if (!status)
7073 : : status = decode_putrootfh(xdr);
7074 : : if (!status)
7075 : : status = decode_fsinfo(xdr, res->lr_fsinfo);
7076 : : return status;
7077 : : }
7078 : :
7079 : : /*
7080 : : * Decode RECLAIM_COMPLETE response
7081 : : */
7082 : : static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7083 : : struct xdr_stream *xdr,
7084 : : struct nfs41_reclaim_complete_res *res)
7085 : : {
7086 : : struct compound_hdr hdr;
7087 : : int status;
7088 : :
7089 : : status = decode_compound_hdr(xdr, &hdr);
7090 : : if (!status)
7091 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7092 : : if (!status)
7093 : : status = decode_reclaim_complete(xdr, (void *)NULL);
7094 : : return status;
7095 : : }
7096 : :
7097 : : /*
7098 : : * Decode GETDEVICELIST response
7099 : : */
7100 : : static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
7101 : : struct xdr_stream *xdr,
7102 : : struct nfs4_getdevicelist_res *res)
7103 : : {
7104 : : struct compound_hdr hdr;
7105 : : int status;
7106 : :
7107 : : dprintk("encoding getdevicelist!\n");
7108 : :
7109 : : status = decode_compound_hdr(xdr, &hdr);
7110 : : if (status != 0)
7111 : : goto out;
7112 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7113 : : if (status != 0)
7114 : : goto out;
7115 : : status = decode_putfh(xdr);
7116 : : if (status != 0)
7117 : : goto out;
7118 : : status = decode_getdevicelist(xdr, res->devlist);
7119 : : out:
7120 : : return status;
7121 : : }
7122 : :
7123 : : /*
7124 : : * Decode GETDEVINFO response
7125 : : */
7126 : : static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7127 : : struct xdr_stream *xdr,
7128 : : struct nfs4_getdeviceinfo_res *res)
7129 : : {
7130 : : struct compound_hdr hdr;
7131 : : int status;
7132 : :
7133 : : status = decode_compound_hdr(xdr, &hdr);
7134 : : if (status != 0)
7135 : : goto out;
7136 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7137 : : if (status != 0)
7138 : : goto out;
7139 : : status = decode_getdeviceinfo(xdr, res->pdev);
7140 : : out:
7141 : : return status;
7142 : : }
7143 : :
7144 : : /*
7145 : : * Decode LAYOUTGET response
7146 : : */
7147 : : static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7148 : : struct xdr_stream *xdr,
7149 : : struct nfs4_layoutget_res *res)
7150 : : {
7151 : : struct compound_hdr hdr;
7152 : : int status;
7153 : :
7154 : : status = decode_compound_hdr(xdr, &hdr);
7155 : : if (status)
7156 : : goto out;
7157 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7158 : : if (status)
7159 : : goto out;
7160 : : status = decode_putfh(xdr);
7161 : : if (status)
7162 : : goto out;
7163 : : status = decode_layoutget(xdr, rqstp, res);
7164 : : out:
7165 : : return status;
7166 : : }
7167 : :
7168 : : /*
7169 : : * Decode LAYOUTRETURN response
7170 : : */
7171 : : static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7172 : : struct xdr_stream *xdr,
7173 : : struct nfs4_layoutreturn_res *res)
7174 : : {
7175 : : struct compound_hdr hdr;
7176 : : int status;
7177 : :
7178 : : status = decode_compound_hdr(xdr, &hdr);
7179 : : if (status)
7180 : : goto out;
7181 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7182 : : if (status)
7183 : : goto out;
7184 : : status = decode_putfh(xdr);
7185 : : if (status)
7186 : : goto out;
7187 : : status = decode_layoutreturn(xdr, res);
7188 : : out:
7189 : : return status;
7190 : : }
7191 : :
7192 : : /*
7193 : : * Decode LAYOUTCOMMIT response
7194 : : */
7195 : : static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7196 : : struct xdr_stream *xdr,
7197 : : struct nfs4_layoutcommit_res *res)
7198 : : {
7199 : : struct compound_hdr hdr;
7200 : : int status;
7201 : :
7202 : : status = decode_compound_hdr(xdr, &hdr);
7203 : : if (status)
7204 : : goto out;
7205 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7206 : : if (status)
7207 : : goto out;
7208 : : status = decode_putfh(xdr);
7209 : : if (status)
7210 : : goto out;
7211 : : status = decode_layoutcommit(xdr, rqstp, res);
7212 : : if (status)
7213 : : goto out;
7214 : : decode_getfattr(xdr, res->fattr, res->server);
7215 : : out:
7216 : : return status;
7217 : : }
7218 : :
7219 : : /*
7220 : : * Decode SECINFO_NO_NAME response
7221 : : */
7222 : : static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7223 : : struct xdr_stream *xdr,
7224 : : struct nfs4_secinfo_res *res)
7225 : : {
7226 : : struct compound_hdr hdr;
7227 : : int status;
7228 : :
7229 : : status = decode_compound_hdr(xdr, &hdr);
7230 : : if (status)
7231 : : goto out;
7232 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7233 : : if (status)
7234 : : goto out;
7235 : : status = decode_putrootfh(xdr);
7236 : : if (status)
7237 : : goto out;
7238 : : status = decode_secinfo_no_name(xdr, res);
7239 : : out:
7240 : : return status;
7241 : : }
7242 : :
7243 : : /*
7244 : : * Decode TEST_STATEID response
7245 : : */
7246 : : static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7247 : : struct xdr_stream *xdr,
7248 : : struct nfs41_test_stateid_res *res)
7249 : : {
7250 : : struct compound_hdr hdr;
7251 : : int status;
7252 : :
7253 : : status = decode_compound_hdr(xdr, &hdr);
7254 : : if (status)
7255 : : goto out;
7256 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7257 : : if (status)
7258 : : goto out;
7259 : : status = decode_test_stateid(xdr, res);
7260 : : out:
7261 : : return status;
7262 : : }
7263 : :
7264 : : /*
7265 : : * Decode FREE_STATEID response
7266 : : */
7267 : : static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7268 : : struct xdr_stream *xdr,
7269 : : struct nfs41_free_stateid_res *res)
7270 : : {
7271 : : struct compound_hdr hdr;
7272 : : int status;
7273 : :
7274 : : status = decode_compound_hdr(xdr, &hdr);
7275 : : if (status)
7276 : : goto out;
7277 : : status = decode_sequence(xdr, &res->seq_res, rqstp);
7278 : : if (status)
7279 : : goto out;
7280 : : status = decode_free_stateid(xdr, res);
7281 : : out:
7282 : : return status;
7283 : : }
7284 : : #endif /* CONFIG_NFS_V4_1 */
7285 : :
7286 : : /**
7287 : : * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7288 : : * the local page cache.
7289 : : * @xdr: XDR stream where entry resides
7290 : : * @entry: buffer to fill in with entry data
7291 : : * @plus: boolean indicating whether this should be a readdirplus entry
7292 : : *
7293 : : * Returns zero if successful, otherwise a negative errno value is
7294 : : * returned.
7295 : : *
7296 : : * This function is not invoked during READDIR reply decoding, but
7297 : : * rather whenever an application invokes the getdents(2) system call
7298 : : * on a directory already in our cache.
7299 : : */
7300 : 0 : int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7301 : : int plus)
7302 : : {
7303 : : unsigned int savep;
7304 : 0 : uint32_t bitmap[3] = {0};
7305 : : uint32_t len;
7306 : 0 : __be32 *p = xdr_inline_decode(xdr, 4);
7307 [ # # ]: 0 : if (unlikely(!p))
7308 : : goto out_overflow;
7309 [ # # ]: 0 : if (*p == xdr_zero) {
7310 : 0 : p = xdr_inline_decode(xdr, 4);
7311 [ # # ]: 0 : if (unlikely(!p))
7312 : : goto out_overflow;
7313 [ # # ]: 0 : if (*p == xdr_zero)
7314 : : return -EAGAIN;
7315 : 0 : entry->eof = 1;
7316 : 0 : return -EBADCOOKIE;
7317 : : }
7318 : :
7319 : 0 : p = xdr_inline_decode(xdr, 12);
7320 [ # # ]: 0 : if (unlikely(!p))
7321 : : goto out_overflow;
7322 : 0 : entry->prev_cookie = entry->cookie;
7323 : : p = xdr_decode_hyper(p, &entry->cookie);
7324 : 0 : entry->len = be32_to_cpup(p);
7325 : :
7326 : 0 : p = xdr_inline_decode(xdr, entry->len);
7327 [ # # ]: 0 : if (unlikely(!p))
7328 : : goto out_overflow;
7329 : 0 : entry->name = (const char *) p;
7330 : :
7331 : : /*
7332 : : * In case the server doesn't return an inode number,
7333 : : * we fake one here. (We don't use inode number 0,
7334 : : * since glibc seems to choke on it...)
7335 : : */
7336 : 0 : entry->ino = 1;
7337 : 0 : entry->fattr->valid = 0;
7338 : :
7339 [ # # ]: 0 : if (decode_attr_bitmap(xdr, bitmap) < 0)
7340 : : goto out_overflow;
7341 : :
7342 [ # # ]: 0 : if (decode_attr_length(xdr, &len, &savep) < 0)
7343 : : goto out_overflow;
7344 : :
7345 [ # # ]: 0 : if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7346 : 0 : NULL, entry->label, entry->server) < 0)
7347 : : goto out_overflow;
7348 [ # # ]: 0 : if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7349 : 0 : entry->ino = entry->fattr->mounted_on_fileid;
7350 [ # # ]: 0 : else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7351 : 0 : entry->ino = entry->fattr->fileid;
7352 : :
7353 : 0 : entry->d_type = DT_UNKNOWN;
7354 [ # # ]: 0 : if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7355 : 0 : entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7356 : :
7357 : : return 0;
7358 : :
7359 : : out_overflow:
7360 : : print_overflow_msg(__func__, xdr);
7361 : : return -EAGAIN;
7362 : : }
7363 : :
7364 : : /*
7365 : : * We need to translate between nfs status return values and
7366 : : * the local errno values which may not be the same.
7367 : : */
7368 : : static struct {
7369 : : int stat;
7370 : : int errno;
7371 : : } nfs_errtbl[] = {
7372 : : { NFS4_OK, 0 },
7373 : : { NFS4ERR_PERM, -EPERM },
7374 : : { NFS4ERR_NOENT, -ENOENT },
7375 : : { NFS4ERR_IO, -errno_NFSERR_IO},
7376 : : { NFS4ERR_NXIO, -ENXIO },
7377 : : { NFS4ERR_ACCESS, -EACCES },
7378 : : { NFS4ERR_EXIST, -EEXIST },
7379 : : { NFS4ERR_XDEV, -EXDEV },
7380 : : { NFS4ERR_NOTDIR, -ENOTDIR },
7381 : : { NFS4ERR_ISDIR, -EISDIR },
7382 : : { NFS4ERR_INVAL, -EINVAL },
7383 : : { NFS4ERR_FBIG, -EFBIG },
7384 : : { NFS4ERR_NOSPC, -ENOSPC },
7385 : : { NFS4ERR_ROFS, -EROFS },
7386 : : { NFS4ERR_MLINK, -EMLINK },
7387 : : { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7388 : : { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7389 : : { NFS4ERR_DQUOT, -EDQUOT },
7390 : : { NFS4ERR_STALE, -ESTALE },
7391 : : { NFS4ERR_BADHANDLE, -EBADHANDLE },
7392 : : { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7393 : : { NFS4ERR_NOTSUPP, -ENOTSUPP },
7394 : : { NFS4ERR_TOOSMALL, -ETOOSMALL },
7395 : : { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7396 : : { NFS4ERR_BADTYPE, -EBADTYPE },
7397 : : { NFS4ERR_LOCKED, -EAGAIN },
7398 : : { NFS4ERR_SYMLINK, -ELOOP },
7399 : : { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7400 : : { NFS4ERR_DEADLOCK, -EDEADLK },
7401 : : { -1, -EIO }
7402 : : };
7403 : :
7404 : : /*
7405 : : * Convert an NFS error code to a local one.
7406 : : * This one is used jointly by NFSv2 and NFSv3.
7407 : : */
7408 : : static int
7409 : : nfs4_stat_to_errno(int stat)
7410 : : {
7411 : : int i;
7412 [ # # ][ # # ]: 0 : for (i = 0; nfs_errtbl[i].stat != -1; i++) {
[ # # ]
7413 [ # # ][ # # ]: 0 : if (nfs_errtbl[i].stat == stat)
[ # # ]
7414 : 0 : return nfs_errtbl[i].errno;
7415 : : }
7416 [ # # ][ # # ]: 0 : if (stat <= 10000 || stat > 10100) {
[ # # ]
7417 : : /* The server is looney tunes. */
7418 : : return -EREMOTEIO;
7419 : : }
7420 : : /* If we cannot translate the error, the recovery routines should
7421 : : * handle it.
7422 : : * Note: remaining NFSv4 error codes have values > 10000, so should
7423 : : * not conflict with native Linux error codes.
7424 : : */
7425 : 0 : return -stat;
7426 : : }
7427 : :
7428 : : #define PROC(proc, argtype, restype) \
7429 : : [NFSPROC4_CLNT_##proc] = { \
7430 : : .p_proc = NFSPROC4_COMPOUND, \
7431 : : .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7432 : : .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7433 : : .p_arglen = NFS4_##argtype##_sz, \
7434 : : .p_replen = NFS4_##restype##_sz, \
7435 : : .p_statidx = NFSPROC4_CLNT_##proc, \
7436 : : .p_name = #proc, \
7437 : : }
7438 : :
7439 : : struct rpc_procinfo nfs4_procedures[] = {
7440 : : PROC(READ, enc_read, dec_read),
7441 : : PROC(WRITE, enc_write, dec_write),
7442 : : PROC(COMMIT, enc_commit, dec_commit),
7443 : : PROC(OPEN, enc_open, dec_open),
7444 : : PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7445 : : PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7446 : : PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7447 : : PROC(CLOSE, enc_close, dec_close),
7448 : : PROC(SETATTR, enc_setattr, dec_setattr),
7449 : : PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7450 : : PROC(RENEW, enc_renew, dec_renew),
7451 : : PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7452 : : PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7453 : : PROC(LOCK, enc_lock, dec_lock),
7454 : : PROC(LOCKT, enc_lockt, dec_lockt),
7455 : : PROC(LOCKU, enc_locku, dec_locku),
7456 : : PROC(ACCESS, enc_access, dec_access),
7457 : : PROC(GETATTR, enc_getattr, dec_getattr),
7458 : : PROC(LOOKUP, enc_lookup, dec_lookup),
7459 : : PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7460 : : PROC(REMOVE, enc_remove, dec_remove),
7461 : : PROC(RENAME, enc_rename, dec_rename),
7462 : : PROC(LINK, enc_link, dec_link),
7463 : : PROC(SYMLINK, enc_symlink, dec_symlink),
7464 : : PROC(CREATE, enc_create, dec_create),
7465 : : PROC(PATHCONF, enc_pathconf, dec_pathconf),
7466 : : PROC(STATFS, enc_statfs, dec_statfs),
7467 : : PROC(READLINK, enc_readlink, dec_readlink),
7468 : : PROC(READDIR, enc_readdir, dec_readdir),
7469 : : PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7470 : : PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7471 : : PROC(GETACL, enc_getacl, dec_getacl),
7472 : : PROC(SETACL, enc_setacl, dec_setacl),
7473 : : PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7474 : : PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7475 : : PROC(SECINFO, enc_secinfo, dec_secinfo),
7476 : : PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
7477 : : #if defined(CONFIG_NFS_V4_1)
7478 : : PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7479 : : PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7480 : : PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7481 : : PROC(SEQUENCE, enc_sequence, dec_sequence),
7482 : : PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7483 : : PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7484 : : PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7485 : : PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7486 : : PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7487 : : PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7488 : : PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7489 : : PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7490 : : PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7491 : : PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
7492 : : PROC(BIND_CONN_TO_SESSION,
7493 : : enc_bind_conn_to_session, dec_bind_conn_to_session),
7494 : : PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7495 : : #endif /* CONFIG_NFS_V4_1 */
7496 : : };
7497 : :
7498 : : const struct rpc_version nfs_version4 = {
7499 : : .number = 4,
7500 : : .nrprocs = ARRAY_SIZE(nfs4_procedures),
7501 : : .procs = nfs4_procedures
7502 : : };
7503 : :
7504 : : /*
7505 : : * Local variables:
7506 : : * c-basic-offset: 8
7507 : : * End:
7508 : : */
|