* [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code
@ 2019-04-30 10:08 Alberto Garcia
2019-04-30 10:08 ` Alberto Garcia
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alberto Garcia @ 2019-04-30 10:08 UTC (permalink / raw)
To: qemu-devel
Cc: Alberto Garcia, qemu-block, Vladimir Sementsov-Ogievskiy,
Kevin Wolf, Max Reitz
This patch fixes a few things in the way error codes are handled in
the qcow2 compression code:
a) qcow2_co_pwritev_compressed() expects qcow2_co_compress() to only
return -1 or -2 on failure, but this is not correct. Since the
change from qcow2_compress() to qcow2_co_compress() in commit
ceb029cd6feccf9f7607 the new code can also return -EINVAL (although
there does not seem to exist any code path that would cause that
error in the current implementation).
b) -1 and -2 are ad-hoc error codes defined in qcow2_compress().
This patch replaces them with standard constants from errno.h.
c) Both qcow2_compress() and qcow2_co_do_compress() return a negative
value on failure, but qcow2_co_pwritev_compressed() stores the
value in an unsigned data type.
Signed-off-by: Alberto Garcia <berto@igalia.com>
---
block/qcow2.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 3ace3b2209..502a81720a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3923,8 +3923,8 @@ fail:
* @src - source buffer, @src_size bytes
*
* Returns: compressed size on success
- * -1 destination buffer is not enough to store compressed data
- * -2 on any other error
+ * -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)
@@ -3937,7 +3937,7 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size,
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
-12, 9, Z_DEFAULT_STRATEGY);
if (ret != Z_OK) {
- return -2;
+ return -EIO;
}
/* strm.next_in is not const in old zlib versions, such as those used on
@@ -3951,7 +3951,7 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size,
if (ret == Z_STREAM_END) {
ret = dest_size - strm.avail_out;
} else {
- ret = (ret == Z_OK ? -1 : -2);
+ ret = (ret == Z_OK ? -ENOMEM : -EIO);
}
deflateEnd(&strm);
@@ -4090,7 +4090,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
BDRVQcow2State *s = bs->opaque;
QEMUIOVector hd_qiov;
int ret;
- size_t out_len;
+ ssize_t out_len;
uint8_t *buf, *out_buf;
uint64_t cluster_offset;
@@ -4129,16 +4129,16 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
out_len = qcow2_co_compress(bs, out_buf, s->cluster_size - 1,
buf, s->cluster_size);
- if (out_len == -2) {
- ret = -EINVAL;
- goto fail;
- } else if (out_len == -1) {
+ if (out_len == -ENOMEM) {
/* could not compress: write normal cluster */
ret = qcow2_co_pwritev(bs, offset, bytes, qiov, 0);
if (ret < 0) {
goto fail;
}
goto success;
+ } else if (out_len < 0) {
+ ret = -EINVAL;
+ goto fail;
}
qemu_co_mutex_lock(&s->lock);
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code
2019-04-30 10:08 [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code Alberto Garcia
@ 2019-04-30 10:08 ` Alberto Garcia
2019-04-30 10:31 ` Kevin Wolf
2019-05-02 11:13 ` no-reply
2 siblings, 0 replies; 6+ messages in thread
From: Alberto Garcia @ 2019-04-30 10:08 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Vladimir Sementsov-Ogievskiy, Alberto Garcia,
qemu-block, Max Reitz
This patch fixes a few things in the way error codes are handled in
the qcow2 compression code:
a) qcow2_co_pwritev_compressed() expects qcow2_co_compress() to only
return -1 or -2 on failure, but this is not correct. Since the
change from qcow2_compress() to qcow2_co_compress() in commit
ceb029cd6feccf9f7607 the new code can also return -EINVAL (although
there does not seem to exist any code path that would cause that
error in the current implementation).
b) -1 and -2 are ad-hoc error codes defined in qcow2_compress().
This patch replaces them with standard constants from errno.h.
c) Both qcow2_compress() and qcow2_co_do_compress() return a negative
value on failure, but qcow2_co_pwritev_compressed() stores the
value in an unsigned data type.
Signed-off-by: Alberto Garcia <berto@igalia.com>
---
block/qcow2.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 3ace3b2209..502a81720a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3923,8 +3923,8 @@ fail:
* @src - source buffer, @src_size bytes
*
* Returns: compressed size on success
- * -1 destination buffer is not enough to store compressed data
- * -2 on any other error
+ * -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)
@@ -3937,7 +3937,7 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size,
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
-12, 9, Z_DEFAULT_STRATEGY);
if (ret != Z_OK) {
- return -2;
+ return -EIO;
}
/* strm.next_in is not const in old zlib versions, such as those used on
@@ -3951,7 +3951,7 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size,
if (ret == Z_STREAM_END) {
ret = dest_size - strm.avail_out;
} else {
- ret = (ret == Z_OK ? -1 : -2);
+ ret = (ret == Z_OK ? -ENOMEM : -EIO);
}
deflateEnd(&strm);
@@ -4090,7 +4090,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
BDRVQcow2State *s = bs->opaque;
QEMUIOVector hd_qiov;
int ret;
- size_t out_len;
+ ssize_t out_len;
uint8_t *buf, *out_buf;
uint64_t cluster_offset;
@@ -4129,16 +4129,16 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
out_len = qcow2_co_compress(bs, out_buf, s->cluster_size - 1,
buf, s->cluster_size);
- if (out_len == -2) {
- ret = -EINVAL;
- goto fail;
- } else if (out_len == -1) {
+ if (out_len == -ENOMEM) {
/* could not compress: write normal cluster */
ret = qcow2_co_pwritev(bs, offset, bytes, qiov, 0);
if (ret < 0) {
goto fail;
}
goto success;
+ } else if (out_len < 0) {
+ ret = -EINVAL;
+ goto fail;
}
qemu_co_mutex_lock(&s->lock);
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code
2019-04-30 10:08 [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code Alberto Garcia
2019-04-30 10:08 ` Alberto Garcia
@ 2019-04-30 10:31 ` Kevin Wolf
2019-04-30 10:31 ` Kevin Wolf
2019-05-02 11:13 ` no-reply
2 siblings, 1 reply; 6+ messages in thread
From: Kevin Wolf @ 2019-04-30 10:31 UTC (permalink / raw)
To: Alberto Garcia
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Max Reitz
Am 30.04.2019 um 12:08 hat Alberto Garcia geschrieben:
> This patch fixes a few things in the way error codes are handled in
> the qcow2 compression code:
>
> a) qcow2_co_pwritev_compressed() expects qcow2_co_compress() to only
> return -1 or -2 on failure, but this is not correct. Since the
> change from qcow2_compress() to qcow2_co_compress() in commit
> ceb029cd6feccf9f7607 the new code can also return -EINVAL (although
> there does not seem to exist any code path that would cause that
> error in the current implementation).
>
> b) -1 and -2 are ad-hoc error codes defined in qcow2_compress().
> This patch replaces them with standard constants from errno.h.
>
> c) Both qcow2_compress() and qcow2_co_do_compress() return a negative
> value on failure, but qcow2_co_pwritev_compressed() stores the
> value in an unsigned data type.
>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code
2019-04-30 10:31 ` Kevin Wolf
@ 2019-04-30 10:31 ` Kevin Wolf
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2019-04-30 10:31 UTC (permalink / raw)
To: Alberto Garcia
Cc: Vladimir Sementsov-Ogievskiy, qemu-devel, qemu-block, Max Reitz
Am 30.04.2019 um 12:08 hat Alberto Garcia geschrieben:
> This patch fixes a few things in the way error codes are handled in
> the qcow2 compression code:
>
> a) qcow2_co_pwritev_compressed() expects qcow2_co_compress() to only
> return -1 or -2 on failure, but this is not correct. Since the
> change from qcow2_compress() to qcow2_co_compress() in commit
> ceb029cd6feccf9f7607 the new code can also return -EINVAL (although
> there does not seem to exist any code path that would cause that
> error in the current implementation).
>
> b) -1 and -2 are ad-hoc error codes defined in qcow2_compress().
> This patch replaces them with standard constants from errno.h.
>
> c) Both qcow2_compress() and qcow2_co_do_compress() return a negative
> value on failure, but qcow2_co_pwritev_compressed() stores the
> value in an unsigned data type.
>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code
2019-04-30 10:08 [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code Alberto Garcia
2019-04-30 10:08 ` Alberto Garcia
2019-04-30 10:31 ` Kevin Wolf
@ 2019-05-02 11:13 ` no-reply
2019-05-02 11:13 ` no-reply
2 siblings, 1 reply; 6+ messages in thread
From: no-reply @ 2019-05-02 11:13 UTC (permalink / raw)
To: berto; +Cc: fam, qemu-devel, kwolf, vsementsov, qemu-block, mreitz
Patchew URL: https://patchew.org/QEMU/20190430100802.15368-1-berto@igalia.com/
Hi,
This series failed the docker-mingw@fedora build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===
The full log is available at
http://patchew.org/logs/20190430100802.15368-1-berto@igalia.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code
2019-05-02 11:13 ` no-reply
@ 2019-05-02 11:13 ` no-reply
0 siblings, 0 replies; 6+ messages in thread
From: no-reply @ 2019-05-02 11:13 UTC (permalink / raw)
To: berto; +Cc: fam, kwolf, vsementsov, berto, qemu-block, qemu-devel, mreitz
Patchew URL: https://patchew.org/QEMU/20190430100802.15368-1-berto@igalia.com/
Hi,
This series failed the docker-mingw@fedora build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===
The full log is available at
http://patchew.org/logs/20190430100802.15368-1-berto@igalia.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-05-05 15:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-30 10:08 [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code Alberto Garcia
2019-04-30 10:08 ` Alberto Garcia
2019-04-30 10:31 ` Kevin Wolf
2019-04-30 10:31 ` Kevin Wolf
2019-05-02 11:13 ` no-reply
2019-05-02 11:13 ` no-reply
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).