[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 15/27] qcow2: Fix error handling in the compression c
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 15/27] qcow2: Fix error handling in the compression code |
Date: |
Tue, 30 Apr 2019 17:42:32 +0200 |
From: Alberto Garcia <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 840f289a48..c5c17734d7 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3929,8 +3929,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)
@@ -3943,7 +3943,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
@@ -3957,7 +3957,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);
@@ -4096,7 +4096,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;
@@ -4135,16 +4135,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.20.1
- [Qemu-block] [PULL 05/27] block/vhdx: Remove redundant IEC binary prefixes definition, (continued)
- [Qemu-block] [PULL 05/27] block/vhdx: Remove redundant IEC binary prefixes definition, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 06/27] block/vhdx: Use IEC binary prefixes for size constants, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 01/27] tests/qemu-iotests: Fix output of qemu-io related tests, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 07/27] cutils: Fix size_to_str() on 32-bit platforms, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 09/27] qcow2: Avoid COW during metadata preallocation, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 11/27] qcow2: Fix full preallocation with external data file, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 10/27] qcow2: Add errp to preallocate_co(), Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 08/27] qemu-img: Saner printing of large file sizes, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 12/27] iotests: Perform the correct test in 082, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 14/27] qcow2: Fix qcow2_make_empty() with external data file, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 15/27] qcow2: Fix error handling in the compression code,
Kevin Wolf <=
- [Qemu-block] [PULL 16/27] block: introduce byte-based io helpers, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 13/27] qemu-img: Make create hint at protocol options, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 20/27] block/parallels: use buffer-based io, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 23/27] block/stream: use buffer-based io, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 17/27] block/qcow2: use buffer-based io, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 18/27] block/qcow: use buffer-based io, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 21/27] block/backup: use buffer-based io, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 19/27] block/qed: use buffer-based io, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 25/27] commit: Make base read-only if there is an early failure, Kevin Wolf, 2019/04/30
- [Qemu-block] [PULL 24/27] qemu-img: use buffer-based io, Kevin Wolf, 2019/04/30