From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380276; b=mq3k0z3VW2Y+3hW+qlALlk9B5HoRWy16+P5x56IxDUWYWpEyZ8mBEEm53+vcV08FPOaX d5G9A62+nVRissHRhpbVeHc02qgCckfVShqSIRkZ33KJ+8b4X65AbDwFknZaRd+oZqlwK uKTLfDsbEexfZzRcOtvMnTrV9pOWF+3guIl4f09b+7mfMnQvjrzishd21oPEkCNPVtxAY 8Gj//lskHuibpB4/ySUIsu5OhxemB6mADFkPzXcaIrcnsSUho43FmWOYfqnY9xiqemVGp y7c55gGC5SdnFgOFHcKgQqQWe/UHtdB7UoqjGNIWhoWqJPhDuZRSxpP07QPZoDB2b0A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380276; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=VWxKBuHZBmYwj91ugILwrPr658Og3ebhYusjZz9VXl8=; b=AwbGCY2jNhNDTF17UGEg4bEJSfr9wLpIPQnEy/EJjnYChw48nGHu26VYwxPMvz+lkvTQ klG7+CVRKdbr1JaOUfrqpnFDJm9hq8N1QtXIUc2k6eygmJwZkaN1z3IfLJNZgMXisOErG hv3asTeHv6miEjL942fJoSfsi9GM/knJGn5nF/GsWpQeBmwodD2Q7UV7P5S0jVGcgZ2SM t4qANnwNiOt4ZsxYx4fWWej3/SXssH4dcvbSHzI91Ge1HUVFcQ2yTNmOgTUzgFmJlh5HK zG2eeqXIY3V1rdOzBkPuaKUV5R3GW6165QibsRL158LjQag2WCezk11V1kf4VWx8ZTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uk16LwlN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF665606A33B; Fri, 4 Dec 2026 10:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uk16LwlN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 677B91F000C2; Fri, 4 Dec 2026 10:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380275; bh=VWxKBuHZBmYwj91ugILwrPr658Og3ebhYusjZz9VXl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uk16LwlNGHRqb6eSqkNmurHyAECdTz9SwS8WhT+afFdy+sBemvUZ8ud3bscAVp/7I jxxG4b+/c7lXWKq78RbojNGQaiN2v2MuQzL5jYhTfauny0pMMHIYgaGW9FZVIUIAWG HYXTuSeybR/s7WoR95YzfgP4d3ssE9015w4Eo+D4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tristan Elvers , Qu Wenruo , Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 7.3 203/742] btrfs: send: fix missing hole punching during incremental send Date: Fri, 4 Dec 2026 19:01:07 +0900 Message-ID: <20261204100640.477017987@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana [ Upstream commit 398ee8a011d9187e83fc24738b3391e508da91da ] When using the no-holes feature (enabled by default since btrfs-progs v5.15) and doing an incremental send, we can miss issuing a hole punching command when the following conditions happen: 1) A hole is punched in a tail section of a file extent item that happens to be the last item in a leaf (for example the extent covers the file range [1M, 3M) and a hole is punched in the range [2M, 3M)). Between the end of this file extent item's range and the i_size, there are other file extent items; 2) The next leaf was not modified in the send snapshot, remaining shared with the parent snapshot. In this scenario we are unable to detect a hole was punched and never issue a hole punch command because with no-holes there we don't have an explicit file extent item to mark a hole. Fix this by teaching maybe_send_hole() to detect such case. A test case for fstests will follow soon. Reported-by: Tristan Elvers Link: https://lore.kernel.org/linux-btrfs/CAFoLKK+aErV4p6ZJPnVeH5SHQ5++0f=8ZgxPWe-E-CkeKBs8PA@mail.gmail.com/ Fixes: 16e7549f045d ("Btrfs: incompatible format change to remove hole extents") Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/send.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 5c59b9abedcd7..d4b498ebfa56a 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -6371,6 +6371,9 @@ static int range_is_hole_in_parent(struct send_ctx *sctx, static int maybe_send_hole(struct send_ctx *sctx, struct btrfs_path *path, struct btrfs_key *key) { + BTRFS_PATH_AUTO_FREE(next_path); + const u64 cur_extent_end = btrfs_file_extent_end(path); + u64 next_offset; int ret = 0; if (sctx->cur_ino != key->objectid || !need_send_hole(sctx)) @@ -6397,14 +6400,72 @@ static int maybe_send_hole(struct send_ctx *sctx, struct btrfs_path *path, ret = range_is_hole_in_parent(sctx, sctx->cur_inode_last_extent, key->offset); + if (ret == 0) + ret = send_hole(sctx, key->offset); + else if (ret == 1) + ret = 0; + if (ret < 0) return ret; - else if (ret == 0) - ret = send_hole(sctx, key->offset); + } + sctx->cur_inode_last_extent = cur_extent_end; + + /* + * If we are the last file extent item in a leaf, we may have had a tail + * section that got a hole punched or the extent replaced with a smaller + * one, and if there is no change in the next leaf, we must find out if + * we have such a hole and punch it. + */ + if (!btrfs_fs_incompat(sctx->send_root->fs_info, NO_HOLES) || + (sctx->cur_inode_size <= cur_extent_end) || + (path->slots[0] != btrfs_header_nritems(path->nodes[0]) - 1)) + return 0; + + next_path = alloc_path_for_send(); + if (!next_path) + return -ENOMEM; + + ret = btrfs_search_slot(NULL, sctx->send_root, key, next_path, 0, 0); + if (ret < 0) + return ret; + if (WARN_ON(ret != 0)) + return -EUCLEAN; + + ret = btrfs_next_leaf(sctx->send_root, next_path); + if (ret < 0) { + return ret; + } else if (ret > 0) { + /* + * No next leaf, must punch hole to i_size and set the path back + * to where it was before. + */ + next_offset = sctx->cur_inode_size; + } else { + struct btrfs_key next_key; + + btrfs_item_key_to_cpu(next_path->nodes[0], &next_key, + next_path->slots[0]); + if (next_key.objectid != key->objectid || + next_key.type != BTRFS_EXTENT_DATA_KEY) + next_offset = sctx->cur_inode_size; else - ret = 0; + next_offset = next_key.offset; } - sctx->cur_inode_last_extent = btrfs_file_extent_end(path); + + if (next_offset == cur_extent_end) + return 0; + + btrfs_free_path(next_path); + next_path = NULL; + + ret = range_is_hole_in_parent(sctx, sctx->cur_inode_last_extent, next_offset); + if (ret == 0) + ret = send_hole(sctx, next_offset); + else if (ret == 1) + ret = 0; + + sctx->cur_inode_last_extent = next_offset; + return ret; } -- 2.53.0