{"id":2221459,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2221459/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260409131404.1545834-18-aalbersh@kernel.org/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/1.2/projects/8/?format=json","name":"Linux ext4 filesystem development","link_name":"linux-ext4","list_id":"linux-ext4.vger.kernel.org","list_email":"linux-ext4@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260409131404.1545834-18-aalbersh@kernel.org>","list_archive_url":null,"date":"2026-04-09T13:13:49","name":"[v7,17/22] xfs: remove unwritten extents after preallocations in fsverity metadata","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":false,"hash":"00a99ad4d1170a19858a877d97aefe12aaa2774d","submitter":{"id":92821,"url":"http://patchwork.ozlabs.org/api/1.2/people/92821/?format=json","name":"Andrey Albershteyn","email":"aalbersh@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260409131404.1545834-18-aalbersh@kernel.org/mbox/","series":[{"id":499292,"url":"http://patchwork.ozlabs.org/api/1.2/series/499292/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=499292","date":"2026-04-09T13:13:34","name":"fs-verity support for XFS with post EOF merkle tree","version":7,"mbox":"http://patchwork.ozlabs.org/series/499292/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2221459/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221459/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <SRS0=qQaV=CI=vger.kernel.org=linux-ext4+bounces-15714-patchwork-incoming=ozlabs.org@ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-ext4@vger.kernel.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","patchwork-incoming@ozlabs.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=D1TuV60r;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org\n (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org;\n envelope-from=srs0=qqav=ci=vger.kernel.org=linux-ext4+bounces-15714-patchwork-incoming=ozlabs.org@ozlabs.org;\n receiver=patchwork.ozlabs.org)","gandalf.ozlabs.org;\n arc=pass smtp.remote-ip=172.232.135.74 arc.chain=subspace.kernel.org","gandalf.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org","gandalf.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=D1TuV60r;\n\tdkim-atps=neutral","gandalf.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.232.135.74; helo=sto.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15714-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"D1TuV60r\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fs0vd2pJbz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 23:21:49 +1000 (AEST)","from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\tby gandalf.ozlabs.org (Postfix) with ESMTP id 4fs0vd2Jnxz4wLM\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 23:21:49 +1000 (AEST)","by gandalf.ozlabs.org (Postfix)\n\tid 4fs0vd2DPTz4wLh; Thu, 09 Apr 2026 23:21:49 +1000 (AEST)","from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby gandalf.ozlabs.org (Postfix) with ESMTPS id 4fs0vY4hlVz4wLM\n\tfor <patchwork-incoming@ozlabs.org>; Thu, 09 Apr 2026 23:21:45 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id B0785304D978\n\tfor <patchwork-incoming@ozlabs.org>; Thu,  9 Apr 2026 13:18:13 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 607943A5E62;\n\tThu,  9 Apr 2026 13:15:02 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F0603D34A4;\n\tThu,  9 Apr 2026 13:15:01 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id B90F7C2BCB2;\n\tThu,  9 Apr 2026 13:14:58 +0000 (UTC)"],"ARC-Seal":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1775740909; cv=pass;\n\tb=YsdBH1Ge0e9ySvcrP4M/XTG26S/d9Fw3IFBmN6GlyLOIF+VQ3hO4HQK3d0z5XCXJf8vPCotSWpZIxdRDSEqUWsizYyeahS+9WVifLm37N4a1YkgK6BhPdhIDqRgAmKGh25uho1mlG/eWr8WXcQq6MbDyGgrtNi2zzjJa9uTHol8QPZlX2TAQ0Q7VF8JtZ+gUOoqBSVocyK3CJGIls1Hpd4wGRI197bRl15VF7aR6lrZW8KkFKJsPlu4wmRTCndlWujtY9P/iccdWm8r0j82E3m7KAP3W03gV4K/yshGwJem7RgpwnIGanqVt9M8BcP5JKC8IrVSTNoijUKOBrT0fCA==","i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775740501; cv=none;\n b=ObrjM4ujLGSjFQXNu8QZhhpufwDa1wzqcBmOKhZ8L1T/zG5ttHoTouzfHGOxtEmgOw12RxEzexIVhtLLh+ndzWYxRhgH6fZe4pybnpoGJBbUDkeUCzcs+sDB2SkUzmfQVrKjQLy0pFHJcLFQke+E1tZmrdB5e4zfx1OxSPMlP0g="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707;\n\tt=1775740909; c=relaxed/relaxed;\n\tbh=ASIE8u84SXr/O1twKzR6PDUlhzPsyBT8ml0lj8w63g0=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=wKrC6JHN+fysTNCcUwTRUhAcVUD6aqqN8quwCIGVFXUAEqfW49qpQITXAifQqkivhd+fubofRXQMkdGI5pg7FnvnguBN2GMkXdlm0djddABrL4prI5OfOOGUcuESqV1zqVNkYDkcBm/TxoLYVfWKP0XL6YvuzwGQRgj/UPnyc+/djoxQGjh5FAp6oqq3ZN1o7qYrkso8LEN8Or68LcjHKLzbEofq5OxhD/fcDlIbCa5qd5B93E+mh0yYos+yl533S09ppV8+/zNplNaRU0qUZATY791/6PsgqQSudeZ6OMHsNIgWko38vrfIVaSxo9ZbqAFODjos7DoYuMxqi9Z97A==","i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775740501; c=relaxed/simple;\n\tbh=Huny4r4Jjz1UBLXAMcUst2XzWC1esUlxzb3uDndhMAg=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=buqwSLE7jTL29PLdlRPKvd0iIgnFwRJz5h4rmB2hyQudpKVVLRAbp8eb9XGmtH5EyRIHsjTJ2o5mJuQZTHRUV5W0Ksgvda2eqeVHWQ73K7K1Dwa1SkSp1wlAyqx/SL5KQvmfN1YELyFN14QWPk6A6qTepLBkqwdQ5ekzwcBaVnI="],"ARC-Authentication-Results":["i=2; gandalf.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org;\n dkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=D1TuV60r; dkim-atps=neutral;\n spf=pass (client-ip=172.232.135.74; helo=sto.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15714-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org","i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=D1TuV60r; arc=none smtp.client-ip=10.30.226.201"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1775740501;\n\tbh=Huny4r4Jjz1UBLXAMcUst2XzWC1esUlxzb3uDndhMAg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=D1TuV60rIPD8bM8QG5t+BltoGhmXK33cRHEdb+55mNjHnSXKURamC4kVqwSd6lBfS\n\t 6QG1Ta8F6BNGlQG/73UsY0PdRaQYygxsA5zgLt11tt2teNf+2ESNpJzdMtXxwyEueK\n\t FP38LpUb8q0XPFaFB9Y1HEwHhoqv4GBJ17sCNd90I44ADZgIT+wOsLsg9j9q0nzoR2\n\t t6Njr0zcIRKyXTg2Grvit3OAxj558DJzNypI8705Fl4NWG855msz1e0ybdIvY76CEM\n\t 7wRqeaAvUMpWHGTKWWqvQTVTIE+wJIhA2C2pH9SkWgROa2jaItlGSP3puzho8K6/uO\n\t NU+/5hjr+KJvA==","From":"Andrey Albershteyn <aalbersh@kernel.org>","To":"linux-xfs@vger.kernel.org,\n\tfsverity@lists.linux.dev,\n\tlinux-fsdevel@vger.kernel.org,\n\tebiggers@kernel.org","Cc":"Andrey Albershteyn <aalbersh@kernel.org>,\n\thch@lst.de,\n\tlinux-ext4@vger.kernel.org,\n\tlinux-f2fs-devel@lists.sourceforge.net,\n\tlinux-btrfs@vger.kernel.org,\n\tdjwong@kernel.org","Subject":"[PATCH v7 17/22] xfs: remove unwritten extents after preallocations\n in fsverity metadata","Date":"Thu,  9 Apr 2026 15:13:49 +0200","Message-ID":"<20260409131404.1545834-18-aalbersh@kernel.org>","X-Mailer":"git-send-email 2.51.2","In-Reply-To":"<20260409131404.1545834-1-aalbersh@kernel.org>","References":"<20260409131404.1545834-1-aalbersh@kernel.org>","Precedence":"bulk","X-Mailing-List":"linux-ext4@vger.kernel.org","List-Id":"<linux-ext4.vger.kernel.org>","List-Subscribe":"<mailto:linux-ext4+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-ext4+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Spam-Status":"No, score=-1.2 required=5.0 tests=ARC_SIGNED,ARC_VALID,\n\tDKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS,\n\tMAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=disabled\n\tversion=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org"},"content":"XFS preallocates spaces during writes. In normal I/O this space, if\nunused, is removed by truncate. For files with fsverity XFS does not use\ntruncate as fsverity metadata is stored past EOF.\n\nAfter we're done with writing fsverity metadata iterate over extents in\nthat region and remove any unwritten ones. These would be left overs in\nthe holes in the merkle tree and past fsverity descriptor.\n\nReviewed-by: Christoph Hellwig <hch@lst.de>\nReviewed-by: Darrick J. Wong <djwong@kernel.org>\nSigned-off-by: Andrey Albershteyn <aalbersh@kernel.org>\n---\n fs/xfs/xfs_fsverity.c | 67 +++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 67 insertions(+)","diff":"diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c\nindex 68d9736d19d9..ef5cf97ad700 100644\n--- a/fs/xfs/xfs_fsverity.c\n+++ b/fs/xfs/xfs_fsverity.c\n@@ -21,6 +21,8 @@\n #include \"xfs_iomap.h\"\n #include \"xfs_error.h\"\n #include \"xfs_health.h\"\n+#include \"xfs_bmap.h\"\n+#include \"xfs_bmap_util.h\"\n #include <linux/fsverity.h>\n #include <linux/iomap.h>\n #include <linux/pagemap.h>\n@@ -173,6 +175,63 @@ xfs_fsverity_delete_metadata(\n \treturn error;\n }\n \n+static int\n+xfs_fsverity_cancel_unwritten(\n+\tstruct xfs_inode\t*ip,\n+\txfs_fileoff_t\t\tstart,\n+\txfs_fileoff_t\t\tend)\n+{\n+\tstruct xfs_mount\t*mp = ip->i_mount;\n+\tstruct xfs_trans\t*tp;\n+\txfs_fileoff_t\t\toffset_fsb = XFS_B_TO_FSB(mp, start);\n+\txfs_fileoff_t\t\tend_fsb = XFS_B_TO_FSB(mp, end);\n+\tstruct xfs_bmbt_irec\timap;\n+\tint\t\t\tnimaps;\n+\tint\t\t\terror = 0;\n+\tint\t\t\tdone;\n+\n+\n+\twhile (offset_fsb < end_fsb) {\n+\t\tnimaps = 1;\n+\n+\t\terror = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0,\n+\t\t\t\t0, &tp);\n+\t\tif (error)\n+\t\t\treturn error;\n+\n+\t\txfs_ilock(ip, XFS_ILOCK_EXCL);\n+\t\terror = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,\n+\t\t\t\t&imap, &nimaps, 0);\n+\t\tif (error)\n+\t\t\tgoto out_cancel;\n+\n+\t\tif (nimaps == 0)\n+\t\t\tgoto out_cancel;\n+\n+\t\tif (imap.br_state == XFS_EXT_UNWRITTEN) {\n+\t\t\txfs_trans_ijoin(tp, ip, 0);\n+\n+\t\t\terror = xfs_bunmapi(tp, ip, imap.br_startoff,\n+\t\t\t\t\timap.br_blockcount, 0, 1, &done);\n+\t\t\tif (error)\n+\t\t\t\tgoto out_cancel;\n+\n+\t\t\terror = xfs_trans_commit(tp);\n+\t\t} else {\n+\t\t\txfs_trans_cancel(tp);\n+\t\t}\n+\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\n+\t\toffset_fsb = imap.br_startoff + imap.br_blockcount;\n+\t}\n+\n+\treturn error;\n+out_cancel:\n+\txfs_trans_cancel(tp);\n+\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\treturn error;\n+}\n+\n \n /*\n  * Prepare to enable fsverity by clearing old metadata.\n@@ -248,6 +307,14 @@ xfs_fsverity_end_enable(\n \tif (error)\n \t\tgoto out;\n \n+\t/*\n+\t * Remove unwritten extents left by COW preallocations and write\n+\t * preallocation in the merkle tree holes and past descriptor\n+\t */\n+\terror = xfs_fsverity_cancel_unwritten(ip, range_start, LLONG_MAX);\n+\tif (error)\n+\t\tgoto out;\n+\n \t/*\n \t * Proactively drop any delayed allocations in COW fork, the fsverity\n \t * files are read-only\n","prefixes":["v7","17/22"]}