{"id":2225125,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2225125/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260420114714.1621982-18-aalbersh@kernel.org/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/1.1/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},"msgid":"<20260420114714.1621982-18-aalbersh@kernel.org>","date":"2026-04-20T11:47:04","name":"[v8,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.1/people/92821/?format=json","name":"Andrey Albershteyn","email":"aalbersh@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260420114714.1621982-18-aalbersh@kernel.org/mbox/","series":[{"id":500600,"url":"http://patchwork.ozlabs.org/api/1.1/series/500600/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=500600","date":"2026-04-20T11:46:51","name":"fs-verity support for XFS with post EOF merkle tree","version":8,"mbox":"http://patchwork.ozlabs.org/series/500600/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225125/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225125/checks/","tags":{},"headers":{"Return-Path":"\n <SRS0=xxr/=CT=vger.kernel.org=linux-ext4+bounces-15930-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=hdyMVg/0;\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=xxr/=ct=vger.kernel.org=linux-ext4+bounces-15930-patchwork-incoming=ozlabs.org@ozlabs.org;\n receiver=patchwork.ozlabs.org)","gandalf.ozlabs.org;\n arc=pass smtp.remote-ip=\"2600:3c09:e001:a7::12fc:5321\"\n 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=hdyMVg/0;\n\tdkim-atps=neutral","gandalf.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15930-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=\"hdyMVg/0\"","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 4fzkLy3WdSz1yD4\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 21:50:18 +1000 (AEST)","from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\tby gandalf.ozlabs.org (Postfix) with ESMTP id 4fzkLy344tz4wCQ\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 21:50:18 +1000 (AEST)","by gandalf.ozlabs.org (Postfix)\n\tid 4fzkLy30J8z4wCm; Mon, 20 Apr 2026 21:50:18 +1000 (AEST)","from sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::12fc:5321])\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 4fzkLt6LYFz4wCQ\n\tfor <patchwork-incoming@ozlabs.org>; Mon, 20 Apr 2026 21:50:14 +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 C245830285F4\n\tfor <patchwork-incoming@ozlabs.org>; Mon, 20 Apr 2026 11:48:40 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 5A59039E6FE;\n\tMon, 20 Apr 2026 11:48:26 +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 18A2338423A;\n\tMon, 20 Apr 2026 11:48:25 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 4EA62C19425;\n\tMon, 20 Apr 2026 11:48:23 +0000 (UTC)"],"ARC-Seal":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1776685818; cv=pass;\n\tb=kIn58nSi3cqA+m8cDdsrXr+H6JDzc9efrvDBGRlqGJGRRe+p3Co5W5ME5ewl5u1anYyJSwYoKiyvDYa35lEHbQCLIlaf5zzUs/efPZYWtq9E+r4Nqc1QEysEitIB80aA+PViVRBDbFVzJF2mx9C5MqT3y3EKo6djOIxPDgDP9IRw0bwXBTVj3a/vhZXJRJ28O9lOl6zxaJg8ZHzuW4ILnDyKCwKA1Iu25W8rFUjPgbFSdGlWIoOeHZuwX+0FJpEImcZA6gBQcGVjqq6iXeDhNMa3QHIyUGl/cPmz3WDh3nc1ObscW7nwGklX5orMORJkxTbai7RFHrmYNo9lITYBWA==","i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776685706; cv=none;\n b=D+tsqYfdmUQWulV0LYZrIEGxEXtqbajhZQ2VXLyGx3tZVVrSntHEZdtrEERdX2h55i4Gw+d5I85yFffwSEKYi4yCnsjHWR/bD0XvufpQLSitYmSn6anL9fp/o1RD9Ud3Krb0mygebp4xSbqG5F99hvtco0HLrgJVjh0vDY+72RE="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707;\n\tt=1776685818; 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=o+1lmgFmQQo93IoTM880EM92fi/XKQfOoTUr0LgJaJdp/n1FFCcGtIIGOVseSKyej2wNGqSGLn8PYVTInjFRbhH78EA5hf+Q0WqCwXzRUJMZrj9AXX7BrXauD25Ps7yp7vNZLx/yEBAYS+FAp5pJYdVqCPIdhkIQM0YZO027nQ3LN0O49W2cefM02wVoVxZP8PPolGkqcTBfOkj4ExrKvsW6aqPxtJaZ6si0EHr3Up26CFdVfk0meQy+Vdr1XlTFm2W/bgkpqeX53CJaHJ5LiqTC40SMxTyrkx2l/hQiDjDNmUywW52uWoJTU6kjsY6m3X6tXUo52o+QXHYzcRPRsA==","i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776685706; 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=H5FZ6rVgzCr1yC6jhEfgjBLIsp+5JU7o76Bgz7wkbCzGI5uqdgMzOgkJCZG0/t+xXHUWJ11AIlNas063OB4fLBr3AFUnaLNipPZdQ1HCvMr61p7FCYuPgp0lvbCLA8XqZrj45pZDAc90lILOtm1Uh6+OQ6lBinai1+prscm9Ew8="],"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=hdyMVg/0; dkim-atps=neutral;\n spf=pass (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15930-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=hdyMVg/0; 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=1776685705;\n\tbh=Huny4r4Jjz1UBLXAMcUst2XzWC1esUlxzb3uDndhMAg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=hdyMVg/0xlbCmSL1mfFHsc+AWnC+Wy2UJyNgc9tq779543h+54qsan3Znn24F2rt7\n\t kfhzANJn6pSwUz+4l2BYdF3UAtOfYWdAxkgPJ9WEZJvhBsB707/wkjOCBn4AWfdj/N\n\t 0NWkR5qmJckQ4ci1VKm+U2xIyLEMsbhi4R50bbwntgvFxIA7auu01cT0QYYpnAnj68\n\t hzmdxERXlw1OgwXGOZKq2OJQKVYc+gXdhAIsAb5kkzL5itiMtNXrcPN3Z0NSCiwmX3\n\t TwvtZV6cZ0u+Xn+ZgKlDizyMMmqReQeJX52pkBPU6ojKiGl+NnVXF+enehA7bokzLW\n\t KkzTc56Cg5R1Q==","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\tlinux-unionfs@vger.kernel.org,\n\tdjwong@kernel.org","Subject":"[PATCH v8 17/22] xfs: remove unwritten extents after preallocations\n in fsverity metadata","Date":"Mon, 20 Apr 2026 13:47:04 +0200","Message-ID":"<20260420114714.1621982-18-aalbersh@kernel.org>","X-Mailer":"git-send-email 2.51.2","In-Reply-To":"<20260420114714.1621982-1-aalbersh@kernel.org>","References":"<20260420114714.1621982-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":["v8","17/22"]}