From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1DF7280CCE for ; Mon, 28 Jul 2025 20:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753734707; cv=none; b=Soen60+veZAxg+GbPKMFK2P+r1xGhVG4oe70+EX8nWqLk6TN51b4XhYXurrSlmi4yQb4cO2wfQ7i6B8o74J+92vW+y5MvufBfMKGidII9uiW+Bqws9zh3PBU3CZ6dFdv/6TJgevi4r8STw4adLIHteoqmq9VCB3f5nw7/4oqlwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753734707; c=relaxed/simple; bh=hehlWCL4DnH1hXGZwMMuYJcNu8D2DJbAccQcjormcfo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MhvEZuOftZPL92Fo0TZ+CthSsS74OxJO4S9IrYCpBkSbmE3nMabTISHXDw0RV3sBR2MmNO0+MK/vj615DoOL6UHqw6qtp3DDvhDZYT8MemfV0TboHEO3DMoTv1pXejGthUMhSLbqkvknLZ/eaocGgjZ7+pfWDWJy6MVxQa8e38o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MF5VS5C8; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MF5VS5C8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753734705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F+cTONg/x1WR5SJCmcwZqVY3Un6rgLMjRuTOy/YQqvw=; b=MF5VS5C8P88qroqmMOIwhMN6VIhj65MfEUOWJJAu+AF2xatdrdXKfvq/iSkI90QHapx2Sq PI2PlU6Z/ie2UrajdUOo2f01rElpS5LhpkJu/+ZpXuMTnh1217wDi/CNWE1OTPhSypesLe 5kDg+8NKfev+OAfN/IB414q1y2zm4Dk= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-375-b-tlvye-MqaZ8Ph1-OVTxg-1; Mon, 28 Jul 2025 16:31:43 -0400 X-MC-Unique: b-tlvye-MqaZ8Ph1-OVTxg-1 X-Mimecast-MFC-AGG-ID: b-tlvye-MqaZ8Ph1-OVTxg_1753734701 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ade5b98537dso520906966b.2 for ; Mon, 28 Jul 2025 13:31:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753734701; x=1754339501; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F+cTONg/x1WR5SJCmcwZqVY3Un6rgLMjRuTOy/YQqvw=; b=D8EB/CrjgITUy0m/YJwxqZls2UU/0VtfixSFfG7vu2fjF/19or2C5aB+aksnvaHU4j m5Yv6kh8RvmWxZZU3dpWKgaLzpGDGs6P8gJ9I81q4vIYFkEr4ToFWXd82Z3a/APCq4T+ Y2D0VZ8eWZBuTRUByvuwvi8XX7tDnWBbEWe+UVshucs15O6WjI49mmrlXs1NiRgvUmpI 6vXTuPp0nEAKHiLhtnY8XuIkeq0QnyFM0lIoC9KFXjK/gAIgBxsgBsei3iT2t1pkdMnI XbSBr3olAxjxXFow/TLn/GOs7I2fbicePmzNmjNNw+OTki/czv0K3XJyPq0Bf+PRkdYH ytmA== X-Forwarded-Encrypted: i=1; AJvYcCWMP/7QRvTmRbCumtzvGUvqcooEoke1QA/vDFU+uCT57IedOcZE4kZM152dCRMR8WgLw+jHoW85+Dw=@vger.kernel.org X-Gm-Message-State: AOJu0YymrL6Ma+YeexztH/NZRf/j+g6/rGfvsWdxSf7qNvl6P5qqEW+9 E0jUFgN9RbwHFvM/F701MBbnZYZ8A+MFj8JSQh8b9GCpzN3a6DV7QdSfS3vIchr/fWV5Myo8PgU ozz4vrteTBryzvRSd2zN/aJrIc6H+axGK/QY8UYw7CK41ZbbHQFavzFoisWK7 X-Gm-Gg: ASbGncsGDY3qJauplMaKdCKaoGZbJjd9cl9tbrMxmbw10zmkmPrnhpHG8aOPjoKtO8h ykCOjU55D5yvgXvj3uGICSaA2gb/I9oaW036R1vuBVQa1jWJxnPSprQGgtdjAJmekKAa/tLiYfj K3cIJgIWm3MJ4bnQ1Fh6iTdTBspKayDQ5GLr0XqqNSa1Z6hqPDaxQQwWszV5it8a+W7WKRHGa8m jJsnYark4xEfZfCetP0EXRKMTUwFQsnmPgEmJ+D7oy8oQaHhEfw/qYij8HrKZBJPOnWE6/zAtq6 iFnELeGiT8qH3ZXGuG0kpY3792wqR8SstFJKMtAsIYSkuw== X-Received: by 2002:a17:907:960c:b0:ae3:5212:c906 with SMTP id a640c23a62f3a-af616d05693mr1403398966b.10.1753734701188; Mon, 28 Jul 2025 13:31:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQMx6515Qysg+2ceeonp9KrxJ6j3Yt04QTkOPLGdwZHs5oma63j7vjBI22ZBCvngDmor2gpA== X-Received: by 2002:a17:907:960c:b0:ae3:5212:c906 with SMTP id a640c23a62f3a-af616d05693mr1403396666b.10.1753734700735; Mon, 28 Jul 2025 13:31:40 -0700 (PDT) Received: from [127.0.0.2] (ip-217-030-074-039.aim-net.cz. [217.30.74.39]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-615226558d3sm2730656a12.45.2025.07.28.13.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jul 2025 13:31:40 -0700 (PDT) From: Andrey Albershteyn X-Google-Original-From: Andrey Albershteyn Date: Mon, 28 Jul 2025 22:30:24 +0200 Subject: [PATCH RFC 20/29] xfs: disable preallocations for fsverity Merkle tree writes Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250728-fsverity-v1-20-9e5443af0e34@kernel.org> References: <20250728-fsverity-v1-0-9e5443af0e34@kernel.org> In-Reply-To: <20250728-fsverity-v1-0-9e5443af0e34@kernel.org> To: fsverity@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, david@fromorbit.com, djwong@kernel.org, ebiggers@kernel.org, hch@lst.de Cc: Andrey Albershteyn X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2007; i=aalbersh@kernel.org; h=from:subject:message-id; bh=hehlWCL4DnH1hXGZwMMuYJcNu8D2DJbAccQcjormcfo=; b=owJ4nJvAy8zAJea2/JXEGuOHHIyn1ZIYMtrvSYQcst7EMZH/uvLO7Xneqfu2v2znSnPLyz+vu 8LS2CpfeFlHKQuDGBeDrJgiyzppralJRVL5Rwxq5GHmsDKBDGHg4hSAiUxoZfif3iN7yNq+8uiX 2UEiKrUTV5qcU+PM8A6z0eeZ1vVy+wZWhv9Oj7IedRWtyLef8+6qxeZJD09vsNvmKiv9J+9z3Rt RCQVGAHVsRks= X-Developer-Key: i=aalbersh@kernel.org; a=openpgp; fpr=AE1B2A9562721A6FC4307C1F46A7EA18AC33E108 While writing Merkle tree, file is read-only and there's no further writes except Merkle tree building. The file is truncated beforehand to remove any preallocated extents. The Merkle tree is the only data XFS will write. As we don't want XFS to truncate file after we done writing, let's also skip truncation on fsverity files. Therefore, we also need to disable preallocations while writing merkle tree as we don't want any unused extents past the tree. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_iomap.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index ff05e6b1b0bb..00ec1a738b39 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -32,6 +32,8 @@ #include "xfs_rtbitmap.h" #include "xfs_icache.h" #include "xfs_zone_alloc.h" +#include "xfs_fsverity.h" +#include #define XFS_ALLOC_ALIGN(mp, off) \ (((off) >> mp->m_allocsize_log) << mp->m_allocsize_log) @@ -1849,7 +1851,9 @@ xfs_buffered_write_iomap_begin( * Determine the initial size of the preallocation. * We clean up any extra preallocation when the file is closed. */ - if (xfs_has_allocsize(mp)) + if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION)) + prealloc_blocks = 0; + else if (xfs_has_allocsize(mp)) prealloc_blocks = mp->m_allocsize_blocks; else if (allocfork == XFS_DATA_FORK) prealloc_blocks = xfs_iomap_prealloc_size(ip, allocfork, @@ -1976,6 +1980,13 @@ xfs_buffered_write_iomap_end( if (flags & IOMAP_FAULT) return 0; + /* + * While writing Merkle tree to disk we would not have any other + * delayed allocations + */ + if (xfs_iflags_test(XFS_I(inode), XFS_VERITY_CONSTRUCTION)) + return 0; + /* Nothing to do if we've written the entire delalloc extent */ start_byte = iomap_last_written_block(inode, offset, written); end_byte = round_up(offset + length, i_blocksize(inode)); -- 2.50.0