From: Ryusuke Konishi <konishi.ryusuke@gmail.com>
To: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: Wang Jianjian <wangjianjian3@huawei.com>,
linux-nilfs <linux-nilfs@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Zheng Zheng <fengaojigui88@gmail.com>,
Joshua Crofts <joshua.crofts1@gmail.com>
Subject: [PATCH 4/8] nilfs2: drop redirected buffer flag from DAT when clearing shadow map
Date: Fri, 27 Nov 2026 13:40:57 +0900 [thread overview]
Message-ID: <20261127044231.37630-5-konishi.ryusuke@gmail.com> (raw)
In-Reply-To: <20261127044231.37630-1-konishi.ryusuke@gmail.com>
During garbage collection, the nilfs_redirected flag is set on buffer
heads in the primary mapping of the DAT inode when their blocks are
frozen into the shadow map. Normally, this flag is cleared when the
DAT blocks are written out, so it did not cause issues before.
However, since commit ce5a5ad1a833 ("nilfs2: fix infinite loop in
nilfs_clean_segments()"), if GC is aborted due to an error before the
DAT blocks are written, nilfs_mdt_clear_shadow_map() releases the frozen
buffers without clearing the nilfs_redirected flag from the corresponding
primary buffer heads. As a result, stale nilfs_redirected flags remain
on the DAT buffers, causing subsequent GC operations to skip freezing
those buffers into the shadow map.
Fix this by looking up the corresponding buffer head in the primary
mapping of @inode and clearing its nilfs_redirected flag inside
nilfs_release_frozen_buffers().
Fixes: ce5a5ad1a833 ("nilfs2: fix infinite loop in nilfs_clean_segments()")
Cc: stable@vger.kernel.org
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
fs/nilfs2/mdt.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
index 77dc2be2ce65..91b8455e7f94 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -602,16 +602,43 @@ nilfs_mdt_get_frozen_buffer(struct inode *inode, struct buffer_head *bh)
return bh_frozen;
}
-static void nilfs_release_frozen_buffers(struct nilfs_shadow_map *shadow)
+static void nilfs_release_frozen_buffers(struct inode *inode,
+ struct nilfs_shadow_map *shadow)
{
struct list_head *head = &shadow->frozen_buffers;
- struct buffer_head *bh;
+ unsigned int blkbits = inode->i_blkbits;
while (!list_empty(head)) {
- bh = list_first_entry(head, struct buffer_head,
- b_assoc_buffers);
- list_del_init(&bh->b_assoc_buffers);
- brelse(bh); /* drop ref-count to make it releasable */
+ struct buffer_head *bh_frozen, *bh;
+ struct folio *folio;
+ unsigned int n;
+
+ bh_frozen = list_first_entry(head, struct buffer_head,
+ b_assoc_buffers);
+
+ /*
+ * Clear the nilfs_redirected flag from the primary buffer head
+ * corresponding to bh_frozen to ensure that the flag does not
+ * remain on the non-shadow DAT blocks when a GC operation
+ * terminates due to an error.
+ */
+ folio = filemap_lock_folio(inode->i_mapping,
+ bh_frozen->b_folio->index);
+ if (!IS_ERR(folio)) {
+ bh = folio_buffers(folio);
+ if (bh) {
+ n = offset_in_folio(bh_frozen->b_folio,
+ bh_frozen->b_data) >> blkbits;
+ bh = get_nth_bh(bh, n);
+ clear_buffer_nilfs_redirected(bh);
+ brelse(bh);
+ }
+ folio_unlock(folio);
+ folio_put(folio);
+ }
+
+ list_del_init(&bh_frozen->b_assoc_buffers);
+ brelse(bh_frozen); /* drop ref-count to make it releasable */
}
}
@@ -653,7 +680,7 @@ void nilfs_mdt_clear_shadow_map(struct inode *inode)
struct inode *shadow_btnc_inode = NILFS_I(shadow->inode)->i_assoc_inode;
down_write(&mi->mi_sem);
- nilfs_release_frozen_buffers(shadow);
+ nilfs_release_frozen_buffers(inode, shadow);
truncate_inode_pages(shadow->inode->i_mapping, 0);
truncate_inode_pages(shadow_btnc_inode->i_mapping, 0);
up_write(&mi->mi_sem);
--
2.53.0
next prev parent reply other threads:[~2026-11-27 4:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 4:40 [PATCH 0/8] nilfs2: support GC error rollback and avoid infinite retry hangs Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 1/8] nilfs2: fix leak of gc inodes on error Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 2/8] nilfs2: cancel the relocation of GC-targeted blocks if log writing fails Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 3/8] nilfs2: restore segment usage from the save buffer when aborting GC Ryusuke Konishi
2026-11-27 4:40 ` Ryusuke Konishi [this message]
2026-11-27 4:40 ` [PATCH 5/8] nilfs2: save DAT entry blocks to shadow mapping before freeing Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 6/8] nilfs2: restore removed DAT entries when aborting GC Ryusuke Konishi
2026-11-27 4:41 ` [PATCH 7/8] nilfs2: free virtual block numbers just before collecting DAT changes Ryusuke Konishi
2026-11-27 4:41 ` [PATCH 8/8] nilfs2: avoid infinite retry loop on GC failure Ryusuke Konishi
2026-11-27 18:13 ` [PATCH 0/8] nilfs2: support GC error rollback and avoid infinite retry hangs Viacheslav Dubeyko
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=20261127044231.37630-5-konishi.ryusuke@gmail.com \
--to=konishi.ryusuke@gmail.com \
--cc=fengaojigui88@gmail.com \
--cc=joshua.crofts1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=wangjianjian3@huawei.com \
/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
all inboxes | Powered by JetHome®