Re: [PATCH v6 15/22] xfs: add fs-verity support

Eric Biggers
2026-04-01T23:57:15Z

On Tue, Mar 31, 2026 at 11:28:16PM +0200, Andrey Albershteyn wrote:
> + /*
> + * If this is a block full of hashes of zeroed blocks, don't bother
> + * storing the block. We can synthesize them later.
> + *
> + * However, do this only in case Merkle tree block == fs block size.
> + * Iomap synthesizes these blocks based on holes in the merkle tree. We
> + * won't be able to tell if something need to be synthesizes for the
> + * range in the fs block. For example, for 4k filesystem block
> + *
> + * [ 1k | zero hashes | zero hashes | 1k ]
> + *
> + * Iomap won't know about these empty blocks.
> + */
> + for (i = 0, p = buf; i < size; i += digest_size, p += digest_size)
> + if (memcmp(p, zero_digest, digest_size))
> + break;
> + if (i == size && size == ip->i_mount->m_sb.sb_blocksize)
> + return 0;

Might be too subtle, but this could be done more efficiently with just
two calls to memcmp():

if (size == ip->i_mount->m_sb.sb_blocksize &&
/* first digest is zero_digest */
memcmp(buf, zero_digest, digest_size) == 0 &&
/* every digest is same as previous, thus all are zero_digest */
memcmp(buf + digest_size, buf, size - digest_size) == 0)
return 0;

- Eric