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=1796230716; b=Lx+N0Rk/6NbArOTFWHaHWiAvtQEJicFuVMdMluOcd9XGah4oPUndEUesIhrNmDhnBeAU B9psLz7gQOV3f0NSGg0khXaWaxRhNkB6MEzj/mJj0xxhvCsGr0xjS/Ntr66VmKN0Y4HUo G2qgTZjtVvZe1tBc6OQ+4YVVYonGHAZWC76YO/yKYs618LWeO35dQhvj59vQgBpUF4B+q /b1qy8JYaSvzbNm8x394Dzp1domWIj4crrGlRQIITjPELPfCxSN9M7yjBC4g2wsp8LAAj JgstqbdDOy6p7IxIdDtksXCeYMNhTtdqzi2J+EN1sA9sVa6P7rdHOp9Q6v0Pqo2HvWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230716; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=h5gLrgw/6N1aLNJHircGtagzUssbJ+Rlq5SBJ0+C5+0=; b=ZYFhvUKFBl7BqTxI0+GjG2s0aLo/IFwmaRNNThuW+iCnXLss5NvCfsVRhO3yQZ4nxubi VONYGT9/tPe6NMWlhjun0zmZwR3gd52CmFHMu/VVYgV7My9I9pJlsts4Zne2oXKQ3Spqk 4+sMBtCaiGu3OHQeysGHKnyKUMMC82ovS9GAPwhBhF55kg7y7+yO9itMSt14UdEmJuGYM GgCXlbu7z0f8Ucl0UtfFlbPDosFmnO3z4dA2R65LYSfCkLnoDcM8C2ut+FvhhStzJiGnC 9HRb5MtxDjdh9VAD4KFkS4VH0APNEkIx4NGK9daMb7RVNUePGBtaZR2il7/tr16MXPQ== 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=IB0lOzea; 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 47512606A31A; Wed, 2 Dec 2026 16:58:36 +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=IB0lOzea Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBD3F1F00A15; Wed, 2 Dec 2026 16:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796230715; bh=h5gLrgw/6N1aLNJHircGtagzUssbJ+Rlq5SBJ0+C5+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IB0lOzeaYItY8uh9iP9ubpf4YLprsOF6RaIpHDuKZ/Z2jA+0QcqG4vNssz5unk/KG Yanz5V2u1WVJN+tS5tJ3wCWrsqtCFJnSwcx+9uJihP5EkI3XfEvNuA2rJEb4tVzNfK At3XzhW5JKpJTREfsnp5S7PV1DCbngRN6q/jCwXX3q4yjF8HDrDHsJ0xNf9mj2+M1h fdvLpiybeWF8PauHCt0AwoSLJhuUuL/Q1PXWrQeenjfoVe5ixfwFVKbqhULPEcBEVY vm1ELXgorPKMe0JZfTony7fsWqvif24sMr5sgQWeg0ubJ6OsPJH3o8a4BLJGWTb8oP ak0bGStZCKCwQ== 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, "Darrick J. Wong" Subject: [PATCH v20 15/23] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Date: Wed, 2 Dec 2026 17:56:45 +0100 Message-ID: <20261202165653.767961-16-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 The __xfs_bunmapi() is used to remove all extents past EOF. Add XFS_BMAPI_UNWRITTEN to remove only unwritten extents, while leaving written ones in place. This will be used in following patch to clean up unwritten extents on fsverity inodes. Signed-off-by: Andrey Albershteyn Reviewed-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 22 +++++++++++++++++++++- fs/xfs/libxfs/xfs_bmap.h | 6 +++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index f74411312901..667b693aacb8 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5220,6 +5220,22 @@ __xfs_bunmapi( ASSERT(len > 0); ASSERT(nexts >= 0); + /* + * XFS_BMAPI_UNWRITTEN is only used by fs-verity to drop unwritten + * blocks past EOF while keeping written ones (fsverity metadata). + * + * The XFS_BMAPI_UNWRITTEN could not be used with realtime inodes with + * realtime extent larger than 1 filesystem block. This is because the + * realtime inode with larger extents could have EOF in the middle of + * the extent. Removing these unwritten extent beyond EOF could lead to + * removal of data before EOF. + * + * fs-verity is not allowed to be enabled on realtime files whose + * extent size is larger than 1. + */ + ASSERT(!((flags & XFS_BMAPI_UNWRITTEN) && + xfs_inode_has_bigrtalloc(ip))); + error = xfs_iread_extents(tp, ip, whichfork); if (error) return error; @@ -5281,6 +5297,10 @@ __xfs_bunmapi( if (del.br_startoff + del.br_blockcount > end + 1) del.br_blockcount = end + 1 - del.br_startoff; + if ((flags & XFS_BMAPI_UNWRITTEN) && + del.br_state != XFS_EXT_UNWRITTEN) + goto skip; + if (!isrt || (flags & XFS_BMAPI_REMAP)) goto delete; @@ -5415,7 +5435,7 @@ __xfs_bunmapi( if (error) goto error0; } - +skip: end = del.br_startoff - 1; nodelete: /* diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index fb7481e8190c..f1df6b4b695e 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -97,6 +97,9 @@ struct xfs_bmalloca { */ #define XFS_BMAPI_CONVERT_ONLY (1u << 12) +/* Process unwritten extents only. Used for unmapping */ +#define XFS_BMAPI_UNWRITTEN (1u << 13) + #define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \ { XFS_BMAPI_METADATA, "METADATA" }, \ @@ -110,7 +113,8 @@ struct xfs_bmalloca { { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ { XFS_BMAPI_NORMAP, "NORMAP" },\ { XFS_BMAPI_EXTSZALIGN, "EXTSZALIGN" }, \ - { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" } + { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" }, \ + { XFS_BMAPI_UNWRITTEN, "UNWRITTEN" } static inline int xfs_bmapi_aflag(int w) -- 2.54.0