From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=46.30.189.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795959627; b=EGdU4WFeTea4Zq7vraM0193oOY1yQtHsvLUcn9NTTrCky7vZAw9IZN5jWjd9rbLQBiVH Ve40cHjHQ6FBINSUlKBEtlRkt2M+cCmGwVTpxrImP5CC8h4nVVPAwUBcJEN7aCQd9BJAR J0OBuTOWAhZZZX8IhhRbpN6s/otV18vSTfh6r6Ta3QFb2f6WRb7kDdSXo+yGGEQKP4ogO jdCXktmNelZ0X4hX7+ryH79FhxAM++5ReXLUvxWymATGqCzRQPhYB3WZewuG1Ze+8wVJp Cv/EzRxZYYpBm9VpCsJof0PYzj/Ld/gdQ3Rb0uMo6lorLU9EV7juNipuMvm9opo8/UQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795959627; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=8gf28RLR2hFROZRZoUNAN5GGPvlrxZXbp87JwCoNJXs=; b=V2WFXuQpPh8/8ZKSQNbStxKlTesxK8EK50E3n9vDixeflIoqNcHNbChMLoJc09mROqCe ZgWnSsyHAQvm/elGgvNq5goAkrLiO7DLnVUOP59Bc/0/PU2wZDpIDD2L7Vn+1B1jJ2smV MwMYhFkEbIzZZx1fiexGlKa4R0ay4TZEngse9U+pElLkRpv2ukVHD3dzKKItPEqCo7lEe VuxHP7V2hM73SOiTf6rBvSXvUgwXWqGLB23BKvMfG2lH8BidHmMRAC8P5SXvcHM8mES6K FaFG9gcew06sGO1A/4zxIhaFtIRcNENNmlspUmP4YeOJaEq17a7kUiBaVEIwY4yxbAA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=iodev.co.uk; spf=pass smtp.mailfrom=iodev.co.uk; arc=none smtp.remote-ip=46.30.189.100 Received: from iodev.co.uk (iodev.co.uk [46.30.189.100]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECE62606A331; Sun, 29 Nov 2026 13:40:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ECE62606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iodev.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iodev.co.uk Received: from localhost (unknown [79.116.217.174]) by iodev.co.uk (Postfix) with ESMTPSA id ECAF75F0B99; Sun, 29 Nov 2026 14:31:36 +0100 (CET) From: Ismael Luceno To: linux-btrfs@vger.kernel.org, David Sterba , Chris Mason Cc: Ismael Luceno , linux-kernel@vger.kernel.org, Qu Wenruo , Anand Jain , Filipe Manana Subject: [PATCH 2/6] btrfs: allow NOCOW writeback into data relocation extents Date: Sun, 29 Nov 2026 14:31:15 +0100 Message-ID: <20261129133125.3293-3-ismael@iodev.co.uk> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261129133125.3293-1-ismael@iodev.co.uk> References: <20261129133125.3293-1-ismael@iodev.co.uk> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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