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=3huXd54Y+PkXClniP2ig6uIX4lMLtMw9DivPXWUwxAETlwUJPAg0iA0t9Df7XywspGXK vVzkUXUF3ocNlh9ismZOjhXZu+ETJcKHTGy3P2DXzB/mz7qH+IAIDBGvG0LAOAtFWbhAN bt4IKzEafwSujIssrbQfQKgdMBZTSF3ofcRYzkPA2jkolUpLExLEL0kZLqIV24d9/sIpe eVyrrror6yRZuTgJ1pDbNO3hbgldi95tONUUkIJjGTrFDo3z2CQ+PdjEYtAQoaoUH+5v6 WNfE0FJK/l4afzuLAZzJriGbkHwX1jW6D1/zSccUCh8Ohi62/pNFhxfKiJrlenSXJgQ== 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=ZLtVYNGSAS5M2ggivB1etaoT7Uj/nJ+FcFVrAfud7H0=; b=0M4apuevCfrgYP/QRPW6cvzrq5x3td+tD1nrrtsVhLnjrB+CRthVUerIGrPwETdMPFzi +UCjo0/T/zcjTUNG9TDv9IF9KZ0WUemHC0exXunRW57ePlabf/Lm2FmVrO6xLjC1lckrT Woi53zN7QLfwC1QjlHOh8Fnh7MbDNLy6jNPKWenu1Vli73sp+IXRBvdiEGfLAiNAuIuIh dAxj6wneeA6pzBz/UTkmON6VhPqpjCchemGUW2UP8NC3dRcJaa7eaifnWliP0Q2BEWCBJ DYwqNxb/WRA135lVivnHcNmvfv5YwsVP7lVJ2XTHseP5F/+fi4xoilIOBzInVzvEyaw== 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 EBFB2606A32F; Sun, 29 Nov 2026 13:40:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EBFB2606A32F 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 13A7E5F0BA0; Sun, 29 Nov 2026 14:31:49 +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 4/6] btrfs: scan the running transaction for data extent references Date: Sun, 29 Nov 2026 14:31:17 +0100 Message-ID: <20261129133125.3293-5-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 The reference scan of a data extent walks the trees without a transaction handle, so the backref walk reads the commit root. A reference made by the running transaction, such as a reflink made during balance, is not in the commit root, so the scan misses it, while the extent item already counts it. Run the scan under a joined transaction, so the walk sees the running transaction and its pending delayed refs. The transaction is not flushed: the walk accounts for pending refs itself. Signed-off-by: Ismael Luceno --- fs/btrfs/relocation.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index a9da7a6468fa5..75300c21fe06e 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3255,19 +3255,31 @@ static int collect_extent_segments(struct reloc_control *rc, { struct btrfs_fs_info *fs_info = rc->extent_root->fs_info; struct btrfs_backref_walk_ctx ctx = { 0 }; + struct btrfs_trans_handle *trans; struct ulist_iterator leaf_uiter; struct ulist_node *ref_node; const u64 bytenr = extent_key->objectid; const u64 num_bytes = extent_key->offset; int ret; + /* + * Walk the running transaction, delayed refs included, so the scan sees + * the references made by it. They are not flushed. + */ + trans = btrfs_join_transaction(rc->extent_root); + if (IS_ERR(trans)) + return PTR_ERR(trans); + ctx.bytenr = bytenr; ctx.skip_inode_ref_list = true; ctx.fs_info = fs_info; + ctx.trans = trans; ret = btrfs_find_all_leafs(&ctx); - if (ret < 0) + if (ret < 0) { + btrfs_end_transaction(trans); return ret; + } ULIST_ITER_INIT(&leaf_uiter); while ((ref_node = ulist_next(ctx.refs, &leaf_uiter))) { @@ -3315,6 +3327,7 @@ static int collect_extent_segments(struct reloc_control *rc, break; } ulist_free(ctx.refs); + btrfs_end_transaction(trans); if (ret) return ret; -- 2.56.0