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