From: Jeff Layton <jlayton@kernel.org>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: Omar Sandoval <osandov@osandov.com>, Chris Mason <clm@fb.com>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH RFC 2/2] nfs: pr_warn if plh_segs or plh_return_segs are non-empty when freeing
Date: Mon, 28 Apr 2025 13:24:39 -0700 [thread overview]
Message-ID: <20250428-nfs-6-16-v1-2-2d45b80facef@kernel.org> (raw)
In-Reply-To: <20250428-nfs-6-16-v1-0-2d45b80facef@kernel.org>
pnfs_layoutreturn_before_put_layout_hdr() currently throws a WARN if
plh_segs still has entries when the layout_hdr is freed.
Add a new routine that prints info about leftover segments when this
occurs, before dumping the stack. Call that for both plh_segs and
plh_return_segs lists.
Suggested-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfs/pnfs.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 0bcb5a4bd420c157069ee63457518b206223b7cb..4387b1f77a3140b88a0644db1a565a4b71ab64bf 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -302,6 +302,22 @@ pnfs_detach_layout_hdr(struct pnfs_layout_hdr *lo)
nfsi->read_io = 0;
}
+static void
+pnfs_warn_dangling_lsegs(struct list_head *list, const char *name)
+{
+ struct pnfs_layout_segment *lseg;
+
+ if (list_empty(list))
+ return;
+
+ pr_warn("NFS: BUG unfreed layout segments on %s\n", name);
+ list_for_each_entry(lseg, list, pls_list)
+ pr_warn("%p: refs=%d flags=0x%lx seq=%u\n", lseg,
+ refcount_read(&lseg->pls_refcount), lseg->pls_flags,
+ lseg->pls_seq);
+ dump_stack();
+}
+
void
pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo)
{
@@ -315,8 +331,8 @@ pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo)
pnfs_layoutreturn_before_put_layout_hdr(lo);
if (refcount_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
- if (!list_empty(&lo->plh_segs))
- WARN_ONCE(1, "NFS: BUG unfreed layout segments.\n");
+ pnfs_warn_dangling_lsegs(&lo->plh_segs, "plh_segs");
+ pnfs_warn_dangling_lsegs(&lo->plh_return_segs, "plh_return_segs");
pnfs_mark_layout_stateid_invalid(lo, &tmp_list);
pnfs_detach_layout_hdr(lo);
i_state = inode->i_state;
--
2.49.0
next prev parent reply other threads:[~2025-04-28 20:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 20:24 [PATCH RFC 0/2] nfs: free leftover lsegs before freeing a layout in pnfs_put_layout_hdr Jeff Layton
2025-04-28 20:24 ` [PATCH RFC 1/2] " Jeff Layton
2025-04-28 20:24 ` Jeff Layton [this message]
2025-05-05 14:57 ` [PATCH RFC 0/2] " Jeff Layton
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=20250428-nfs-6-16-v1-2-2d45b80facef@kernel.org \
--to=jlayton@kernel.org \
--cc=anna@kernel.org \
--cc=clm@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=osandov@osandov.com \
--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