[PATCH 18/29] xfs: don't store trailing zeroes of merkle tree blocks

Darrick J. Wong
2024-03-30T00:40:46Z

From: Darrick J. Wong <djwong@kernel.org>

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@kernel.org>
Reviewed-by: Andrey Albershteyn <aalbersh@redhat.com>
---
fs/xfs/xfs_fsverity.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
index d675b0f71bde5..8d87d411a9ccb 100644
--- a/fs/xfs/xfs_fsverity.c
+++ b/fs/xfs/xfs_fsverity.c
@@ -667,11 +667,6 @@ xfs_fsverity_read_merkle(
if (error)
goto out_new_mk;

- if (!args.valuelen) {
- error = -ENODATA;
- goto out_new_mk;
- }
-
mk = xfs_fsverity_cache_store(ip, key, new_mk);
if (mk != new_mk) {
/*
@@ -722,6 +717,12 @@ xfs_fsverity_write_merkle(
.value = (void *)buf,
.valuelen = size,
};
+ const char *p = buf + size - 1;
+
+ /* Don't store trailing zeroes. */
+ while (p >= (const char *)buf && *p == 0)
+ p--;
+ args.valuelen = p - (const char *)buf + 1;

xfs_fsverity_init_merkle_args(ip, &name, pos, &args);
return xfs_attr_setname(&args, false);