From: Denis Plotnikov <dplotnikov@virtuozzo.com>
To: Alberto Garcia <berto@igalia.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com,
qemu-block@nongnu.org, armbru@redhat.com, mreitz@redhat.com,
den@openvz.org
Subject: Re: [PATCH v18 3/4] qcow2: add zstd cluster compression
Date: Thu, 16 Apr 2020 16:07:55 +0300 [thread overview]
Message-ID: <bce6f462-f448-e66b-605c-a9d5d1de31fa@virtuozzo.com> (raw)
In-Reply-To: <w51d087a8uu.fsf@maestria.local.igalia.com>
On 16.04.2020 15:55, Alberto Garcia wrote:
> On Thu 02 Apr 2020 08:36:44 AM CEST, Denis Plotnikov wrote:
>> +static ssize_t qcow2_zstd_compress(void *dest, size_t dest_size,
>> + const void *src, size_t src_size)
>> +{
>> + ssize_t ret;
>> + ZSTD_outBuffer output = { dest, dest_size, 0 };
>> + ZSTD_inBuffer input = { src, src_size, 0 };
>> + ZSTD_CCtx *cctx = ZSTD_createCCtx();
>> +
>> + if (!cctx) {
>> + return -EIO;
>> + }
>> + /*
>> + * Use the zstd streamed interface for symmetry with decompression,
>> + * where streaming is essential since we don't record the exact
>> + * compressed size.
>> + *
>> + * In the loop, we try to compress all the data into one zstd frame.
>> + * ZSTD_compressStream2 potentially can finish a frame earlier
>> + * than the full input data is consumed. That's why we are looping
>> + * until all the input data is consumed.
>> + */
>> + while (input.pos < input.size) {
>> + size_t zstd_ret;
>> + /*
>> + * ZSTD spec: "You must continue calling ZSTD_compressStream2()
>> + * with ZSTD_e_end until it returns 0, at which point you are
>> + * free to start a new frame". We assume that "start a new frame"
>> + * means call ZSTD_compressStream2 in the very beginning or when
>> + * ZSTD_compressStream2 has returned with 0.
>> + */
>> + do {
>> + zstd_ret = ZSTD_compressStream2(cctx, &output, &input, ZSTD_e_end);
>> +
>> + if (ZSTD_isError(zstd_ret)) {
>> + ret = -EIO;
>> + goto out;
>> + }
>> + /* Dest buffer isn't big enough to store compressed content */
>> + if (zstd_ret > output.size - output.pos) {
>> + ret = -ENOMEM;
>> + goto out;
>> + }
>> + } while (zstd_ret);
>> + }
>> + /* make sure we can safely return compressed buffer size with ssize_t */
>> + assert(output.pos <= SSIZE_MAX);
> The patch looks good to me, but why don't you assert this at the
> beginning of the function? You already know the buffer sizes...
Yes, that's true. But I thought that it's reasonable to check what is
returned.
"output.pos" could be less then or equal to ssize_max when output.size >
ssize_max.
Anyway, this case most probably won't exist, and this is just an
overflow inssurance.
>
> Either way
>
> Reviewed-by: Alberto Garcia <berto@igalia.com>
>
> Berto
Thanks for reviewing!
Denis
next prev parent reply other threads:[~2020-04-16 13:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-02 6:36 [PATCH v18 0/4] qcow2: Implement zstd cluster compression method Denis Plotnikov
2020-04-02 6:36 ` [PATCH v18 1/4] qcow2: introduce compression type feature Denis Plotnikov
2020-04-02 6:36 ` [PATCH v18 2/4] qcow2: rework the cluster compression routine Denis Plotnikov
2020-04-02 6:36 ` [PATCH v18 3/4] qcow2: add zstd cluster compression Denis Plotnikov
2020-04-16 12:55 ` Alberto Garcia
2020-04-16 13:07 ` Denis Plotnikov [this message]
2020-04-02 6:36 ` [PATCH v18 4/4] iotests: 287: add qcow2 compression type test Denis Plotnikov
2020-04-17 21:24 ` Eric Blake
2020-04-13 12:27 ` [PATCH v18 0/4] qcow2: Implement zstd cluster compression method 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=bce6f462-f448-e66b-605c-a9d5d1de31fa@virtuozzo.com \
--to=dplotnikov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/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).