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