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