qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Denis Plotnikov <dplotnikov@virtuozzo.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, den@openvz.com, qemu-block@nongnu.org,
	armbru@redhat.com, mreitz@redhat.com
Subject: Re: [PATCH v2 2/4] qcow2: rework the cluster compression routine
Date: Mon, 2 Mar 2020 16:02:36 +0300	[thread overview]
Message-ID: <ee9870ef-ae7b-15d5-4229-bf2565b3fd38@virtuozzo.com> (raw)
In-Reply-To: <20200302082111.21205-3-dplotnikov@virtuozzo.com>

02.03.2020 11:21, Denis Plotnikov wrote:
> The patch enables processing the image compression type defined
> for the image and chooses an appropriate method for image clusters
> (de)compression.
> 
> Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
> ---
>   block/qcow2-threads.c | 77 +++++++++++++++++++++++++++++++++++--------
>   1 file changed, 63 insertions(+), 14 deletions(-)
> 
> diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
> index 77bb578cdf..9288a4f852 100644
> --- a/block/qcow2-threads.c
> +++ b/block/qcow2-threads.c
> @@ -74,7 +74,9 @@ typedef struct Qcow2CompressData {
>   } Qcow2CompressData;
>   
>   /*
> - * qcow2_compress()
> + * qcow2_zlib_compress()
> + *
> + * Compress @src_size bytes of data using zlib compression method
>    *
>    * @dest - destination buffer, @dest_size bytes
>    * @src - source buffer, @src_size bytes
> @@ -83,8 +85,8 @@ typedef struct Qcow2CompressData {
>    *          -ENOMEM destination buffer is not enough to store compressed data
>    *          -EIO    on any other error
>    */
> -static ssize_t qcow2_compress(void *dest, size_t dest_size,
> -                              const void *src, size_t src_size)
> +static ssize_t qcow2_zlib_compress(void *dest, size_t dest_size,
> +                                   const void *src, size_t src_size)
>   {
>       ssize_t ret;
>       z_stream strm;
> @@ -119,19 +121,19 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size,
>   }
>   
>   /*
> - * qcow2_decompress()
> + * qcow2_zlib_decompress()
>    *
>    * Decompress some data (not more than @src_size bytes) to produce exactly
> - * @dest_size bytes.
> + * @dest_size bytes using zlib compression method
>    *
>    * @dest - destination buffer, @dest_size bytes
>    * @src - source buffer, @src_size bytes
>    *
>    * Returns: 0 on success
> - *          -1 on fail
> + *          -EIO on failure
>    */
> -static ssize_t qcow2_decompress(void *dest, size_t dest_size,
> -                                const void *src, size_t src_size)
> +static ssize_t qcow2_zlib_decompress(void *dest, size_t dest_size,
> +                                     const void *src, size_t src_size)
>   {
>       int ret = 0;
>       z_stream strm;
> @@ -144,7 +146,7 @@ static ssize_t qcow2_decompress(void *dest, size_t dest_size,
>   
>       ret = inflateInit2(&strm, -12);
>       if (ret != Z_OK) {
> -        return -1;
> +        return -EIO;
>       }
>   
>       ret = inflate(&strm, Z_FINISH);


more context:

     if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || strm.avail_out != 0) {
         /*
          * We approve Z_BUF_ERROR because we need @dest buffer to be filled, but



>            * @src buffer may be processed partly (because in qcow2 we know size of
>            * compressed data with precision of one sector)
>            */
> -        ret = -1;
> +        ret = -EIO;
>       }

Good thing that you've changed -1 to -EIO, to be more compatible with _compress() function.

But seems, that there is an actual (preexisting) bug here, as we return direct ret of inflate, which is
incompatible with our function defined API. And this mean, that Z_STREAM_END most probably work,
as it is positive. But Z_BUF_ERROR will be treated as error actually.

Hmm, it was broken in far 341926ab83e2b4d in 2018.. By me of course :(

I think, I'll send a separate patch with stable@ in cc.


>   
>       inflateEnd(&strm);
> @@ -189,20 +191,67 @@ qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
>       return arg.ret;
>   }
>   
> +/*
> + * qcow2_co_compress()
> + *
> + * Compress @src_size bytes of data using the compression
> + * method defined by the image compression type
> + *
> + * @dest - destination buffer, @dest_size bytes
> + * @src - source buffer, @src_size bytes
> + *
> + * Returns: compressed size on success
> + *          a negative error code on failure
> + */
>   ssize_t coroutine_fn
>   qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
>                     const void *src, size_t src_size)
>   {
> -    return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
> -                                qcow2_compress);
> +    BDRVQcow2State *s = bs->opaque;
> +    Qcow2CompressFunc fn;
> +
> +    switch (s->compression_type) {
> +    case QCOW2_COMPRESSION_TYPE_ZLIB:
> +        fn = qcow2_zlib_compress;
> +        break;
> +
> +    default:
> +        abort();
> +    }
> +
> +    return qcow2_co_do_compress(bs, dest, dest_size, src, src_size, fn);
>   }
>   
> +/*
> + * qcow2_co_decompress()
> + *
> + * Decompress some data (not more than @src_size bytes) to produce exactly
> + * @dest_size bytes using the compression method defined by the image
> + * compression type
> + *
> + * @dest - destination buffer, @dest_size bytes
> + * @src - source buffer, @src_size bytes
> + *
> + * Returns: 0 on success
> + *          a negative error code on failure
> + */
>   ssize_t coroutine_fn
>   qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
>                       const void *src, size_t src_size)
>   {
> -    return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
> -                                qcow2_decompress);
> +    BDRVQcow2State *s = bs->opaque;
> +    Qcow2CompressFunc fn;
> +
> +    switch (s->compression_type) {
> +    case QCOW2_COMPRESSION_TYPE_ZLIB:
> +        fn = qcow2_zlib_decompress;
> +        break;
> +
> +    default:
> +        return -ENOTSUP;
> +    }
> +
> +    return qcow2_co_do_compress(bs, dest, dest_size, src, src_size, fn);
>   }
>   
>   
> 


-- 
Best regards,
Vladimir


  reply	other threads:[~2020-03-02 13:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-02  8:21 [PATCH v2 0/4] qcow2: Implement zstd cluster compression method Denis Plotnikov
2020-03-02  8:21 ` [PATCH v2 1/4] qcow2: introduce compression type feature Denis Plotnikov
2020-03-02 11:24   ` Vladimir Sementsov-Ogievskiy
2020-03-02 11:29     ` Denis Plotnikov
2020-03-02  8:21 ` [PATCH v2 2/4] qcow2: rework the cluster compression routine Denis Plotnikov
2020-03-02 13:02   ` Vladimir Sementsov-Ogievskiy [this message]
2020-03-02  8:21 ` [PATCH v2 3/4] qcow2: add zstd cluster compression Denis Plotnikov
2020-03-02  8:21 ` [PATCH v2 4/4] iotests: 287: add qcow2 compression type test Denis Plotnikov
2020-03-02  8:51 ` [PATCH v2 0/4] qcow2: Implement zstd cluster compression method Vladimir Sementsov-Ogievskiy
2020-03-02  8:54   ` Denis Plotnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee9870ef-ae7b-15d5-4229-bf2565b3fd38@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.com \
    --cc=dplotnikov@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).