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/slab.h> 42 #include <linux/utsname.h> 43 #include <linux/errno.h> 44 #include <linux/string.h> 45 #include <linux/in.h> 46 #include <linux/pagemap.h> 47 #include <linux/proc_fs.h> 48 #include <linux/kdev_t.h> 49 #include <linux/sunrpc/clnt.h> 50 #include <linux/nfs.h> 51 #include <linux/nfs4.h> 52 #include <linux/nfs_fs.h> 53 #include <linux/nfs_idmap.h> 54 #include "nfs4_fs.h" 55 56 #define NFSDBG_FACILITY NFSDBG_XDR 57 58 /* Mapping from NFS error code to "errno" error code. */ 59 #define errno_NFSERR_IO EIO 60 61 static int nfs4_stat_to_errno(int); 62 63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 64 #ifdef DEBUG 65 #define NFS4_MAXTAGLEN 20 66 #else 67 #define NFS4_MAXTAGLEN 0 68 #endif 69 70 /* lock,open owner id: 71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2) 72 */ 73 #define owner_id_maxsz (1 + 1) 74 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 75 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 76 #define op_encode_hdr_maxsz (1) 77 #define op_decode_hdr_maxsz (2) 78 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 79 (NFS4_FHSIZE >> 2)) 80 #define decode_putfh_maxsz (op_decode_hdr_maxsz) 81 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 82 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 83 #define encode_getfh_maxsz (op_encode_hdr_maxsz) 84 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 85 ((3+NFS4_FHSIZE) >> 2)) 86 #define nfs4_fattr_bitmap_maxsz 3 87 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 88 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 89 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 90 /* This is based on getfattr, which uses the most attributes: */ 91 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 92 3 + 3 + 3 + 2 * nfs4_name_maxsz)) 93 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 94 nfs4_fattr_value_maxsz) 95 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 96 #define encode_savefh_maxsz (op_encode_hdr_maxsz) 97 #define decode_savefh_maxsz (op_decode_hdr_maxsz) 98 #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 99 #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 100 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2) 101 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11) 102 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 103 #define decode_renew_maxsz (op_decode_hdr_maxsz) 104 #define encode_setclientid_maxsz \ 105 (op_encode_hdr_maxsz + \ 106 4 /*server->ip_addr*/ + \ 107 1 /*Netid*/ + \ 108 6 /*uaddr*/ + \ 109 6 + (NFS4_VERIFIER_SIZE >> 2)) 110 #define decode_setclientid_maxsz \ 111 (op_decode_hdr_maxsz + \ 112 2 + \ 113 1024) /* large value for CLID_INUSE */ 114 #define encode_setclientid_confirm_maxsz \ 115 (op_encode_hdr_maxsz + \ 116 3 + (NFS4_VERIFIER_SIZE >> 2)) 117 #define decode_setclientid_confirm_maxsz \ 118 (op_decode_hdr_maxsz) 119 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \ 120 1 + ((3 + NFS4_FHSIZE) >> 2)) 121 #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 122 nfs4_name_maxsz) 123 #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 124 2 * nfs4_name_maxsz) 125 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5) 126 #define encode_link_maxsz (op_encode_hdr_maxsz + \ 127 nfs4_name_maxsz) 128 #define decode_link_maxsz (op_decode_hdr_maxsz + 5) 129 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 130 1 + nfs4_name_maxsz + \ 131 1 + \ 132 nfs4_fattr_maxsz) 133 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 134 #define encode_create_maxsz (op_encode_hdr_maxsz + \ 135 2 + nfs4_name_maxsz + \ 136 nfs4_fattr_maxsz) 137 #define decode_create_maxsz (op_decode_hdr_maxsz + 8) 138 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 139 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 140 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 141 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 142 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 143 encode_putfh_maxsz + \ 144 op_encode_hdr_maxsz + 7) 145 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 146 decode_putfh_maxsz + \ 147 op_decode_hdr_maxsz + 2) 148 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 149 encode_putfh_maxsz + \ 150 op_encode_hdr_maxsz) 151 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 152 decode_putfh_maxsz + \ 153 op_decode_hdr_maxsz) 154 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 155 encode_putfh_maxsz + \ 156 op_encode_hdr_maxsz + 9) 157 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 158 decode_putfh_maxsz + \ 159 op_decode_hdr_maxsz + 2) 160 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 161 encode_putfh_maxsz + \ 162 op_encode_hdr_maxsz + 8 + \ 163 encode_getattr_maxsz) 164 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 165 decode_putfh_maxsz + \ 166 op_decode_hdr_maxsz + 4 + \ 167 decode_getattr_maxsz) 168 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 169 encode_putfh_maxsz + \ 170 op_encode_hdr_maxsz + 3 + \ 171 encode_getattr_maxsz) 172 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 173 decode_putfh_maxsz + \ 174 op_decode_hdr_maxsz + 2 + \ 175 decode_getattr_maxsz) 176 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 177 encode_putfh_maxsz + \ 178 op_encode_hdr_maxsz + \ 179 13 + 3 + 2 + 64 + \ 180 encode_getattr_maxsz + \ 181 encode_getfh_maxsz) 182 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 183 decode_putfh_maxsz + \ 184 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \ 185 decode_getattr_maxsz + \ 186 decode_getfh_maxsz) 187 #define NFS4_enc_open_confirm_sz \ 188 (compound_encode_hdr_maxsz + \ 189 encode_putfh_maxsz + \ 190 op_encode_hdr_maxsz + 5) 191 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \ 192 decode_putfh_maxsz + \ 193 op_decode_hdr_maxsz + 4) 194 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 195 encode_putfh_maxsz + \ 196 op_encode_hdr_maxsz + \ 197 11) 198 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 199 decode_putfh_maxsz + \ 200 op_decode_hdr_maxsz + \ 201 4 + 5 + 2 + 3) 202 #define NFS4_enc_open_downgrade_sz \ 203 (compound_encode_hdr_maxsz + \ 204 encode_putfh_maxsz + \ 205 op_encode_hdr_maxsz + 7 + \ 206 encode_getattr_maxsz) 207 #define NFS4_dec_open_downgrade_sz \ 208 (compound_decode_hdr_maxsz + \ 209 decode_putfh_maxsz + \ 210 op_decode_hdr_maxsz + 4 + \ 211 decode_getattr_maxsz) 212 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 213 encode_putfh_maxsz + \ 214 op_encode_hdr_maxsz + 5 + \ 215 encode_getattr_maxsz) 216 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 217 decode_putfh_maxsz + \ 218 op_decode_hdr_maxsz + 4 + \ 219 decode_getattr_maxsz) 220 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 221 encode_putfh_maxsz + \ 222 op_encode_hdr_maxsz + 4 + \ 223 nfs4_fattr_maxsz + \ 224 encode_getattr_maxsz) 225 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 226 decode_putfh_maxsz + \ 227 op_decode_hdr_maxsz + 3) 228 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 229 encode_putfh_maxsz + \ 230 encode_fsinfo_maxsz) 231 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 232 decode_putfh_maxsz + \ 233 decode_fsinfo_maxsz) 234 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 235 encode_renew_maxsz) 236 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 237 decode_renew_maxsz) 238 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 239 encode_setclientid_maxsz) 240 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 241 decode_setclientid_maxsz) 242 #define NFS4_enc_setclientid_confirm_sz \ 243 (compound_encode_hdr_maxsz + \ 244 encode_setclientid_confirm_maxsz + \ 245 encode_putrootfh_maxsz + \ 246 encode_fsinfo_maxsz) 247 #define NFS4_dec_setclientid_confirm_sz \ 248 (compound_decode_hdr_maxsz + \ 249 decode_setclientid_confirm_maxsz + \ 250 decode_putrootfh_maxsz + \ 251 decode_fsinfo_maxsz) 252 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 253 encode_putfh_maxsz + \ 254 encode_getattr_maxsz + \ 255 op_encode_hdr_maxsz + \ 256 1 + 1 + 2 + 2 + \ 257 1 + 4 + 1 + 2 + \ 258 owner_id_maxsz) 259 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 260 decode_putfh_maxsz + \ 261 decode_getattr_maxsz + \ 262 op_decode_hdr_maxsz + \ 263 2 + 2 + 1 + 2 + \ 264 owner_id_maxsz) 265 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 266 encode_putfh_maxsz + \ 267 encode_getattr_maxsz + \ 268 op_encode_hdr_maxsz + \ 269 1 + 2 + 2 + 2 + \ 270 owner_id_maxsz) 271 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz) 272 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 273 encode_putfh_maxsz + \ 274 encode_getattr_maxsz + \ 275 op_encode_hdr_maxsz + \ 276 1 + 1 + 4 + 2 + 2) 277 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 278 decode_putfh_maxsz + \ 279 decode_getattr_maxsz + \ 280 op_decode_hdr_maxsz + 4) 281 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 282 encode_putfh_maxsz + \ 283 op_encode_hdr_maxsz + 1) 284 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 285 decode_putfh_maxsz + \ 286 op_decode_hdr_maxsz + 2) 287 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 288 encode_putfh_maxsz + \ 289 encode_getattr_maxsz) 290 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 291 decode_putfh_maxsz + \ 292 decode_getattr_maxsz) 293 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 294 encode_putfh_maxsz + \ 295 encode_lookup_maxsz + \ 296 encode_getattr_maxsz + \ 297 encode_getfh_maxsz) 298 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 299 decode_putfh_maxsz + \ 300 op_decode_hdr_maxsz + \ 301 decode_getattr_maxsz + \ 302 decode_getfh_maxsz) 303 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 304 encode_putrootfh_maxsz + \ 305 encode_getattr_maxsz + \ 306 encode_getfh_maxsz) 307 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 308 decode_putrootfh_maxsz + \ 309 decode_getattr_maxsz + \ 310 decode_getfh_maxsz) 311 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 312 encode_putfh_maxsz + \ 313 encode_remove_maxsz + \ 314 encode_getattr_maxsz) 315 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 316 decode_putfh_maxsz + \ 317 op_decode_hdr_maxsz + 5 + \ 318 decode_getattr_maxsz) 319 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 320 encode_putfh_maxsz + \ 321 encode_savefh_maxsz + \ 322 encode_putfh_maxsz + \ 323 encode_rename_maxsz + \ 324 encode_getattr_maxsz + \ 325 encode_restorefh_maxsz + \ 326 encode_getattr_maxsz) 327 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 328 decode_putfh_maxsz + \ 329 decode_savefh_maxsz + \ 330 decode_putfh_maxsz + \ 331 decode_rename_maxsz + \ 332 decode_getattr_maxsz + \ 333 decode_restorefh_maxsz + \ 334 decode_getattr_maxsz) 335 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 336 encode_putfh_maxsz + \ 337 encode_savefh_maxsz + \ 338 encode_putfh_maxsz + \ 339 encode_link_maxsz + \ 340 decode_getattr_maxsz + \ 341 encode_restorefh_maxsz + \ 342 decode_getattr_maxsz) 343 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 344 decode_putfh_maxsz + \ 345 decode_savefh_maxsz + \ 346 decode_putfh_maxsz + \ 347 decode_link_maxsz + \ 348 decode_getattr_maxsz + \ 349 decode_restorefh_maxsz + \ 350 decode_getattr_maxsz) 351 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 352 encode_putfh_maxsz + \ 353 encode_symlink_maxsz + \ 354 encode_getattr_maxsz + \ 355 encode_getfh_maxsz) 356 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 357 decode_putfh_maxsz + \ 358 decode_symlink_maxsz + \ 359 decode_getattr_maxsz + \ 360 decode_getfh_maxsz) 361 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 362 encode_putfh_maxsz + \ 363 encode_savefh_maxsz + \ 364 encode_create_maxsz + \ 365 encode_getfh_maxsz + \ 366 encode_getattr_maxsz + \ 367 encode_restorefh_maxsz + \ 368 encode_getattr_maxsz) 369 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 370 decode_putfh_maxsz + \ 371 decode_savefh_maxsz + \ 372 decode_create_maxsz + \ 373 decode_getfh_maxsz + \ 374 decode_getattr_maxsz + \ 375 decode_restorefh_maxsz + \ 376 decode_getattr_maxsz) 377 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 378 encode_putfh_maxsz + \ 379 encode_getattr_maxsz) 380 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 381 decode_putfh_maxsz + \ 382 decode_getattr_maxsz) 383 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 384 encode_putfh_maxsz + \ 385 encode_getattr_maxsz) 386 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 387 decode_putfh_maxsz + \ 388 op_decode_hdr_maxsz + 12) 389 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 390 encode_putfh_maxsz + \ 391 encode_getattr_maxsz) 392 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 393 decode_putfh_maxsz + \ 394 decode_getattr_maxsz) 395 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 396 encode_putfh_maxsz + \ 397 encode_delegreturn_maxsz + \ 398 encode_getattr_maxsz) 399 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 400 decode_delegreturn_maxsz + \ 401 decode_getattr_maxsz) 402 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 403 encode_putfh_maxsz + \ 404 encode_getattr_maxsz) 405 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 406 decode_putfh_maxsz + \ 407 op_decode_hdr_maxsz + \ 408 nfs4_fattr_bitmap_maxsz + 1) 409 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 410 encode_putfh_maxsz + \ 411 op_encode_hdr_maxsz + 4 + \ 412 nfs4_fattr_bitmap_maxsz + 1) 413 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 414 decode_putfh_maxsz + \ 415 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 416 #define NFS4_enc_fs_locations_sz \ 417 (compound_encode_hdr_maxsz + \ 418 encode_putfh_maxsz + \ 419 encode_getattr_maxsz) 420 #define NFS4_dec_fs_locations_sz \ 421 (compound_decode_hdr_maxsz + \ 422 decode_putfh_maxsz + \ 423 op_decode_hdr_maxsz + \ 424 nfs4_fattr_bitmap_maxsz) 425 426 static struct { 427 unsigned int mode; 428 unsigned int nfs2type; 429 } nfs_type2fmt[] = { 430 { 0, NFNON }, 431 { S_IFREG, NFREG }, 432 { S_IFDIR, NFDIR }, 433 { S_IFBLK, NFBLK }, 434 { S_IFCHR, NFCHR }, 435 { S_IFLNK, NFLNK }, 436 { S_IFSOCK, NFSOCK }, 437 { S_IFIFO, NFFIFO }, 438 { 0, NFNON }, 439 { 0, NFNON }, 440 }; 441 442 struct compound_hdr { 443 int32_t status; 444 uint32_t nops; 445 uint32_t taglen; 446 char * tag; 447 }; 448 449 /* 450 * START OF "GENERIC" ENCODE ROUTINES. 451 * These may look a little ugly since they are imported from a "generic" 452 * set of XDR encode/decode routines which are intended to be shared by 453 * all of our NFSv4 implementations (OpenBSD, MacOS X...). 454 * 455 * If the pain of reading these is too great, it should be a straightforward 456 * task to translate them into Linux-specific versions which are more 457 * consistent with the style used in NFSv2/v3... 458 */ 459 #define WRITE32(n) *p++ = htonl(n) 460 #define WRITE64(n) do { \ 461 *p++ = htonl((uint32_t)((n) >> 32)); \ 462 *p++ = htonl((uint32_t)(n)); \ 463 } while (0) 464 #define WRITEMEM(ptr,nbytes) do { \ 465 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \ 466 } while (0) 467 468 #define RESERVE_SPACE(nbytes) do { \ 469 p = xdr_reserve_space(xdr, nbytes); \ 470 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \ 471 BUG_ON(!p); \ 472 } while (0) 473 474 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 475 { 476 __be32 *p; 477 478 p = xdr_reserve_space(xdr, 4 + len); 479 BUG_ON(p == NULL); 480 xdr_encode_opaque(p, str, len); 481 } 482 483 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 484 { 485 __be32 *p; 486 487 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); 488 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 489 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2)); 490 WRITE32(hdr->taglen); 491 WRITEMEM(hdr->tag, hdr->taglen); 492 WRITE32(NFS4_MINOR_VERSION); 493 WRITE32(hdr->nops); 494 return 0; 495 } 496 497 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 498 { 499 __be32 *p; 500 501 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); 502 BUG_ON(p == NULL); 503 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); 504 } 505 506 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) 507 { 508 char owner_name[IDMAP_NAMESZ]; 509 char owner_group[IDMAP_NAMESZ]; 510 int owner_namelen = 0; 511 int owner_grouplen = 0; 512 __be32 *p; 513 __be32 *q; 514 int len; 515 uint32_t bmval0 = 0; 516 uint32_t bmval1 = 0; 517 int status; 518 519 /* 520 * We reserve enough space to write the entire attribute buffer at once. 521 * In the worst-case, this would be 522 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 523 * = 36 bytes, plus any contribution from variable-length fields 524 * such as owner/group. 525 */ 526 len = 16; 527 528 /* Sigh */ 529 if (iap->ia_valid & ATTR_SIZE) 530 len += 8; 531 if (iap->ia_valid & ATTR_MODE) 532 len += 4; 533 if (iap->ia_valid & ATTR_UID) { 534 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name); 535 if (owner_namelen < 0) { 536 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n", 537 iap->ia_uid); 538 /* XXX */ 539 strcpy(owner_name, "nobody"); 540 owner_namelen = sizeof("nobody") - 1; 541 /* goto out; */ 542 } 543 len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 544 } 545 if (iap->ia_valid & ATTR_GID) { 546 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group); 547 if (owner_grouplen < 0) { 548 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n", 549 iap->ia_gid); 550 strcpy(owner_group, "nobody"); 551 owner_grouplen = sizeof("nobody") - 1; 552 /* goto out; */ 553 } 554 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 555 } 556 if (iap->ia_valid & ATTR_ATIME_SET) 557 len += 16; 558 else if (iap->ia_valid & ATTR_ATIME) 559 len += 4; 560 if (iap->ia_valid & ATTR_MTIME_SET) 561 len += 16; 562 else if (iap->ia_valid & ATTR_MTIME) 563 len += 4; 564 RESERVE_SPACE(len); 565 566 /* 567 * We write the bitmap length now, but leave the bitmap and the attribute 568 * buffer length to be backfilled at the end of this routine. 569 */ 570 WRITE32(2); 571 q = p; 572 p += 3; 573 574 if (iap->ia_valid & ATTR_SIZE) { 575 bmval0 |= FATTR4_WORD0_SIZE; 576 WRITE64(iap->ia_size); 577 } 578 if (iap->ia_valid & ATTR_MODE) { 579 bmval1 |= FATTR4_WORD1_MODE; 580 WRITE32(iap->ia_mode & S_IALLUGO); 581 } 582 if (iap->ia_valid & ATTR_UID) { 583 bmval1 |= FATTR4_WORD1_OWNER; 584 WRITE32(owner_namelen); 585 WRITEMEM(owner_name, owner_namelen); 586 } 587 if (iap->ia_valid & ATTR_GID) { 588 bmval1 |= FATTR4_WORD1_OWNER_GROUP; 589 WRITE32(owner_grouplen); 590 WRITEMEM(owner_group, owner_grouplen); 591 } 592 if (iap->ia_valid & ATTR_ATIME_SET) { 593 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 594 WRITE32(NFS4_SET_TO_CLIENT_TIME); 595 WRITE32(0); 596 WRITE32(iap->ia_mtime.tv_sec); 597 WRITE32(iap->ia_mtime.tv_nsec); 598 } 599 else if (iap->ia_valid & ATTR_ATIME) { 600 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 601 WRITE32(NFS4_SET_TO_SERVER_TIME); 602 } 603 if (iap->ia_valid & ATTR_MTIME_SET) { 604 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 605 WRITE32(NFS4_SET_TO_CLIENT_TIME); 606 WRITE32(0); 607 WRITE32(iap->ia_mtime.tv_sec); 608 WRITE32(iap->ia_mtime.tv_nsec); 609 } 610 else if (iap->ia_valid & ATTR_MTIME) { 611 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 612 WRITE32(NFS4_SET_TO_SERVER_TIME); 613 } 614 615 /* 616 * Now we backfill the bitmap and the attribute buffer length. 617 */ 618 if (len != ((char *)p - (char *)q) + 4) { 619 printk ("encode_attr: Attr length calculation error! %u != %Zu\n", 620 len, ((char *)p - (char *)q) + 4); 621 BUG(); 622 } 623 len = (char *)p - (char *)q - 12; 624 *q++ = htonl(bmval0); 625 *q++ = htonl(bmval1); 626 *q++ = htonl(len); 627 628 status = 0; 629 /* out: */ 630 return status; 631 } 632 633 static int encode_access(struct xdr_stream *xdr, u32 access) 634 { 635 __be32 *p; 636 637 RESERVE_SPACE(8); 638 WRITE32(OP_ACCESS); 639 WRITE32(access); 640 641 return 0; 642 } 643 644 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg) 645 { 646 __be32 *p; 647 648 RESERVE_SPACE(8+sizeof(arg->stateid->data)); 649 WRITE32(OP_CLOSE); 650 WRITE32(arg->seqid->sequence->counter); 651 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); 652 653 return 0; 654 } 655 656 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args) 657 { 658 __be32 *p; 659 660 RESERVE_SPACE(16); 661 WRITE32(OP_COMMIT); 662 WRITE64(args->offset); 663 WRITE32(args->count); 664 665 return 0; 666 } 667 668 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create) 669 { 670 __be32 *p; 671 672 RESERVE_SPACE(8); 673 WRITE32(OP_CREATE); 674 WRITE32(create->ftype); 675 676 switch (create->ftype) { 677 case NF4LNK: 678 RESERVE_SPACE(4); 679 WRITE32(create->u.symlink.len); 680 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 681 break; 682 683 case NF4BLK: case NF4CHR: 684 RESERVE_SPACE(8); 685 WRITE32(create->u.device.specdata1); 686 WRITE32(create->u.device.specdata2); 687 break; 688 689 default: 690 break; 691 } 692 693 RESERVE_SPACE(4 + create->name->len); 694 WRITE32(create->name->len); 695 WRITEMEM(create->name->name, create->name->len); 696 697 return encode_attrs(xdr, create->attrs, create->server); 698 } 699 700 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap) 701 { 702 __be32 *p; 703 704 RESERVE_SPACE(12); 705 WRITE32(OP_GETATTR); 706 WRITE32(1); 707 WRITE32(bitmap); 708 return 0; 709 } 710 711 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1) 712 { 713 __be32 *p; 714 715 RESERVE_SPACE(16); 716 WRITE32(OP_GETATTR); 717 WRITE32(2); 718 WRITE32(bm0); 719 WRITE32(bm1); 720 return 0; 721 } 722 723 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask) 724 { 725 return encode_getattr_two(xdr, 726 bitmask[0] & nfs4_fattr_bitmap[0], 727 bitmask[1] & nfs4_fattr_bitmap[1]); 728 } 729 730 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask) 731 { 732 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0], 733 bitmask[1] & nfs4_fsinfo_bitmap[1]); 734 } 735 736 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask) 737 { 738 return encode_getattr_two(xdr, 739 bitmask[0] & nfs4_fs_locations_bitmap[0], 740 bitmask[1] & nfs4_fs_locations_bitmap[1]); 741 } 742 743 static int encode_getfh(struct xdr_stream *xdr) 744 { 745 __be32 *p; 746 747 RESERVE_SPACE(4); 748 WRITE32(OP_GETFH); 749 750 return 0; 751 } 752 753 static int encode_link(struct xdr_stream *xdr, const struct qstr *name) 754 { 755 __be32 *p; 756 757 RESERVE_SPACE(8 + name->len); 758 WRITE32(OP_LINK); 759 WRITE32(name->len); 760 WRITEMEM(name->name, name->len); 761 762 return 0; 763 } 764 765 static inline int nfs4_lock_type(struct file_lock *fl, int block) 766 { 767 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) 768 return block ? NFS4_READW_LT : NFS4_READ_LT; 769 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 770 } 771 772 static inline uint64_t nfs4_lock_length(struct file_lock *fl) 773 { 774 if (fl->fl_end == OFFSET_MAX) 775 return ~(uint64_t)0; 776 return fl->fl_end - fl->fl_start + 1; 777 } 778 779 /* 780 * opcode,type,reclaim,offset,length,new_lock_owner = 32 781 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 782 */ 783 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args) 784 { 785 __be32 *p; 786 787 RESERVE_SPACE(32); 788 WRITE32(OP_LOCK); 789 WRITE32(nfs4_lock_type(args->fl, args->block)); 790 WRITE32(args->reclaim); 791 WRITE64(args->fl->fl_start); 792 WRITE64(nfs4_lock_length(args->fl)); 793 WRITE32(args->new_lock_owner); 794 if (args->new_lock_owner){ 795 RESERVE_SPACE(40); 796 WRITE32(args->open_seqid->sequence->counter); 797 WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data)); 798 WRITE32(args->lock_seqid->sequence->counter); 799 WRITE64(args->lock_owner.clientid); 800 WRITE32(4); 801 WRITE32(args->lock_owner.id); 802 } 803 else { 804 RESERVE_SPACE(20); 805 WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data)); 806 WRITE32(args->lock_seqid->sequence->counter); 807 } 808 809 return 0; 810 } 811 812 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args) 813 { 814 __be32 *p; 815 816 RESERVE_SPACE(40); 817 WRITE32(OP_LOCKT); 818 WRITE32(nfs4_lock_type(args->fl, 0)); 819 WRITE64(args->fl->fl_start); 820 WRITE64(nfs4_lock_length(args->fl)); 821 WRITE64(args->lock_owner.clientid); 822 WRITE32(4); 823 WRITE32(args->lock_owner.id); 824 825 return 0; 826 } 827 828 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args) 829 { 830 __be32 *p; 831 832 RESERVE_SPACE(44); 833 WRITE32(OP_LOCKU); 834 WRITE32(nfs4_lock_type(args->fl, 0)); 835 WRITE32(args->seqid->sequence->counter); 836 WRITEMEM(args->stateid->data, sizeof(args->stateid->data)); 837 WRITE64(args->fl->fl_start); 838 WRITE64(nfs4_lock_length(args->fl)); 839 840 return 0; 841 } 842 843 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name) 844 { 845 int len = name->len; 846 __be32 *p; 847 848 RESERVE_SPACE(8 + len); 849 WRITE32(OP_LOOKUP); 850 WRITE32(len); 851 WRITEMEM(name->name, len); 852 853 return 0; 854 } 855 856 static void encode_share_access(struct xdr_stream *xdr, int open_flags) 857 { 858 __be32 *p; 859 860 RESERVE_SPACE(8); 861 switch (open_flags & (FMODE_READ|FMODE_WRITE)) { 862 case FMODE_READ: 863 WRITE32(NFS4_SHARE_ACCESS_READ); 864 break; 865 case FMODE_WRITE: 866 WRITE32(NFS4_SHARE_ACCESS_WRITE); 867 break; 868 case FMODE_READ|FMODE_WRITE: 869 WRITE32(NFS4_SHARE_ACCESS_BOTH); 870 break; 871 default: 872 BUG(); 873 } 874 WRITE32(0); /* for linux, share_deny = 0 always */ 875 } 876 877 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 878 { 879 __be32 *p; 880 /* 881 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 882 * owner 4 = 32 883 */ 884 RESERVE_SPACE(8); 885 WRITE32(OP_OPEN); 886 WRITE32(arg->seqid->sequence->counter); 887 encode_share_access(xdr, arg->open_flags); 888 RESERVE_SPACE(16); 889 WRITE64(arg->clientid); 890 WRITE32(4); 891 WRITE32(arg->id); 892 } 893 894 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 895 { 896 __be32 *p; 897 898 RESERVE_SPACE(4); 899 switch(arg->open_flags & O_EXCL) { 900 case 0: 901 WRITE32(NFS4_CREATE_UNCHECKED); 902 encode_attrs(xdr, arg->u.attrs, arg->server); 903 break; 904 default: 905 WRITE32(NFS4_CREATE_EXCLUSIVE); 906 encode_nfs4_verifier(xdr, &arg->u.verifier); 907 } 908 } 909 910 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 911 { 912 __be32 *p; 913 914 RESERVE_SPACE(4); 915 switch (arg->open_flags & O_CREAT) { 916 case 0: 917 WRITE32(NFS4_OPEN_NOCREATE); 918 break; 919 default: 920 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 921 WRITE32(NFS4_OPEN_CREATE); 922 encode_createmode(xdr, arg); 923 } 924 } 925 926 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type) 927 { 928 __be32 *p; 929 930 RESERVE_SPACE(4); 931 switch (delegation_type) { 932 case 0: 933 WRITE32(NFS4_OPEN_DELEGATE_NONE); 934 break; 935 case FMODE_READ: 936 WRITE32(NFS4_OPEN_DELEGATE_READ); 937 break; 938 case FMODE_WRITE|FMODE_READ: 939 WRITE32(NFS4_OPEN_DELEGATE_WRITE); 940 break; 941 default: 942 BUG(); 943 } 944 } 945 946 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 947 { 948 __be32 *p; 949 950 RESERVE_SPACE(4); 951 WRITE32(NFS4_OPEN_CLAIM_NULL); 952 encode_string(xdr, name->len, name->name); 953 } 954 955 static inline void encode_claim_previous(struct xdr_stream *xdr, int type) 956 { 957 __be32 *p; 958 959 RESERVE_SPACE(4); 960 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS); 961 encode_delegation_type(xdr, type); 962 } 963 964 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 965 { 966 __be32 *p; 967 968 RESERVE_SPACE(4+sizeof(stateid->data)); 969 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 970 WRITEMEM(stateid->data, sizeof(stateid->data)); 971 encode_string(xdr, name->len, name->name); 972 } 973 974 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg) 975 { 976 encode_openhdr(xdr, arg); 977 encode_opentype(xdr, arg); 978 switch (arg->claim) { 979 case NFS4_OPEN_CLAIM_NULL: 980 encode_claim_null(xdr, arg->name); 981 break; 982 case NFS4_OPEN_CLAIM_PREVIOUS: 983 encode_claim_previous(xdr, arg->u.delegation_type); 984 break; 985 case NFS4_OPEN_CLAIM_DELEGATE_CUR: 986 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 987 break; 988 default: 989 BUG(); 990 } 991 return 0; 992 } 993 994 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg) 995 { 996 __be32 *p; 997 998 RESERVE_SPACE(8+sizeof(arg->stateid->data)); 999 WRITE32(OP_OPEN_CONFIRM); 1000 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); 1001 WRITE32(arg->seqid->sequence->counter); 1002 1003 return 0; 1004 } 1005 1006 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg) 1007 { 1008 __be32 *p; 1009 1010 RESERVE_SPACE(8+sizeof(arg->stateid->data)); 1011 WRITE32(OP_OPEN_DOWNGRADE); 1012 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); 1013 WRITE32(arg->seqid->sequence->counter); 1014 encode_share_access(xdr, arg->open_flags); 1015 return 0; 1016 } 1017 1018 static int 1019 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh) 1020 { 1021 int len = fh->size; 1022 __be32 *p; 1023 1024 RESERVE_SPACE(8 + len); 1025 WRITE32(OP_PUTFH); 1026 WRITE32(len); 1027 WRITEMEM(fh->data, len); 1028 1029 return 0; 1030 } 1031 1032 static int encode_putrootfh(struct xdr_stream *xdr) 1033 { 1034 __be32 *p; 1035 1036 RESERVE_SPACE(4); 1037 WRITE32(OP_PUTROOTFH); 1038 1039 return 0; 1040 } 1041 1042 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx) 1043 { 1044 nfs4_stateid stateid; 1045 __be32 *p; 1046 1047 RESERVE_SPACE(16); 1048 if (ctx->state != NULL) { 1049 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner); 1050 WRITEMEM(stateid.data, sizeof(stateid.data)); 1051 } else 1052 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data)); 1053 } 1054 1055 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args) 1056 { 1057 __be32 *p; 1058 1059 RESERVE_SPACE(4); 1060 WRITE32(OP_READ); 1061 1062 encode_stateid(xdr, args->context); 1063 1064 RESERVE_SPACE(12); 1065 WRITE64(args->offset); 1066 WRITE32(args->count); 1067 1068 return 0; 1069 } 1070 1071 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req) 1072 { 1073 struct rpc_auth *auth = req->rq_task->tk_auth; 1074 uint32_t attrs[2] = { 1075 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID, 1076 FATTR4_WORD1_MOUNTED_ON_FILEID, 1077 }; 1078 int replen; 1079 __be32 *p; 1080 1081 RESERVE_SPACE(32+sizeof(nfs4_verifier)); 1082 WRITE32(OP_READDIR); 1083 WRITE64(readdir->cookie); 1084 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data)); 1085 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */ 1086 WRITE32(readdir->count); 1087 WRITE32(2); 1088 /* Switch to mounted_on_fileid if the server supports it */ 1089 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) 1090 attrs[0] &= ~FATTR4_WORD0_FILEID; 1091 else 1092 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 1093 WRITE32(attrs[0] & readdir->bitmask[0]); 1094 WRITE32(attrs[1] & readdir->bitmask[1]); 1095 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n", 1096 __FUNCTION__, 1097 (unsigned long long)readdir->cookie, 1098 ((u32 *)readdir->verifier.data)[0], 1099 ((u32 *)readdir->verifier.data)[1], 1100 attrs[0] & readdir->bitmask[0], 1101 attrs[1] & readdir->bitmask[1]); 1102 1103 /* set up reply kvec 1104 * toplevel_status + taglen + rescount + OP_PUTFH + status 1105 * + OP_READDIR + status + verifer(2) = 9 1106 */ 1107 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2; 1108 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages, 1109 readdir->pgbase, readdir->count); 1110 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 1111 __FUNCTION__, replen, readdir->pages, 1112 readdir->pgbase, readdir->count); 1113 1114 return 0; 1115 } 1116 1117 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req) 1118 { 1119 struct rpc_auth *auth = req->rq_task->tk_auth; 1120 unsigned int replen; 1121 __be32 *p; 1122 1123 RESERVE_SPACE(4); 1124 WRITE32(OP_READLINK); 1125 1126 /* set up reply kvec 1127 * toplevel_status + taglen + rescount + OP_PUTFH + status 1128 * + OP_READLINK + status + string length = 8 1129 */ 1130 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2; 1131 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages, 1132 readlink->pgbase, readlink->pglen); 1133 1134 return 0; 1135 } 1136 1137 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name) 1138 { 1139 __be32 *p; 1140 1141 RESERVE_SPACE(8 + name->len); 1142 WRITE32(OP_REMOVE); 1143 WRITE32(name->len); 1144 WRITEMEM(name->name, name->len); 1145 1146 return 0; 1147 } 1148 1149 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname) 1150 { 1151 __be32 *p; 1152 1153 RESERVE_SPACE(8 + oldname->len); 1154 WRITE32(OP_RENAME); 1155 WRITE32(oldname->len); 1156 WRITEMEM(oldname->name, oldname->len); 1157 1158 RESERVE_SPACE(4 + newname->len); 1159 WRITE32(newname->len); 1160 WRITEMEM(newname->name, newname->len); 1161 1162 return 0; 1163 } 1164 1165 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid) 1166 { 1167 __be32 *p; 1168 1169 RESERVE_SPACE(12); 1170 WRITE32(OP_RENEW); 1171 WRITE64(client_stateid->cl_clientid); 1172 1173 return 0; 1174 } 1175 1176 static int 1177 encode_restorefh(struct xdr_stream *xdr) 1178 { 1179 __be32 *p; 1180 1181 RESERVE_SPACE(4); 1182 WRITE32(OP_RESTOREFH); 1183 1184 return 0; 1185 } 1186 1187 static int 1188 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg) 1189 { 1190 __be32 *p; 1191 1192 RESERVE_SPACE(4+sizeof(zero_stateid.data)); 1193 WRITE32(OP_SETATTR); 1194 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data)); 1195 RESERVE_SPACE(2*4); 1196 WRITE32(1); 1197 WRITE32(FATTR4_WORD0_ACL); 1198 if (arg->acl_len % 4) 1199 return -EINVAL; 1200 RESERVE_SPACE(4); 1201 WRITE32(arg->acl_len); 1202 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 1203 return 0; 1204 } 1205 1206 static int 1207 encode_savefh(struct xdr_stream *xdr) 1208 { 1209 __be32 *p; 1210 1211 RESERVE_SPACE(4); 1212 WRITE32(OP_SAVEFH); 1213 1214 return 0; 1215 } 1216 1217 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server) 1218 { 1219 int status; 1220 __be32 *p; 1221 1222 RESERVE_SPACE(4+sizeof(arg->stateid.data)); 1223 WRITE32(OP_SETATTR); 1224 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); 1225 1226 if ((status = encode_attrs(xdr, arg->iap, server))) 1227 return status; 1228 1229 return 0; 1230 } 1231 1232 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid) 1233 { 1234 __be32 *p; 1235 1236 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data)); 1237 WRITE32(OP_SETCLIENTID); 1238 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data)); 1239 1240 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 1241 RESERVE_SPACE(4); 1242 WRITE32(setclientid->sc_prog); 1243 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 1244 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 1245 RESERVE_SPACE(4); 1246 WRITE32(setclientid->sc_cb_ident); 1247 1248 return 0; 1249 } 1250 1251 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state) 1252 { 1253 __be32 *p; 1254 1255 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data)); 1256 WRITE32(OP_SETCLIENTID_CONFIRM); 1257 WRITE64(client_state->cl_clientid); 1258 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data)); 1259 1260 return 0; 1261 } 1262 1263 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args) 1264 { 1265 __be32 *p; 1266 1267 RESERVE_SPACE(4); 1268 WRITE32(OP_WRITE); 1269 1270 encode_stateid(xdr, args->context); 1271 1272 RESERVE_SPACE(16); 1273 WRITE64(args->offset); 1274 WRITE32(args->stable); 1275 WRITE32(args->count); 1276 1277 xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 1278 1279 return 0; 1280 } 1281 1282 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1283 { 1284 __be32 *p; 1285 1286 RESERVE_SPACE(20); 1287 1288 WRITE32(OP_DELEGRETURN); 1289 WRITEMEM(stateid->data, sizeof(stateid->data)); 1290 return 0; 1291 1292 } 1293 /* 1294 * END OF "GENERIC" ENCODE ROUTINES. 1295 */ 1296 1297 /* 1298 * Encode an ACCESS request 1299 */ 1300 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args) 1301 { 1302 struct xdr_stream xdr; 1303 struct compound_hdr hdr = { 1304 .nops = 2, 1305 }; 1306 int status; 1307 1308 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1309 encode_compound_hdr(&xdr, &hdr); 1310 if ((status = encode_putfh(&xdr, args->fh)) == 0) 1311 status = encode_access(&xdr, args->access); 1312 return status; 1313 } 1314 1315 /* 1316 * Encode LOOKUP request 1317 */ 1318 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args) 1319 { 1320 struct xdr_stream xdr; 1321 struct compound_hdr hdr = { 1322 .nops = 4, 1323 }; 1324 int status; 1325 1326 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1327 encode_compound_hdr(&xdr, &hdr); 1328 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) 1329 goto out; 1330 if ((status = encode_lookup(&xdr, args->name)) != 0) 1331 goto out; 1332 if ((status = encode_getfh(&xdr)) != 0) 1333 goto out; 1334 status = encode_getfattr(&xdr, args->bitmask); 1335 out: 1336 return status; 1337 } 1338 1339 /* 1340 * Encode LOOKUP_ROOT request 1341 */ 1342 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args) 1343 { 1344 struct xdr_stream xdr; 1345 struct compound_hdr hdr = { 1346 .nops = 3, 1347 }; 1348 int status; 1349 1350 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1351 encode_compound_hdr(&xdr, &hdr); 1352 if ((status = encode_putrootfh(&xdr)) != 0) 1353 goto out; 1354 if ((status = encode_getfh(&xdr)) == 0) 1355 status = encode_getfattr(&xdr, args->bitmask); 1356 out: 1357 return status; 1358 } 1359 1360 /* 1361 * Encode REMOVE request 1362 */ 1363 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args) 1364 { 1365 struct xdr_stream xdr; 1366 struct compound_hdr hdr = { 1367 .nops = 3, 1368 }; 1369 int status; 1370 1371 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1372 encode_compound_hdr(&xdr, &hdr); 1373 if ((status = encode_putfh(&xdr, args->fh)) != 0) 1374 goto out; 1375 if ((status = encode_remove(&xdr, args->name)) != 0) 1376 goto out; 1377 status = encode_getfattr(&xdr, args->bitmask); 1378 out: 1379 return status; 1380 } 1381 1382 /* 1383 * Encode RENAME request 1384 */ 1385 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args) 1386 { 1387 struct xdr_stream xdr; 1388 struct compound_hdr hdr = { 1389 .nops = 7, 1390 }; 1391 int status; 1392 1393 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1394 encode_compound_hdr(&xdr, &hdr); 1395 if ((status = encode_putfh(&xdr, args->old_dir)) != 0) 1396 goto out; 1397 if ((status = encode_savefh(&xdr)) != 0) 1398 goto out; 1399 if ((status = encode_putfh(&xdr, args->new_dir)) != 0) 1400 goto out; 1401 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0) 1402 goto out; 1403 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) 1404 goto out; 1405 if ((status = encode_restorefh(&xdr)) != 0) 1406 goto out; 1407 status = encode_getfattr(&xdr, args->bitmask); 1408 out: 1409 return status; 1410 } 1411 1412 /* 1413 * Encode LINK request 1414 */ 1415 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args) 1416 { 1417 struct xdr_stream xdr; 1418 struct compound_hdr hdr = { 1419 .nops = 7, 1420 }; 1421 int status; 1422 1423 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1424 encode_compound_hdr(&xdr, &hdr); 1425 if ((status = encode_putfh(&xdr, args->fh)) != 0) 1426 goto out; 1427 if ((status = encode_savefh(&xdr)) != 0) 1428 goto out; 1429 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) 1430 goto out; 1431 if ((status = encode_link(&xdr, args->name)) != 0) 1432 goto out; 1433 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) 1434 goto out; 1435 if ((status = encode_restorefh(&xdr)) != 0) 1436 goto out; 1437 status = encode_getfattr(&xdr, args->bitmask); 1438 out: 1439 return status; 1440 } 1441 1442 /* 1443 * Encode CREATE request 1444 */ 1445 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) 1446 { 1447 struct xdr_stream xdr; 1448 struct compound_hdr hdr = { 1449 .nops = 7, 1450 }; 1451 int status; 1452 1453 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1454 encode_compound_hdr(&xdr, &hdr); 1455 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) 1456 goto out; 1457 if ((status = encode_savefh(&xdr)) != 0) 1458 goto out; 1459 if ((status = encode_create(&xdr, args)) != 0) 1460 goto out; 1461 if ((status = encode_getfh(&xdr)) != 0) 1462 goto out; 1463 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0) 1464 goto out; 1465 if ((status = encode_restorefh(&xdr)) != 0) 1466 goto out; 1467 status = encode_getfattr(&xdr, args->bitmask); 1468 out: 1469 return status; 1470 } 1471 1472 /* 1473 * Encode SYMLINK request 1474 */ 1475 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) 1476 { 1477 return nfs4_xdr_enc_create(req, p, args); 1478 } 1479 1480 /* 1481 * Encode GETATTR request 1482 */ 1483 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args) 1484 { 1485 struct xdr_stream xdr; 1486 struct compound_hdr hdr = { 1487 .nops = 2, 1488 }; 1489 int status; 1490 1491 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1492 encode_compound_hdr(&xdr, &hdr); 1493 if ((status = encode_putfh(&xdr, args->fh)) == 0) 1494 status = encode_getfattr(&xdr, args->bitmask); 1495 return status; 1496 } 1497 1498 /* 1499 * Encode a CLOSE request 1500 */ 1501 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) 1502 { 1503 struct xdr_stream xdr; 1504 struct compound_hdr hdr = { 1505 .nops = 3, 1506 }; 1507 int status; 1508 1509 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1510 encode_compound_hdr(&xdr, &hdr); 1511 status = encode_putfh(&xdr, args->fh); 1512 if(status) 1513 goto out; 1514 status = encode_close(&xdr, args); 1515 if (status != 0) 1516 goto out; 1517 status = encode_getfattr(&xdr, args->bitmask); 1518 out: 1519 return status; 1520 } 1521 1522 /* 1523 * Encode an OPEN request 1524 */ 1525 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) 1526 { 1527 struct xdr_stream xdr; 1528 struct compound_hdr hdr = { 1529 .nops = 7, 1530 }; 1531 int status; 1532 1533 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1534 encode_compound_hdr(&xdr, &hdr); 1535 status = encode_putfh(&xdr, args->fh); 1536 if (status) 1537 goto out; 1538 status = encode_savefh(&xdr); 1539 if (status) 1540 goto out; 1541 status = encode_open(&xdr, args); 1542 if (status) 1543 goto out; 1544 status = encode_getfh(&xdr); 1545 if (status) 1546 goto out; 1547 status = encode_getfattr(&xdr, args->bitmask); 1548 if (status) 1549 goto out; 1550 status = encode_restorefh(&xdr); 1551 if (status) 1552 goto out; 1553 status = encode_getfattr(&xdr, args->bitmask); 1554 out: 1555 return status; 1556 } 1557 1558 /* 1559 * Encode an OPEN_CONFIRM request 1560 */ 1561 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args) 1562 { 1563 struct xdr_stream xdr; 1564 struct compound_hdr hdr = { 1565 .nops = 2, 1566 }; 1567 int status; 1568 1569 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1570 encode_compound_hdr(&xdr, &hdr); 1571 status = encode_putfh(&xdr, args->fh); 1572 if(status) 1573 goto out; 1574 status = encode_open_confirm(&xdr, args); 1575 out: 1576 return status; 1577 } 1578 1579 /* 1580 * Encode an OPEN request with no attributes. 1581 */ 1582 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) 1583 { 1584 struct xdr_stream xdr; 1585 struct compound_hdr hdr = { 1586 .nops = 3, 1587 }; 1588 int status; 1589 1590 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1591 encode_compound_hdr(&xdr, &hdr); 1592 status = encode_putfh(&xdr, args->fh); 1593 if (status) 1594 goto out; 1595 status = encode_open(&xdr, args); 1596 if (status) 1597 goto out; 1598 status = encode_getfattr(&xdr, args->bitmask); 1599 out: 1600 return status; 1601 } 1602 1603 /* 1604 * Encode an OPEN_DOWNGRADE request 1605 */ 1606 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) 1607 { 1608 struct xdr_stream xdr; 1609 struct compound_hdr hdr = { 1610 .nops = 3, 1611 }; 1612 int status; 1613 1614 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1615 encode_compound_hdr(&xdr, &hdr); 1616 status = encode_putfh(&xdr, args->fh); 1617 if (status) 1618 goto out; 1619 status = encode_open_downgrade(&xdr, args); 1620 if (status != 0) 1621 goto out; 1622 status = encode_getfattr(&xdr, args->bitmask); 1623 out: 1624 return status; 1625 } 1626 1627 /* 1628 * Encode a LOCK request 1629 */ 1630 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args) 1631 { 1632 struct xdr_stream xdr; 1633 struct compound_hdr hdr = { 1634 .nops = 2, 1635 }; 1636 int status; 1637 1638 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1639 encode_compound_hdr(&xdr, &hdr); 1640 status = encode_putfh(&xdr, args->fh); 1641 if(status) 1642 goto out; 1643 status = encode_lock(&xdr, args); 1644 out: 1645 return status; 1646 } 1647 1648 /* 1649 * Encode a LOCKT request 1650 */ 1651 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args) 1652 { 1653 struct xdr_stream xdr; 1654 struct compound_hdr hdr = { 1655 .nops = 2, 1656 }; 1657 int status; 1658 1659 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1660 encode_compound_hdr(&xdr, &hdr); 1661 status = encode_putfh(&xdr, args->fh); 1662 if(status) 1663 goto out; 1664 status = encode_lockt(&xdr, args); 1665 out: 1666 return status; 1667 } 1668 1669 /* 1670 * Encode a LOCKU request 1671 */ 1672 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args) 1673 { 1674 struct xdr_stream xdr; 1675 struct compound_hdr hdr = { 1676 .nops = 2, 1677 }; 1678 int status; 1679 1680 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1681 encode_compound_hdr(&xdr, &hdr); 1682 status = encode_putfh(&xdr, args->fh); 1683 if(status) 1684 goto out; 1685 status = encode_locku(&xdr, args); 1686 out: 1687 return status; 1688 } 1689 1690 /* 1691 * Encode a READLINK request 1692 */ 1693 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args) 1694 { 1695 struct xdr_stream xdr; 1696 struct compound_hdr hdr = { 1697 .nops = 2, 1698 }; 1699 int status; 1700 1701 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1702 encode_compound_hdr(&xdr, &hdr); 1703 status = encode_putfh(&xdr, args->fh); 1704 if(status) 1705 goto out; 1706 status = encode_readlink(&xdr, args, req); 1707 out: 1708 return status; 1709 } 1710 1711 /* 1712 * Encode a READDIR request 1713 */ 1714 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args) 1715 { 1716 struct xdr_stream xdr; 1717 struct compound_hdr hdr = { 1718 .nops = 2, 1719 }; 1720 int status; 1721 1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1723 encode_compound_hdr(&xdr, &hdr); 1724 status = encode_putfh(&xdr, args->fh); 1725 if(status) 1726 goto out; 1727 status = encode_readdir(&xdr, args, req); 1728 out: 1729 return status; 1730 } 1731 1732 /* 1733 * Encode a READ request 1734 */ 1735 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) 1736 { 1737 struct rpc_auth *auth = req->rq_task->tk_auth; 1738 struct xdr_stream xdr; 1739 struct compound_hdr hdr = { 1740 .nops = 2, 1741 }; 1742 int replen, status; 1743 1744 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1745 encode_compound_hdr(&xdr, &hdr); 1746 status = encode_putfh(&xdr, args->fh); 1747 if (status) 1748 goto out; 1749 status = encode_read(&xdr, args); 1750 if (status) 1751 goto out; 1752 1753 /* set up reply kvec 1754 * toplevel status + taglen=0 + rescount + OP_PUTFH + status 1755 * + OP_READ + status + eof + datalen = 9 1756 */ 1757 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2; 1758 xdr_inline_pages(&req->rq_rcv_buf, replen, 1759 args->pages, args->pgbase, args->count); 1760 out: 1761 return status; 1762 } 1763 1764 /* 1765 * Encode an SETATTR request 1766 */ 1767 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args) 1768 1769 { 1770 struct xdr_stream xdr; 1771 struct compound_hdr hdr = { 1772 .nops = 3, 1773 }; 1774 int status; 1775 1776 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1777 encode_compound_hdr(&xdr, &hdr); 1778 status = encode_putfh(&xdr, args->fh); 1779 if(status) 1780 goto out; 1781 status = encode_setattr(&xdr, args, args->server); 1782 if(status) 1783 goto out; 1784 status = encode_getfattr(&xdr, args->bitmask); 1785 out: 1786 return status; 1787 } 1788 1789 /* 1790 * Encode a GETACL request 1791 */ 1792 static int 1793 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p, 1794 struct nfs_getaclargs *args) 1795 { 1796 struct xdr_stream xdr; 1797 struct rpc_auth *auth = req->rq_task->tk_auth; 1798 struct compound_hdr hdr = { 1799 .nops = 2, 1800 }; 1801 int replen, status; 1802 1803 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1804 encode_compound_hdr(&xdr, &hdr); 1805 status = encode_putfh(&xdr, args->fh); 1806 if (status) 1807 goto out; 1808 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0); 1809 /* set up reply buffer: */ 1810 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2; 1811 xdr_inline_pages(&req->rq_rcv_buf, replen, 1812 args->acl_pages, args->acl_pgbase, args->acl_len); 1813 out: 1814 return status; 1815 } 1816 1817 /* 1818 * Encode a WRITE request 1819 */ 1820 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 1821 { 1822 struct xdr_stream xdr; 1823 struct compound_hdr hdr = { 1824 .nops = 3, 1825 }; 1826 int status; 1827 1828 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1829 encode_compound_hdr(&xdr, &hdr); 1830 status = encode_putfh(&xdr, args->fh); 1831 if (status) 1832 goto out; 1833 status = encode_write(&xdr, args); 1834 if (status) 1835 goto out; 1836 status = encode_getfattr(&xdr, args->bitmask); 1837 out: 1838 return status; 1839 } 1840 1841 /* 1842 * a COMMIT request 1843 */ 1844 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 1845 { 1846 struct xdr_stream xdr; 1847 struct compound_hdr hdr = { 1848 .nops = 3, 1849 }; 1850 int status; 1851 1852 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1853 encode_compound_hdr(&xdr, &hdr); 1854 status = encode_putfh(&xdr, args->fh); 1855 if (status) 1856 goto out; 1857 status = encode_commit(&xdr, args); 1858 if (status) 1859 goto out; 1860 status = encode_getfattr(&xdr, args->bitmask); 1861 out: 1862 return status; 1863 } 1864 1865 /* 1866 * FSINFO request 1867 */ 1868 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args) 1869 { 1870 struct xdr_stream xdr; 1871 struct compound_hdr hdr = { 1872 .nops = 2, 1873 }; 1874 int status; 1875 1876 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1877 encode_compound_hdr(&xdr, &hdr); 1878 status = encode_putfh(&xdr, args->fh); 1879 if (!status) 1880 status = encode_fsinfo(&xdr, args->bitmask); 1881 return status; 1882 } 1883 1884 /* 1885 * a PATHCONF request 1886 */ 1887 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args) 1888 { 1889 struct xdr_stream xdr; 1890 struct compound_hdr hdr = { 1891 .nops = 2, 1892 }; 1893 int status; 1894 1895 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1896 encode_compound_hdr(&xdr, &hdr); 1897 status = encode_putfh(&xdr, args->fh); 1898 if (!status) 1899 status = encode_getattr_one(&xdr, 1900 args->bitmask[0] & nfs4_pathconf_bitmap[0]); 1901 return status; 1902 } 1903 1904 /* 1905 * a STATFS request 1906 */ 1907 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args) 1908 { 1909 struct xdr_stream xdr; 1910 struct compound_hdr hdr = { 1911 .nops = 2, 1912 }; 1913 int status; 1914 1915 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1916 encode_compound_hdr(&xdr, &hdr); 1917 status = encode_putfh(&xdr, args->fh); 1918 if (status == 0) 1919 status = encode_getattr_two(&xdr, 1920 args->bitmask[0] & nfs4_statfs_bitmap[0], 1921 args->bitmask[1] & nfs4_statfs_bitmap[1]); 1922 return status; 1923 } 1924 1925 /* 1926 * GETATTR_BITMAP request 1927 */ 1928 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle) 1929 { 1930 struct xdr_stream xdr; 1931 struct compound_hdr hdr = { 1932 .nops = 2, 1933 }; 1934 int status; 1935 1936 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1937 encode_compound_hdr(&xdr, &hdr); 1938 status = encode_putfh(&xdr, fhandle); 1939 if (status == 0) 1940 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 1941 FATTR4_WORD0_LINK_SUPPORT| 1942 FATTR4_WORD0_SYMLINK_SUPPORT| 1943 FATTR4_WORD0_ACLSUPPORT); 1944 return status; 1945 } 1946 1947 /* 1948 * a RENEW request 1949 */ 1950 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) 1951 { 1952 struct xdr_stream xdr; 1953 struct compound_hdr hdr = { 1954 .nops = 1, 1955 }; 1956 1957 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1958 encode_compound_hdr(&xdr, &hdr); 1959 return encode_renew(&xdr, clp); 1960 } 1961 1962 /* 1963 * a SETCLIENTID request 1964 */ 1965 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc) 1966 { 1967 struct xdr_stream xdr; 1968 struct compound_hdr hdr = { 1969 .nops = 1, 1970 }; 1971 1972 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1973 encode_compound_hdr(&xdr, &hdr); 1974 return encode_setclientid(&xdr, sc); 1975 } 1976 1977 /* 1978 * a SETCLIENTID_CONFIRM request 1979 */ 1980 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) 1981 { 1982 struct xdr_stream xdr; 1983 struct compound_hdr hdr = { 1984 .nops = 3, 1985 }; 1986 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; 1987 int status; 1988 1989 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1990 encode_compound_hdr(&xdr, &hdr); 1991 status = encode_setclientid_confirm(&xdr, clp); 1992 if (!status) 1993 status = encode_putrootfh(&xdr); 1994 if (!status) 1995 status = encode_fsinfo(&xdr, lease_bitmap); 1996 return status; 1997 } 1998 1999 /* 2000 * DELEGRETURN request 2001 */ 2002 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args) 2003 { 2004 struct xdr_stream xdr; 2005 struct compound_hdr hdr = { 2006 .nops = 3, 2007 }; 2008 int status; 2009 2010 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2011 encode_compound_hdr(&xdr, &hdr); 2012 status = encode_putfh(&xdr, args->fhandle); 2013 if (status != 0) 2014 goto out; 2015 status = encode_delegreturn(&xdr, args->stateid); 2016 if (status != 0) 2017 goto out; 2018 status = encode_getfattr(&xdr, args->bitmask); 2019 out: 2020 return status; 2021 } 2022 2023 /* 2024 * Encode FS_LOCATIONS request 2025 */ 2026 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args) 2027 { 2028 struct xdr_stream xdr; 2029 struct compound_hdr hdr = { 2030 .nops = 3, 2031 }; 2032 struct rpc_auth *auth = req->rq_task->tk_auth; 2033 int replen; 2034 int status; 2035 2036 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2037 encode_compound_hdr(&xdr, &hdr); 2038 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0) 2039 goto out; 2040 if ((status = encode_lookup(&xdr, args->name)) != 0) 2041 goto out; 2042 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0) 2043 goto out; 2044 /* set up reply 2045 * toplevel_status + OP_PUTFH + status 2046 * + OP_LOOKUP + status + OP_GETATTR + status = 7 2047 */ 2048 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2; 2049 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page, 2050 0, PAGE_SIZE); 2051 out: 2052 return status; 2053 } 2054 2055 /* 2056 * START OF "GENERIC" DECODE ROUTINES. 2057 * These may look a little ugly since they are imported from a "generic" 2058 * set of XDR encode/decode routines which are intended to be shared by 2059 * all of our NFSv4 implementations (OpenBSD, MacOS X...). 2060 * 2061 * If the pain of reading these is too great, it should be a straightforward 2062 * task to translate them into Linux-specific versions which are more 2063 * consistent with the style used in NFSv2/v3... 2064 */ 2065 #define READ32(x) (x) = ntohl(*p++) 2066 #define READ64(x) do { \ 2067 (x) = (u64)ntohl(*p++) << 32; \ 2068 (x) |= ntohl(*p++); \ 2069 } while (0) 2070 #define READTIME(x) do { \ 2071 p++; \ 2072 (x.tv_sec) = ntohl(*p++); \ 2073 (x.tv_nsec) = ntohl(*p++); \ 2074 } while (0) 2075 #define COPYMEM(x,nbytes) do { \ 2076 memcpy((x), p, nbytes); \ 2077 p += XDR_QUADLEN(nbytes); \ 2078 } while (0) 2079 2080 #define READ_BUF(nbytes) do { \ 2081 p = xdr_inline_decode(xdr, nbytes); \ 2082 if (!p) { \ 2083 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \ 2084 __FUNCTION__, __LINE__); \ 2085 return -EIO; \ 2086 } \ 2087 } while (0) 2088 2089 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 2090 { 2091 __be32 *p; 2092 2093 READ_BUF(4); 2094 READ32(*len); 2095 READ_BUF(*len); 2096 *string = (char *)p; 2097 return 0; 2098 } 2099 2100 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 2101 { 2102 __be32 *p; 2103 2104 READ_BUF(8); 2105 READ32(hdr->status); 2106 READ32(hdr->taglen); 2107 2108 READ_BUF(hdr->taglen + 4); 2109 hdr->tag = (char *)p; 2110 p += XDR_QUADLEN(hdr->taglen); 2111 READ32(hdr->nops); 2112 return 0; 2113 } 2114 2115 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 2116 { 2117 __be32 *p; 2118 uint32_t opnum; 2119 int32_t nfserr; 2120 2121 READ_BUF(8); 2122 READ32(opnum); 2123 if (opnum != expected) { 2124 printk(KERN_NOTICE 2125 "nfs4_decode_op_hdr: Server returned operation" 2126 " %d but we issued a request for %d\n", 2127 opnum, expected); 2128 return -EIO; 2129 } 2130 READ32(nfserr); 2131 if (nfserr != NFS_OK) 2132 return -nfs4_stat_to_errno(nfserr); 2133 return 0; 2134 } 2135 2136 /* Dummy routine */ 2137 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 2138 { 2139 __be32 *p; 2140 unsigned int strlen; 2141 char *str; 2142 2143 READ_BUF(12); 2144 return decode_opaque_inline(xdr, &strlen, &str); 2145 } 2146 2147 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 2148 { 2149 uint32_t bmlen; 2150 __be32 *p; 2151 2152 READ_BUF(4); 2153 READ32(bmlen); 2154 2155 bitmap[0] = bitmap[1] = 0; 2156 READ_BUF((bmlen << 2)); 2157 if (bmlen > 0) { 2158 READ32(bitmap[0]); 2159 if (bmlen > 1) 2160 READ32(bitmap[1]); 2161 } 2162 return 0; 2163 } 2164 2165 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) 2166 { 2167 __be32 *p; 2168 2169 READ_BUF(4); 2170 READ32(*attrlen); 2171 *savep = xdr->p; 2172 return 0; 2173 } 2174 2175 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 2176 { 2177 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 2178 decode_attr_bitmap(xdr, bitmask); 2179 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 2180 } else 2181 bitmask[0] = bitmask[1] = 0; 2182 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]); 2183 return 0; 2184 } 2185 2186 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 2187 { 2188 __be32 *p; 2189 2190 *type = 0; 2191 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 2192 return -EIO; 2193 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 2194 READ_BUF(4); 2195 READ32(*type); 2196 if (*type < NF4REG || *type > NF4NAMEDATTR) { 2197 dprintk("%s: bad type %d\n", __FUNCTION__, *type); 2198 return -EIO; 2199 } 2200 bitmap[0] &= ~FATTR4_WORD0_TYPE; 2201 } 2202 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type); 2203 return 0; 2204 } 2205 2206 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 2207 { 2208 __be32 *p; 2209 2210 *change = 0; 2211 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 2212 return -EIO; 2213 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 2214 READ_BUF(8); 2215 READ64(*change); 2216 bitmap[0] &= ~FATTR4_WORD0_CHANGE; 2217 } 2218 dprintk("%s: change attribute=%Lu\n", __FUNCTION__, 2219 (unsigned long long)*change); 2220 return 0; 2221 } 2222 2223 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 2224 { 2225 __be32 *p; 2226 2227 *size = 0; 2228 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 2229 return -EIO; 2230 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 2231 READ_BUF(8); 2232 READ64(*size); 2233 bitmap[0] &= ~FATTR4_WORD0_SIZE; 2234 } 2235 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size); 2236 return 0; 2237 } 2238 2239 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2240 { 2241 __be32 *p; 2242 2243 *res = 0; 2244 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 2245 return -EIO; 2246 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 2247 READ_BUF(4); 2248 READ32(*res); 2249 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 2250 } 2251 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true"); 2252 return 0; 2253 } 2254 2255 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2256 { 2257 __be32 *p; 2258 2259 *res = 0; 2260 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 2261 return -EIO; 2262 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 2263 READ_BUF(4); 2264 READ32(*res); 2265 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 2266 } 2267 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true"); 2268 return 0; 2269 } 2270 2271 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 2272 { 2273 __be32 *p; 2274 2275 fsid->major = 0; 2276 fsid->minor = 0; 2277 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 2278 return -EIO; 2279 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 2280 READ_BUF(16); 2281 READ64(fsid->major); 2282 READ64(fsid->minor); 2283 bitmap[0] &= ~FATTR4_WORD0_FSID; 2284 } 2285 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__, 2286 (unsigned long long)fsid->major, 2287 (unsigned long long)fsid->minor); 2288 return 0; 2289 } 2290 2291 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2292 { 2293 __be32 *p; 2294 2295 *res = 60; 2296 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 2297 return -EIO; 2298 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 2299 READ_BUF(4); 2300 READ32(*res); 2301 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 2302 } 2303 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res); 2304 return 0; 2305 } 2306 2307 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2308 { 2309 __be32 *p; 2310 2311 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 2312 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 2313 return -EIO; 2314 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 2315 READ_BUF(4); 2316 READ32(*res); 2317 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 2318 } 2319 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res); 2320 return 0; 2321 } 2322 2323 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 2324 { 2325 __be32 *p; 2326 2327 *fileid = 0; 2328 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 2329 return -EIO; 2330 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 2331 READ_BUF(8); 2332 READ64(*fileid); 2333 bitmap[0] &= ~FATTR4_WORD0_FILEID; 2334 } 2335 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid); 2336 return 0; 2337 } 2338 2339 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 2340 { 2341 __be32 *p; 2342 2343 *fileid = 0; 2344 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 2345 return -EIO; 2346 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 2347 READ_BUF(8); 2348 READ64(*fileid); 2349 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 2350 } 2351 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid); 2352 return 0; 2353 } 2354 2355 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2356 { 2357 __be32 *p; 2358 int status = 0; 2359 2360 *res = 0; 2361 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 2362 return -EIO; 2363 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 2364 READ_BUF(8); 2365 READ64(*res); 2366 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 2367 } 2368 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res); 2369 return status; 2370 } 2371 2372 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2373 { 2374 __be32 *p; 2375 int status = 0; 2376 2377 *res = 0; 2378 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 2379 return -EIO; 2380 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 2381 READ_BUF(8); 2382 READ64(*res); 2383 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 2384 } 2385 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res); 2386 return status; 2387 } 2388 2389 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2390 { 2391 __be32 *p; 2392 int status = 0; 2393 2394 *res = 0; 2395 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 2396 return -EIO; 2397 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 2398 READ_BUF(8); 2399 READ64(*res); 2400 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 2401 } 2402 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res); 2403 return status; 2404 } 2405 2406 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 2407 { 2408 int n; 2409 __be32 *p; 2410 int status = 0; 2411 2412 READ_BUF(4); 2413 READ32(n); 2414 if (n < 0) 2415 goto out_eio; 2416 if (n == 0) 2417 goto root_path; 2418 dprintk("path "); 2419 path->ncomponents = 0; 2420 while (path->ncomponents < n) { 2421 struct nfs4_string *component = &path->components[path->ncomponents]; 2422 status = decode_opaque_inline(xdr, &component->len, &component->data); 2423 if (unlikely(status != 0)) 2424 goto out_eio; 2425 if (path->ncomponents != n) 2426 dprintk("/"); 2427 dprintk("%s", component->data); 2428 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 2429 path->ncomponents++; 2430 else { 2431 dprintk("cannot parse %d components in path\n", n); 2432 goto out_eio; 2433 } 2434 } 2435 out: 2436 dprintk("\n"); 2437 return status; 2438 root_path: 2439 /* a root pathname is sent as a zero component4 */ 2440 path->ncomponents = 1; 2441 path->components[0].len=0; 2442 path->components[0].data=NULL; 2443 dprintk("path /\n"); 2444 goto out; 2445 out_eio: 2446 dprintk(" status %d", status); 2447 status = -EIO; 2448 goto out; 2449 } 2450 2451 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 2452 { 2453 int n; 2454 __be32 *p; 2455 int status = -EIO; 2456 2457 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 2458 goto out; 2459 status = 0; 2460 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 2461 goto out; 2462 dprintk("%s: fsroot ", __FUNCTION__); 2463 status = decode_pathname(xdr, &res->fs_path); 2464 if (unlikely(status != 0)) 2465 goto out; 2466 READ_BUF(4); 2467 READ32(n); 2468 if (n <= 0) 2469 goto out_eio; 2470 res->nlocations = 0; 2471 while (res->nlocations < n) { 2472 int m; 2473 struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 2474 2475 READ_BUF(4); 2476 READ32(m); 2477 if (m <= 0) 2478 goto out_eio; 2479 2480 loc->nservers = 0; 2481 dprintk("%s: servers ", __FUNCTION__); 2482 while (loc->nservers < m) { 2483 struct nfs4_string *server = &loc->servers[loc->nservers]; 2484 status = decode_opaque_inline(xdr, &server->len, &server->data); 2485 if (unlikely(status != 0)) 2486 goto out_eio; 2487 dprintk("%s ", server->data); 2488 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) 2489 loc->nservers++; 2490 else { 2491 int i; 2492 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations); 2493 for (i = loc->nservers; i < m; i++) { 2494 int len; 2495 char *data; 2496 status = decode_opaque_inline(xdr, &len, &data); 2497 if (unlikely(status != 0)) 2498 goto out_eio; 2499 } 2500 } 2501 } 2502 status = decode_pathname(xdr, &loc->rootpath); 2503 if (unlikely(status != 0)) 2504 goto out_eio; 2505 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) 2506 res->nlocations++; 2507 } 2508 out: 2509 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status); 2510 return status; 2511 out_eio: 2512 status = -EIO; 2513 goto out; 2514 } 2515 2516 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2517 { 2518 __be32 *p; 2519 int status = 0; 2520 2521 *res = 0; 2522 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 2523 return -EIO; 2524 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 2525 READ_BUF(8); 2526 READ64(*res); 2527 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 2528 } 2529 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res); 2530 return status; 2531 } 2532 2533 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 2534 { 2535 __be32 *p; 2536 int status = 0; 2537 2538 *maxlink = 1; 2539 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 2540 return -EIO; 2541 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 2542 READ_BUF(4); 2543 READ32(*maxlink); 2544 bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 2545 } 2546 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink); 2547 return status; 2548 } 2549 2550 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 2551 { 2552 __be32 *p; 2553 int status = 0; 2554 2555 *maxname = 1024; 2556 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 2557 return -EIO; 2558 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 2559 READ_BUF(4); 2560 READ32(*maxname); 2561 bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 2562 } 2563 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname); 2564 return status; 2565 } 2566 2567 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2568 { 2569 __be32 *p; 2570 int status = 0; 2571 2572 *res = 1024; 2573 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 2574 return -EIO; 2575 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 2576 uint64_t maxread; 2577 READ_BUF(8); 2578 READ64(maxread); 2579 if (maxread > 0x7FFFFFFF) 2580 maxread = 0x7FFFFFFF; 2581 *res = (uint32_t)maxread; 2582 bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 2583 } 2584 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res); 2585 return status; 2586 } 2587 2588 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2589 { 2590 __be32 *p; 2591 int status = 0; 2592 2593 *res = 1024; 2594 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 2595 return -EIO; 2596 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 2597 uint64_t maxwrite; 2598 READ_BUF(8); 2599 READ64(maxwrite); 2600 if (maxwrite > 0x7FFFFFFF) 2601 maxwrite = 0x7FFFFFFF; 2602 *res = (uint32_t)maxwrite; 2603 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 2604 } 2605 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res); 2606 return status; 2607 } 2608 2609 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode) 2610 { 2611 __be32 *p; 2612 2613 *mode = 0; 2614 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 2615 return -EIO; 2616 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 2617 READ_BUF(4); 2618 READ32(*mode); 2619 *mode &= ~S_IFMT; 2620 bitmap[1] &= ~FATTR4_WORD1_MODE; 2621 } 2622 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode); 2623 return 0; 2624 } 2625 2626 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 2627 { 2628 __be32 *p; 2629 2630 *nlink = 1; 2631 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 2632 return -EIO; 2633 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 2634 READ_BUF(4); 2635 READ32(*nlink); 2636 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 2637 } 2638 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink); 2639 return 0; 2640 } 2641 2642 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *uid) 2643 { 2644 uint32_t len; 2645 __be32 *p; 2646 2647 *uid = -2; 2648 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 2649 return -EIO; 2650 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 2651 READ_BUF(4); 2652 READ32(len); 2653 READ_BUF(len); 2654 if (len < XDR_MAX_NETOBJ) { 2655 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0) 2656 dprintk("%s: nfs_map_name_to_uid failed!\n", 2657 __FUNCTION__); 2658 } else 2659 printk(KERN_WARNING "%s: name too long (%u)!\n", 2660 __FUNCTION__, len); 2661 bitmap[1] &= ~FATTR4_WORD1_OWNER; 2662 } 2663 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid); 2664 return 0; 2665 } 2666 2667 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *gid) 2668 { 2669 uint32_t len; 2670 __be32 *p; 2671 2672 *gid = -2; 2673 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 2674 return -EIO; 2675 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 2676 READ_BUF(4); 2677 READ32(len); 2678 READ_BUF(len); 2679 if (len < XDR_MAX_NETOBJ) { 2680 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0) 2681 dprintk("%s: nfs_map_group_to_gid failed!\n", 2682 __FUNCTION__); 2683 } else 2684 printk(KERN_WARNING "%s: name too long (%u)!\n", 2685 __FUNCTION__, len); 2686 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 2687 } 2688 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid); 2689 return 0; 2690 } 2691 2692 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 2693 { 2694 uint32_t major = 0, minor = 0; 2695 __be32 *p; 2696 2697 *rdev = MKDEV(0,0); 2698 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 2699 return -EIO; 2700 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 2701 dev_t tmp; 2702 2703 READ_BUF(8); 2704 READ32(major); 2705 READ32(minor); 2706 tmp = MKDEV(major, minor); 2707 if (MAJOR(tmp) == major && MINOR(tmp) == minor) 2708 *rdev = tmp; 2709 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 2710 } 2711 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor); 2712 return 0; 2713 } 2714 2715 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2716 { 2717 __be32 *p; 2718 int status = 0; 2719 2720 *res = 0; 2721 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 2722 return -EIO; 2723 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 2724 READ_BUF(8); 2725 READ64(*res); 2726 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 2727 } 2728 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res); 2729 return status; 2730 } 2731 2732 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2733 { 2734 __be32 *p; 2735 int status = 0; 2736 2737 *res = 0; 2738 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 2739 return -EIO; 2740 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 2741 READ_BUF(8); 2742 READ64(*res); 2743 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 2744 } 2745 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res); 2746 return status; 2747 } 2748 2749 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2750 { 2751 __be32 *p; 2752 int status = 0; 2753 2754 *res = 0; 2755 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 2756 return -EIO; 2757 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 2758 READ_BUF(8); 2759 READ64(*res); 2760 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 2761 } 2762 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res); 2763 return status; 2764 } 2765 2766 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 2767 { 2768 __be32 *p; 2769 2770 *used = 0; 2771 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 2772 return -EIO; 2773 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 2774 READ_BUF(8); 2775 READ64(*used); 2776 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 2777 } 2778 dprintk("%s: space used=%Lu\n", __FUNCTION__, 2779 (unsigned long long)*used); 2780 return 0; 2781 } 2782 2783 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 2784 { 2785 __be32 *p; 2786 uint64_t sec; 2787 uint32_t nsec; 2788 2789 READ_BUF(12); 2790 READ64(sec); 2791 READ32(nsec); 2792 time->tv_sec = (time_t)sec; 2793 time->tv_nsec = (long)nsec; 2794 return 0; 2795 } 2796 2797 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 2798 { 2799 int status = 0; 2800 2801 time->tv_sec = 0; 2802 time->tv_nsec = 0; 2803 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 2804 return -EIO; 2805 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 2806 status = decode_attr_time(xdr, time); 2807 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 2808 } 2809 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec); 2810 return status; 2811 } 2812 2813 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 2814 { 2815 int status = 0; 2816 2817 time->tv_sec = 0; 2818 time->tv_nsec = 0; 2819 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 2820 return -EIO; 2821 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 2822 status = decode_attr_time(xdr, time); 2823 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 2824 } 2825 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec); 2826 return status; 2827 } 2828 2829 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 2830 { 2831 int status = 0; 2832 2833 time->tv_sec = 0; 2834 time->tv_nsec = 0; 2835 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 2836 return -EIO; 2837 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 2838 status = decode_attr_time(xdr, time); 2839 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 2840 } 2841 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec); 2842 return status; 2843 } 2844 2845 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) 2846 { 2847 unsigned int attrwords = XDR_QUADLEN(attrlen); 2848 unsigned int nwords = xdr->p - savep; 2849 2850 if (unlikely(attrwords != nwords)) { 2851 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n", 2852 __FUNCTION__, 2853 attrwords << 2, 2854 (attrwords < nwords) ? '<' : '>', 2855 nwords << 2); 2856 return -EIO; 2857 } 2858 return 0; 2859 } 2860 2861 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 2862 { 2863 __be32 *p; 2864 2865 READ_BUF(20); 2866 READ32(cinfo->atomic); 2867 READ64(cinfo->before); 2868 READ64(cinfo->after); 2869 return 0; 2870 } 2871 2872 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 2873 { 2874 __be32 *p; 2875 uint32_t supp, acc; 2876 int status; 2877 2878 status = decode_op_hdr(xdr, OP_ACCESS); 2879 if (status) 2880 return status; 2881 READ_BUF(8); 2882 READ32(supp); 2883 READ32(acc); 2884 access->supported = supp; 2885 access->access = acc; 2886 return 0; 2887 } 2888 2889 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 2890 { 2891 __be32 *p; 2892 int status; 2893 2894 status = decode_op_hdr(xdr, OP_CLOSE); 2895 if (status) 2896 return status; 2897 READ_BUF(sizeof(res->stateid.data)); 2898 COPYMEM(res->stateid.data, sizeof(res->stateid.data)); 2899 return 0; 2900 } 2901 2902 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) 2903 { 2904 __be32 *p; 2905 int status; 2906 2907 status = decode_op_hdr(xdr, OP_COMMIT); 2908 if (status) 2909 return status; 2910 READ_BUF(8); 2911 COPYMEM(res->verf->verifier, 8); 2912 return 0; 2913 } 2914 2915 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 2916 { 2917 __be32 *p; 2918 uint32_t bmlen; 2919 int status; 2920 2921 status = decode_op_hdr(xdr, OP_CREATE); 2922 if (status) 2923 return status; 2924 if ((status = decode_change_info(xdr, cinfo))) 2925 return status; 2926 READ_BUF(4); 2927 READ32(bmlen); 2928 READ_BUF(bmlen << 2); 2929 return 0; 2930 } 2931 2932 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 2933 { 2934 __be32 *savep; 2935 uint32_t attrlen, 2936 bitmap[2] = {0}; 2937 int status; 2938 2939 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 2940 goto xdr_error; 2941 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 2942 goto xdr_error; 2943 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 2944 goto xdr_error; 2945 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 2946 goto xdr_error; 2947 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 2948 goto xdr_error; 2949 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 2950 goto xdr_error; 2951 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 2952 goto xdr_error; 2953 status = verify_attr_len(xdr, savep, attrlen); 2954 xdr_error: 2955 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); 2956 return status; 2957 } 2958 2959 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 2960 { 2961 __be32 *savep; 2962 uint32_t attrlen, 2963 bitmap[2] = {0}; 2964 int status; 2965 2966 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 2967 goto xdr_error; 2968 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 2969 goto xdr_error; 2970 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 2971 goto xdr_error; 2972 2973 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 2974 goto xdr_error; 2975 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 2976 goto xdr_error; 2977 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 2978 goto xdr_error; 2979 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 2980 goto xdr_error; 2981 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 2982 goto xdr_error; 2983 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 2984 goto xdr_error; 2985 2986 status = verify_attr_len(xdr, savep, attrlen); 2987 xdr_error: 2988 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); 2989 return status; 2990 } 2991 2992 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 2993 { 2994 __be32 *savep; 2995 uint32_t attrlen, 2996 bitmap[2] = {0}; 2997 int status; 2998 2999 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3000 goto xdr_error; 3001 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3002 goto xdr_error; 3003 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3004 goto xdr_error; 3005 3006 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 3007 goto xdr_error; 3008 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 3009 goto xdr_error; 3010 3011 status = verify_attr_len(xdr, savep, attrlen); 3012 xdr_error: 3013 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); 3014 return status; 3015 } 3016 3017 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server) 3018 { 3019 __be32 *savep; 3020 uint32_t attrlen, 3021 bitmap[2] = {0}, 3022 type; 3023 int status, fmode = 0; 3024 uint64_t fileid; 3025 3026 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3027 goto xdr_error; 3028 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3029 goto xdr_error; 3030 3031 fattr->bitmap[0] = bitmap[0]; 3032 fattr->bitmap[1] = bitmap[1]; 3033 3034 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3035 goto xdr_error; 3036 3037 3038 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0) 3039 goto xdr_error; 3040 fattr->type = nfs_type2fmt[type].nfs2type; 3041 fmode = nfs_type2fmt[type].mode; 3042 3043 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0) 3044 goto xdr_error; 3045 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0) 3046 goto xdr_error; 3047 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0) 3048 goto xdr_error; 3049 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0) 3050 goto xdr_error; 3051 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, 3052 struct nfs4_fs_locations, 3053 fattr))) != 0) 3054 goto xdr_error; 3055 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0) 3056 goto xdr_error; 3057 fattr->mode |= fmode; 3058 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0) 3059 goto xdr_error; 3060 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0) 3061 goto xdr_error; 3062 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0) 3063 goto xdr_error; 3064 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0) 3065 goto xdr_error; 3066 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0) 3067 goto xdr_error; 3068 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0) 3069 goto xdr_error; 3070 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0) 3071 goto xdr_error; 3072 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0) 3073 goto xdr_error; 3074 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0) 3075 goto xdr_error; 3076 if (fattr->fileid == 0 && fileid != 0) 3077 fattr->fileid = fileid; 3078 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) 3079 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4; 3080 xdr_error: 3081 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status); 3082 return status; 3083 } 3084 3085 3086 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 3087 { 3088 __be32 *savep; 3089 uint32_t attrlen, bitmap[2]; 3090 int status; 3091 3092 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3093 goto xdr_error; 3094 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3095 goto xdr_error; 3096 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3097 goto xdr_error; 3098 3099 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 3100 3101 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 3102 goto xdr_error; 3103 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 3104 goto xdr_error; 3105 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 3106 goto xdr_error; 3107 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 3108 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 3109 goto xdr_error; 3110 fsinfo->wtpref = fsinfo->wtmax; 3111 3112 status = verify_attr_len(xdr, savep, attrlen); 3113 xdr_error: 3114 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status); 3115 return status; 3116 } 3117 3118 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 3119 { 3120 __be32 *p; 3121 uint32_t len; 3122 int status; 3123 3124 status = decode_op_hdr(xdr, OP_GETFH); 3125 if (status) 3126 return status; 3127 /* Zero handle first to allow comparisons */ 3128 memset(fh, 0, sizeof(*fh)); 3129 3130 READ_BUF(4); 3131 READ32(len); 3132 if (len > NFS4_FHSIZE) 3133 return -EIO; 3134 fh->size = len; 3135 READ_BUF(len); 3136 COPYMEM(fh->data, len); 3137 return 0; 3138 } 3139 3140 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 3141 { 3142 int status; 3143 3144 status = decode_op_hdr(xdr, OP_LINK); 3145 if (status) 3146 return status; 3147 return decode_change_info(xdr, cinfo); 3148 } 3149 3150 /* 3151 * We create the owner, so we know a proper owner.id length is 4. 3152 */ 3153 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 3154 { 3155 uint64_t offset, length, clientid; 3156 __be32 *p; 3157 uint32_t namelen, type; 3158 3159 READ_BUF(32); 3160 READ64(offset); 3161 READ64(length); 3162 READ32(type); 3163 if (fl != NULL) { 3164 fl->fl_start = (loff_t)offset; 3165 fl->fl_end = fl->fl_start + (loff_t)length - 1; 3166 if (length == ~(uint64_t)0) 3167 fl->fl_end = OFFSET_MAX; 3168 fl->fl_type = F_WRLCK; 3169 if (type & 1) 3170 fl->fl_type = F_RDLCK; 3171 fl->fl_pid = 0; 3172 } 3173 READ64(clientid); 3174 READ32(namelen); 3175 READ_BUF(namelen); 3176 return -NFS4ERR_DENIED; 3177 } 3178 3179 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 3180 { 3181 __be32 *p; 3182 int status; 3183 3184 status = decode_op_hdr(xdr, OP_LOCK); 3185 if (status == 0) { 3186 READ_BUF(sizeof(res->stateid.data)); 3187 COPYMEM(res->stateid.data, sizeof(res->stateid.data)); 3188 } else if (status == -NFS4ERR_DENIED) 3189 return decode_lock_denied(xdr, NULL); 3190 return status; 3191 } 3192 3193 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 3194 { 3195 int status; 3196 status = decode_op_hdr(xdr, OP_LOCKT); 3197 if (status == -NFS4ERR_DENIED) 3198 return decode_lock_denied(xdr, res->denied); 3199 return status; 3200 } 3201 3202 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 3203 { 3204 __be32 *p; 3205 int status; 3206 3207 status = decode_op_hdr(xdr, OP_LOCKU); 3208 if (status == 0) { 3209 READ_BUF(sizeof(res->stateid.data)); 3210 COPYMEM(res->stateid.data, sizeof(res->stateid.data)); 3211 } 3212 return status; 3213 } 3214 3215 static int decode_lookup(struct xdr_stream *xdr) 3216 { 3217 return decode_op_hdr(xdr, OP_LOOKUP); 3218 } 3219 3220 /* This is too sick! */ 3221 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 3222 { 3223 __be32 *p; 3224 uint32_t limit_type, nblocks, blocksize; 3225 3226 READ_BUF(12); 3227 READ32(limit_type); 3228 switch (limit_type) { 3229 case 1: 3230 READ64(*maxsize); 3231 break; 3232 case 2: 3233 READ32(nblocks); 3234 READ32(blocksize); 3235 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 3236 } 3237 return 0; 3238 } 3239 3240 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 3241 { 3242 __be32 *p; 3243 uint32_t delegation_type; 3244 3245 READ_BUF(4); 3246 READ32(delegation_type); 3247 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 3248 res->delegation_type = 0; 3249 return 0; 3250 } 3251 READ_BUF(20); 3252 COPYMEM(res->delegation.data, sizeof(res->delegation.data)); 3253 READ32(res->do_recall); 3254 switch (delegation_type) { 3255 case NFS4_OPEN_DELEGATE_READ: 3256 res->delegation_type = FMODE_READ; 3257 break; 3258 case NFS4_OPEN_DELEGATE_WRITE: 3259 res->delegation_type = FMODE_WRITE|FMODE_READ; 3260 if (decode_space_limit(xdr, &res->maxsize) < 0) 3261 return -EIO; 3262 } 3263 return decode_ace(xdr, NULL, res->server->nfs_client); 3264 } 3265 3266 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 3267 { 3268 __be32 *p; 3269 uint32_t bmlen; 3270 int status; 3271 3272 status = decode_op_hdr(xdr, OP_OPEN); 3273 if (status) 3274 return status; 3275 READ_BUF(sizeof(res->stateid.data)); 3276 COPYMEM(res->stateid.data, sizeof(res->stateid.data)); 3277 3278 decode_change_info(xdr, &res->cinfo); 3279 3280 READ_BUF(8); 3281 READ32(res->rflags); 3282 READ32(bmlen); 3283 if (bmlen > 10) 3284 goto xdr_error; 3285 3286 READ_BUF(bmlen << 2); 3287 p += bmlen; 3288 return decode_delegation(xdr, res); 3289 xdr_error: 3290 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen); 3291 return -EIO; 3292 } 3293 3294 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 3295 { 3296 __be32 *p; 3297 int status; 3298 3299 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 3300 if (status) 3301 return status; 3302 READ_BUF(sizeof(res->stateid.data)); 3303 COPYMEM(res->stateid.data, sizeof(res->stateid.data)); 3304 return 0; 3305 } 3306 3307 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 3308 { 3309 __be32 *p; 3310 int status; 3311 3312 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 3313 if (status) 3314 return status; 3315 READ_BUF(sizeof(res->stateid.data)); 3316 COPYMEM(res->stateid.data, sizeof(res->stateid.data)); 3317 return 0; 3318 } 3319 3320 static int decode_putfh(struct xdr_stream *xdr) 3321 { 3322 return decode_op_hdr(xdr, OP_PUTFH); 3323 } 3324 3325 static int decode_putrootfh(struct xdr_stream *xdr) 3326 { 3327 return decode_op_hdr(xdr, OP_PUTROOTFH); 3328 } 3329 3330 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 3331 { 3332 struct kvec *iov = req->rq_rcv_buf.head; 3333 __be32 *p; 3334 uint32_t count, eof, recvd, hdrlen; 3335 int status; 3336 3337 status = decode_op_hdr(xdr, OP_READ); 3338 if (status) 3339 return status; 3340 READ_BUF(8); 3341 READ32(eof); 3342 READ32(count); 3343 hdrlen = (u8 *) p - (u8 *) iov->iov_base; 3344 recvd = req->rq_rcv_buf.len - hdrlen; 3345 if (count > recvd) { 3346 printk(KERN_WARNING "NFS: server cheating in read reply: " 3347 "count %u > recvd %u\n", count, recvd); 3348 count = recvd; 3349 eof = 0; 3350 } 3351 xdr_read_pages(xdr, count); 3352 res->eof = eof; 3353 res->count = count; 3354 return 0; 3355 } 3356 3357 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 3358 { 3359 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 3360 struct page *page = *rcvbuf->pages; 3361 struct kvec *iov = rcvbuf->head; 3362 unsigned int nr, pglen = rcvbuf->page_len; 3363 __be32 *end, *entry, *p, *kaddr; 3364 uint32_t len, attrlen, xlen; 3365 int hdrlen, recvd, status; 3366 3367 status = decode_op_hdr(xdr, OP_READDIR); 3368 if (status) 3369 return status; 3370 READ_BUF(8); 3371 COPYMEM(readdir->verifier.data, 8); 3372 dprintk("%s: verifier = 0x%x%x\n", 3373 __FUNCTION__, 3374 ((u32 *)readdir->verifier.data)[0], 3375 ((u32 *)readdir->verifier.data)[1]); 3376 3377 3378 hdrlen = (char *) p - (char *) iov->iov_base; 3379 recvd = rcvbuf->len - hdrlen; 3380 if (pglen > recvd) 3381 pglen = recvd; 3382 xdr_read_pages(xdr, pglen); 3383 3384 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE); 3385 kaddr = p = kmap_atomic(page, KM_USER0); 3386 end = p + ((pglen + readdir->pgbase) >> 2); 3387 entry = p; 3388 for (nr = 0; *p++; nr++) { 3389 if (end - p < 3) 3390 goto short_pkt; 3391 dprintk("cookie = %Lu, ", *((unsigned long long *)p)); 3392 p += 2; /* cookie */ 3393 len = ntohl(*p++); /* filename length */ 3394 if (len > NFS4_MAXNAMLEN) { 3395 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len); 3396 goto err_unmap; 3397 } 3398 xlen = XDR_QUADLEN(len); 3399 if (end - p < xlen + 1) 3400 goto short_pkt; 3401 dprintk("filename = %*s\n", len, (char *)p); 3402 p += xlen; 3403 len = ntohl(*p++); /* bitmap length */ 3404 if (end - p < len + 1) 3405 goto short_pkt; 3406 p += len; 3407 attrlen = XDR_QUADLEN(ntohl(*p++)); 3408 if (end - p < attrlen + 2) 3409 goto short_pkt; 3410 p += attrlen; /* attributes */ 3411 entry = p; 3412 } 3413 if (!nr && (entry[0] != 0 || entry[1] == 0)) 3414 goto short_pkt; 3415 out: 3416 kunmap_atomic(kaddr, KM_USER0); 3417 return 0; 3418 short_pkt: 3419 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr); 3420 entry[0] = entry[1] = 0; 3421 /* truncate listing ? */ 3422 if (!nr) { 3423 printk(KERN_NOTICE "NFS: readdir reply truncated!\n"); 3424 entry[1] = 1; 3425 } 3426 goto out; 3427 err_unmap: 3428 kunmap_atomic(kaddr, KM_USER0); 3429 return -errno_NFSERR_IO; 3430 } 3431 3432 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 3433 { 3434 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 3435 struct kvec *iov = rcvbuf->head; 3436 int hdrlen, len, recvd; 3437 __be32 *p; 3438 char *kaddr; 3439 int status; 3440 3441 status = decode_op_hdr(xdr, OP_READLINK); 3442 if (status) 3443 return status; 3444 3445 /* Convert length of symlink */ 3446 READ_BUF(4); 3447 READ32(len); 3448 if (len >= rcvbuf->page_len || len <= 0) { 3449 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n"); 3450 return -ENAMETOOLONG; 3451 } 3452 hdrlen = (char *) xdr->p - (char *) iov->iov_base; 3453 recvd = req->rq_rcv_buf.len - hdrlen; 3454 if (recvd < len) { 3455 printk(KERN_WARNING "NFS: server cheating in readlink reply: " 3456 "count %u > recvd %u\n", len, recvd); 3457 return -EIO; 3458 } 3459 xdr_read_pages(xdr, len); 3460 /* 3461 * The XDR encode routine has set things up so that 3462 * the link text will be copied directly into the 3463 * buffer. We just have to do overflow-checking, 3464 * and and null-terminate the text (the VFS expects 3465 * null-termination). 3466 */ 3467 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); 3468 kaddr[len+rcvbuf->page_base] = '\0'; 3469 kunmap_atomic(kaddr, KM_USER0); 3470 return 0; 3471 } 3472 3473 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 3474 { 3475 int status; 3476 3477 status = decode_op_hdr(xdr, OP_REMOVE); 3478 if (status) 3479 goto out; 3480 status = decode_change_info(xdr, cinfo); 3481 out: 3482 return status; 3483 } 3484 3485 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 3486 struct nfs4_change_info *new_cinfo) 3487 { 3488 int status; 3489 3490 status = decode_op_hdr(xdr, OP_RENAME); 3491 if (status) 3492 goto out; 3493 if ((status = decode_change_info(xdr, old_cinfo))) 3494 goto out; 3495 status = decode_change_info(xdr, new_cinfo); 3496 out: 3497 return status; 3498 } 3499 3500 static int decode_renew(struct xdr_stream *xdr) 3501 { 3502 return decode_op_hdr(xdr, OP_RENEW); 3503 } 3504 3505 static int 3506 decode_restorefh(struct xdr_stream *xdr) 3507 { 3508 return decode_op_hdr(xdr, OP_RESTOREFH); 3509 } 3510 3511 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 3512 size_t *acl_len) 3513 { 3514 __be32 *savep; 3515 uint32_t attrlen, 3516 bitmap[2] = {0}; 3517 struct kvec *iov = req->rq_rcv_buf.head; 3518 int status; 3519 3520 *acl_len = 0; 3521 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3522 goto out; 3523 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3524 goto out; 3525 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3526 goto out; 3527 3528 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 3529 return -EIO; 3530 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 3531 int hdrlen, recvd; 3532 3533 /* We ignore &savep and don't do consistency checks on 3534 * the attr length. Let userspace figure it out.... */ 3535 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; 3536 recvd = req->rq_rcv_buf.len - hdrlen; 3537 if (attrlen > recvd) { 3538 printk(KERN_WARNING "NFS: server cheating in getattr" 3539 " acl reply: attrlen %u > recvd %u\n", 3540 attrlen, recvd); 3541 return -EINVAL; 3542 } 3543 xdr_read_pages(xdr, attrlen); 3544 *acl_len = attrlen; 3545 } else 3546 status = -EOPNOTSUPP; 3547 3548 out: 3549 return status; 3550 } 3551 3552 static int 3553 decode_savefh(struct xdr_stream *xdr) 3554 { 3555 return decode_op_hdr(xdr, OP_SAVEFH); 3556 } 3557 3558 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res) 3559 { 3560 __be32 *p; 3561 uint32_t bmlen; 3562 int status; 3563 3564 3565 status = decode_op_hdr(xdr, OP_SETATTR); 3566 if (status) 3567 return status; 3568 READ_BUF(4); 3569 READ32(bmlen); 3570 READ_BUF(bmlen << 2); 3571 return 0; 3572 } 3573 3574 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp) 3575 { 3576 __be32 *p; 3577 uint32_t opnum; 3578 int32_t nfserr; 3579 3580 READ_BUF(8); 3581 READ32(opnum); 3582 if (opnum != OP_SETCLIENTID) { 3583 printk(KERN_NOTICE 3584 "nfs4_decode_setclientid: Server returned operation" 3585 " %d\n", opnum); 3586 return -EIO; 3587 } 3588 READ32(nfserr); 3589 if (nfserr == NFS_OK) { 3590 READ_BUF(8 + sizeof(clp->cl_confirm.data)); 3591 READ64(clp->cl_clientid); 3592 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data)); 3593 } else if (nfserr == NFSERR_CLID_INUSE) { 3594 uint32_t len; 3595 3596 /* skip netid string */ 3597 READ_BUF(4); 3598 READ32(len); 3599 READ_BUF(len); 3600 3601 /* skip uaddr string */ 3602 READ_BUF(4); 3603 READ32(len); 3604 READ_BUF(len); 3605 return -NFSERR_CLID_INUSE; 3606 } else 3607 return -nfs4_stat_to_errno(nfserr); 3608 3609 return 0; 3610 } 3611 3612 static int decode_setclientid_confirm(struct xdr_stream *xdr) 3613 { 3614 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 3615 } 3616 3617 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 3618 { 3619 __be32 *p; 3620 int status; 3621 3622 status = decode_op_hdr(xdr, OP_WRITE); 3623 if (status) 3624 return status; 3625 3626 READ_BUF(16); 3627 READ32(res->count); 3628 READ32(res->verf->committed); 3629 COPYMEM(res->verf->verifier, 8); 3630 return 0; 3631 } 3632 3633 static int decode_delegreturn(struct xdr_stream *xdr) 3634 { 3635 return decode_op_hdr(xdr, OP_DELEGRETURN); 3636 } 3637 3638 /* 3639 * Decode OPEN_DOWNGRADE response 3640 */ 3641 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) 3642 { 3643 struct xdr_stream xdr; 3644 struct compound_hdr hdr; 3645 int status; 3646 3647 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3648 status = decode_compound_hdr(&xdr, &hdr); 3649 if (status) 3650 goto out; 3651 status = decode_putfh(&xdr); 3652 if (status) 3653 goto out; 3654 status = decode_open_downgrade(&xdr, res); 3655 if (status != 0) 3656 goto out; 3657 decode_getfattr(&xdr, res->fattr, res->server); 3658 out: 3659 return status; 3660 } 3661 3662 /* 3663 * END OF "GENERIC" DECODE ROUTINES. 3664 */ 3665 3666 /* 3667 * Decode ACCESS response 3668 */ 3669 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res) 3670 { 3671 struct xdr_stream xdr; 3672 struct compound_hdr hdr; 3673 int status; 3674 3675 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3676 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 3677 goto out; 3678 if ((status = decode_putfh(&xdr)) == 0) 3679 status = decode_access(&xdr, res); 3680 out: 3681 return status; 3682 } 3683 3684 /* 3685 * Decode LOOKUP response 3686 */ 3687 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) 3688 { 3689 struct xdr_stream xdr; 3690 struct compound_hdr hdr; 3691 int status; 3692 3693 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3694 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 3695 goto out; 3696 if ((status = decode_putfh(&xdr)) != 0) 3697 goto out; 3698 if ((status = decode_lookup(&xdr)) != 0) 3699 goto out; 3700 if ((status = decode_getfh(&xdr, res->fh)) != 0) 3701 goto out; 3702 status = decode_getfattr(&xdr, res->fattr, res->server); 3703 out: 3704 return status; 3705 } 3706 3707 /* 3708 * Decode LOOKUP_ROOT response 3709 */ 3710 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) 3711 { 3712 struct xdr_stream xdr; 3713 struct compound_hdr hdr; 3714 int status; 3715 3716 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3717 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 3718 goto out; 3719 if ((status = decode_putrootfh(&xdr)) != 0) 3720 goto out; 3721 if ((status = decode_getfh(&xdr, res->fh)) == 0) 3722 status = decode_getfattr(&xdr, res->fattr, res->server); 3723 out: 3724 return status; 3725 } 3726 3727 /* 3728 * Decode REMOVE response 3729 */ 3730 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res) 3731 { 3732 struct xdr_stream xdr; 3733 struct compound_hdr hdr; 3734 int status; 3735 3736 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3737 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 3738 goto out; 3739 if ((status = decode_putfh(&xdr)) != 0) 3740 goto out; 3741 if ((status = decode_remove(&xdr, &res->cinfo)) != 0) 3742 goto out; 3743 decode_getfattr(&xdr, res->dir_attr, res->server); 3744 out: 3745 return status; 3746 } 3747 3748 /* 3749 * Decode RENAME response 3750 */ 3751 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res) 3752 { 3753 struct xdr_stream xdr; 3754 struct compound_hdr hdr; 3755 int status; 3756 3757 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3758 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 3759 goto out; 3760 if ((status = decode_putfh(&xdr)) != 0) 3761 goto out; 3762 if ((status = decode_savefh(&xdr)) != 0) 3763 goto out; 3764 if ((status = decode_putfh(&xdr)) != 0) 3765 goto out; 3766 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) 3767 goto out; 3768 /* Current FH is target directory */ 3769 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0) 3770 goto out; 3771 if ((status = decode_restorefh(&xdr)) != 0) 3772 goto out; 3773 decode_getfattr(&xdr, res->old_fattr, res->server); 3774 out: 3775 return status; 3776 } 3777 3778 /* 3779 * Decode LINK response 3780 */ 3781 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res) 3782 { 3783 struct xdr_stream xdr; 3784 struct compound_hdr hdr; 3785 int status; 3786 3787 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3788 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 3789 goto out; 3790 if ((status = decode_putfh(&xdr)) != 0) 3791 goto out; 3792 if ((status = decode_savefh(&xdr)) != 0) 3793 goto out; 3794 if ((status = decode_putfh(&xdr)) != 0) 3795 goto out; 3796 if ((status = decode_link(&xdr, &res->cinfo)) != 0) 3797 goto out; 3798 /* 3799 * Note order: OP_LINK leaves the directory as the current 3800 * filehandle. 3801 */ 3802 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0) 3803 goto out; 3804 if ((status = decode_restorefh(&xdr)) != 0) 3805 goto out; 3806 decode_getfattr(&xdr, res->fattr, res->server); 3807 out: 3808 return status; 3809 } 3810 3811 /* 3812 * Decode CREATE response 3813 */ 3814 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) 3815 { 3816 struct xdr_stream xdr; 3817 struct compound_hdr hdr; 3818 int status; 3819 3820 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3821 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 3822 goto out; 3823 if ((status = decode_putfh(&xdr)) != 0) 3824 goto out; 3825 if ((status = decode_savefh(&xdr)) != 0) 3826 goto out; 3827 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) 3828 goto out; 3829 if ((status = decode_getfh(&xdr, res->fh)) != 0) 3830 goto out; 3831 if (decode_getfattr(&xdr, res->fattr, res->server) != 0) 3832 goto out; 3833 if ((status = decode_restorefh(&xdr)) != 0) 3834 goto out; 3835 decode_getfattr(&xdr, res->dir_fattr, res->server); 3836 out: 3837 return status; 3838 } 3839 3840 /* 3841 * Decode SYMLINK response 3842 */ 3843 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) 3844 { 3845 return nfs4_xdr_dec_create(rqstp, p, res); 3846 } 3847 3848 /* 3849 * Decode GETATTR response 3850 */ 3851 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res) 3852 { 3853 struct xdr_stream xdr; 3854 struct compound_hdr hdr; 3855 int status; 3856 3857 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3858 status = decode_compound_hdr(&xdr, &hdr); 3859 if (status) 3860 goto out; 3861 status = decode_putfh(&xdr); 3862 if (status) 3863 goto out; 3864 status = decode_getfattr(&xdr, res->fattr, res->server); 3865 out: 3866 return status; 3867 3868 } 3869 3870 /* 3871 * Encode an SETACL request 3872 */ 3873 static int 3874 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args) 3875 { 3876 struct xdr_stream xdr; 3877 struct compound_hdr hdr = { 3878 .nops = 2, 3879 }; 3880 int status; 3881 3882 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 3883 encode_compound_hdr(&xdr, &hdr); 3884 status = encode_putfh(&xdr, args->fh); 3885 if (status) 3886 goto out; 3887 status = encode_setacl(&xdr, args); 3888 out: 3889 return status; 3890 } 3891 /* 3892 * Decode SETACL response 3893 */ 3894 static int 3895 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res) 3896 { 3897 struct xdr_stream xdr; 3898 struct compound_hdr hdr; 3899 int status; 3900 3901 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3902 status = decode_compound_hdr(&xdr, &hdr); 3903 if (status) 3904 goto out; 3905 status = decode_putfh(&xdr); 3906 if (status) 3907 goto out; 3908 status = decode_setattr(&xdr, res); 3909 out: 3910 return status; 3911 } 3912 3913 /* 3914 * Decode GETACL response 3915 */ 3916 static int 3917 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len) 3918 { 3919 struct xdr_stream xdr; 3920 struct compound_hdr hdr; 3921 int status; 3922 3923 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3924 status = decode_compound_hdr(&xdr, &hdr); 3925 if (status) 3926 goto out; 3927 status = decode_putfh(&xdr); 3928 if (status) 3929 goto out; 3930 status = decode_getacl(&xdr, rqstp, acl_len); 3931 3932 out: 3933 return status; 3934 } 3935 3936 /* 3937 * Decode CLOSE response 3938 */ 3939 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) 3940 { 3941 struct xdr_stream xdr; 3942 struct compound_hdr hdr; 3943 int status; 3944 3945 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3946 status = decode_compound_hdr(&xdr, &hdr); 3947 if (status) 3948 goto out; 3949 status = decode_putfh(&xdr); 3950 if (status) 3951 goto out; 3952 status = decode_close(&xdr, res); 3953 if (status != 0) 3954 goto out; 3955 /* 3956 * Note: Server may do delete on close for this file 3957 * in which case the getattr call will fail with 3958 * an ESTALE error. Shouldn't be a problem, 3959 * though, since fattr->valid will remain unset. 3960 */ 3961 decode_getfattr(&xdr, res->fattr, res->server); 3962 out: 3963 return status; 3964 } 3965 3966 /* 3967 * Decode OPEN response 3968 */ 3969 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) 3970 { 3971 struct xdr_stream xdr; 3972 struct compound_hdr hdr; 3973 int status; 3974 3975 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 3976 status = decode_compound_hdr(&xdr, &hdr); 3977 if (status) 3978 goto out; 3979 status = decode_putfh(&xdr); 3980 if (status) 3981 goto out; 3982 status = decode_savefh(&xdr); 3983 if (status) 3984 goto out; 3985 status = decode_open(&xdr, res); 3986 if (status) 3987 goto out; 3988 status = decode_getfh(&xdr, &res->fh); 3989 if (status) 3990 goto out; 3991 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0) 3992 goto out; 3993 if ((status = decode_restorefh(&xdr)) != 0) 3994 goto out; 3995 decode_getfattr(&xdr, res->dir_attr, res->server); 3996 out: 3997 return status; 3998 } 3999 4000 /* 4001 * Decode OPEN_CONFIRM response 4002 */ 4003 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res) 4004 { 4005 struct xdr_stream xdr; 4006 struct compound_hdr hdr; 4007 int status; 4008 4009 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4010 status = decode_compound_hdr(&xdr, &hdr); 4011 if (status) 4012 goto out; 4013 status = decode_putfh(&xdr); 4014 if (status) 4015 goto out; 4016 status = decode_open_confirm(&xdr, res); 4017 out: 4018 return status; 4019 } 4020 4021 /* 4022 * Decode OPEN response 4023 */ 4024 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) 4025 { 4026 struct xdr_stream xdr; 4027 struct compound_hdr hdr; 4028 int status; 4029 4030 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4031 status = decode_compound_hdr(&xdr, &hdr); 4032 if (status) 4033 goto out; 4034 status = decode_putfh(&xdr); 4035 if (status) 4036 goto out; 4037 status = decode_open(&xdr, res); 4038 if (status) 4039 goto out; 4040 decode_getfattr(&xdr, res->f_attr, res->server); 4041 out: 4042 return status; 4043 } 4044 4045 /* 4046 * Decode SETATTR response 4047 */ 4048 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res) 4049 { 4050 struct xdr_stream xdr; 4051 struct compound_hdr hdr; 4052 int status; 4053 4054 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4055 status = decode_compound_hdr(&xdr, &hdr); 4056 if (status) 4057 goto out; 4058 status = decode_putfh(&xdr); 4059 if (status) 4060 goto out; 4061 status = decode_setattr(&xdr, res); 4062 if (status) 4063 goto out; 4064 status = decode_getfattr(&xdr, res->fattr, res->server); 4065 if (status == NFS4ERR_DELAY) 4066 status = 0; 4067 out: 4068 return status; 4069 } 4070 4071 /* 4072 * Decode LOCK response 4073 */ 4074 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res) 4075 { 4076 struct xdr_stream xdr; 4077 struct compound_hdr hdr; 4078 int status; 4079 4080 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4081 status = decode_compound_hdr(&xdr, &hdr); 4082 if (status) 4083 goto out; 4084 status = decode_putfh(&xdr); 4085 if (status) 4086 goto out; 4087 status = decode_lock(&xdr, res); 4088 out: 4089 return status; 4090 } 4091 4092 /* 4093 * Decode LOCKT response 4094 */ 4095 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res) 4096 { 4097 struct xdr_stream xdr; 4098 struct compound_hdr hdr; 4099 int status; 4100 4101 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4102 status = decode_compound_hdr(&xdr, &hdr); 4103 if (status) 4104 goto out; 4105 status = decode_putfh(&xdr); 4106 if (status) 4107 goto out; 4108 status = decode_lockt(&xdr, res); 4109 out: 4110 return status; 4111 } 4112 4113 /* 4114 * Decode LOCKU response 4115 */ 4116 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res) 4117 { 4118 struct xdr_stream xdr; 4119 struct compound_hdr hdr; 4120 int status; 4121 4122 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4123 status = decode_compound_hdr(&xdr, &hdr); 4124 if (status) 4125 goto out; 4126 status = decode_putfh(&xdr); 4127 if (status) 4128 goto out; 4129 status = decode_locku(&xdr, res); 4130 out: 4131 return status; 4132 } 4133 4134 /* 4135 * Decode READLINK response 4136 */ 4137 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res) 4138 { 4139 struct xdr_stream xdr; 4140 struct compound_hdr hdr; 4141 int status; 4142 4143 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4144 status = decode_compound_hdr(&xdr, &hdr); 4145 if (status) 4146 goto out; 4147 status = decode_putfh(&xdr); 4148 if (status) 4149 goto out; 4150 status = decode_readlink(&xdr, rqstp); 4151 out: 4152 return status; 4153 } 4154 4155 /* 4156 * Decode READDIR response 4157 */ 4158 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res) 4159 { 4160 struct xdr_stream xdr; 4161 struct compound_hdr hdr; 4162 int status; 4163 4164 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4165 status = decode_compound_hdr(&xdr, &hdr); 4166 if (status) 4167 goto out; 4168 status = decode_putfh(&xdr); 4169 if (status) 4170 goto out; 4171 status = decode_readdir(&xdr, rqstp, res); 4172 out: 4173 return status; 4174 } 4175 4176 /* 4177 * Decode Read response 4178 */ 4179 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res) 4180 { 4181 struct xdr_stream xdr; 4182 struct compound_hdr hdr; 4183 int status; 4184 4185 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4186 status = decode_compound_hdr(&xdr, &hdr); 4187 if (status) 4188 goto out; 4189 status = decode_putfh(&xdr); 4190 if (status) 4191 goto out; 4192 status = decode_read(&xdr, rqstp, res); 4193 if (!status) 4194 status = res->count; 4195 out: 4196 return status; 4197 } 4198 4199 /* 4200 * Decode WRITE response 4201 */ 4202 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) 4203 { 4204 struct xdr_stream xdr; 4205 struct compound_hdr hdr; 4206 int status; 4207 4208 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4209 status = decode_compound_hdr(&xdr, &hdr); 4210 if (status) 4211 goto out; 4212 status = decode_putfh(&xdr); 4213 if (status) 4214 goto out; 4215 status = decode_write(&xdr, res); 4216 if (status) 4217 goto out; 4218 decode_getfattr(&xdr, res->fattr, res->server); 4219 if (!status) 4220 status = res->count; 4221 out: 4222 return status; 4223 } 4224 4225 /* 4226 * Decode COMMIT response 4227 */ 4228 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) 4229 { 4230 struct xdr_stream xdr; 4231 struct compound_hdr hdr; 4232 int status; 4233 4234 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4235 status = decode_compound_hdr(&xdr, &hdr); 4236 if (status) 4237 goto out; 4238 status = decode_putfh(&xdr); 4239 if (status) 4240 goto out; 4241 status = decode_commit(&xdr, res); 4242 if (status) 4243 goto out; 4244 decode_getfattr(&xdr, res->fattr, res->server); 4245 out: 4246 return status; 4247 } 4248 4249 /* 4250 * FSINFO request 4251 */ 4252 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo) 4253 { 4254 struct xdr_stream xdr; 4255 struct compound_hdr hdr; 4256 int status; 4257 4258 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 4259 status = decode_compound_hdr(&xdr, &hdr); 4260 if (!status) 4261 status = decode_putfh(&xdr); 4262 if (!status) 4263 status = decode_fsinfo(&xdr, fsinfo); 4264 if (!status) 4265 status = -nfs4_stat_to_errno(hdr.status); 4266 return status; 4267 } 4268 4269 /* 4270 * PATHCONF request 4271 */ 4272 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf) 4273 { 4274 struct xdr_stream xdr; 4275 struct compound_hdr hdr; 4276 int status; 4277 4278 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 4279 status = decode_compound_hdr(&xdr, &hdr); 4280 if (!status) 4281 status = decode_putfh(&xdr); 4282 if (!status) 4283 status = decode_pathconf(&xdr, pathconf); 4284 return status; 4285 } 4286 4287 /* 4288 * STATFS request 4289 */ 4290 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat) 4291 { 4292 struct xdr_stream xdr; 4293 struct compound_hdr hdr; 4294 int status; 4295 4296 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 4297 status = decode_compound_hdr(&xdr, &hdr); 4298 if (!status) 4299 status = decode_putfh(&xdr); 4300 if (!status) 4301 status = decode_statfs(&xdr, fsstat); 4302 return status; 4303 } 4304 4305 /* 4306 * GETATTR_BITMAP request 4307 */ 4308 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res) 4309 { 4310 struct xdr_stream xdr; 4311 struct compound_hdr hdr; 4312 int status; 4313 4314 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 4315 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0) 4316 goto out; 4317 if ((status = decode_putfh(&xdr)) != 0) 4318 goto out; 4319 status = decode_server_caps(&xdr, res); 4320 out: 4321 return status; 4322 } 4323 4324 /* 4325 * Decode RENEW response 4326 */ 4327 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy) 4328 { 4329 struct xdr_stream xdr; 4330 struct compound_hdr hdr; 4331 int status; 4332 4333 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4334 status = decode_compound_hdr(&xdr, &hdr); 4335 if (!status) 4336 status = decode_renew(&xdr); 4337 return status; 4338 } 4339 4340 /* 4341 * a SETCLIENTID request 4342 */ 4343 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p, 4344 struct nfs_client *clp) 4345 { 4346 struct xdr_stream xdr; 4347 struct compound_hdr hdr; 4348 int status; 4349 4350 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 4351 status = decode_compound_hdr(&xdr, &hdr); 4352 if (!status) 4353 status = decode_setclientid(&xdr, clp); 4354 if (!status) 4355 status = -nfs4_stat_to_errno(hdr.status); 4356 return status; 4357 } 4358 4359 /* 4360 * a SETCLIENTID_CONFIRM request 4361 */ 4362 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo) 4363 { 4364 struct xdr_stream xdr; 4365 struct compound_hdr hdr; 4366 int status; 4367 4368 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 4369 status = decode_compound_hdr(&xdr, &hdr); 4370 if (!status) 4371 status = decode_setclientid_confirm(&xdr); 4372 if (!status) 4373 status = decode_putrootfh(&xdr); 4374 if (!status) 4375 status = decode_fsinfo(&xdr, fsinfo); 4376 if (!status) 4377 status = -nfs4_stat_to_errno(hdr.status); 4378 return status; 4379 } 4380 4381 /* 4382 * DELEGRETURN request 4383 */ 4384 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res) 4385 { 4386 struct xdr_stream xdr; 4387 struct compound_hdr hdr; 4388 int status; 4389 4390 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4391 status = decode_compound_hdr(&xdr, &hdr); 4392 if (status != 0) 4393 goto out; 4394 status = decode_putfh(&xdr); 4395 if (status != 0) 4396 goto out; 4397 status = decode_delegreturn(&xdr); 4398 decode_getfattr(&xdr, res->fattr, res->server); 4399 out: 4400 return status; 4401 } 4402 4403 /* 4404 * FS_LOCATIONS request 4405 */ 4406 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res) 4407 { 4408 struct xdr_stream xdr; 4409 struct compound_hdr hdr; 4410 int status; 4411 4412 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 4413 status = decode_compound_hdr(&xdr, &hdr); 4414 if (status != 0) 4415 goto out; 4416 if ((status = decode_putfh(&xdr)) != 0) 4417 goto out; 4418 if ((status = decode_lookup(&xdr)) != 0) 4419 goto out; 4420 xdr_enter_page(&xdr, PAGE_SIZE); 4421 status = decode_getfattr(&xdr, &res->fattr, res->server); 4422 out: 4423 return status; 4424 } 4425 4426 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus) 4427 { 4428 uint32_t bitmap[2] = {0}; 4429 uint32_t len; 4430 4431 if (!*p++) { 4432 if (!*p) 4433 return ERR_PTR(-EAGAIN); 4434 entry->eof = 1; 4435 return ERR_PTR(-EBADCOOKIE); 4436 } 4437 4438 entry->prev_cookie = entry->cookie; 4439 p = xdr_decode_hyper(p, &entry->cookie); 4440 entry->len = ntohl(*p++); 4441 entry->name = (const char *) p; 4442 p += XDR_QUADLEN(entry->len); 4443 4444 /* 4445 * In case the server doesn't return an inode number, 4446 * we fake one here. (We don't use inode number 0, 4447 * since glibc seems to choke on it...) 4448 */ 4449 entry->ino = 1; 4450 4451 len = ntohl(*p++); /* bitmap length */ 4452 if (len-- > 0) { 4453 bitmap[0] = ntohl(*p++); 4454 if (len-- > 0) { 4455 bitmap[1] = ntohl(*p++); 4456 p += len; 4457 } 4458 } 4459 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */ 4460 if (len > 0) { 4461 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) { 4462 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 4463 /* Ignore the return value of rdattr_error for now */ 4464 p++; 4465 len--; 4466 } 4467 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID) 4468 xdr_decode_hyper(p, &entry->ino); 4469 else if (bitmap[0] == FATTR4_WORD0_FILEID) 4470 xdr_decode_hyper(p, &entry->ino); 4471 p += len; 4472 } 4473 4474 entry->eof = !p[0] && p[1]; 4475 return p; 4476 } 4477 4478 /* 4479 * We need to translate between nfs status return values and 4480 * the local errno values which may not be the same. 4481 */ 4482 static struct { 4483 int stat; 4484 int errno; 4485 } nfs_errtbl[] = { 4486 { NFS4_OK, 0 }, 4487 { NFS4ERR_PERM, EPERM }, 4488 { NFS4ERR_NOENT, ENOENT }, 4489 { NFS4ERR_IO, errno_NFSERR_IO }, 4490 { NFS4ERR_NXIO, ENXIO }, 4491 { NFS4ERR_ACCESS, EACCES }, 4492 { NFS4ERR_EXIST, EEXIST }, 4493 { NFS4ERR_XDEV, EXDEV }, 4494 { NFS4ERR_NOTDIR, ENOTDIR }, 4495 { NFS4ERR_ISDIR, EISDIR }, 4496 { NFS4ERR_INVAL, EINVAL }, 4497 { NFS4ERR_FBIG, EFBIG }, 4498 { NFS4ERR_NOSPC, ENOSPC }, 4499 { NFS4ERR_ROFS, EROFS }, 4500 { NFS4ERR_MLINK, EMLINK }, 4501 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG }, 4502 { NFS4ERR_NOTEMPTY, ENOTEMPTY }, 4503 { NFS4ERR_DQUOT, EDQUOT }, 4504 { NFS4ERR_STALE, ESTALE }, 4505 { NFS4ERR_BADHANDLE, EBADHANDLE }, 4506 { NFS4ERR_BADOWNER, EINVAL }, 4507 { NFS4ERR_BADNAME, EINVAL }, 4508 { NFS4ERR_BAD_COOKIE, EBADCOOKIE }, 4509 { NFS4ERR_NOTSUPP, ENOTSUPP }, 4510 { NFS4ERR_TOOSMALL, ETOOSMALL }, 4511 { NFS4ERR_SERVERFAULT, ESERVERFAULT }, 4512 { NFS4ERR_BADTYPE, EBADTYPE }, 4513 { NFS4ERR_LOCKED, EAGAIN }, 4514 { NFS4ERR_RESOURCE, EREMOTEIO }, 4515 { NFS4ERR_SYMLINK, ELOOP }, 4516 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP }, 4517 { NFS4ERR_DEADLOCK, EDEADLK }, 4518 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs 4519 * to be handled by a 4520 * middle-layer. 4521 */ 4522 { -1, EIO } 4523 }; 4524 4525 /* 4526 * Convert an NFS error code to a local one. 4527 * This one is used jointly by NFSv2 and NFSv3. 4528 */ 4529 static int 4530 nfs4_stat_to_errno(int stat) 4531 { 4532 int i; 4533 for (i = 0; nfs_errtbl[i].stat != -1; i++) { 4534 if (nfs_errtbl[i].stat == stat) 4535 return nfs_errtbl[i].errno; 4536 } 4537 if (stat <= 10000 || stat > 10100) { 4538 /* The server is looney tunes. */ 4539 return ESERVERFAULT; 4540 } 4541 /* If we cannot translate the error, the recovery routines should 4542 * handle it. 4543 * Note: remaining NFSv4 error codes have values > 10000, so should 4544 * not conflict with native Linux error codes. 4545 */ 4546 return stat; 4547 } 4548 4549 #ifndef MAX 4550 # define MAX(a, b) (((a) > (b))? (a) : (b)) 4551 #endif 4552 4553 #define PROC(proc, argtype, restype) \ 4554 [NFSPROC4_CLNT_##proc] = { \ 4555 .p_proc = NFSPROC4_COMPOUND, \ 4556 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ 4557 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ 4558 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \ 4559 .p_statidx = NFSPROC4_CLNT_##proc, \ 4560 .p_name = #proc, \ 4561 } 4562 4563 struct rpc_procinfo nfs4_procedures[] = { 4564 PROC(READ, enc_read, dec_read), 4565 PROC(WRITE, enc_write, dec_write), 4566 PROC(COMMIT, enc_commit, dec_commit), 4567 PROC(OPEN, enc_open, dec_open), 4568 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 4569 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 4570 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 4571 PROC(CLOSE, enc_close, dec_close), 4572 PROC(SETATTR, enc_setattr, dec_setattr), 4573 PROC(FSINFO, enc_fsinfo, dec_fsinfo), 4574 PROC(RENEW, enc_renew, dec_renew), 4575 PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 4576 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 4577 PROC(LOCK, enc_lock, dec_lock), 4578 PROC(LOCKT, enc_lockt, dec_lockt), 4579 PROC(LOCKU, enc_locku, dec_locku), 4580 PROC(ACCESS, enc_access, dec_access), 4581 PROC(GETATTR, enc_getattr, dec_getattr), 4582 PROC(LOOKUP, enc_lookup, dec_lookup), 4583 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 4584 PROC(REMOVE, enc_remove, dec_remove), 4585 PROC(RENAME, enc_rename, dec_rename), 4586 PROC(LINK, enc_link, dec_link), 4587 PROC(SYMLINK, enc_symlink, dec_symlink), 4588 PROC(CREATE, enc_create, dec_create), 4589 PROC(PATHCONF, enc_pathconf, dec_pathconf), 4590 PROC(STATFS, enc_statfs, dec_statfs), 4591 PROC(READLINK, enc_readlink, dec_readlink), 4592 PROC(READDIR, enc_readdir, dec_readdir), 4593 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 4594 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 4595 PROC(GETACL, enc_getacl, dec_getacl), 4596 PROC(SETACL, enc_setacl, dec_setacl), 4597 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 4598 }; 4599 4600 struct rpc_version nfs_version4 = { 4601 .number = 4, 4602 .nrprocs = ARRAY_SIZE(nfs4_procedures), 4603 .procs = nfs4_procedures 4604 }; 4605 4606 /* 4607 * Local variables: 4608 * c-basic-offset: 8 4609 * End: 4610 */ 4611