From: Ernest Borowski via B4 Relay <devnull+ernest.borowski.git.proton.me@kernel.org>
To: Namjae Jeon <linkinjeon@kernel.org>,
Hyunchul Lee <hyc.lee@gmail.com>,
Baolin Liu <liubaolin12138@163.com>
Cc: Christian Brauner <brauner@kernel.org>,
Christoph Hellwig <hch@lst.de>,
"Darrick J. Wong" <djwong@kernel.org>,
ntfs@lists.linux.dev, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Zhan Xusheng <zhanxusheng1024@gmail.com>,
stable@vger.kernel.org,
Ernest Borowski <ernest.borowski.git@proton.me>
Subject: [PATCH v4 07/11] ntfs: do not shift the cluster number of a delalloc run on split
Date: Tue, 01 Dec 2026 18:42:42 +0100 [thread overview]
Message-ID: <20261201-b4-ntfs-delalloc-fixes-v4-7-e5dd6f77016a@proton.me> (raw)
In-Reply-To: <20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@proton.me>
From: Ernest Borowski <ernest.borowski.git@proton.me>
ntfs_rl_punch_hole() and ntfs_rl_collapse_range() advance the lcn of a
run they split with "if (lcn > LCN_HOLE) lcn += n". LCN_DELALLOC (-1)
is greater than LCN_HOLE (-2), so splitting a delalloc run turns its
tail into a run of real clusters starting at n - 1.
ntfs_rl_insert_range() advances it unconditionally; its callers insert
holes, so only a hole split for a non-hole source and a split delalloc
run are affected. ntfs_rle_lcn_contiguous() has the same problem and
can merge a delalloc run with a following real run.
The punched-out part then goes to ntfs_cluster_free_from_rl(), which
frees clusters that belong to other files or to metadata, and the part
left in the runlist maps the file onto them. Delalloc runs normally do
not survive the writeback that fallocate() does first, but a buffered
write that fails after ->iomap_begin() leaves one without dirty folios
(fixed by the next patch); FALLOC_FL_PUNCH_HOLE or COLLAPSE_RANGE
through it then corrupts the volume (ntfsck: "Found 1 inconsistent
bitmap block(s)").
Only shift the lcn of runs that have real clusters.
Fixes: 11ccc9107dc4 ("ntfs: update runlist handling and cluster allocator")
Cc: stable@vger.kernel.org
Signed-off-by: Ernest Borowski <ernest.borowski.git@proton.me>
---
fs/ntfs/runlist.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/fs/ntfs/runlist.c b/fs/ntfs/runlist.c
index 76ba6ab72b..1e87db35ce 100644
--- a/fs/ntfs/runlist.c
+++ b/fs/ntfs/runlist.c
@@ -1770,7 +1770,7 @@ s64 ntfs_rl_get_compressed_size(struct ntfs_volume *vol, struct runlist_element
static inline bool ntfs_rle_lcn_contiguous(struct runlist_element *left_rle,
struct runlist_element *right_rle)
{
- if (left_rle->lcn > LCN_HOLE &&
+ if (left_rle->lcn >= 0 &&
left_rle->lcn + left_rle->length == right_rle->lcn)
return true;
else if (left_rle->lcn == LCN_HOLE && right_rle->lcn == LCN_HOLE)
@@ -1832,7 +1832,8 @@ struct runlist_element *ntfs_rl_insert_range(struct runlist_element *dst_rl, int
i_rl[0].vcn = start_vcn;
i_rl[0].length -= dst_rl_split.length;
- i_rl[0].lcn += dst_rl_split.length;
+ if (i_rl[0].lcn >= 0)
+ i_rl[0].lcn += dst_rl_split.length;
} else {
struct runlist_element *dst_rle, *src_rle;
merge_src_rle:
@@ -1988,7 +1989,7 @@ struct runlist_element *ntfs_rl_punch_hole(struct runlist_element *dst_rl, int d
(*punch_rl)[0].vcn = start_vcn;
(*punch_rl)[0].length -= first_cnt;
- if ((*punch_rl)[0].lcn > LCN_HOLE)
+ if ((*punch_rl)[0].lcn >= 0)
(*punch_rl)[0].lcn += first_cnt;
}
@@ -2008,7 +2009,7 @@ struct runlist_element *ntfs_rl_punch_hole(struct runlist_element *dst_rl, int d
new_rl[new_1st_cnt + 1].vcn = end_vcn + 1;
new_rl[new_1st_cnt + 1].length -= first_cnt;
- if (new_rl[new_1st_cnt + 1].lcn > LCN_HOLE)
+ if (new_rl[new_1st_cnt + 1].lcn >= 0)
new_rl[new_1st_cnt + 1].lcn += first_cnt;
if (one_split_3)
@@ -2136,7 +2137,7 @@ struct runlist_element *ntfs_rl_collapse_range(struct runlist_element *dst_rl, i
(*punch_rl)[0].vcn = start_vcn;
(*punch_rl)[0].length -= first_cnt;
- if ((*punch_rl)[0].lcn > LCN_HOLE)
+ if ((*punch_rl)[0].lcn >= 0)
(*punch_rl)[0].lcn += first_cnt;
}
@@ -2150,7 +2151,7 @@ struct runlist_element *ntfs_rl_collapse_range(struct runlist_element *dst_rl, i
new_rl[new_1st_cnt].vcn = end_vcn + 1;
new_rl[new_1st_cnt].length -= first_cnt;
- if (new_rl[new_1st_cnt].lcn > LCN_HOLE)
+ if (new_rl[new_1st_cnt].lcn >= 0)
new_rl[new_1st_cnt].lcn += first_cnt;
if (one_split_3)
--
2.56.1
next prev parent reply other threads:[~2026-12-01 17:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 17:42 [PATCH v4 00/11] ntfs: delayed allocation accounting and stale data fixes, part 1 Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 01/11] iomap: punch out a run of clean blocks in one call Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 02/11] iomap: add a helper to mark a range of a folio dirty Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 03/11] ntfs: release delalloc reservations cut off by truncate Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 04/11] ntfs: do not consume delalloc reservations when filling holes Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 05/11] ntfs: keep delalloc reservations when a cluster allocation fails Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 06/11] ntfs: release the delalloc reservations of an evicted inode Ernest Borowski via B4 Relay
2026-12-01 17:42 ` Ernest Borowski via B4 Relay [this message]
2026-12-01 17:42 ` [PATCH v4 08/11] ntfs: punch out the delalloc reservation of a failed buffered write Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 09/11] ntfs: zero new delalloc clusters even when writeback allocates them Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 10/11] ntfs: zero the rest of a new cluster after a short buffered write Ernest Borowski via B4 Relay
2026-12-01 17:42 ` [PATCH v4 11/11] ntfs: revalidate a buffered write's mapping after its clusters were allocated Ernest Borowski via B4 Relay
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=20261201-b4-ntfs-delalloc-fixes-v4-7-e5dd6f77016a@proton.me \
--to=devnull+ernest.borowski.git.proton.me@kernel.org \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=ernest.borowski.git@proton.me \
--cc=hch@lst.de \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=liubaolin12138@163.com \
--cc=ntfs@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zhanxusheng1024@gmail.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®