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