From nobody Mon Nov 10 11:22:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1556619627; cv=none; d=zoho.com; s=zohoarc; b=eXTtHdxGdFI/NPGpSriDPvIt2jBNCjLLvTkdkZZR0aeElqZM3dF9bDF3/TcywycW/BXxe4IRNM9Skdtz0QI8X9kBU9dz9w/Bu1vgDamAh9ULzHGS13/vakAKpkMMoeTW4QY6PpcUTdra5fMhO7aNLxG+8vQso/DQlNS9TqJxp/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556619627; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=p/Caes+/jnKIif73dQN9bmBtOkUAHK1lCGA6hIeyb8A=; b=HiIi8nF9rbahEX3lttTxqSakkJAiGLlQ/IT3c4NLJSmhFckwGHynJFJZLOO4ymfQDE3mFsDOOGhofzSwwKOiz6WhrRw5dP/fenrG+aeLeEFhkuGTAUCistaDbEFtDuo8Rc5u+/PbfT719gZK0i4XEO0BpGv1rvezwQuRDdls+KQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556619626006744.9100506830316; Tue, 30 Apr 2019 03:20:26 -0700 (PDT) Received: from localhost ([127.0.0.1]:42603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLPs7-0002tF-0j for importer@patchew.org; Tue, 30 Apr 2019 06:20:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLPpz-0001PR-UM for qemu-devel@nongnu.org; Tue, 30 Apr 2019 06:18:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLPgU-0005KA-UV for qemu-devel@nongnu.org; Tue, 30 Apr 2019 06:08:23 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:60616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLPgU-0005J2-Dg; Tue, 30 Apr 2019 06:08:22 -0400 Received: from 87-92-6-174.bb.dnainternet.fi ([87.92.6.174] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1hLPgR-0004wn-Kn; Tue, 30 Apr 2019 12:08:19 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1hLPgD-00040a-1Y; Tue, 30 Apr 2019 13:08:05 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=p/Caes+/jnKIif73dQN9bmBtOkUAHK1lCGA6hIeyb8A=; b=J0WpLSlSF5pA/qSqfmkjoVEl0LMzqfQnqU0nJ3O0oidqrK6fZqB5hIQfVsMpy4IqwMOwl7RbTQbHpVy+euTVirfeBf2NJADEZCIeUd0qEHUlSbGkrshM5e8i1baygfsPyQyPhjGj7Me61aN6bc/E0enycP8pUVAus1nUk/BGB0N1fDeuTv4ImeTge6e8w5I88YPymBiKethbiHMFoZg1DfSW6EOBFEt15R6HujT9LjpILbxikVMpD+A1UJaY4L+5e4IlA1v3Uv8llfzXpt4dC7ICBTO5EJzed0fNh3/L7wbc+/MMGBhmRoQ2HZQlo0kU7E/pDvXh7aZscnBQYzFdYA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 30 Apr 2019 13:08:02 +0300 Message-Id: <20190430100802.15368-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH] qcow2: Fix error handling in the compression code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 d= ata + * -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 =3D deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY); if (ret !=3D Z_OK) { - return -2; + return -EIO; } =20 /* 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 =3D=3D Z_STREAM_END) { ret =3D dest_size - strm.avail_out; } else { - ret =3D (ret =3D=3D Z_OK ? -1 : -2); + ret =3D (ret =3D=3D Z_OK ? -ENOMEM : -EIO); } =20 deflateEnd(&strm); @@ -4090,7 +4090,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, BDRVQcow2State *s =3D bs->opaque; QEMUIOVector hd_qiov; int ret; - size_t out_len; + ssize_t out_len; uint8_t *buf, *out_buf; uint64_t cluster_offset; =20 @@ -4129,16 +4129,16 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, u= int64_t offset, =20 out_len =3D qcow2_co_compress(bs, out_buf, s->cluster_size - 1, buf, s->cluster_size); - if (out_len =3D=3D -2) { - ret =3D -EINVAL; - goto fail; - } else if (out_len =3D=3D -1) { + if (out_len =3D=3D -ENOMEM) { /* could not compress: write normal cluster */ ret =3D qcow2_co_pwritev(bs, offset, bytes, qiov, 0); if (ret < 0) { goto fail; } goto success; + } else if (out_len < 0) { + ret =3D -EINVAL; + goto fail; } =20 qemu_co_mutex_lock(&s->lock); --=20 2.11.0