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 5/8] nilfs2: save DAT entry blocks to shadow mapping before freeing
Date: Fri, 27 Nov 2026 13:40:58 +0900 [thread overview]
Message-ID: <20261127044231.37630-6-konishi.ryusuke@gmail.com> (raw)
In-Reply-To: <20261127044231.37630-1-konishi.ryusuke@gmail.com>
In preparation for restoring removed DAT entries when GC is aborted,
modify nilfs_dat_freev() to freeze the buffer heads of target DAT entry
blocks before freeing virtual block numbers, saving their original
contents in the shadow mapping.
Cc: stable@vger.kernel.org
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
fs/nilfs2/dat.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c
index d2718944368b..b4156945e433 100644
--- a/fs/nilfs2/dat.c
+++ b/fs/nilfs2/dat.c
@@ -11,6 +11,7 @@
#include <linux/buffer_head.h>
#include <linux/string.h>
#include <linux/errno.h>
+#include <linux/math64.h>
#include "nilfs.h"
#include "mdt.h"
#include "alloc.h"
@@ -306,11 +307,48 @@ int nilfs_dat_mark_dirty(struct inode *dat, __u64 vblocknr)
* Return: 0 on success, or one of the following negative error codes on
* failure:
* * %-EIO - I/O error (including metadata corruption).
- * * %-ENOENT - The virtual block number have not been allocated.
+ * * %-ENOENT - An unallocated management block was found.
* * %-ENOMEM - Insufficient memory available.
*/
int nilfs_dat_freev(struct inode *dat, __u64 *vblocknrs, size_t nitems)
{
+ unsigned long entries_per_block = NILFS_MDT(dat)->mi_entries_per_block;
+ struct buffer_head *entry_bh = NULL;
+ __u64 start_vblocknr = 0, end_vblocknr = 0;
+ u64 rem;
+ size_t i;
+ int ret;
+
+ /* Save the DAT entries to the shadow mapping before removal */
+ for (i = 0; i < nitems; i++) {
+ if (entry_bh && vblocknrs[i] >= start_vblocknr &&
+ vblocknrs[i] < end_vblocknr)
+ continue;
+
+ brelse(entry_bh);
+ entry_bh = NULL;
+
+ ret = nilfs_palloc_get_entry_block(dat, vblocknrs[i], 0,
+ &entry_bh);
+ if (unlikely(ret < 0)) {
+ if (ret != -ENOENT)
+ return ret;
+ continue;
+ }
+ if (!buffer_nilfs_redirected(entry_bh)) {
+ ret = nilfs_mdt_freeze_buffer(dat, entry_bh);
+ if (unlikely(ret < 0)) {
+ brelse(entry_bh);
+ return ret;
+ }
+ }
+
+ div64_u64_rem(vblocknrs[i], entries_per_block, &rem);
+ start_vblocknr = vblocknrs[i] - rem;
+ end_vblocknr = start_vblocknr + entries_per_block;
+ }
+ brelse(entry_bh);
+
return nilfs_palloc_freev(dat, vblocknrs, nitems);
}
--
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 ` [PATCH 4/8] nilfs2: drop redirected buffer flag from DAT when clearing shadow map Ryusuke Konishi
2026-11-27 4:40 ` Ryusuke Konishi [this message]
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-6-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®