From nobody Thu Mar 28 20:42:26 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573137646; cv=none; d=zoho.com; s=zohoarc; b=QPvQjLha9IB7x8Xdz5l4ArOWP0Q/yPc4QazkgYt9G4zKbqM2qi6KKFx6TM4t/R4nzPoj1t8iv6m5ZGdzL1bsGt4nsmyXS3nzbxFtJlMh9a/iAIPArjA1gyEDq7fGQAhRc3Il3OMQIjyj50zqmqrPSqALpLdZLapCacuvRWYVGQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573137646; h=Content-Type: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; bh=QQoys9Fp0rlvDcgt58MGNDgLRHS46GURBKcm4JuCSHU=; b=MwI3eIUwItB0+etBtEGJAf/1rxW2KIrhjFG4FkSuEANwvRWyyqXLatdqmFeYSMPtS81344m/oGu503/9fo6v9IJZTEVMZos2S8JBVmEI6rTWcPuqtMgWrTp5ecKoieJ95+o6IR8G8lv4lxSbD9gWuDNwix9xRb6OVSRGjpL6eh8= 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; 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 157313764691684.94546647749848; Thu, 7 Nov 2019 06:40:46 -0800 (PST) Received: from localhost ([::1]:43530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSixp-000116-KP for importer@patchew.org; Thu, 07 Nov 2019 09:40:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48869) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSirP-0002kH-KH for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iSirO-0004dI-C9 for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:07 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:45578 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iSirO-0004cy-8F for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:06 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-233-zzj2RgM_OkmHGktzGrPFyg-1; Thu, 07 Nov 2019 09:34:02 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01017800EB3; Thu, 7 Nov 2019 14:34:01 +0000 (UTC) Received: from localhost (ovpn-117-149.ams2.redhat.com [10.36.117.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96BB45DA7C; Thu, 7 Nov 2019 14:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573137245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QQoys9Fp0rlvDcgt58MGNDgLRHS46GURBKcm4JuCSHU=; b=VdWxdVYtrPHkKT9pfmCa29jGilQAeHBObswFwvzLCfxe6vdgSsc6mYX1zQAOgoPJxZm+Sj +bKUP114EY5SAUN76aiU7/AlXEuWuCSeABh46XCG7euegSV1Y3JGR0jjdHGyE1dLzulmDX jzFrz7TIZBBg7EsANVOjn28KGM6Aqf0= From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 1/3] qcow2-bitmap: Fix uint64_t left-shift overflow Date: Thu, 7 Nov 2019 15:33:54 +0100 Message-Id: <20191107143356.579334-2-mreitz@redhat.com> In-Reply-To: <20191107143356.579334-1-mreitz@redhat.com> References: <20191107143356.579334-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: zzj2RgM_OkmHGktzGrPFyg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-stable@nongnu.org, qemu-devel@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-Type: text/plain; charset="utf-8" From: Tuguoyi There are two issues in In check_constraints_on_bitmap(), 1) The sanity check on the granularity will cause uint64_t integer left-shift overflow when cluster_size is 2M and the granularity is BIGGER than 32K. 2) The way to calculate image size that the maximum bitmap supported can map to is a bit incorrect. This patch fix it by add a helper function to calculate the number of bytes needed by a normal bitmap in image and compare it to the maximum bitmap bytes supported by qemu. Fixes: 5f72826e7fc62167cf3a Signed-off-by: Guoyi Tu Message-id: 4ba40cd1e7ee4a708b40899952e49f22@h3c.com Reviewed-by: Vladimir Sementsov-Ogievskiy Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 98294a7696..ef9ef628a0 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -142,6 +142,13 @@ static int check_table_entry(uint64_t entry, int clust= er_size) return 0; } =20 +static int64_t get_bitmap_bytes_needed(int64_t len, uint32_t granularity) +{ + int64_t num_bits =3D DIV_ROUND_UP(len, granularity); + + return DIV_ROUND_UP(num_bits, 8); +} + static int check_constraints_on_bitmap(BlockDriverState *bs, const char *name, uint32_t granularity, @@ -150,6 +157,7 @@ static int check_constraints_on_bitmap(BlockDriverState= *bs, BDRVQcow2State *s =3D bs->opaque; int granularity_bits =3D ctz32(granularity); int64_t len =3D bdrv_getlength(bs); + int64_t bitmap_bytes; =20 assert(granularity > 0); assert((granularity & (granularity - 1)) =3D=3D 0); @@ -171,9 +179,9 @@ static int check_constraints_on_bitmap(BlockDriverState= *bs, return -EINVAL; } =20 - if ((len > (uint64_t)BME_MAX_PHYS_SIZE << granularity_bits) || - (len > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size << - granularity_bits)) + bitmap_bytes =3D get_bitmap_bytes_needed(len, granularity); + if ((bitmap_bytes > (uint64_t)BME_MAX_PHYS_SIZE) || + (bitmap_bytes > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size)) { error_setg(errp, "Too much space will be occupied by the bitmap. " "Use larger granularity"); --=20 2.23.0 From nobody Thu Mar 28 20:42:26 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573137970; cv=none; d=zoho.com; s=zohoarc; b=RybYsq0wfywwlCikmXEjtpqjWBJk4Pzl5pGdAoja7JHZLH48+SCx1u6rjIKzeXaLfhpuXEkjcr1n+OfVCzlyx9yJaMZBtV50rrXzpKYla8MSYKJlnWvOwCPnQ1hJ2atqQ0ORh4jLZfLdWg7XEXkV5xlugtz0y+tGPp6/f8ek7Fc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573137970; h=Content-Type: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; bh=Dnuw8u1q37vefHEQnKZU67QaPnGVLgBesJKqyJGleBw=; b=bJFxBTji1OmbBTKI2BE/3wWxnNtYX5AyNgyfNDIMuEKamEd2rChTrq7aj7fvpfOEIuyI2/WxOZTFCSredmXrvgUmoMqy74ATcXSCvsysZCrO0xMiKKrm2/dJIk5EhLpKvuTL6LKJgxcOoPy+LmT1Ur0JLK+q7X3k6yNHwPcrv1A= 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; 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 1573137970275696.8597104112176; Thu, 7 Nov 2019 06:46:10 -0800 (PST) Received: from localhost ([::1]:43646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSj32-0007Tj-G8 for importer@patchew.org; Thu, 07 Nov 2019 09:46:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48967) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSirZ-0002tV-Is for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iSirT-0004gd-V7 for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:17 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21643 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iSirT-0004g7-S0 for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-245-V010637SO9qDdWvKjCFkcQ-1; Thu, 07 Nov 2019 09:34:06 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA3811005500; Thu, 7 Nov 2019 14:34:05 +0000 (UTC) Received: from localhost (ovpn-117-149.ams2.redhat.com [10.36.117.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9EA715DA7C; Thu, 7 Nov 2019 14:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573137250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dnuw8u1q37vefHEQnKZU67QaPnGVLgBesJKqyJGleBw=; b=A/ehPzaX8NGCsliUQ9baCAdJW1hEav3eUmcTmiuWXEnLUnkHmSaHz9u90Ue7E64hTBz1mh UaKgP4NHi8UMhWkaRmkr6BawYxClLZiX8OmTKmBeVzWzKdjRDY4NIi2EMpftk8uJCTbv1f MvnrNQV7rFRCLYZJg275tGI4MuXswBE= From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 2/3] qcow2: Fix QCOW2_COMPRESSED_SECTOR_MASK Date: Thu, 7 Nov 2019 15:33:55 +0100 Message-Id: <20191107143356.579334-3-mreitz@redhat.com> In-Reply-To: <20191107143356.579334-1-mreitz@redhat.com> References: <20191107143356.579334-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: V010637SO9qDdWvKjCFkcQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-stable@nongnu.org, qemu-devel@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-Type: text/plain; charset="utf-8" Masks for L2 table entries should have 64 bit. Fixes: b6c246942b14d3e0dec46a6c5868ed84e7dbea19 Buglink: https://bugs.launchpad.net/qemu/+bug/1850000 Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20191028161841.1198-2-mreitz@redhat.com Reviewed-by: Alberto Garcia Signed-off-by: Max Reitz --- block/qcow2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.h b/block/qcow2.h index 601c2e4c82..0942126232 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -83,7 +83,7 @@ =20 /* Defined in the qcow2 spec (compressed cluster descriptor) */ #define QCOW2_COMPRESSED_SECTOR_SIZE 512U -#define QCOW2_COMPRESSED_SECTOR_MASK (~(QCOW2_COMPRESSED_SECTOR_SIZE - 1)) +#define QCOW2_COMPRESSED_SECTOR_MASK (~(QCOW2_COMPRESSED_SECTOR_SIZE - 1UL= L)) =20 /* Must be at least 2 to cover COW */ #define MIN_L2_CACHE_SIZE 2 /* cache entries */ --=20 2.23.0 From nobody Thu Mar 28 20:42:26 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573137768; cv=none; d=zoho.com; s=zohoarc; b=Mm3QVrTYkfIxK0kM01BcZ7zzmfmAbizUR9ZNnr0a3cAhOl3GTP1n3hwh0P9leeyRu4zZzD09L/Tk++A/Dph3YbYH9+UWEMuSnU0bPhY3bHymcb0C7yXv4tDDkxNl3INa01ZTaojE+KRZ7mrWur3ZZ1heeHVftHplFsBlrbHdpyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573137768; h=Content-Type: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; bh=jwdFC7oQTGsEL9kJ3nbZjPDNCd3b12TNmsXjvR8S1OU=; b=fwCPZz4RecTAReaMILMTM0fdQmGkYmYPPSYlnATU7vzX0NMTd989w7mj5Zjx8TZPDbVtbFDyGcaNXd8pnjbrqKSMRw+oQ/60JJiGhTcWI1NZDdzhvsTkbVJCxoR0483AFTXo3J2y5wDWtBncLz7XoVnypGeC7rXLEs7OAp2pY/0= 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; 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 1573137768709903.8082598273733; Thu, 7 Nov 2019 06:42:48 -0800 (PST) Received: from localhost ([::1]:43596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSizn-0004SJ-76 for importer@patchew.org; Thu, 07 Nov 2019 09:42:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48966) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSirZ-0002tT-IM for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iSirX-0004jC-1B for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:16 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34977 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iSirW-0004is-5Y for qemu-devel@nongnu.org; Thu, 07 Nov 2019 09:34:14 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-91-q9lEkRTKP3O69NoxKSEjiw-1; Thu, 07 Nov 2019 09:34:10 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BD561800D6B; Thu, 7 Nov 2019 14:34:09 +0000 (UTC) Received: from localhost (ovpn-117-149.ams2.redhat.com [10.36.117.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E58660BFB; Thu, 7 Nov 2019 14:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573137253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jwdFC7oQTGsEL9kJ3nbZjPDNCd3b12TNmsXjvR8S1OU=; b=gYU2BNVYxC5TI8qrY3Z6MhK9sCYZMLPIvYDIfzp5vsM/htBBJC7XqB8PoD7zf89jGiIuOt UPdDKz34380zcGqEe1RgV0zsgL9S+V9yTCPxBY4/9qmBf3K4a5HnstQ71sTJuObvwzQKS6 vOlManMyDtd2x407GLTol/ZcnmQm8PU= From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 3/3] iotests: Add test for 4G+ compressed qcow2 write Date: Thu, 7 Nov 2019 15:33:56 +0100 Message-Id: <20191107143356.579334-4-mreitz@redhat.com> In-Reply-To: <20191107143356.579334-1-mreitz@redhat.com> References: <20191107143356.579334-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: q9lEkRTKP3O69NoxKSEjiw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-stable@nongnu.org, qemu-devel@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-Type: text/plain; charset="utf-8" Test what qemu-img check says about an image after one has written compressed data to an offset above 4 GB. Signed-off-by: Max Reitz Message-id: 20191028161841.1198-3-mreitz@redhat.com Reviewed-by: Alberto Garcia Signed-off-by: Max Reitz --- tests/qemu-iotests/272 | 79 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/272.out | 10 +++++ tests/qemu-iotests/group | 1 + 3 files changed, 90 insertions(+) create mode 100755 tests/qemu-iotests/272 create mode 100644 tests/qemu-iotests/272.out diff --git a/tests/qemu-iotests/272 b/tests/qemu-iotests/272 new file mode 100755 index 0000000000..c2f782d47b --- /dev/null +++ b/tests/qemu-iotests/272 @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# +# Test compressed write to a qcow2 image at an offset above 4 GB +# +# Copyright (C) 2019 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +seq=3D$(basename "$0") +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +# This is a qcow2 regression test +_supported_fmt qcow2 +_supported_proto file + +# External data files do not support compression; +# We need an exact cluster size (2M) and refcount width (2) so we can +# get this test quickly over with; and this in turn require +# compat=3D1.1 +_unsupported_imgopts data_file cluster_size refcount_bits 'compat=3D0.10' + +# The idea is: Create an empty file, mark the first 4 GB as used, then +# do a compressed write that thus must be put beyond 4 GB. +# (This used to fail because the compressed sector mask was just a +# 32 bit mask, so qemu-img check will count a cluster before 4 GB as +# referenced twice.) + +# We would like to use refcount_bits=3D1 here, but then qemu-img check +# will throw an error when trying to count a cluster as referenced +# twice. +_make_test_img -o cluster_size=3D2M,refcount_bits=3D2 64M + +reft_offs=3D$(peek_file_be "$TEST_IMG" 48 8) +refb_offs=3D$(peek_file_be "$TEST_IMG" $reft_offs 8) + +# We want to cover 4 GB, those are 2048 clusters, equivalent to +# 4096 bit =3D 512 B. +truncate -s 4G "$TEST_IMG" +for ((in_refb_offs =3D 0; in_refb_offs < 512; in_refb_offs +=3D 8)); do + poke_file "$TEST_IMG" $((refb_offs + in_refb_offs)) \ + '\x55\x55\x55\x55\x55\x55\x55\x55' +done + +$QEMU_IO -c 'write -c -P 42 0 2M' "$TEST_IMG" | _filter_qemu_io + +echo +echo '--- Check ---' + +# This should only print the leaked clusters in the first 4 GB +_check_test_img | grep -v '^Leaked cluster ' + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/272.out b/tests/qemu-iotests/272.out new file mode 100644 index 0000000000..35698b0e73 --- /dev/null +++ b/tests/qemu-iotests/272.out @@ -0,0 +1,10 @@ +QA output created by 272 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 +wrote 2097152/2097152 bytes at offset 0 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- Check --- + +2044 leaked clusters were found on the image. +This means waste of disk space, but no harm to data. +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 095ed1b880..065040398d 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -283,3 +283,4 @@ 267 rw auto quick snapshot 268 rw auto quick 270 rw backing quick +272 rw --=20 2.23.0