From nobody Wed Dec 17 05:46:17 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556639848; cv=none; d=zoho.com; s=zohoarc; b=ikzHsItVw8WT3XjARnSmRMEefohcBG2peoJDkKUUqfwxRPUKQ9Ect6omdOZX6wu014JavMWsG8Yf8AncMBJqAatgY1ivsQYxRVZIkhy76oy3lp1qH4fFybuItbETgUj/ElozMURZdQDsb1q7pWAc+fnuAJlOBIFRKCCWWepgAu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556639848; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=CIPjUtotky0Ra3l8u37KQWHOeUZbkmEkFzRC1GI/T0o=; b=dyQgTpfO5JwW4TyBa/VCxjQyAibWwCsRoIXEVglh0+sf7dK2zi6g8DOkEGr6UeyRYVCQ2f7P38/Uh33SXhjafETPLD5Hq/lfX6I9DKXut8VIsHBfTNzeV+B5sJU1B328oafCnr6gL4mSMAtr5GpgI47BrmNecOORNcTMCUKtUBQ= ARC-Authentication-Results: i=1; mx.zoho.com; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556639848927404.6784232854659; Tue, 30 Apr 2019 08:57:28 -0700 (PDT) Received: from localhost ([127.0.0.1]:49025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLV8H-0002Pi-Qi for importer@patchew.org; Tue, 30 Apr 2019 11:57:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLUur-000833-Kf for qemu-devel@nongnu.org; Tue, 30 Apr 2019 11:43:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLUup-00025l-2Y for qemu-devel@nongnu.org; Tue, 30 Apr 2019 11:43:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38416) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hLUuk-0001wg-5b; Tue, 30 Apr 2019 11:43:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 901D43084249; Tue, 30 Apr 2019 15:43:22 +0000 (UTC) Received: from linux.fritz.box.com (unknown [10.36.118.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94DB117106; Tue, 30 Apr 2019 15:43:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 30 Apr 2019 17:42:32 +0200 Message-Id: <20190430154244.30083-16-kwolf@redhat.com> In-Reply-To: <20190430154244.30083-1-kwolf@redhat.com> References: <20190430154244.30083-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 30 Apr 2019 15:43:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/27] 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia 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 Signed-off-by: Kevin Wolf --- 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 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) @@ -3943,7 +3943,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 @@ -3957,7 +3957,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); @@ -4096,7 +4096,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 @@ -4135,16 +4135,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.20.1