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