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