From: Andrey Albershteyn <aalbersh@kernel.org>
To: "fsdevel" <linux-fsdevel@vger.kernel.org>,
"linux-ext4" <linux-ext4@vger.kernel.org>,
"linux-btrfs" <linux-btrfs@vger.kernel.org>,
"linux-f2fs" <linux-f2fs-devel@lists.sourceforge.net>,
"Eric Biggers" <ebiggers@kernel.org>,
"Christoph Hellwig" <hch@lst.de>,
"Carlos Maiolino" <cem@kernel.org>,
"fsverity" <fsverity@lists.linux.dev>,
"linux-xfs" <linux-xfs@vger.kernel.org>
Cc: "Christian Brauner" <brauner@kernel.org>,
Andrey Albershteyn <aalbersh@kernel.org>,
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 [thread overview]
Message-ID: <20261202165653.767961-17-aalbersh@kernel.org> (raw)
In-Reply-To: <20261202165653.767961-1-aalbersh@kernel.org>
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 <aalbersh@kernel.org>
---
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 <linux/fsverity.h>
/* 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 <linux/fsverity.h>
#include <linux/iversion.h>
/* 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
next prev parent reply other threads:[~2026-12-02 16:58 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 16:56 [PATCH v20 00/23] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 01/23] fs: constify inode argument of inode_state_read_once() Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 02/23] fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 03/23] fs,fsverity: add I_VERITY_BUILDING inode state flag Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 04/23] fs,fsverity: reject S_APPEND on fsverity inodes Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 05/23] iomap: use fsverity_is_building() to check for fsverity IO Andrey Albershteyn
2026-12-02 17:09 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 06/23] btrfs: use I_VERITY_BUILDING instead of private flags Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 07/23] ext4: " Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 08/23] f2fs: " Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 09/23] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 10/23] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 11/23] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 12/23] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 13/23] xfs: handle fsverity I/O in write/read path Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 14/23] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-12-02 17:15 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 15/23] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-12-02 17:09 ` sashiko-bot
2026-12-02 16:56 ` Andrey Albershteyn [this message]
2026-12-02 16:56 ` [PATCH v20 17/23] xfs: add fs-verity support Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 18/23] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 19/23] xfs: add fs-verity ioctls Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 20/23] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 21/23] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 22/23] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-12-02 17:17 ` [f2fs-dev] " sashiko-bot
2026-12-02 16:56 ` [PATCH v20 23/23] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-12-02 17:17 ` [f2fs-dev] " sashiko-bot
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=20261202165653.767961-17-aalbersh@kernel.org \
--to=aalbersh@kernel.org \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=ebiggers@kernel.org \
--cc=fsverity@lists.linux.dev \
--cc=hch@lst.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/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