linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Coddington <ben.coddington@hammerspace.com>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org, Mike Snitzer <snitzer@kernel.org>
Subject: [PATCH 1/2] NFSv4/pnfs: Give the data server cache its own reference
Date: Fri, 18 Sep 2026 08:21:01 -0400	[thread overview]
Message-ID: <037fabd833135d24ca8498e5fa8d6ff25a1c0383.1789733774.git.bcodding@hammerspace.com> (raw)
In-Reply-To: <cover.1789733774.git.bcodding@hammerspace.com>

Prepare the DS cache to allow data servers to outlive their layout
references.  Take a reference for the cache itself.  An entry is created
with a count of two, one for the caller and one for the cache, so a count
of one now means it is still hashed with no users left.

Entries are still torn down at exactly the same point as before; only
the bookkeeping changes.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
---
 fs/nfs/pnfs_nfs.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c
index 7adb6f941cf2..6d6a4d05d13e 100644
--- a/fs/nfs/pnfs_nfs.c
+++ b/fs/nfs/pnfs_nfs.c
@@ -713,11 +713,18 @@ void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds)
 {
 	struct nfs_net *nn = net_generic(ds->ds_net, nfs_net_id);
 
-	if (refcount_dec_and_lock(&ds->ds_count, &nn->nfs4_data_server_lock)) {
-		hlist_del_init(&ds->ds_node);
+	spin_lock(&nn->nfs4_data_server_lock);
+	refcount_dec(&ds->ds_count);
+	if (refcount_read(&ds->ds_count) > 1) {
 		spin_unlock(&nn->nfs4_data_server_lock);
-		destroy_ds(ds);
+		return;
 	}
+	hlist_del_init(&ds->ds_node);
+	spin_unlock(&nn->nfs4_data_server_lock);
+
+	/* The cache's reference is the last one */
+	if (refcount_dec_and_test(&ds->ds_count))
+		destroy_ds(ds);
 }
 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_put);
 
@@ -803,7 +810,7 @@ nfs4_pnfs_ds_add(const struct net *net, struct list_head *dsaddrs, u32 version,
 		INIT_LIST_HEAD(&ds->ds_addrs);
 		list_splice_init(dsaddrs, &ds->ds_addrs);
 		ds->ds_remotestr = remotestr;
-		refcount_set(&ds->ds_count, 1);
+		refcount_set(&ds->ds_count, 2);
 		INIT_HLIST_NODE(&ds->ds_node);
 		ds->ds_net = net;
 		ds->ds_clp = NULL;
-- 
2.53.0


  reply	other threads:[~2026-09-18 12:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 12:21 [PATCH 0/2] NFSv4/pnfs: Keep data server connections across deviceid eviction Benjamin Coddington
2026-09-18 12:21 ` Benjamin Coddington [this message]
2026-09-18 12:21 ` [PATCH 2/2] NFSv4/pnfs: Let unused data server connections linger Benjamin Coddington

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=037fabd833135d24ca8498e5fa8d6ff25a1c0383.1789733774.git.bcodding@hammerspace.com \
    --to=ben.coddington@hammerspace.com \
    --cc=anna@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=snitzer@kernel.org \
    --cc=trondmy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).