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