fsverity: pass digest size and hash of the all-zeroes block to ->write

Let filesystem iterate over hashes in the block and check if these are
hashes of zeroed data blocks. XFS will use this to decide if it want to
store tree block full of these hashes.

Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Acked-by: Eric Biggers <ebiggers@kernel.org>
Acked-by: David Sterba <dsterba@suse.com>
Link: https://patch.msgid.link/20261002223705.2175542-4-aalbersh@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
Andrey Albershteyn 2026-10-03 00:36:44 +02:00 committed by Eric Biggers
parent 7a59a56fe4
commit ad7be74b38
5 changed files with 19 additions and 5 deletions

View File

@ -779,11 +779,15 @@ static struct page *btrfs_read_merkle_tree_page(struct inode *inode,
* @buf: Merkle tree block to write
* @pos: the position of the block in the Merkle tree (in bytes)
* @size: the Merkle tree block size (in bytes)
* @zero_digest: the hash of the all-zeroes block
* @digest_size: size of zero_digest, in bytes
*
* Returns 0 on success or negative error code on failure
*/
static int btrfs_write_merkle_tree_block(struct file *file, const void *buf,
u64 pos, unsigned int size)
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size)
{
struct inode *inode = file_inode(file);
loff_t merkle_pos = merkle_file_pos(inode);

View File

@ -374,7 +374,9 @@ static void ext4_readahead_merkle_tree(struct inode *inode, pgoff_t index,
}
static int ext4_write_merkle_tree_block(struct file *file, const void *buf,
u64 pos, unsigned int size)
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size)
{
pos += ext4_verity_metadata_pos(file_inode(file));

View File

@ -272,7 +272,9 @@ static void f2fs_readahead_merkle_tree(struct inode *inode, pgoff_t index,
}
static int f2fs_write_merkle_tree_block(struct file *file, const void *buf,
u64 pos, unsigned int size)
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size)
{
pos += f2fs_verity_metadata_pos(file_inode(file));

View File

@ -50,7 +50,9 @@ static int write_merkle_tree_block(struct file *file, const u8 *buf,
int err;
err = inode->i_sb->s_vop->write_merkle_tree_block(file, buf, pos,
params->block_size);
params->block_size,
params->zero_digest,
params->digest_size);
if (err)
fsverity_err(inode, "Error %d writing Merkle tree block %lu",
err, index);

View File

@ -124,6 +124,8 @@ struct fsverity_operations {
* @buf: the Merkle tree block to write
* @pos: the position of the block in the Merkle tree (in bytes)
* @size: the Merkle tree block size (in bytes)
* @zero_digest: the hash of the all-zeroes block
* @digest_size: size of zero_digest, in bytes
*
* This is only called between ->begin_enable_verity() and
* ->end_enable_verity().
@ -131,7 +133,9 @@ struct fsverity_operations {
* Return: 0 on success, -errno on failure
*/
int (*write_merkle_tree_block)(struct file *file, const void *buf,
u64 pos, unsigned int size);
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size);
};
#ifdef CONFIG_FS_VERITY