1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Process version 2 NFS requests. 4 * 5 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de> 6 */ 7 8 #include <linux/namei.h> 9 #include <linux/sunrpc/svc.h> 10 11 #include "nfs2xdr_gen.h" 12 13 #include "auth.h" 14 #include "nfsd.h" 15 #include "cache.h" 16 #include "xdr.h" 17 #include "vfs.h" 18 #include "nfserr.h" 19 #include "trace.h" 20 21 #define NFSDDBG_FACILITY NFSDDBG_PROC 22 23 /* 24 * Wrapper structures combine xdrgen types with legacy structures. 25 * The xdrgen field must be first so the structure can be cast 26 * to its XDR type for the RPC dispatch layer. 27 */ 28 29 struct fhandle_wrapper { 30 fhandle xdrgen; 31 struct svc_fh fh; 32 }; 33 34 static_assert(offsetof(struct fhandle_wrapper, xdrgen) == 0); 35 36 struct attrstat_wrapper { 37 struct attrstat xdrgen; 38 struct kstat stat; 39 }; 40 41 static_assert(offsetof(struct attrstat_wrapper, xdrgen) == 0); 42 43 struct sattrargs_wrapper { 44 struct sattrargs xdrgen; 45 struct svc_fh fh; 46 struct iattr iattrs; 47 }; 48 49 static_assert(offsetof(struct sattrargs_wrapper, xdrgen) == 0); 50 51 struct diropargs_wrapper { 52 struct diropargs xdrgen; 53 struct svc_fh fh; 54 }; 55 56 static_assert(offsetof(struct diropargs_wrapper, xdrgen) == 0); 57 58 struct diropres_wrapper { 59 struct diropres xdrgen; 60 struct svc_fh fh; 61 struct kstat stat; 62 }; 63 64 static_assert(offsetof(struct diropres_wrapper, xdrgen) == 0); 65 66 struct createargs_wrapper { 67 struct createargs xdrgen; 68 struct svc_fh fh; 69 struct iattr iattrs; 70 }; 71 72 static_assert(offsetof(struct createargs_wrapper, xdrgen) == 0); 73 74 struct readargs_wrapper { 75 struct readargs xdrgen; 76 struct svc_fh fh; 77 }; 78 79 static_assert(offsetof(struct readargs_wrapper, xdrgen) == 0); 80 81 struct writeargs_wrapper { 82 struct writeargs xdrgen; 83 struct svc_fh fh; 84 }; 85 86 static_assert(offsetof(struct writeargs_wrapper, xdrgen) == 0); 87 88 struct renameargs_wrapper { 89 struct renameargs xdrgen; 90 struct svc_fh ffh; 91 struct svc_fh tfh; 92 }; 93 94 static_assert(offsetof(struct renameargs_wrapper, xdrgen) == 0); 95 96 struct linkargs_wrapper { 97 struct linkargs xdrgen; 98 struct svc_fh ffh; 99 struct svc_fh tfh; 100 }; 101 102 static_assert(offsetof(struct linkargs_wrapper, xdrgen) == 0); 103 104 struct symlinkargs_wrapper { 105 struct symlinkargs xdrgen; 106 struct svc_fh ffh; 107 struct iattr iattrs; 108 }; 109 110 static_assert(offsetof(struct symlinkargs_wrapper, xdrgen) == 0); 111 112 struct statfsres_wrapper { 113 struct statfsres xdrgen; 114 struct kstatfs stats; 115 }; 116 117 static_assert(offsetof(struct statfsres_wrapper, xdrgen) == 0); 118 119 static __be32 nfsd_map_status(__be32 status) 120 { 121 switch (status) { 122 case nfs_ok: 123 break; 124 case nfserr_nofilehandle: 125 case nfserr_badhandle: 126 status = nfserr_stale; 127 break; 128 case nfserr_wrongsec: 129 case nfserr_xdev: 130 case nfserr_file_open: 131 status = nfserr_acces; 132 break; 133 case nfserr_symlink_not_dir: 134 status = nfserr_notdir; 135 break; 136 case nfserr_symlink: 137 case nfserr_wrong_type: 138 status = nfserr_io; 139 break; 140 } 141 return status; 142 } 143 144 static __always_inline void 145 nfsd_fhandle_to_svc_fh(struct svc_fh *fhp, const fhandle *fhandle) 146 { 147 fh_init(fhp, NFS_FHSIZE); 148 fhp->fh_handle.fh_size = NFS_FHSIZE; 149 memcpy(&fhp->fh_handle.fh_raw, fhandle, NFS_FHSIZE); 150 } 151 152 static __always_inline void 153 nfsd_svc_fh_to_fhandle(fhandle *fhandle, const struct svc_fh *fhp) 154 { 155 memcpy(fhandle, fhp->fh_handle.fh_raw, NFS_FHSIZE); 156 } 157 158 static __always_inline void 159 nfsd_timespec64_to_timeval(struct timeval *dst, 160 const struct timespec64 *src) 161 { 162 dst->seconds = src->tv_sec; 163 dst->useconds = src->tv_nsec / NSEC_PER_USEC; 164 } 165 166 static __always_inline void 167 nfsd_timeval_to_timespec64(struct timespec64 *dst, const struct timeval *src) 168 { 169 dst->tv_sec = src->seconds; 170 dst->tv_nsec = src->useconds * NSEC_PER_USEC; 171 } 172 173 static u32 174 nfsd_mode_to_ftype(umode_t mode) 175 { 176 switch (mode & S_IFMT) { 177 case S_IFREG: return NFREG; 178 case S_IFDIR: return NFDIR; 179 case S_IFBLK: return NFBLK; 180 case S_IFCHR: return NFCHR; 181 case S_IFLNK: return NFLNK; 182 /* 183 * The NFSv2 protocol's ftype enum does not provide specific values 184 * for sockets and FIFOs. 185 */ 186 case S_IFSOCK: return NFNON; 187 case S_IFIFO: return NFNON; 188 } 189 return NFNON; 190 } 191 192 static void 193 nfsd_stat_to_fattr(struct svc_rqst *rqstp, struct fattr *fattr, 194 const struct kstat *stat, const struct svc_fh *fhp) 195 { 196 struct user_namespace *userns = nfsd_user_namespace(rqstp); 197 struct timespec64 time; 198 u32 fsid; 199 200 fattr->type = nfsd_mode_to_ftype(stat->mode); 201 fattr->mode = stat->mode; 202 fattr->nlink = stat->nlink; 203 fattr->uid = from_kuid_munged(userns, stat->uid); 204 fattr->gid = from_kgid_munged(userns, stat->gid); 205 if (S_ISLNK(stat->mode) && stat->size > NFS_MAXPATHLEN) 206 fattr->size = NFS_MAXPATHLEN; 207 else 208 fattr->size = stat->size; 209 fattr->blocksize = stat->blksize; 210 if (S_ISCHR(stat->mode) || S_ISBLK(stat->mode)) 211 fattr->rdev = new_encode_dev(stat->rdev); 212 else 213 fattr->rdev = 0xffffffff; 214 fattr->blocks = stat->blocks; 215 216 switch (fsid_source(fhp)) { 217 case FSIDSOURCE_FSID: 218 fsid = (u32)fhp->fh_export->ex_fsid; 219 break; 220 case FSIDSOURCE_UUID: 221 fsid = ((u32 *)fhp->fh_export->ex_uuid)[0]; 222 fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[1]; 223 fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[2]; 224 fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[3]; 225 break; 226 default: 227 fsid = new_encode_dev(stat->dev); 228 } 229 fattr->fsid = fsid; 230 fattr->fileid = stat->ino; 231 232 nfsd_timespec64_to_timeval(&fattr->atime, &stat->atime); 233 time = stat->mtime; 234 lease_get_mtime(d_inode(fhp->fh_dentry), &time); 235 nfsd_timespec64_to_timeval(&fattr->mtime, &time); 236 nfsd_timespec64_to_timeval(&fattr->ctime, &stat->ctime); 237 } 238 239 /* 240 * Because NFSv2 does not have an NFSERR_SYMLINK, Solaris returns 241 * NFSERR_ISDIR when the target of a READ or WRITE is any object 242 * that is not a regular file. 243 */ 244 static __be32 nfsd_map_io_status(__be32 status) 245 { 246 switch (status) { 247 case nfserr_symlink: 248 case nfserr_wrong_type: 249 return nfserr_isdir; 250 } 251 return nfsd_map_status(status); 252 } 253 254 /* 255 * Sun convention: a sattr time-useconds field of one full second (an 256 * otherwise out-of-range value) means "set this time to the current 257 * server time." It's needed to make permissions checks for the "touch" 258 * program across NFSv2 mounts work correctly. See description of 259 * sattr in section 6.1 of "NFS Illustrated" by Brent Callaghan, 260 * Addison-Wesley, ISBN 0-201-32750-5 261 */ 262 #define NFS2_SATTR_SET_TO_SERVER_TIME (1000000) 263 264 static bool 265 nfsd_sattr_to_iattr(struct svc_rqst *rqstp, struct iattr *iap, 266 const struct sattr *sattr) 267 { 268 static const unsigned int dont_set_it = (unsigned int)-1; 269 270 /* Consumers read ia_size, ia_uid, and ia_gid unguarded by ia_valid */ 271 memset(iap, 0, sizeof(*iap)); 272 273 /* 274 * Some Sun NFS clients put 0xffff in the mode field when they 275 * mean 0xffffffff. 276 */ 277 if (sattr->mode != dont_set_it && sattr->mode != 0xffff) { 278 iap->ia_valid |= ATTR_MODE; 279 iap->ia_mode = sattr->mode; 280 } 281 if (sattr->uid != dont_set_it) { 282 iap->ia_uid = make_kuid(nfsd_user_namespace(rqstp), sattr->uid); 283 if (uid_valid(iap->ia_uid)) 284 iap->ia_valid |= ATTR_UID; 285 } 286 if (sattr->gid != dont_set_it) { 287 iap->ia_gid = make_kgid(nfsd_user_namespace(rqstp), sattr->gid); 288 if (gid_valid(iap->ia_gid)) 289 iap->ia_valid |= ATTR_GID; 290 } 291 if (sattr->size != dont_set_it) { 292 iap->ia_valid |= ATTR_SIZE; 293 iap->ia_size = sattr->size; 294 } 295 if (sattr->atime.seconds != dont_set_it && 296 sattr->atime.useconds != dont_set_it) { 297 /* 298 * Reject out-of-range useconds so the conversion to 299 * nanoseconds cannot wrap to a valid but incorrect 300 * value on 32-bit platforms. 301 */ 302 if (sattr->atime.useconds > NFS2_SATTR_SET_TO_SERVER_TIME) 303 return false; 304 iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET; 305 nfsd_timeval_to_timespec64(&iap->ia_atime, &sattr->atime); 306 307 if (sattr->atime.useconds == NFS2_SATTR_SET_TO_SERVER_TIME) 308 iap->ia_valid &= ~ATTR_ATIME_SET; 309 } 310 if (sattr->mtime.seconds != dont_set_it && 311 sattr->mtime.useconds != dont_set_it) { 312 if (sattr->mtime.useconds > NFS2_SATTR_SET_TO_SERVER_TIME) 313 return false; 314 iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET; 315 nfsd_timeval_to_timespec64(&iap->ia_mtime, &sattr->mtime); 316 317 if (sattr->mtime.useconds == NFS2_SATTR_SET_TO_SERVER_TIME) 318 iap->ia_valid &= ~(ATTR_ATIME_SET | ATTR_MTIME_SET); 319 } 320 321 return true; 322 } 323 324 /* 325 * A full specification of each of the following NFSv2 procedures is 326 * available in RFC 1094 Section 2.2. 327 */ 328 329 /** 330 * nfsd_proc_null - NULL: Do nothing 331 * @rqstp: RPC transaction context 332 * 333 * Return: 334 * %rpc_success: RPC executed successfully 335 * 336 * RPC synopsis: 337 * void NFSPROC_NULL(void) = 0; 338 */ 339 static __be32 nfsd_proc_null(struct svc_rqst *rqstp) 340 { 341 return rpc_success; 342 } 343 344 /** 345 * nfsd_proc_getattr - GETATTR: Get file attributes 346 * @rqstp: RPC transaction context 347 * 348 * Return: 349 * %rpc_success: RPC executed successfully 350 * 351 * RPC synopsis: 352 * attrstat NFSPROC_GETATTR(fhandle) = 1; 353 */ 354 static __be32 nfsd_proc_getattr(struct svc_rqst *rqstp) 355 { 356 struct fhandle_wrapper *argp = rqstp->rq_argp; 357 struct attrstat_wrapper *resp = rqstp->rq_resp; 358 struct kstat *statp = &resp->stat; 359 struct svc_fh *fhp = &argp->fh; 360 361 nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen); 362 trace_nfsd_vfs_getattr(rqstp, fhp); 363 resp->xdrgen.status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP | 364 NFSD_MAY_BYPASS_GSS_ON_ROOT); 365 if (resp->xdrgen.status != nfs_ok) 366 goto out; 367 368 resp->xdrgen.status = fh_getattr(fhp, statp); 369 370 out: 371 if (resp->xdrgen.status == nfs_ok) 372 nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.attributes, statp, fhp); 373 else 374 resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status); 375 376 fh_put(fhp); 377 return rpc_success; 378 } 379 380 /** 381 * nfsd_proc_setattr - SETATTR: Set file attributes 382 * @rqstp: RPC transaction context 383 * 384 * Return: 385 * %rpc_success: RPC executed successfully 386 * 387 * RPC synopsis: 388 * attrstat NFSPROC_SETATTR(sattrargs) = 2; 389 */ 390 static __be32 nfsd_proc_setattr(struct svc_rqst *rqstp) 391 { 392 struct sattrargs_wrapper *argp = rqstp->rq_argp; 393 struct attrstat_wrapper *resp = rqstp->rq_resp; 394 struct kstat *statp = &resp->stat; 395 struct iattr *iap = &argp->iattrs; 396 struct nfsd_attrs nattrs = { 397 .na_iattr = iap, 398 }; 399 struct svc_fh *fhp = &argp->fh; 400 401 nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen.file); 402 if (!nfsd_sattr_to_iattr(rqstp, iap, &argp->xdrgen.attributes)) { 403 resp->xdrgen.status = nfserr_io; 404 goto out; 405 } 406 407 /* 408 * NFSv2 does not differentiate between "set-[ac]time-to-now" 409 * which only requires access, and "set-[ac]time-to-X" which 410 * requires ownership. 411 * So if it looks like it might be "set both to the same time which 412 * is close to now", and if setattr_prepare fails, then we 413 * convert to "set to now" instead of "set to explicit time" 414 * 415 * We only call setattr_prepare as the last test as technically 416 * it is not an interface that we should be using. 417 */ 418 #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET) 419 #define MAX_TOUCH_TIME_ERROR (30*60) 420 if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET && 421 iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) { 422 int hosterr; 423 424 /* 425 * Looks probable. 426 * 427 * Now just make sure time is in the right ballpark. 428 * Solaris, at least, doesn't seem to care what the time 429 * request is. We require it be within 30 minutes of now. 430 */ 431 time64_t delta = iap->ia_atime.tv_sec - ktime_get_real_seconds(); 432 433 resp->xdrgen.status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP); 434 if (resp->xdrgen.status != nfs_ok) 435 goto out; 436 437 hosterr = fh_want_write(fhp); 438 if (hosterr) { 439 resp->xdrgen.status = nfserrno(hosterr); 440 goto out; 441 } 442 443 if (delta < 0) 444 delta = -delta; 445 if (delta < MAX_TOUCH_TIME_ERROR && 446 setattr_prepare(&nop_mnt_idmap, fhp->fh_dentry, iap) != 0) { 447 /* 448 * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME. 449 * This will cause notify_change to set these times 450 * to "now" 451 */ 452 iap->ia_valid &= ~BOTH_TIME_SET; 453 } 454 } 455 456 resp->xdrgen.status = nfsd_setattr(rqstp, fhp, &nattrs, NULL); 457 if (resp->xdrgen.status != nfs_ok) 458 goto out; 459 460 resp->xdrgen.status = fh_getattr(fhp, statp); 461 462 out: 463 if (resp->xdrgen.status == nfs_ok) 464 nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.attributes, statp, fhp); 465 else 466 resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status); 467 468 fh_put(fhp); 469 return rpc_success; 470 } 471 472 /** 473 * nfsd_proc_root - ROOT: Get filesystem root 474 * @rqstp: RPC transaction context 475 * 476 * Obsolete, replaced by MNTPROC_MNT. 477 * 478 * Return: 479 * %rpc_success: RPC executed successfully 480 * 481 * RPC synopsis: 482 * void NFSPROC_ROOT(void) = 3; 483 */ 484 static __be32 nfsd_proc_root(struct svc_rqst *rqstp) 485 { 486 return rpc_success; 487 } 488 489 /** 490 * nfsd_proc_lookup - LOOKUP: Look up file name 491 * @rqstp: RPC transaction context 492 * 493 * Return: 494 * %rpc_success: RPC executed successfully 495 * 496 * RPC synopsis: 497 * diropres NFSPROC_LOOKUP(diropargs) = 4; 498 */ 499 static __be32 nfsd_proc_lookup(struct svc_rqst *rqstp) 500 { 501 struct diropargs_wrapper *argp = rqstp->rq_argp; 502 struct diropres_wrapper *resp = rqstp->rq_resp; 503 struct diropargs *what = &argp->xdrgen; 504 struct kstat *statp = &resp->stat; 505 struct svc_fh *dirfhp = &argp->fh; 506 struct svc_fh *fhp = &resp->fh; 507 508 nfsd_fhandle_to_svc_fh(dirfhp, &what->dir); 509 510 fh_init(fhp, NFS_FHSIZE); 511 resp->xdrgen.status = nfsd_lookup(rqstp, dirfhp, 512 (char *)what->name.data, 513 what->name.len, fhp); 514 if (resp->xdrgen.status != nfs_ok) 515 goto out; 516 resp->xdrgen.status = fh_getattr(fhp, statp); 517 518 out: 519 if (resp->xdrgen.status == nfs_ok) { 520 nfsd_svc_fh_to_fhandle(&resp->xdrgen.u.diropok.file, fhp); 521 nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.diropok.attributes, 522 statp, fhp); 523 } else { 524 resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status); 525 } 526 527 fh_put(fhp); 528 fh_put(dirfhp); 529 return rpc_success; 530 } 531 532 /** 533 * nfsd_proc_readlink - READLINK: Read symbolic link 534 * @rqstp: RPC transaction context 535 * 536 * Return: 537 * %rpc_success: RPC executed successfully 538 * 539 * RPC synopsis: 540 * readlinkres NFSPROC_READLINK(fhandle) = 5; 541 */ 542 static __be32 nfsd_proc_readlink(struct svc_rqst *rqstp) 543 { 544 struct fhandle_wrapper *argp = rqstp->rq_argp; 545 struct readlinkres *resp = rqstp->rq_resp; 546 struct svc_fh *fhp = &argp->fh; 547 struct page *page; 548 u32 len; 549 550 nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen); 551 552 len = NFS_MAXPATHLEN; 553 page = *(rqstp->rq_next_page++); 554 resp->status = nfsd_readlink(rqstp, fhp, page_address(page), &len); 555 if (resp->status == nfs_ok) 556 resp->u.data.len = len; 557 else 558 resp->status = nfsd_map_status(resp->status); 559 560 fh_put(fhp); 561 return rpc_success; 562 } 563 564 /** 565 * nfsd_proc_read - READ: Read from file 566 * @rqstp: RPC transaction context 567 * 568 * Return: 569 * %rpc_success: RPC executed successfully 570 * 571 * RPC synopsis: 572 * readres NFSPROC_READ(readargs) = 6; 573 */ 574 static __be32 nfsd_proc_read(struct svc_rqst *rqstp) 575 { 576 struct readargs_wrapper *argp = rqstp->rq_argp; 577 struct readres *resp = rqstp->rq_resp; 578 unsigned long count = argp->xdrgen.count; 579 u32 offset = argp->xdrgen.offset; 580 struct svc_fh *fhp = &argp->fh; 581 struct kstat stat; 582 u32 eof; 583 584 nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen.file); 585 count = min_t(u32, count, NFS_MAXDATA); 586 count = min_t(u32, count, rqstp->rq_res.buflen); 587 588 /* 589 * 19 is 1 word for status, 17 words for fattr, and 1 word 590 * for the byte count. 591 */ 592 svc_reserve_auth(rqstp, (19 << 2) + count + 4); 593 resp->status = nfsd_read(rqstp, fhp, offset, &count, &eof); 594 595 if (resp->status == nfs_ok) { 596 struct readresok *resok = &resp->u.readresok; 597 598 resok->data.len = count; 599 resp->status = fh_getattr(fhp, &stat); 600 if (resp->status == nfs_ok) 601 nfsd_stat_to_fattr(rqstp, &resok->attributes, &stat, 602 fhp); 603 } 604 if (resp->status == nfserr_jukebox) 605 set_bit(RQ_DROPME, &rqstp->rq_flags); 606 if (resp->status != nfs_ok) 607 resp->status = nfsd_map_io_status(resp->status); 608 609 fh_put(fhp); 610 return rpc_success; 611 } 612 613 /** 614 * nfsd_proc_writecache - WRITECACHE: To-client write cache 615 * @rqstp: RPC transaction context 616 * 617 * Reserved. 618 * 619 * Return: 620 * %rpc_success: RPC executed successfully 621 * 622 * RPC synopsis: 623 * void NFSPROC_WRITECACHE(void) = 7; 624 */ 625 static __be32 nfsd_proc_writecache(struct svc_rqst *rqstp) 626 { 627 return rpc_success; 628 } 629 630 /** 631 * nfsd_proc_write - WRITE: Write to file 632 * @rqstp: RPC transaction context 633 * 634 * Return: 635 * %rpc_success: RPC executed successfully 636 * 637 * RPC synopsis: 638 * attrstat NFSPROC_WRITE(writeargs) = 8; 639 */ 640 static __be32 nfsd_proc_write(struct svc_rqst *rqstp) 641 { 642 struct writeargs_wrapper *argp = rqstp->rq_argp; 643 struct attrstat_wrapper *resp = rqstp->rq_resp; 644 struct kstat *statp = &resp->stat; 645 unsigned long count = argp->xdrgen.data.len; 646 struct svc_fh *fhp = &argp->fh; 647 648 nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen.file); 649 650 resp->xdrgen.status = nfsd_write(rqstp, fhp, argp->xdrgen.offset, 651 &argp->xdrgen.data, &count, 652 IOCB_DSYNC, NULL); 653 if (resp->xdrgen.status == nfs_ok) { 654 resp->xdrgen.status = fh_getattr(fhp, statp); 655 if (resp->xdrgen.status == nfs_ok) 656 nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.attributes, 657 statp, fhp); 658 } 659 if (resp->xdrgen.status == nfserr_jukebox) 660 set_bit(RQ_DROPME, &rqstp->rq_flags); 661 if (resp->xdrgen.status != nfs_ok) 662 resp->xdrgen.status = nfsd_map_io_status(resp->xdrgen.status); 663 664 fh_put(fhp); 665 return rpc_success; 666 } 667 668 /* 669 * Implement NFSv2's unchecked CREATE semantics. Based on type bits in the 670 * mode field, NFSv2 CREATE can create regular files, devices, and FIFOs. 671 * 672 * Caller must release @fhp and @resfhp. 673 */ 674 static __be32 675 nfsd_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, 676 struct svc_fh *resfhp, struct createargs_wrapper *argp) 677 { 678 struct diropargs *where = &argp->xdrgen.where; 679 struct iattr *attr = &argp->iattrs; 680 dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size); 681 struct nfsd_attrs attrs = { 682 .na_iattr = attr, 683 }; 684 struct svc_export *exp; 685 struct dentry *dchild, *dmnt; 686 struct inode *inode; 687 int type, mode; 688 __be32 status; 689 int host_err; 690 691 if (name_is_dot_dotdot(where->name.data, where->name.len)) 692 return nfserr_exist; 693 694 status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC); 695 if (status != nfs_ok) 696 return status; 697 698 host_err = fh_want_write(fhp); 699 if (host_err) 700 return nfserrno(host_err); 701 702 dchild = start_creating(&nop_mnt_idmap, fhp->fh_dentry, 703 &QSTR_LEN(where->name.data, where->name.len)); 704 if (IS_ERR(dchild)) { 705 status = nfserrno(PTR_ERR(dchild)); 706 goto out_drop_write; 707 } 708 exp = exp_get(fhp->fh_export); 709 /* 710 * If name exists we need to check for mountpoints. Cross on a 711 * separate reference: end_creating() unlocks the parent of the 712 * dentry it is given, and only dchild has the locked directory 713 * as its parent. 714 */ 715 dmnt = dget(dchild); 716 if (d_is_reg(dchild) && 717 unlikely(nfsd_mountpoint(dchild, exp))) { 718 status = nfsd_cross_mnt(rqstp, &dmnt, &exp); 719 if (status != nfs_ok) { 720 dput(dmnt); 721 exp_put(exp); 722 goto out; 723 } 724 } 725 726 status = fh_compose(resfhp, exp, dmnt, fhp); 727 dput(dmnt); 728 exp_put(exp); 729 if (!status && d_really_is_negative(dchild)) 730 status = nfserr_noent; 731 if (status) { 732 if (status != nfserr_noent) 733 goto out; 734 /* 735 * If the new file handle wasn't verified, we can't tell 736 * whether the file exists or not. Time to bail ... 737 */ 738 status = nfserr_acces; 739 if (!resfhp->fh_dentry) { 740 printk(KERN_WARNING 741 "nfsd_proc_create: file handle not verified\n"); 742 goto out; 743 } 744 } 745 746 inode = d_inode(resfhp->fh_dentry); 747 748 /* Unfudge the mode bits */ 749 if (attr->ia_valid & ATTR_MODE) { 750 type = attr->ia_mode & S_IFMT; 751 mode = attr->ia_mode & ~S_IFMT; 752 if (!type) { 753 /* no type, so if target exists, assume same as that, 754 * else assume a file */ 755 if (inode) { 756 type = inode->i_mode & S_IFMT; 757 switch (type) { 758 case S_IFCHR: 759 case S_IFBLK: 760 /* reserve rdev for later checking */ 761 rdev = inode->i_rdev; 762 attr->ia_valid |= ATTR_SIZE; 763 fallthrough; 764 case S_IFIFO: 765 /* this is probably a permission check.. 766 * at least IRIX implements perm checking on 767 * echo thing > device-special-file-or-pipe 768 * by doing a CREATE with type==0 769 */ 770 status = nfsd_permission( 771 &rqstp->rq_cred, 772 resfhp->fh_export, 773 resfhp->fh_dentry, 774 NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS); 775 if (status && status != nfserr_rofs) 776 goto out; 777 } 778 } else 779 type = S_IFREG; 780 } 781 } else if (inode) { 782 type = inode->i_mode & S_IFMT; 783 mode = inode->i_mode & ~S_IFMT; 784 } else { 785 type = S_IFREG; 786 mode = 0; /* ??? */ 787 } 788 789 attr->ia_valid |= ATTR_MODE; 790 attr->ia_mode = mode; 791 792 /* Special treatment for non-regular files according to the 793 * gospel of sun micro 794 */ 795 if (type != S_IFREG) { 796 if (type != S_IFBLK && type != S_IFCHR) { 797 rdev = 0; 798 } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) { 799 /* If you think you've seen the worst, grok this. */ 800 type = S_IFIFO; 801 } else { 802 /* Okay, char or block special */ 803 if (!rdev) 804 rdev = wanted; 805 } 806 807 /* we've used the SIZE information, so discard it */ 808 attr->ia_valid &= ~ATTR_SIZE; 809 810 /* Make sure the type and device matches */ 811 status = nfserr_exist; 812 if (inode && inode_wrong_type(inode, type)) 813 goto out; 814 } 815 816 status = nfs_ok; 817 if (!inode) { 818 /* File doesn't exist. Create it and set attrs */ 819 status = nfsd_create_locked(rqstp, fhp, &attrs, type, 820 rdev, resfhp); 821 /* nfsd_create_locked() unlocked the parent */ 822 dput(dchild); 823 goto out_drop_write; 824 } else if (type == S_IFREG) { 825 dprintk("nfsd: existing %s, valid=%x, size=%ld\n", 826 where->name.data, attr->ia_valid, (long)attr->ia_size); 827 /* File already exists. We ignore all attributes except 828 * size, so that creat() behaves exactly like 829 * open(..., O_CREAT|O_TRUNC|O_WRONLY). 830 */ 831 attr->ia_valid &= ATTR_SIZE; 832 if (attr->ia_valid) 833 status = nfsd_setattr(rqstp, resfhp, &attrs, NULL); 834 } 835 836 out: 837 end_creating(dchild); 838 out_drop_write: 839 fh_drop_write(fhp); 840 return status; 841 } 842 843 /** 844 * nfsd_proc_create - CREATE: Create a file 845 * @rqstp: RPC transaction context 846 * 847 * Return: 848 * %rpc_success: RPC executed successfully 849 * 850 * RPC synopsis: 851 * diropres NFSPROC_CREATE(createargs) = 9; 852 */ 853 static __be32 nfsd_proc_create(struct svc_rqst *rqstp) 854 { 855 struct createargs_wrapper *argp = rqstp->rq_argp; 856 struct diropres_wrapper *resp = rqstp->rq_resp; 857 struct kstat *statp = &resp->stat; 858 struct svc_fh *dirfhp = &argp->fh; 859 struct svc_fh *fhp = &resp->fh; 860 861 nfsd_fhandle_to_svc_fh(dirfhp, &argp->xdrgen.where.dir); 862 fh_init(fhp, NFS_FHSIZE); 863 if (!nfsd_sattr_to_iattr(rqstp, &argp->iattrs, &argp->xdrgen.attributes)) { 864 resp->xdrgen.status = nfserr_io; 865 goto out; 866 } 867 868 resp->xdrgen.status = nfsd_create_file(rqstp, dirfhp, fhp, argp); 869 if (resp->xdrgen.status != nfs_ok) 870 goto out; 871 resp->xdrgen.status = fh_getattr(fhp, statp); 872 873 out: 874 if (resp->xdrgen.status == nfs_ok) { 875 nfsd_svc_fh_to_fhandle(&resp->xdrgen.u.diropok.file, fhp); 876 nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.diropok.attributes, 877 statp, fhp); 878 } else { 879 resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status); 880 } 881 882 fh_put(fhp); 883 fh_put(dirfhp); 884 return rpc_success; 885 } 886 887 /** 888 * nfsd_proc_remove - REMOVE: Remove a file 889 * @rqstp: RPC transaction context 890 * 891 * Return: 892 * %rpc_success: RPC executed successfully 893 * 894 * RPC synopsis: 895 * nfsstat NFSPROC_REMOVE(diropargs) = 10; 896 */ 897 static __be32 nfsd_proc_remove(struct svc_rqst *rqstp) 898 { 899 struct diropargs_wrapper *argp = rqstp->rq_argp; 900 struct diropargs *object = &argp->xdrgen; 901 nfsstat *resp = rqstp->rq_resp; 902 struct svc_fh *fhp = &argp->fh; 903 904 nfsd_fhandle_to_svc_fh(fhp, &object->dir); 905 906 /* Unlink. -S_IFDIR means file must not be a directory */ 907 *resp = nfsd_unlink(rqstp, fhp, -S_IFDIR, 908 (char *)object->name.data, object->name.len); 909 *resp = nfsd_map_status(*resp); 910 911 fh_put(fhp); 912 return rpc_success; 913 } 914 915 /** 916 * nfsd_proc_rename - RENAME: Rename a file or directory 917 * @rqstp: RPC transaction context 918 * 919 * Return: 920 * %rpc_success: RPC executed successfully 921 * 922 * RPC synopsis: 923 * nfsstat NFSPROC_RENAME(renameargs) = 11; 924 */ 925 static __be32 nfsd_proc_rename(struct svc_rqst *rqstp) 926 { 927 struct renameargs_wrapper *argp = rqstp->rq_argp; 928 struct diropargs *from = &argp->xdrgen.from; 929 struct diropargs *to = &argp->xdrgen.to; 930 nfsstat *resp = rqstp->rq_resp; 931 struct svc_fh *ffhp = &argp->ffh; 932 struct svc_fh *tfhp = &argp->tfh; 933 934 nfsd_fhandle_to_svc_fh(ffhp, &from->dir); 935 nfsd_fhandle_to_svc_fh(tfhp, &to->dir); 936 937 *resp = nfsd_rename(rqstp, ffhp, (char *)from->name.data, 938 from->name.len, tfhp, (char *)to->name.data, 939 to->name.len); 940 *resp = nfsd_map_status(*resp); 941 942 fh_put(ffhp); 943 fh_put(tfhp); 944 return rpc_success; 945 } 946 947 /** 948 * nfsd_proc_link - LINK: Create Link to an object 949 * @rqstp: RPC transaction context 950 * 951 * Return: 952 * %rpc_success: RPC executed successfully 953 * 954 * RPC synopsis: 955 * nfsstat NFSPROC_LINK(linkargs) = 12; 956 */ 957 static __be32 nfsd_proc_link(struct svc_rqst *rqstp) 958 { 959 struct linkargs_wrapper *argp = rqstp->rq_argp; 960 struct diropargs *to = &argp->xdrgen.to; 961 nfsstat *resp = rqstp->rq_resp; 962 struct svc_fh *ffhp = &argp->ffh; 963 struct svc_fh *tfhp = &argp->tfh; 964 965 nfsd_fhandle_to_svc_fh(ffhp, &argp->xdrgen.from); 966 nfsd_fhandle_to_svc_fh(tfhp, &to->dir); 967 968 *resp = nfsd_link(rqstp, tfhp, (char *)to->name.data, to->name.len, 969 ffhp); 970 *resp = nfsd_map_status(*resp); 971 972 fh_put(ffhp); 973 fh_put(tfhp); 974 return rpc_success; 975 } 976 977 static char *nfsd_symlink_target(const struct xdr_buf *to) 978 { 979 char *result; 980 981 result = kmalloc(to->len + 1, GFP_KERNEL); 982 if (!result) 983 return ERR_PTR(-ESERVERFAULT); 984 /* The target can span the receive buffer's head, pages, and tail */ 985 if (read_bytes_from_xdr_buf(to, 0, result, to->len)) { 986 kfree(result); 987 return ERR_PTR(-ESERVERFAULT); 988 } 989 result[to->len] = '\0'; 990 991 /* The VFS rejects a pathname that contains a NUL byte */ 992 if (strlen(result) != to->len) { 993 kfree(result); 994 return ERR_PTR(-EINVAL); 995 } 996 return result; 997 } 998 999 /** 1000 * nfsd_proc_symlink - SYMLINK: Create a symbolic link 1001 * @rqstp: RPC transaction context 1002 * 1003 * Return: 1004 * %rpc_success: RPC executed successfully 1005 * 1006 * RPC synopsis: 1007 * nfsstat NFSPROC_SYMLINK(symlinkargs) = 13; 1008 */ 1009 static __be32 nfsd_proc_symlink(struct svc_rqst *rqstp) 1010 { 1011 struct symlinkargs_wrapper *argp = rqstp->rq_argp; 1012 struct diropargs *from = &argp->xdrgen.from; 1013 struct xdr_buf *to = &argp->xdrgen.to; 1014 nfsstat *resp = rqstp->rq_resp; 1015 struct svc_fh *fhp = &argp->ffh; 1016 struct nfsd_attrs nattrs = { 1017 .na_iattr = &argp->iattrs, 1018 }; 1019 struct svc_fh newfh; 1020 char *tname; 1021 1022 nfsd_fhandle_to_svc_fh(fhp, &from->dir); 1023 if (!nfsd_sattr_to_iattr(rqstp, &argp->iattrs, &argp->xdrgen.attributes)) { 1024 *resp = nfserr_io; 1025 goto out; 1026 } 1027 1028 tname = nfsd_symlink_target(to); 1029 if (IS_ERR(tname)) { 1030 *resp = nfserrno(PTR_ERR(tname)); 1031 goto out; 1032 } 1033 1034 fh_init(&newfh, NFS_FHSIZE); 1035 *resp = nfsd_symlink(rqstp, fhp, (char *)from->name.data, from->name.len, 1036 tname, &nattrs, &newfh); 1037 kfree(tname); 1038 *resp = nfsd_map_status(*resp); 1039 1040 fh_put(&newfh); 1041 out: 1042 fh_put(fhp); 1043 return rpc_success; 1044 } 1045 1046 /** 1047 * nfsd_proc_mkdir - MKDIR: Create a directory 1048 * @rqstp: RPC transaction context 1049 * 1050 * Return: 1051 * %rpc_success: RPC executed successfully 1052 * 1053 * RPC synopsis: 1054 * diropres NFSPROC_MKDIR(createargs) = 14; 1055 */ 1056 static __be32 nfsd_proc_mkdir(struct svc_rqst *rqstp) 1057 { 1058 struct createargs_wrapper *argp = rqstp->rq_argp; 1059 struct diropargs *where = &argp->xdrgen.where; 1060 struct diropres_wrapper *resp = rqstp->rq_resp; 1061 struct kstat *statp = &resp->stat; 1062 struct svc_fh *dirfhp = &argp->fh; 1063 struct svc_fh *fhp = &resp->fh; 1064 struct nfsd_attrs nattrs = { 1065 .na_iattr = &argp->iattrs, 1066 }; 1067 1068 nfsd_fhandle_to_svc_fh(dirfhp, &where->dir); 1069 fh_init(fhp, NFS_FHSIZE); 1070 if (!nfsd_sattr_to_iattr(rqstp, &argp->iattrs, &argp->xdrgen.attributes)) { 1071 resp->xdrgen.status = nfserr_io; 1072 goto out; 1073 } 1074 1075 argp->iattrs.ia_valid &= ~ATTR_SIZE; 1076 resp->xdrgen.status = nfsd_create(rqstp, dirfhp, 1077 (char *)where->name.data, 1078 where->name.len, &nattrs, 1079 S_IFDIR, 0, fhp); 1080 if (resp->xdrgen.status != nfs_ok) 1081 goto out; 1082 resp->xdrgen.status = fh_getattr(fhp, statp); 1083 1084 out: 1085 if (resp->xdrgen.status == nfs_ok) { 1086 nfsd_svc_fh_to_fhandle(&resp->xdrgen.u.diropok.file, fhp); 1087 nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.diropok.attributes, 1088 statp, fhp); 1089 } else { 1090 resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status); 1091 } 1092 1093 fh_put(fhp); 1094 fh_put(dirfhp); 1095 return rpc_success; 1096 } 1097 1098 /** 1099 * nfsd_proc_rmdir - RMDIR: Remove a directory 1100 * @rqstp: RPC transaction context 1101 * 1102 * Return: 1103 * %rpc_success: RPC executed successfully 1104 * 1105 * RPC synopsis: 1106 * nfsstat NFSPROC_RMDIR(diropargs) = 15; 1107 */ 1108 static __be32 nfsd_proc_rmdir(struct svc_rqst *rqstp) 1109 { 1110 struct diropargs_wrapper *argp = rqstp->rq_argp; 1111 struct diropargs *object = &argp->xdrgen; 1112 nfsstat *resp = rqstp->rq_resp; 1113 struct svc_fh *fhp = &argp->fh; 1114 1115 nfsd_fhandle_to_svc_fh(fhp, &object->dir); 1116 1117 /* Unlink. S_IFDIR means file must be a directory */ 1118 *resp = nfsd_unlink(rqstp, fhp, S_IFDIR, 1119 (char *)object->name.data, object->name.len); 1120 *resp = nfsd_map_status(*resp); 1121 1122 fh_put(fhp); 1123 return rpc_success; 1124 } 1125 1126 /** 1127 * nfsd_proc_readdir - READDIR: Read from directory 1128 * @rqstp: RPC transaction context 1129 * 1130 * The directory is opened here so the reply status reflects any open 1131 * error before the generated encoder writes the status word. The 1132 * entry list is streamed from the reply wrapper's directory reader 1133 * during encode; nfssvc_release_readdirres() closes the reader and 1134 * releases the file handle. 1135 * 1136 * Return: 1137 * %rpc_success: RPC executed successfully 1138 * 1139 * RPC synopsis: 1140 * readdirres NFSPROC_READDIR(readdirargs) = 16; 1141 */ 1142 static __be32 nfsd_proc_readdir(struct svc_rqst *rqstp) 1143 { 1144 struct readdirargs *argp = rqstp->rq_argp; 1145 struct readdirres_wrapper *resp = rqstp->rq_resp; 1146 loff_t offset = be32_to_cpup((__be32 *)argp->cookie); 1147 struct svc_fh *fhp = &resp->fh; 1148 __be32 status; 1149 1150 nfsd_fhandle_to_svc_fh(fhp, &argp->dir); 1151 trace_nfsd_vfs_readdir(rqstp, fhp, argp->count, offset); 1152 1153 resp->count = argp->count; 1154 status = nfsd_readdir_open(rqstp, fhp, &offset, &resp->iter); 1155 1156 resp->xdrgen.status = nfsd_map_status(status); 1157 return rpc_success; 1158 } 1159 1160 /** 1161 * nfsd_proc_statfs - STATFS: Get filesystem attributes 1162 * @rqstp: RPC transaction context 1163 * 1164 * Return: 1165 * %rpc_success: RPC executed successfully 1166 * 1167 * RPC synopsis: 1168 * statfsres NFSPROC_STATFS(fhandle) = 17; 1169 */ 1170 static __be32 nfsd_proc_statfs(struct svc_rqst *rqstp) 1171 { 1172 struct fhandle_wrapper *argp = rqstp->rq_argp; 1173 struct statfsres_wrapper *resp = rqstp->rq_resp; 1174 struct kstatfs *stat = &resp->stats; 1175 struct svc_fh *fhp = &argp->fh; 1176 1177 nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen); 1178 1179 resp->xdrgen.status = nfsd_statfs(rqstp, fhp, stat, 1180 NFSD_MAY_BYPASS_GSS_ON_ROOT); 1181 if (resp->xdrgen.status == nfs_ok) { 1182 struct info *resinfo = &resp->xdrgen.u.info; 1183 1184 resinfo->tsize = NFS_MAXDATA; 1185 resinfo->bsize = stat->f_bsize; 1186 resinfo->blocks = stat->f_blocks; 1187 resinfo->bfree = stat->f_bfree; 1188 resinfo->bavail = stat->f_bavail; 1189 } else { 1190 resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status); 1191 } 1192 1193 fh_put(fhp); 1194 return rpc_success; 1195 } 1196 1197 /* 1198 * NFSv2 Server procedures. 1199 * Only the results of non-idempotent operations are cached. 1200 */ 1201 1202 #define ST 1 /* status */ 1203 #define FH 8 /* filehandle */ 1204 #define AT 18 /* attributes */ 1205 1206 static const struct svc_procedure nfsd_procedures2[18] = { 1207 [NFSPROC_NULL] = { 1208 .pc_func = nfsd_proc_null, 1209 .pc_decode = xdrgen_svc_decode_void, 1210 .pc_encode = xdrgen_svc_encode_void, 1211 .pc_argsize = XDR_void, 1212 .pc_argzero = 0, 1213 .pc_ressize = 0, 1214 .pc_cachetype = RC_NOCACHE, 1215 .pc_xdrressize = XDR_void, 1216 .pc_name = "NULL", 1217 }, 1218 [NFSPROC_GETATTR] = { 1219 .pc_func = nfsd_proc_getattr, 1220 .pc_decode = nfs_svc_decode_fhandle, 1221 .pc_encode = nfs_svc_encode_attrstat, 1222 .pc_argsize = sizeof(struct fhandle_wrapper), 1223 .pc_argzero = 0, 1224 .pc_ressize = sizeof(struct attrstat_wrapper), 1225 .pc_cachetype = RC_NOCACHE, 1226 .pc_xdrressize = NFS2_attrstat_sz, 1227 .pc_name = "GETATTR", 1228 }, 1229 [NFSPROC_SETATTR] = { 1230 .pc_func = nfsd_proc_setattr, 1231 .pc_decode = nfs_svc_decode_sattrargs, 1232 .pc_encode = nfs_svc_encode_attrstat, 1233 .pc_argsize = sizeof(struct sattrargs_wrapper), 1234 .pc_argzero = 0, 1235 .pc_ressize = sizeof(struct attrstat_wrapper), 1236 .pc_cachetype = RC_REPLBUFF, 1237 .pc_xdrressize = NFS2_attrstat_sz, 1238 .pc_name = "SETATTR", 1239 }, 1240 [NFSPROC_ROOT] = { 1241 .pc_func = nfsd_proc_root, 1242 .pc_decode = xdrgen_svc_decode_void, 1243 .pc_encode = xdrgen_svc_encode_void, 1244 .pc_argsize = XDR_void, 1245 .pc_argzero = 0, 1246 .pc_ressize = 0, 1247 .pc_cachetype = RC_NOCACHE, 1248 .pc_xdrressize = XDR_void, 1249 .pc_name = "ROOT", 1250 }, 1251 [NFSPROC_LOOKUP] = { 1252 .pc_func = nfsd_proc_lookup, 1253 .pc_decode = nfs_svc_decode_diropargs, 1254 .pc_encode = nfs_svc_encode_diropres, 1255 .pc_argsize = sizeof(struct diropargs_wrapper), 1256 .pc_argzero = 0, 1257 .pc_ressize = sizeof(struct diropres_wrapper), 1258 .pc_cachetype = RC_NOCACHE, 1259 .pc_xdrressize = NFS2_diropres_sz, 1260 .pc_name = "LOOKUP", 1261 }, 1262 [NFSPROC_READLINK] = { 1263 .pc_func = nfsd_proc_readlink, 1264 .pc_decode = nfs_svc_decode_fhandle, 1265 .pc_encode = nfs_svc_encode_readlinkres, 1266 .pc_argsize = sizeof(struct fhandle_wrapper), 1267 .pc_argzero = 0, 1268 .pc_ressize = sizeof(struct readlinkres), 1269 .pc_cachetype = RC_NOCACHE, 1270 .pc_xdrressize = NFS2_readlinkres_sz, 1271 .pc_name = "READLINK", 1272 }, 1273 [NFSPROC_READ] = { 1274 .pc_func = nfsd_proc_read, 1275 .pc_decode = nfs_svc_decode_readargs, 1276 .pc_encode = nfs_svc_encode_readres, 1277 .pc_argsize = sizeof(struct readargs_wrapper), 1278 .pc_argzero = 0, 1279 .pc_ressize = sizeof(struct readres), 1280 .pc_cachetype = RC_NOCACHE, 1281 .pc_xdrressize = NFS2_readres_sz, 1282 .pc_name = "READ", 1283 }, 1284 [NFSPROC_WRITECACHE] = { 1285 .pc_func = nfsd_proc_writecache, 1286 .pc_decode = xdrgen_svc_decode_void, 1287 .pc_encode = xdrgen_svc_encode_void, 1288 .pc_argsize = XDR_void, 1289 .pc_argzero = 0, 1290 .pc_ressize = 0, 1291 .pc_cachetype = RC_NOCACHE, 1292 .pc_xdrressize = XDR_void, 1293 .pc_name = "WRITECACHE", 1294 }, 1295 [NFSPROC_WRITE] = { 1296 .pc_func = nfsd_proc_write, 1297 .pc_decode = nfs_svc_decode_writeargs, 1298 .pc_encode = nfs_svc_encode_attrstat, 1299 .pc_argsize = sizeof(struct writeargs_wrapper), 1300 .pc_argzero = 0, 1301 .pc_ressize = sizeof(struct attrstat_wrapper), 1302 .pc_cachetype = RC_REPLBUFF, 1303 .pc_xdrressize = NFS2_attrstat_sz, 1304 .pc_name = "WRITE", 1305 }, 1306 [NFSPROC_CREATE] = { 1307 .pc_func = nfsd_proc_create, 1308 .pc_decode = nfs_svc_decode_createargs, 1309 .pc_encode = nfs_svc_encode_diropres, 1310 .pc_argsize = sizeof(struct createargs_wrapper), 1311 .pc_argzero = 0, 1312 .pc_ressize = sizeof(struct diropres_wrapper), 1313 .pc_cachetype = RC_REPLBUFF, 1314 .pc_xdrressize = NFS2_diropres_sz, 1315 .pc_name = "CREATE", 1316 }, 1317 [NFSPROC_REMOVE] = { 1318 .pc_func = nfsd_proc_remove, 1319 .pc_decode = nfs_svc_decode_diropargs, 1320 .pc_encode = nfs_svc_encode_nfsstat, 1321 .pc_argsize = sizeof(struct diropargs_wrapper), 1322 .pc_argzero = 0, 1323 .pc_ressize = sizeof(nfsstat), 1324 .pc_cachetype = RC_REPLSTAT, 1325 .pc_xdrressize = NFS2_nfsstat_sz, 1326 .pc_name = "REMOVE", 1327 }, 1328 [NFSPROC_RENAME] = { 1329 .pc_func = nfsd_proc_rename, 1330 .pc_decode = nfs_svc_decode_renameargs, 1331 .pc_encode = nfs_svc_encode_nfsstat, 1332 .pc_argsize = sizeof(struct renameargs_wrapper), 1333 .pc_argzero = 0, 1334 .pc_ressize = sizeof(nfsstat), 1335 .pc_cachetype = RC_REPLSTAT, 1336 .pc_xdrressize = NFS2_nfsstat_sz, 1337 .pc_name = "RENAME", 1338 }, 1339 [NFSPROC_LINK] = { 1340 .pc_func = nfsd_proc_link, 1341 .pc_decode = nfs_svc_decode_linkargs, 1342 .pc_encode = nfs_svc_encode_nfsstat, 1343 .pc_argsize = sizeof(struct linkargs_wrapper), 1344 .pc_argzero = 0, 1345 .pc_ressize = sizeof(nfsstat), 1346 .pc_cachetype = RC_REPLSTAT, 1347 .pc_xdrressize = NFS2_nfsstat_sz, 1348 .pc_name = "LINK", 1349 }, 1350 [NFSPROC_SYMLINK] = { 1351 .pc_func = nfsd_proc_symlink, 1352 .pc_decode = nfs_svc_decode_symlinkargs, 1353 .pc_encode = nfs_svc_encode_nfsstat, 1354 .pc_argsize = sizeof(struct symlinkargs_wrapper), 1355 .pc_argzero = 0, 1356 .pc_ressize = sizeof(nfsstat), 1357 .pc_cachetype = RC_REPLSTAT, 1358 .pc_xdrressize = NFS2_nfsstat_sz, 1359 .pc_name = "SYMLINK", 1360 }, 1361 [NFSPROC_MKDIR] = { 1362 .pc_func = nfsd_proc_mkdir, 1363 .pc_decode = nfs_svc_decode_createargs, 1364 .pc_encode = nfs_svc_encode_diropres, 1365 .pc_argsize = sizeof(struct createargs_wrapper), 1366 .pc_argzero = 0, 1367 .pc_ressize = sizeof(struct diropres_wrapper), 1368 .pc_cachetype = RC_REPLBUFF, 1369 .pc_xdrressize = NFS2_diropres_sz, 1370 .pc_name = "MKDIR", 1371 }, 1372 [NFSPROC_RMDIR] = { 1373 .pc_func = nfsd_proc_rmdir, 1374 .pc_decode = nfs_svc_decode_diropargs, 1375 .pc_encode = nfs_svc_encode_nfsstat, 1376 .pc_argsize = sizeof(struct diropargs_wrapper), 1377 .pc_argzero = 0, 1378 .pc_ressize = sizeof(nfsstat), 1379 .pc_cachetype = RC_REPLSTAT, 1380 .pc_xdrressize = NFS2_nfsstat_sz, 1381 .pc_name = "RMDIR", 1382 }, 1383 [NFSPROC_READDIR] = { 1384 .pc_func = nfsd_proc_readdir, 1385 .pc_decode = nfs_svc_decode_readdirargs, 1386 .pc_encode = nfs_svc_encode_readdirres, 1387 .pc_release = nfssvc_release_readdirres, 1388 .pc_argsize = sizeof(struct readdirargs), 1389 .pc_argzero = 0, 1390 .pc_ressize = sizeof(struct readdirres_wrapper), 1391 .pc_cachetype = RC_NOCACHE, 1392 .pc_name = "READDIR", 1393 }, 1394 [NFSPROC_STATFS] = { 1395 .pc_func = nfsd_proc_statfs, 1396 .pc_decode = nfs_svc_decode_fhandle, 1397 .pc_encode = nfs_svc_encode_statfsres, 1398 .pc_argsize = sizeof(struct fhandle_wrapper), 1399 .pc_argzero = 0, 1400 .pc_ressize = sizeof(struct statfsres_wrapper), 1401 .pc_cachetype = RC_NOCACHE, 1402 .pc_xdrressize = NFS2_statfsres_sz, 1403 .pc_name = "STATFS", 1404 }, 1405 }; 1406 1407 /* 1408 * Storage requirements for XDR arguments and results. 1409 */ 1410 union nfsd_xdrstore { 1411 struct fhandle_wrapper fhandle; 1412 struct sattrargs_wrapper sattrargs; 1413 struct diropargs_wrapper diropargs; 1414 struct readargs_wrapper readargs; 1415 struct writeargs_wrapper writeargs; 1416 struct createargs_wrapper createargs; 1417 struct renameargs_wrapper renameargs; 1418 struct linkargs_wrapper linkargs; 1419 struct symlinkargs_wrapper symlinkargs; 1420 struct readdirargs readdirargs; 1421 struct attrstat_wrapper attrstat; 1422 struct diropres_wrapper diropres; 1423 struct readlinkres readlinkres; 1424 struct readres readres; 1425 struct readdirres_wrapper readdirres; 1426 struct statfsres_wrapper statfsres; 1427 }; 1428 1429 const struct svc_version nfsd_version2 = { 1430 .vs_vers = 2, 1431 .vs_nproc = ARRAY_SIZE(nfsd_procedures2), 1432 .vs_proc = nfsd_procedures2, 1433 .vs_dispatch = nfsd_dispatch, 1434 .vs_xdrsize = sizeof(union nfsd_xdrstore), 1435 }; 1436