mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ismael Luceno <ismael@iodev.co.uk>
To: linux-btrfs@vger.kernel.org, David Sterba <dsterba@suse.com>,
	Chris Mason <mason@kernel.org>
Cc: Ismael Luceno <ismael@iodev.co.uk>,
	linux-kernel@vger.kernel.org, Qu Wenruo <wqu@suse.com>,
	Anand Jain <asj@kernel.org>, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH 2/6] btrfs: allow NOCOW writeback into data relocation extents
Date: Sun, 29 Nov 2026 14:31:15 +0100	[thread overview]
Message-ID: <20261129133125.3293-3-ismael@iodev.co.uk> (raw)
In-Reply-To: <20261129133125.3293-1-ismael@iodev.co.uk>

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@iodev.co.uk>
---
 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


  parent reply	other threads:[~2026-11-29 13:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 13:31 [PATCH 0/6] btrfs: trim unused space when relocating data extents Ismael Luceno
2026-11-29 13:31 ` [PATCH 1/6] btrfs: add prealloc helper for sharing one allocation Ismael Luceno
2026-11-29 13:31 ` Ismael Luceno [this message]
2026-11-29 13:31 ` [PATCH 3/6] btrfs: relocate only referenced bytes of a data extent Ismael Luceno
2026-11-29 13:31 ` [PATCH 4/6] btrfs: scan the running transaction for data extent references Ismael Luceno
2026-11-29 13:31 ` [PATCH 5/6] btrfs: retry a block group that references survive the update stage Ismael Luceno
2026-11-29 13:31 ` [PATCH 6/6] btrfs: derive relocation group length from its members Ismael Luceno
2026-11-29 21:00 ` [PATCH 0/6] btrfs: trim unused space when relocating data extents Qu Wenruo

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=20261129133125.3293-3-ismael@iodev.co.uk \
    --to=ismael@iodev.co.uk \
    --cc=asj@kernel.org \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=wqu@suse.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®