qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, den@openvz.org,
	vsementsov@virtuozzo.com
Subject: [Qemu-devel] [PATCH 2/7] qcow2: make more generic interface for qcow2_compress
Date: Thu,  1 Nov 2018 21:27:33 +0300	[thread overview]
Message-ID: <20181101182738.70462-3-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20181101182738.70462-1-vsementsov@virtuozzo.com>

Give explicit size both for source and destination buffers, to make it
similar with decompression path and than cleanly reuse parameter
structure for decompression threads.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/qcow2.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 3e9367c449..9eab2dbfb6 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3718,14 +3718,15 @@ fail:
 /*
  * qcow2_compress()
  *
- * @dest - destination buffer, at least of @size-1 bytes
- * @src - source buffer, @size bytes
+ * @dest - destination buffer, @dest_size bytes
+ * @src - source buffer, @src_size bytes
  *
  * Returns: compressed size on success
- *          -1 if compression is inefficient
+ *          -1 destination buffer is not enough to store compressed data
  *          -2 on any other error
  */
-static ssize_t qcow2_compress(void *dest, const void *src, size_t size)
+static ssize_t qcow2_compress(void *dest, size_t dest_size,
+                              const void *src, size_t src_size)
 {
     ssize_t ret;
     z_stream strm;
@@ -3740,14 +3741,14 @@ static ssize_t qcow2_compress(void *dest, const void *src, size_t size)
 
     /* strm.next_in is not const in old zlib versions, such as those used on
      * OpenBSD/NetBSD, so cast the const away */
-    strm.avail_in = size;
+    strm.avail_in = src_size;
     strm.next_in = (void *) src;
-    strm.avail_out = size - 1;
+    strm.avail_out = dest_size;
     strm.next_out = dest;
 
     ret = deflate(&strm, Z_FINISH);
     if (ret == Z_STREAM_END) {
-        ret = size - 1 - strm.avail_out;
+        ret = dest_size - strm.avail_out;
     } else {
         ret = (ret == Z_OK ? -1 : -2);
     }
@@ -3761,8 +3762,9 @@ static ssize_t qcow2_compress(void *dest, const void *src, size_t size)
 
 typedef struct Qcow2CompressData {
     void *dest;
+    size_t dest_size;
     const void *src;
-    size_t size;
+    size_t src_size;
     ssize_t ret;
 } Qcow2CompressData;
 
@@ -3770,7 +3772,8 @@ static int qcow2_compress_pool_func(void *opaque)
 {
     Qcow2CompressData *data = opaque;
 
-    data->ret = qcow2_compress(data->dest, data->src, data->size);
+    data->ret = qcow2_compress(data->dest, data->dest_size,
+                               data->src, data->src_size);
 
     return 0;
 }
@@ -3782,15 +3785,17 @@ static void qcow2_compress_complete(void *opaque, int ret)
 
 /* See qcow2_compress definition for parameters description */
 static ssize_t qcow2_co_compress(BlockDriverState *bs,
-                                 void *dest, const void *src, size_t size)
+                                 void *dest, size_t dest_size,
+                                 const void *src, size_t src_size)
 {
     BDRVQcow2State *s = bs->opaque;
     BlockAIOCB *acb;
     ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
     Qcow2CompressData arg = {
         .dest = dest,
+        .dest_size = dest_size,
         .src = src,
-        .size = size,
+        .src_size = src_size,
     };
 
     while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
@@ -3857,7 +3862,8 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
 
     out_buf = g_malloc(s->cluster_size);
 
-    out_len = qcow2_co_compress(bs, out_buf, buf, s->cluster_size);
+    out_len = qcow2_co_compress(bs, out_buf, s->cluster_size - 1,
+                                buf, s->cluster_size);
     if (out_len == -2) {
         ret = -EINVAL;
         goto fail;
-- 
2.18.0

  parent reply	other threads:[~2018-11-01 18:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-01 18:27 [Qemu-devel] [PATCH 0/7] qcow2 decompress in threads Vladimir Sementsov-Ogievskiy
2018-11-01 18:27 ` [Qemu-devel] [PATCH 1/7] qcow2: use Z_OK instead of 0 for deflateInit2 return code check Vladimir Sementsov-Ogievskiy
2018-11-05 15:30   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-11-01 18:27 ` Vladimir Sementsov-Ogievskiy [this message]
2018-11-05 15:45   ` [Qemu-devel] [Qemu-block] [PATCH 2/7] qcow2: make more generic interface for qcow2_compress Alberto Garcia
2018-11-01 18:27 ` [Qemu-devel] [PATCH 3/7] qcow2: move decompression from qcow2-cluster.c to qcow2.c Vladimir Sementsov-Ogievskiy
2018-11-05 15:45   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-11-01 18:27 ` [Qemu-devel] [PATCH 4/7] qcow2: refactor decompress_buffer Vladimir Sementsov-Ogievskiy
2018-11-06 10:45   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-11-01 18:27 ` [Qemu-devel] [PATCH 5/7] qcow2: use byte-based read in qcow2_decompress_cluster Vladimir Sementsov-Ogievskiy
2018-11-06 13:53   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-11-06 15:18     ` Vladimir Sementsov-Ogievskiy
2018-11-01 18:27 ` [Qemu-devel] [PATCH 6/7] qcow2: aio support for compressed cluster read Vladimir Sementsov-Ogievskiy
2018-11-06 15:06   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-11-06 15:13     ` Vladimir Sementsov-Ogievskiy
2018-11-06 15:30       ` Alberto Garcia
2018-11-06 16:24         ` Vladimir Sementsov-Ogievskiy
2018-11-09 13:51           ` Alberto Garcia
2018-11-01 18:27 ` [Qemu-devel] [PATCH 7/7] qcow2: do decompression in threads Vladimir Sementsov-Ogievskiy
2018-11-06 14:03   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-11-06 23:40   ` [Qemu-devel] " Paolo Bonzini
2018-11-12 15:32 ` [Qemu-devel] [PATCH 0/7] qcow2 decompress " Kevin Wolf
2018-11-12 16:16   ` Vladimir Sementsov-Ogievskiy

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=20181101182738.70462-3-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=den@openvz.org \
    --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).