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