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