Skip to content

Commit 535cb8f

Browse files
committed
lockd: Fix server refcounting
The server shouldn't actually delete the struct nlm_host until it hits the garbage collector. In order to make that work correctly with the refcount API, we can bump the refcount by one, and then use refcount_dec_if_one() in the garbage collector. Signed-off-by: Trond Myklebust <[email protected]> Acked-by: J. Bruce Fields <[email protected]>
1 parent 8f39fce commit 535cb8f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/lockd/host.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
388388
ln->nrhosts++;
389389
nrhosts++;
390390

391+
refcount_inc(&host->h_count);
392+
391393
dprintk("lockd: %s created host %s (%s)\n",
392394
__func__, host->h_name, host->h_addrbuf);
393395

@@ -662,16 +664,16 @@ nlm_gc_hosts(struct net *net)
662664
for_each_host_safe(host, next, chain, nlm_server_hosts) {
663665
if (net && host->net != net)
664666
continue;
665-
if (refcount_read(&host->h_count) || host->h_inuse
666-
|| time_before(jiffies, host->h_expires)) {
667+
if (host->h_inuse || time_before(jiffies, host->h_expires)) {
667668
dprintk("nlm_gc_hosts skipping %s "
668669
"(cnt %d use %d exp %ld net %x)\n",
669670
host->h_name, refcount_read(&host->h_count),
670671
host->h_inuse, host->h_expires,
671672
host->net->ns.inum);
672673
continue;
673674
}
674-
nlm_destroy_host_locked(host);
675+
if (refcount_dec_if_one(&host->h_count))
676+
nlm_destroy_host_locked(host);
675677
}
676678

677679
if (net) {

0 commit comments

Comments
 (0)