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=1796230719; b=d++M8cV1iKwxJ/6iAWRiWLDO2XIHO9l16UFxulQ/WMHfatwDlaLVYgBZRUxiGvhVUmeM 2nuP1JoGubwVz52vswpS9C8aWIwF/sylBne6w9kPTHJlUv6voD37bjYUiDQ8ME1Bv/mlm MvwUP4SOJqMe/JDJzettmvPmOIzwM97XfxC5heJgc1zw7QtIaerJigRPsrmehfgDT2D0X WwySHa+1oSbkoS6PScub4bGplUr55f7u79ojIKzmoYPLL4K7nWSW66fL4TvY+wgaGOAtE gY6VoMNh3vqSz9HTcYD9b55o9McicE8TSZySi9YOFxJHJbrnHrxMz+XRMyAtWBiC+aQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230719; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=LVYLM79E1hRocSx3s1f9aze+0pfqyt3aXePdidpG5NA=; b=1p0KojtTQAMpHHCciqIan3mOt0rKHyqXx31XveXE//XsnOhWda6ob9g48sERfe4hVo10 bMQ2I9m44OLtkANg0u+/8eLJv3/hp8UN6rC2+FbO5wYj34iyPgvAu801T9oPMBMq6jVCB By15VidrUB16ped0zRiZRvjQB2w7opmzf5AHojzLsFGQbCqoXXFV6KnK+sNY/p19CX4rL KyxudvTse+NcVnf/Ms5bXr9WLRDPmKBRInWSx8se8XurH887plez2lEcCAAQmEgyx0yvH 7QQ+hbXq6tUoHUt/IgEYBidAeg32l8Wzzd0rIDW4jj1jiUfAPJfD9u3vhLPsqDJeM9A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=M6E8o1T3; 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 8A558606A31A; Wed, 2 Dec 2026 16:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=M6E8o1T3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA4151F00930; Wed, 2 Dec 2026 16:58:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796230719; bh=LVYLM79E1hRocSx3s1f9aze+0pfqyt3aXePdidpG5NA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M6E8o1T3W+5Z0f+G+Mja7fBkUVHNYxOA3jX79lONs7MuuqQOHaNaRsKZI+BkRkaMN IGnzqEEEufNuNBsSzqahGA7VJ1/Am8myZ2WzKawfHpRQQCNqO/PLs+HoZCpMYYxCvM vuaauv5zool+lvMZajCCbKoy7FrhrsLn6ENZw8087bb1xghIk2uwneFSU8WDTnHVZY kxoBMvPmODmYgiInyF4pR84gS/yuMtINv0Q7sKS5lcr3T77TL7P5E0dMxxjTSghF1l ga25wokHw1+50ck7FpA2Vcc8z+rSzJC8ZBZh1y5uwIqALxXz95W99lpZX1zk/dOPGM 5ydz1Ynv5bs4Q== From: Andrey Albershteyn To: "fsdevel" , "linux-ext4" , "linux-btrfs" , "linux-f2fs" , "Eric Biggers" , "Christoph Hellwig" , "Carlos Maiolino" , "fsverity" , "linux-xfs" Cc: "Christian Brauner" , Andrey Albershteyn , david@fromorbit.com Subject: [PATCH v20 16/23] xfs: don't remove written extents past EOF on fsverity inodes Date: Wed, 2 Dec 2026 17:56:46 +0100 Message-ID: <20261202165653.767961-17-aalbersh@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261202165653.767961-1-aalbersh@kernel.org> References: <20261202165653.767961-1-aalbersh@kernel.org> X-Mailing-List: linux-ext4@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 xfs_free_eofblocks() removes all extents past EOF unless the XFS_DIFLAG_PREALLOC or XFS_DIFLAG_APPEND flags are set. This is undesired for fsverity as it stores metadata beyond EOF. However, while merkle tree is being built, delayed preallocation and unwritten extents are used. After metadata construction is done, fsverity inodes becomes read-only and won't be changed anymore, none of these unwritten extents or preallocations in post EOF region will be used. Let xfs_free_eofblocks() be called on fsverity inode as usual to remove anything which is not written extent. However, inodes which are undergoing merkle tree construction need to be skipped in case reclaim takes place. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_bmap_util.c | 44 +++++++++++++++++++++++++++++++++--------- fs/xfs/xfs_icache.c | 11 ++++++++++- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 73e7db3203c0..3fa4b6a961aa 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -31,6 +31,7 @@ #include "xfs_rtbitmap.h" #include "xfs_rtgroup.h" #include "xfs_zone_alloc.h" +#include /* Kernel only BMAP related definitions and functions */ @@ -553,6 +554,17 @@ xfs_can_free_eofblocks( if (last_fsb <= end_fsb) return false; + /* + * Don't clean fsverity inodes as they already have been cleaned up and + * are read-only. Skip inodes which have merkle tree being built, the + * merkle tree is written beyond EOF. Skip inodes which have + * XFS_DIFLAG2_VERITY in case this kernel has fsverity disabled. + */ + if (fsverity_active(VFS_IC(ip)) || + fsverity_is_building(VFS_I(ip)) || + ip->i_diflags2 & XFS_DIFLAG2_VERITY) + return false; + /* * Check if there is an post-EOF extent to free. If there are any * delalloc blocks attached to the inode (data fork delalloc @@ -579,6 +591,8 @@ xfs_free_eofblocks( struct xfs_trans *tp; struct xfs_mount *mp = ip->i_mount; int error; + int bmapi_flags = XFS_BMAPI_NODISCARD; + xfs_off_t aligned_size; /* Attach the dquots to the inode up front. */ error = xfs_qm_dqattach(ip); @@ -589,17 +603,29 @@ xfs_free_eofblocks( inode_dio_wait(VFS_I(ip)); /* - * For preallocated files only free delayed allocations. + * On fs-verity inodes, while fs-verity builds metadata past EOF, it can + * leave delayed preallocations and unwritten extents. Clear delayed + * preallocation here and tell bmapi to remove unwritten extents. * - * Note that this means we also leave speculative preallocations in - * place for preallocated files. + * The xfs_free_eofblocks() is called by fs-verity when building is + * complete but fsverity_is_building() is still not cleared. */ - if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { - if (ip->i_delayed_blks) { + aligned_size = round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize); + if (fsverity_is_building(VFS_I(ip))) { + if (ip->i_delayed_blks) xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, - round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize), - LLONG_MAX, NULL); - } + aligned_size, LLONG_MAX, NULL); + bmapi_flags |= XFS_BMAPI_UNWRITTEN; + } else if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { + /* + * For preallocated files only free delayed allocations. + * + * Note that this means we also leave speculative preallocations + * in place for preallocated files. + */ + if (ip->i_delayed_blks) + xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, + aligned_size, LLONG_MAX, NULL); xfs_inode_clear_eofblocks_tag(ip); return 0; } @@ -620,7 +646,7 @@ xfs_free_eofblocks( * bug). */ error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK, - XFS_ISIZE(ip), XFS_BMAPI_NODISCARD); + XFS_ISIZE(ip), bmapi_flags); if (error) goto err_cancel; diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index de8be344e987..ca74c9b4f8d3 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -28,7 +28,7 @@ #include "xfs_da_format.h" #include "xfs_dir2.h" #include "xfs_metafile.h" - +#include #include /* Radix tree tags for incore inode tree. */ @@ -1260,6 +1260,15 @@ xfs_inode_free_eofblocks( if (xfs_can_free_eofblocks(ip)) return xfs_free_eofblocks(ip); + /* + * The above xfs_free_eofblocks() is skipped for inodes with fsverity + * tree is being built. However, we don't want to clear EOF tag in this + * case. If building the tree fails, inode will have EOF blocks which + * needs removal. + */ + if (fsverity_is_building(VFS_IC(ip))) + return 0; + /* inode could be preallocated */ trace_xfs_inode_free_eofblocks_invalid(ip); xfs_inode_clear_eofblocks_tag(ip); -- 2.54.0