From: Darrick J. Wong <djwong@xxxxxxxxxx> As a minor space optimization, don't store trailing zeroes of merkle tree blocks to reduce space consumption and copying overhead. This really only affects the rightmost blocks at each level of the tree. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> Reviewed-by: Andrey Albershteyn <aalbersh@xxxxxxxxxx> --- fs/xfs/xfs_fsverity.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c index 546c7ec6daadc..f6c650e81cb26 100644 --- a/fs/xfs/xfs_fsverity.c +++ b/fs/xfs/xfs_fsverity.c @@ -874,6 +874,16 @@ xfs_fsverity_write_merkle( .value = (void *)buf, .valuelen = size, }; + const char *p; + + /* + * Don't store trailing zeroes, except for the first byte, which we + * need to avoid ENODATA errors in the merkle read path. + */ + p = buf + size - 1; + while (p >= (const char *)buf && *p == 0) + p--; + args.valuelen = max(1, p - (const char *)buf + 1); xfs_fsverity_init_merkle_args(ip, &name, pos, &args); return xfs_attr_set(&args, XFS_ATTRUPDATE_UPSERT, false);