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