[PATCH 2/6] btrfs: allow NOCOW writeback into data relocation extents

From: Ismael Luceno

Date: Sun Nov 29 2026 - 08:40:43 EST


can_nocow_file_extent() refuses NOCOW when another inode references the
same disk extent, because a NOCOW write would then change data the other
reference sees. Data relocation writes its destination extents with NOCOW
into preallocated space, and a compacted destination is referenced by
several file extents of the data reloc inode on purpose: one per copied
segment.

Those references can't be seen by anything else before the update stage
remaps them, so the cross reference check only refuses the write. Skip it
for the data reloc root.

Signed-off-by: Ismael Luceno <ismael@xxxxxxxxxxx>
---
fs/btrfs/inode.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 7592588fec64c..90886e5e31f16 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1833,10 +1833,19 @@ static int can_nocow_file_extent(struct btrfs_path *path,
*/
btrfs_release_path(path);

- ret = btrfs_cross_ref_exist(inode, key->offset - args->file_extent.offset,
- args->file_extent.disk_bytenr, path);
- if (ret != 0)
- goto out;
+ /*
+ * The data relocation inode's destination extents are private to it
+ * until the update stage, and a compacted extent is referenced by
+ * several of its file extents on purpose, so they can't be cross
+ * referenced by anything else. Checking them would only refuse NOCOW.
+ */
+ if (!btrfs_is_data_reloc_root(inode->root)) {
+ ret = btrfs_cross_ref_exist(inode,
+ key->offset - args->file_extent.offset,
+ args->file_extent.disk_bytenr, path);
+ if (ret != 0)
+ goto out;
+ }

if (args->free_path) {
/*
--
2.56.0