[PATCH v5 01/19] btrfs: drop the extent maps of the written part of a failed ordered extent
From: Tal Zussman
Date: Thu Oct 15 2026 - 11:28:55 EST
If a truncated ordered extent fails to complete, the extent maps for the
part that was written are kept while the extent itself is freed below.
A later read can follow them to blocks that have been reallocated.
Drop the maps for the whole range on error.
Fixes: 77cef2ec5484 ("Btrfs: allow partial ordered extent completion")
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/btrfs/inode.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 343b6402bb35..271f6024b72b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3390,6 +3390,8 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
/*
* Drop extent maps for the part of the extent we didn't write.
+ * On error the written part is freed below as well, so drop
+ * its maps too.
*
* We have an exception here for the free_space_inode, this is
* because when we do btrfs_get_extent() on the free space inode
@@ -3405,7 +3407,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
if (!btrfs_is_free_space_inode(inode)) {
u64 unwritten_start = start;
- if (truncated)
+ if (truncated && !ret)
unwritten_start += logical_len;
btrfs_drop_extent_map_range(inode, unwritten_start,
--
2.39.5