Skip to content

Commit f273d69

Browse files
author
Herton R. Krzesinski
committed
Merge: nfsd: don't free files unconditionally in __nfsd_file_cache_purge
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1942 Bugzilla: https://bugzilla.redhat.com/2160443 nfsd: don't free files unconditionally in __nfsd_file_cache_purge nfsd_file_cache_purge is called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed. Instead of walking the cache and freeing everything unconditionally, handle it the same as when we have a notification of conflicting access. Fixes: ac3a258 ("nfsd: rework refcounting in filecache") Reported-by: Ruben Vestergaard <rubenv@drcmr.dk> Reported-by: Torkil Svensgaard <torkil@drcmr.dk> Reported-by: Shachar Kagan <skagan@nvidia.com> Signed-off-by: Jeff Layton <jlayton@kernel.org> Tested-by: Shachar Kagan <skagan@nvidia.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Jeffrey Layton <jlayton@redhat.com> Approved-by: Benjamin Coddington <bcodding@redhat.com> Approved-by: Scott Mayhew <smayhew@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents f237cdd + 2d52c6f commit f273d69

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

fs/nfsd/filecache.c

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,39 @@ static struct shrinker nfsd_file_shrinker = {
660660
.seeks = 1,
661661
};
662662

663+
/**
664+
* nfsd_file_cond_queue - conditionally unhash and queue a nfsd_file
665+
* @nf: nfsd_file to attempt to queue
666+
* @dispose: private list to queue successfully-put objects
667+
*
668+
* Unhash an nfsd_file, try to get a reference to it, and then put that
669+
* reference. If it's the last reference, queue it to the dispose list.
670+
*/
671+
static void
672+
nfsd_file_cond_queue(struct nfsd_file *nf, struct list_head *dispose)
673+
__must_hold(RCU)
674+
{
675+
int decrement = 1;
676+
677+
/* If we raced with someone else unhashing, ignore it */
678+
if (!nfsd_file_unhash(nf))
679+
return;
680+
681+
/* If we can't get a reference, ignore it */
682+
if (!nfsd_file_get(nf))
683+
return;
684+
685+
/* Extra decrement if we remove from the LRU */
686+
if (nfsd_file_lru_remove(nf))
687+
++decrement;
688+
689+
/* If refcount goes to 0, then put on the dispose list */
690+
if (refcount_sub_and_test(decrement, &nf->nf_ref)) {
691+
list_add(&nf->nf_lru, dispose);
692+
trace_nfsd_file_closing(nf);
693+
}
694+
}
695+
663696
/**
664697
* nfsd_file_queue_for_close: try to close out any open nfsd_files for an inode
665698
* @inode: inode on which to close out nfsd_files
@@ -687,30 +720,11 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose)
687720

688721
rcu_read_lock();
689722
do {
690-
int decrement = 1;
691-
692723
nf = rhashtable_lookup(&nfsd_file_rhash_tbl, &key,
693724
nfsd_file_rhash_params);
694725
if (!nf)
695726
break;
696-
697-
/* If we raced with someone else unhashing, ignore it */
698-
if (!nfsd_file_unhash(nf))
699-
continue;
700-
701-
/* If we can't get a reference, ignore it */
702-
if (!nfsd_file_get(nf))
703-
continue;
704-
705-
/* Extra decrement if we remove from the LRU */
706-
if (nfsd_file_lru_remove(nf))
707-
++decrement;
708-
709-
/* If refcount goes to 0, then put on the dispose list */
710-
if (refcount_sub_and_test(decrement, &nf->nf_ref)) {
711-
list_add(&nf->nf_lru, dispose);
712-
trace_nfsd_file_closing(nf);
713-
}
727+
nfsd_file_cond_queue(nf, dispose);
714728
} while (1);
715729
rcu_read_unlock();
716730
}
@@ -926,11 +940,8 @@ __nfsd_file_cache_purge(struct net *net)
926940

927941
nf = rhashtable_walk_next(&iter);
928942
while (!IS_ERR_OR_NULL(nf)) {
929-
if (!net || nf->nf_net == net) {
930-
nfsd_file_unhash(nf);
931-
nfsd_file_lru_remove(nf);
932-
list_add(&nf->nf_lru, &dispose);
933-
}
943+
if (!net || nf->nf_net == net)
944+
nfsd_file_cond_queue(nf, &dispose);
934945
nf = rhashtable_walk_next(&iter);
935946
}
936947

0 commit comments

Comments
 (0)