Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nfsd: convert fi_deleg_file and ls_file fields to nfsd_file

Have them keep an nfsd_file reference instead of a struct file.

Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>

authored by

Jeff Layton and committed by
J. Bruce Fields
eb82dd39 fd4f83fd

+85 -81
+1
fs/locks.c
··· 212 212 static DEFINE_PER_CPU(struct file_lock_list_struct, file_lock_list); 213 213 DEFINE_STATIC_PERCPU_RWSEM(file_rwsem); 214 214 215 + 215 216 /* 216 217 * The blocked_hash is used to find POSIX lock loops for deadlock detection. 217 218 * It is protected by blocked_lock_lock.
+2 -1
fs/nfsd/blocklayout.c
··· 15 15 16 16 #include "blocklayoutxdr.h" 17 17 #include "pnfs.h" 18 + #include "filecache.h" 18 19 19 20 #define NFSDDBG_FACILITY NFSDDBG_PNFS 20 21 ··· 405 404 nfsd4_scsi_fence_client(struct nfs4_layout_stateid *ls) 406 405 { 407 406 struct nfs4_client *clp = ls->ls_stid.sc_client; 408 - struct block_device *bdev = ls->ls_file->f_path.mnt->mnt_sb->s_bdev; 407 + struct block_device *bdev = ls->ls_file->nf_file->f_path.mnt->mnt_sb->s_bdev; 409 408 410 409 bdev->bd_disk->fops->pr_ops->pr_preempt(bdev, NFSD_MDS_PR_KEY, 411 410 nfsd4_scsi_pr_key(clp), 0, true);
+6 -6
fs/nfsd/nfs4layouts.c
··· 169 169 spin_unlock(&fp->fi_lock); 170 170 171 171 if (!nfsd4_layout_ops[ls->ls_layout_type]->disable_recalls) 172 - vfs_setlease(ls->ls_file, F_UNLCK, NULL, (void **)&ls); 173 - fput(ls->ls_file); 172 + vfs_setlease(ls->ls_file->nf_file, F_UNLCK, NULL, (void **)&ls); 173 + nfsd_file_put(ls->ls_file); 174 174 175 175 if (ls->ls_recalled) 176 176 atomic_dec(&ls->ls_stid.sc_file->fi_lo_recalls); ··· 197 197 fl->fl_end = OFFSET_MAX; 198 198 fl->fl_owner = ls; 199 199 fl->fl_pid = current->tgid; 200 - fl->fl_file = ls->ls_file; 200 + fl->fl_file = ls->ls_file->nf_file; 201 201 202 202 status = vfs_setlease(fl->fl_file, fl->fl_type, &fl, NULL); 203 203 if (status) { ··· 236 236 NFSPROC4_CLNT_CB_LAYOUT); 237 237 238 238 if (parent->sc_type == NFS4_DELEG_STID) 239 - ls->ls_file = get_file(fp->fi_deleg_file); 239 + ls->ls_file = nfsd_file_get(fp->fi_deleg_file); 240 240 else 241 241 ls->ls_file = find_any_file(fp); 242 242 BUG_ON(!ls->ls_file); 243 243 244 244 if (nfsd4_layout_setlease(ls)) { 245 - fput(ls->ls_file); 245 + nfsd_file_put(ls->ls_file); 246 246 put_nfs4_file(fp); 247 247 kmem_cache_free(nfs4_layout_stateid_cache, ls); 248 248 return NULL; ··· 626 626 627 627 argv[0] = (char *)nfsd_recall_failed; 628 628 argv[1] = addr_str; 629 - argv[2] = ls->ls_file->f_path.mnt->mnt_sb->s_id; 629 + argv[2] = ls->ls_file->nf_file->f_path.mnt->mnt_sb->s_id; 630 630 argv[3] = NULL; 631 631 632 632 error = call_usermodehelper(nfsd_recall_failed, argv, envp,
+73 -71
fs/nfsd/nfs4state.c
··· 430 430 } 431 431 } 432 432 433 - static struct file * 433 + static struct nfsd_file * 434 434 __nfs4_get_fd(struct nfs4_file *f, int oflag) 435 435 { 436 436 if (f->fi_fds[oflag]) 437 - return get_file(f->fi_fds[oflag]->nf_file); 437 + return nfsd_file_get(f->fi_fds[oflag]); 438 438 return NULL; 439 439 } 440 440 441 - static struct file * 441 + static struct nfsd_file * 442 442 find_writeable_file_locked(struct nfs4_file *f) 443 443 { 444 - struct file *ret; 444 + struct nfsd_file *ret; 445 445 446 446 lockdep_assert_held(&f->fi_lock); 447 447 ··· 451 451 return ret; 452 452 } 453 453 454 - static struct file * 454 + static struct nfsd_file * 455 455 find_writeable_file(struct nfs4_file *f) 456 456 { 457 - struct file *ret; 457 + struct nfsd_file *ret; 458 458 459 459 spin_lock(&f->fi_lock); 460 460 ret = find_writeable_file_locked(f); ··· 463 463 return ret; 464 464 } 465 465 466 - static struct file *find_readable_file_locked(struct nfs4_file *f) 466 + static struct nfsd_file * 467 + find_readable_file_locked(struct nfs4_file *f) 467 468 { 468 - struct file *ret; 469 + struct nfsd_file *ret; 469 470 470 471 lockdep_assert_held(&f->fi_lock); 471 472 ··· 476 475 return ret; 477 476 } 478 477 479 - static struct file * 478 + static struct nfsd_file * 480 479 find_readable_file(struct nfs4_file *f) 481 480 { 482 - struct file *ret; 481 + struct nfsd_file *ret; 483 482 484 483 spin_lock(&f->fi_lock); 485 484 ret = find_readable_file_locked(f); ··· 488 487 return ret; 489 488 } 490 489 491 - struct file * 490 + struct nfsd_file * 492 491 find_any_file(struct nfs4_file *f) 493 492 { 494 - struct file *ret; 493 + struct nfsd_file *ret; 495 494 496 495 spin_lock(&f->fi_lock); 497 496 ret = __nfs4_get_fd(f, O_RDWR); ··· 935 934 936 935 static void put_deleg_file(struct nfs4_file *fp) 937 936 { 938 - struct file *filp = NULL; 937 + struct nfsd_file *nf = NULL; 939 938 940 939 spin_lock(&fp->fi_lock); 941 940 if (--fp->fi_delegees == 0) 942 - swap(filp, fp->fi_deleg_file); 941 + swap(nf, fp->fi_deleg_file); 943 942 spin_unlock(&fp->fi_lock); 944 943 945 - if (filp) 946 - fput(filp); 944 + if (nf) 945 + nfsd_file_put(nf); 947 946 } 948 947 949 948 static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp) 950 949 { 951 950 struct nfs4_file *fp = dp->dl_stid.sc_file; 952 - struct file *filp = fp->fi_deleg_file; 951 + struct nfsd_file *nf = fp->fi_deleg_file; 953 952 954 953 WARN_ON_ONCE(!fp->fi_delegees); 955 954 956 - vfs_setlease(filp, F_UNLCK, NULL, (void **)&dp); 955 + vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp); 957 956 put_deleg_file(fp); 958 957 } 959 958 ··· 1291 1290 { 1292 1291 struct nfs4_ol_stateid *stp = openlockstateid(stid); 1293 1292 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); 1294 - struct file *file; 1293 + struct nfsd_file *nf; 1295 1294 1296 - file = find_any_file(stp->st_stid.sc_file); 1297 - if (file) 1298 - filp_close(file, (fl_owner_t)lo); 1295 + nf = find_any_file(stp->st_stid.sc_file); 1296 + if (nf) { 1297 + get_file(nf->nf_file); 1298 + filp_close(nf->nf_file, (fl_owner_t)lo); 1299 + nfsd_file_put(nf); 1300 + } 1299 1301 nfs4_free_ol_stateid(stid); 1300 1302 } 1301 1303 ··· 2415 2411 { 2416 2412 struct nfs4_delegation *ds; 2417 2413 struct nfs4_file *nf; 2418 - struct file *file; 2414 + struct nfsd_file *file; 2419 2415 2420 2416 ds = delegstateid(st); 2421 2417 nf = st->sc_file; ··· 2438 2434 static int nfs4_show_layout(struct seq_file *s, struct nfs4_stid *st) 2439 2435 { 2440 2436 struct nfs4_layout_stateid *ls; 2441 - struct file *file; 2437 + struct nfsd_file *file; 2442 2438 2443 2439 ls = container_of(st, struct nfs4_layout_stateid, ls_stid); 2444 2440 file = ls->ls_file; ··· 4772 4768 fl->fl_end = OFFSET_MAX; 4773 4769 fl->fl_owner = (fl_owner_t)dp; 4774 4770 fl->fl_pid = current->tgid; 4775 - fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file; 4771 + fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; 4776 4772 return fl; 4777 4773 } 4778 4774 ··· 4782 4778 { 4783 4779 int status = 0; 4784 4780 struct nfs4_delegation *dp; 4785 - struct file *filp; 4781 + struct nfsd_file *nf; 4786 4782 struct file_lock *fl; 4787 4783 4788 4784 /* ··· 4793 4789 if (fp->fi_had_conflict) 4794 4790 return ERR_PTR(-EAGAIN); 4795 4791 4796 - filp = find_readable_file(fp); 4797 - if (!filp) { 4792 + nf = find_readable_file(fp); 4793 + if (!nf) { 4798 4794 /* We should always have a readable file here */ 4799 4795 WARN_ON_ONCE(1); 4800 4796 return ERR_PTR(-EBADF); ··· 4804 4800 if (nfs4_delegation_exists(clp, fp)) 4805 4801 status = -EAGAIN; 4806 4802 else if (!fp->fi_deleg_file) { 4807 - fp->fi_deleg_file = filp; 4803 + fp->fi_deleg_file = nf; 4808 4804 /* increment early to prevent fi_deleg_file from being 4809 4805 * cleared */ 4810 4806 fp->fi_delegees = 1; 4811 - filp = NULL; 4807 + nf = NULL; 4812 4808 } else 4813 4809 fp->fi_delegees++; 4814 4810 spin_unlock(&fp->fi_lock); 4815 4811 spin_unlock(&state_lock); 4816 - if (filp) 4817 - fput(filp); 4812 + if (nf) 4813 + nfsd_file_put(nf); 4818 4814 if (status) 4819 4815 return ERR_PTR(status); 4820 4816 ··· 4827 4823 if (!fl) 4828 4824 goto out_clnt_odstate; 4829 4825 4830 - status = vfs_setlease(fp->fi_deleg_file, fl->fl_type, &fl, NULL); 4826 + status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL); 4831 4827 if (fl) 4832 4828 locks_free_lock(fl); 4833 4829 if (status) ··· 4847 4843 4848 4844 return dp; 4849 4845 out_unlock: 4850 - vfs_setlease(fp->fi_deleg_file, F_UNLCK, NULL, (void **)&dp); 4846 + vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp); 4851 4847 out_clnt_odstate: 4852 4848 put_clnt_odstate(dp->dl_clnt_odstate); 4853 4849 nfs4_put_stid(&dp->dl_stid); ··· 5518 5514 return nfs_ok; 5519 5515 } 5520 5516 5521 - static struct file * 5517 + static struct nfsd_file * 5522 5518 nfs4_find_file(struct nfs4_stid *s, int flags) 5523 5519 { 5524 5520 if (!s) ··· 5528 5524 case NFS4_DELEG_STID: 5529 5525 if (WARN_ON_ONCE(!s->sc_file->fi_deleg_file)) 5530 5526 return NULL; 5531 - return get_file(s->sc_file->fi_deleg_file); 5527 + return nfsd_file_get(s->sc_file->fi_deleg_file); 5532 5528 case NFS4_OPEN_STID: 5533 5529 case NFS4_LOCK_STID: 5534 5530 if (flags & RD_STATE) ··· 5557 5553 struct file **filpp, bool *tmp_file, int flags) 5558 5554 { 5559 5555 int acc = (flags & RD_STATE) ? NFSD_MAY_READ : NFSD_MAY_WRITE; 5560 - struct file *file; 5556 + struct nfsd_file *nf; 5561 5557 __be32 status; 5562 5558 5563 - file = nfs4_find_file(s, flags); 5564 - if (file) { 5559 + nf = nfs4_find_file(s, flags); 5560 + if (nf) { 5565 5561 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry, 5566 5562 acc | NFSD_MAY_OWNER_OVERRIDE); 5567 - if (status) { 5568 - fput(file); 5569 - return status; 5570 - } 5571 - 5572 - *filpp = file; 5563 + if (status) 5564 + goto out; 5573 5565 } else { 5574 - status = nfsd_open(rqstp, fhp, S_IFREG, acc, filpp); 5566 + status = nfsd_file_acquire(rqstp, fhp, acc, &nf); 5575 5567 if (status) 5576 5568 return status; 5577 5569 5578 5570 if (tmp_file) 5579 5571 *tmp_file = true; 5580 5572 } 5581 - 5582 - return 0; 5573 + *filpp = get_file(nf->nf_file); 5574 + out: 5575 + nfsd_file_put(nf); 5576 + return status; 5583 5577 } 5584 5578 5585 5579 /* ··· 6395 6393 struct nfs4_ol_stateid *lock_stp = NULL; 6396 6394 struct nfs4_ol_stateid *open_stp = NULL; 6397 6395 struct nfs4_file *fp; 6398 - struct file *filp = NULL; 6396 + struct nfsd_file *nf = NULL; 6399 6397 struct nfsd4_blocked_lock *nbl = NULL; 6400 6398 struct file_lock *file_lock = NULL; 6401 6399 struct file_lock *conflock = NULL; ··· 6477 6475 /* Fallthrough */ 6478 6476 case NFS4_READ_LT: 6479 6477 spin_lock(&fp->fi_lock); 6480 - filp = find_readable_file_locked(fp); 6481 - if (filp) 6478 + nf = find_readable_file_locked(fp); 6479 + if (nf) 6482 6480 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_READ); 6483 6481 spin_unlock(&fp->fi_lock); 6484 6482 fl_type = F_RDLCK; ··· 6489 6487 /* Fallthrough */ 6490 6488 case NFS4_WRITE_LT: 6491 6489 spin_lock(&fp->fi_lock); 6492 - filp = find_writeable_file_locked(fp); 6493 - if (filp) 6490 + nf = find_writeable_file_locked(fp); 6491 + if (nf) 6494 6492 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_WRITE); 6495 6493 spin_unlock(&fp->fi_lock); 6496 6494 fl_type = F_WRLCK; ··· 6500 6498 goto out; 6501 6499 } 6502 6500 6503 - if (!filp) { 6501 + if (!nf) { 6504 6502 status = nfserr_openmode; 6505 6503 goto out; 6506 6504 } ··· 6516 6514 file_lock->fl_type = fl_type; 6517 6515 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner)); 6518 6516 file_lock->fl_pid = current->tgid; 6519 - file_lock->fl_file = filp; 6517 + file_lock->fl_file = nf->nf_file; 6520 6518 file_lock->fl_flags = fl_flags; 6521 6519 file_lock->fl_lmops = &nfsd_posix_mng_ops; 6522 6520 file_lock->fl_start = lock->lk_offset; ··· 6538 6536 spin_unlock(&nn->blocked_locks_lock); 6539 6537 } 6540 6538 6541 - err = vfs_lock_file(filp, F_SETLK, file_lock, conflock); 6539 + err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock); 6542 6540 switch (err) { 6543 6541 case 0: /* success! */ 6544 6542 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid); ··· 6573 6571 } 6574 6572 free_blocked_lock(nbl); 6575 6573 } 6576 - if (filp) 6577 - fput(filp); 6574 + if (nf) 6575 + nfsd_file_put(nf); 6578 6576 if (lock_stp) { 6579 6577 /* Bump seqid manually if the 4.0 replay owner is openowner */ 6580 6578 if (cstate->replay_owner && ··· 6701 6699 { 6702 6700 struct nfsd4_locku *locku = &u->locku; 6703 6701 struct nfs4_ol_stateid *stp; 6704 - struct file *filp = NULL; 6702 + struct nfsd_file *nf = NULL; 6705 6703 struct file_lock *file_lock = NULL; 6706 6704 __be32 status; 6707 6705 int err; ··· 6719 6717 &stp, nn); 6720 6718 if (status) 6721 6719 goto out; 6722 - filp = find_any_file(stp->st_stid.sc_file); 6723 - if (!filp) { 6720 + nf = find_any_file(stp->st_stid.sc_file); 6721 + if (!nf) { 6724 6722 status = nfserr_lock_range; 6725 6723 goto put_stateid; 6726 6724 } ··· 6728 6726 if (!file_lock) { 6729 6727 dprintk("NFSD: %s: unable to allocate lock!\n", __func__); 6730 6728 status = nfserr_jukebox; 6731 - goto fput; 6729 + goto put_file; 6732 6730 } 6733 6731 6734 6732 file_lock->fl_type = F_UNLCK; 6735 6733 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner)); 6736 6734 file_lock->fl_pid = current->tgid; 6737 - file_lock->fl_file = filp; 6735 + file_lock->fl_file = nf->nf_file; 6738 6736 file_lock->fl_flags = FL_POSIX; 6739 6737 file_lock->fl_lmops = &nfsd_posix_mng_ops; 6740 6738 file_lock->fl_start = locku->lu_offset; ··· 6743 6741 locku->lu_length); 6744 6742 nfs4_transform_lock_offset(file_lock); 6745 6743 6746 - err = vfs_lock_file(filp, F_SETLK, file_lock, NULL); 6744 + err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL); 6747 6745 if (err) { 6748 6746 dprintk("NFSD: nfs4_locku: vfs_lock_file failed!\n"); 6749 6747 goto out_nfserr; 6750 6748 } 6751 6749 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid); 6752 - fput: 6753 - fput(filp); 6750 + put_file: 6751 + nfsd_file_put(nf); 6754 6752 put_stateid: 6755 6753 mutex_unlock(&stp->st_mutex); 6756 6754 nfs4_put_stid(&stp->st_stid); ··· 6762 6760 6763 6761 out_nfserr: 6764 6762 status = nfserrno(err); 6765 - goto fput; 6763 + goto put_file; 6766 6764 } 6767 6765 6768 6766 /* ··· 6775 6773 { 6776 6774 struct file_lock *fl; 6777 6775 int status = false; 6778 - struct file *filp = find_any_file(fp); 6776 + struct nfsd_file *nf = find_any_file(fp); 6779 6777 struct inode *inode; 6780 6778 struct file_lock_context *flctx; 6781 6779 6782 - if (!filp) { 6780 + if (!nf) { 6783 6781 /* Any valid lock stateid should have some sort of access */ 6784 6782 WARN_ON_ONCE(1); 6785 6783 return status; 6786 6784 } 6787 6785 6788 - inode = locks_inode(filp); 6786 + inode = locks_inode(nf->nf_file); 6789 6787 flctx = inode->i_flctx; 6790 6788 6791 6789 if (flctx && !list_empty_careful(&flctx->flc_posix)) { ··· 6798 6796 } 6799 6797 spin_unlock(&flctx->flc_lock); 6800 6798 } 6801 - fput(filp); 6799 + nfsd_file_put(nf); 6802 6800 return status; 6803 6801 } 6804 6802
+3 -3
fs/nfsd/state.h
··· 516 516 */ 517 517 atomic_t fi_access[2]; 518 518 u32 fi_share_deny; 519 - struct file *fi_deleg_file; 519 + struct nfsd_file *fi_deleg_file; 520 520 int fi_delegees; 521 521 struct knfsd_fh fi_fhandle; 522 522 bool fi_had_conflict; ··· 565 565 spinlock_t ls_lock; 566 566 struct list_head ls_layouts; 567 567 u32 ls_layout_type; 568 - struct file *ls_file; 568 + struct nfsd_file *ls_file; 569 569 struct nfsd4_callback ls_recall; 570 570 stateid_t ls_recall_sid; 571 571 bool ls_recalled; ··· 657 657 { 658 658 refcount_inc(&fi->fi_ref); 659 659 } 660 - struct file *find_any_file(struct nfs4_file *f); 660 + struct nfsd_file *find_any_file(struct nfs4_file *f); 661 661 662 662 /* grace period management */ 663 663 void nfsd4_end_grace(struct nfsd_net *nn);