On 11.02.20 17:03, Stefan Hajnoczi wrote:
> The qcow2 .bdrv_measure() code calculates the crypto payload offset.
> This logic really belongs in crypto/block.c where it can be reused by
> other image formats.
> 
> The "luks" block driver will need this same logic in order to implement
> .bdrv_measure(), so extract the qcrypto_block_calculate_payload_offset()
> function now.
> 
> Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com>
> ---
>  block/qcow2.c          | 74 +++++++++++-------------------------------
>  crypto/block.c         | 40 +++++++++++++++++++++++
>  include/crypto/block.h | 22 +++++++++++++
>  3 files changed, 81 insertions(+), 55 deletions(-)

[...]

> diff --git a/crypto/block.c b/crypto/block.c
> index 325752871c..a9e1b8cc36 100644
> --- a/crypto/block.c
> +++ b/crypto/block.c
> @@ -115,6 +115,46 @@ QCryptoBlock 
> *qcrypto_block_create(QCryptoBlockCreateOptions *options,

[...]

> +bool
> +qcrypto_block_calculate_payload_offset(QCryptoBlockCreateOptions 
> *create_opts,
> +                                       const char *optprefix,
> +                                       size_t *len,
> +                                       Error **errp)
> +{
> +    QCryptoBlock *crypto;
> +    bool ok;
> +
> +    /* Fake LUKS creation in order to determine the payload size */
> +    crypto = qcrypto_block_create(create_opts, optprefix,
> +                                  qcrypto_block_headerlen_hdr_init_func,
> +                                  qcrypto_block_headerlen_hdr_write_func,
> +                                  len, errp);
> +    ok = crypto != NULL;
> +    qcrypto_block_free(crypto);
> +    return ok;

Speaking of g_autoptr...  Would g_autoptr(QCryptoBlock) crypto; suffice
to contract these three lines into “return crypto != NULL;”?

Either way:

Reviewed-by: Max Reitz <mre...@redhat.com>

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to