Re: [PATCH v3 09/28] fsverity: pass log_blocksize to end_enable_verity()

Eric Biggers
2023-10-12T07:34:46Z

On Wed, Oct 11, 2023 at 01:17:36PM +0200, Andrey Albershteyn wrote:
> On 2023-10-10 20:19:06, Eric Biggers wrote:
> > On Fri, Oct 06, 2023 at 08:49:03PM +0200, Andrey Albershteyn wrote:
> > > diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h
> > > index 252b2668894c..cac012d4c86a 100644
> > > --- a/include/linux/fsverity.h
> > > +++ b/include/linux/fsverity.h
> > > @@ -51,6 +51,7 @@ struct fsverity_operations {
> > > * @desc: the verity descriptor to write, or NULL on failure
> > > * @desc_size: size of verity descriptor, or 0 on failure
> > > * @merkle_tree_size: total bytes the Merkle tree took up
> > > + * @log_blocksize: log size of the Merkle tree block
> > > *
> > > * If desc == NULL, then enabling verity failed and the filesystem only
> > > * must do any necessary cleanups. Else, it must also store the given
> > > @@ -65,7 +66,8 @@ struct fsverity_operations {
> > > * Return: 0 on success, -errno on failure
> > > */
> > > int (*end_enable_verity)(struct file *filp, const void *desc,
> > > - size_t desc_size, u64 merkle_tree_size);
> > > + size_t desc_size, u64 merkle_tree_size,
> > > + u8 log_blocksize);
> >
> > Maybe just pass the block_size itself instead of log2(block_size)?
>
> XFS will still do `index << log2(block_size)` to get block's offset.
> So, not sure if there's any difference.

It's only used in the following:

offset = 0;
for (index = 1; offset < merkle_tree_size; index++) {
xfs_fsverity_merkle_key_to_disk(&name, offset);
args.name = (const uint8_t *)&name.merkleoff;
args.attr_filter = XFS_ATTR_VERITY;
error = xfs_attr_set(&args);
offset = index << log_blocksize;
}

... which can be the following instead:

for (offset = 0; offset < merkle_tree_size; offset += block_size) {
xfs_fsverity_merkle_key_to_disk(&name, offset);
args.name = (const uint8_t *)&name.merkleoff;
args.attr_filter = XFS_ATTR_VERITY;
error = xfs_attr_set(&args);
}