From nobody Tue May 21 10:00:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578505916; cv=none; d=zohomail.com; s=zohoarc; b=BS77tWFHBeT31zQp7velhy+4PnqzNHcZqoJhK5DEHxogNNPDwA2SkjrREsgfXP7hMrlgkYyMrk6FB3kr/ObItjtFrHjkC0V7zeV0uR5Ia29NrwOdVV95wB7iglrTJ/gVP5W1I32qhqMbOKaiPIAQT981r84QX+8/KkcRTfxMnKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578505916; 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; bh=WHZ4UJ9Q3KqOEAfitcpL3sAcFDRvjYEeqxAs3TRiPiU=; b=CyQi5jEFCNx0z2j+XAGmiAfaxGfYth8HIQlafWvlSdK2ecsvgACkVSdQT/kAY+EqlwVqFYGVUBrOU7GoCzH7sbaIq8Fq19kcedz6ujVw4NRxWMZiPL+hEDLLUtD/dxVZ0OgNV2LdKSH/UyX8DJUzIm2r/xHEXTUS1W4bCG1Nank= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578505915212340.40547500987907; Wed, 8 Jan 2020 09:51:55 -0800 (PST) Received: from localhost ([::1]:47446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipFUm-0006qo-OK for importer@patchew.org; Wed, 08 Jan 2020 12:51:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48341) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipFTM-0005Si-11 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 12:50:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipFTK-000165-OV for qemu-devel@nongnu.org; Wed, 08 Jan 2020 12:50:23 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:55163) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipFTK-0000YS-2Y; Wed, 08 Jan 2020 12:50:22 -0500 Received: from [213.99.255.143] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ipFT1-0001HP-PO; Wed, 08 Jan 2020 18:50:03 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1ipFSD-0000DZ-Aw; Wed, 08 Jan 2020 18:49:13 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WHZ4UJ9Q3KqOEAfitcpL3sAcFDRvjYEeqxAs3TRiPiU=; b=fM/DwPbWsNkZVRSwyNvyEOcVzh0NyoORD9BOH7Jc0EFTYEXnEZPznd62tonmB2Juci95IM0+fqi2EmPuzK5MvEaiKGUTnorkRkEEOlPMHf8Yei0Xv1RnAsNJipkJN9rcqlq33d0i6URQlyMVsybfcRLUenmiDrKMrMyqd3h5yAc957xFXC+eD1gtGx39m4nPvk1ah8c4TJP1cmmA07AuYASe6e9jdGDpQuPSXVJvgPCWvsp76T381UIm7bAkWdjxdDTVBNWTfa+HJcRvM3txDzIlUtM9NenvvCzVGvda8B7LonNoq/ueIu2VNSK3PRUV45SYUz05iMw/Yu2aKaEbjg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH 1/3] qcow2: Require that the virtual size is a multiple of the sector size Date: Wed, 8 Jan 2020 18:49:08 +0100 Message-Id: <4a27dc359f8211700662949bdecdd992f8918c12.1578505678.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 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 , 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-Type: text/plain; charset="utf-8" The qcow2 header specifies the virtual size of the image in bytes, but BlockDriverState stores it as a number of 512-byte sectors. If the user tries to create an image with a size that is not a multiple of the sector size then this is fixed on creation by silently rounding the image size up (see commit c2eb918e32). qcow2_co_truncate() is more strict and returns an error instead. However when an image is opened the virtual size is rounded down, which means that trying to access the last few advertised bytes will result in an error. As seen above QEMU cannot create such images and there's no good use case that would require us to try to handle them so let's just treat them as unsupported. Signed-off-by: Alberto Garcia --- block/qcow2.c | 7 +++++++ docs/interop/qcow2.txt | 3 ++- tests/qemu-iotests/080 | 7 +++++++ tests/qemu-iotests/080.out | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 7fbaac8457..92474849db 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1326,6 +1326,13 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, goto fail; } =20 + if (header.size % BDRV_SECTOR_SIZE) { + error_setg(errp, "Virtual size is not a multiple of %u", + (unsigned) BDRV_SECTOR_SIZE); + ret =3D -EINVAL; + goto fail; + } + if (header.header_length > sizeof(header)) { s->unknown_header_fields_size =3D header.header_length - sizeof(he= ader); s->unknown_header_fields =3D g_malloc(s->unknown_header_fields_siz= e); diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index af5711e533..891f5662d8 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -40,7 +40,8 @@ The first cluster of a qcow2 image contains the file head= er: with larger cluster sizes. =20 24 - 31: size - Virtual disk size in bytes. + Virtual disk size in bytes. qemu can only handle + sizes that are a multiple of 512 bytes. =20 Note: qemu has an implementation limit of 32 MB as the maximum L1 table size. With a 2 MB cluster diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080 index 4bcb5021e8..2563b2c052 100755 --- a/tests/qemu-iotests/080 +++ b/tests/qemu-iotests/080 @@ -48,6 +48,7 @@ header_size=3D104 =20 offset_backing_file_offset=3D8 offset_backing_file_size=3D16 +offset_virtual_size=3D24 offset_l1_size=3D36 offset_l1_table_offset=3D40 offset_refcount_table_offset=3D48 @@ -197,6 +198,12 @@ poke_file "$TEST_IMG" "$offset_snap1_l1_size" "\x10\x0= 0\x00\x00" { $QEMU_IMG snapshot -d test $TEST_IMG; } 2>&1 | _filter_testdir _check_test_img =20 +echo +echo "=3D=3D Image size not a multiple of the sector size =3D=3D" +_make_test_img 64k +poke_file "$TEST_IMG" "$offset_virtual_size" "\x00\x00\x00\x00\x00\x00\xff= \xff" +{ $QEMU_IO -c "write 65530 1" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filte= r_testdir + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index 45ab01db8e..e1c969e2ba 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -104,4 +104,8 @@ Data may be corrupted, or further writes to the image m= ay corrupt it. =20 3 leaked clusters were found on the image. This means waste of disk space, but no harm to data. + +=3D=3D Image size not a multiple of the sector size =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D65536 +qemu-io: can't open device TEST_DIR/t.qcow2: Virtual size is not a multipl= e of 512 *** done --=20 2.20.1 From nobody Tue May 21 10:00:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578506014; cv=none; d=zohomail.com; s=zohoarc; b=YZ2il+Etx4DJ+9NjpcPTg2ZfTe9QvgtE8tQoWgLGJtu9dk1CeKSyZJY5YHA66VubgM4rfuKKu8Xl8VrfA9hWWfisEXGZO+adzAheaxAEtUTt++WkzbUuJvgwpTU6ERMPDQOhaPmAW86pblx9PIgcX3TjKuxZ1Bb7sQYxGVJWIBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578506014; 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; bh=oaC6J/0lUcjbOOUGMSdrNrClykmLQMSX94HkHdlFe6U=; b=ONRLfJHnGEG72Ti2824UuWvNtJ1nQvGgkmKxQXI7m10JiozpGhsqy8Ixosp77vQmaL09RgwWYTMbOhayXqdJUfh1sil4wucDPpfUvnJHblIS/vSb69DTUnzGD//iAUu8ZyhtpXLcGv3ZJX8V7rSvcHhy9+g7xsLIeNhkcf0KFf4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578506014056661.5876071311108; Wed, 8 Jan 2020 09:53:34 -0800 (PST) Received: from localhost ([::1]:47497 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipFWP-0001Vp-2C for importer@patchew.org; Wed, 08 Jan 2020 12:53:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48349) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipFTM-0005Sn-8b for qemu-devel@nongnu.org; Wed, 08 Jan 2020 12:50:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipFTL-00016Y-0V for qemu-devel@nongnu.org; Wed, 08 Jan 2020 12:50:24 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:55159) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipFTK-0000WP-Nj; Wed, 08 Jan 2020 12:50:22 -0500 Received: from [213.99.255.143] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ipFT1-0001HO-Lz; Wed, 08 Jan 2020 18:50:03 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1ipFSD-0000Db-Bs; Wed, 08 Jan 2020 18:49:13 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=oaC6J/0lUcjbOOUGMSdrNrClykmLQMSX94HkHdlFe6U=; b=PotJdK4r3/RsQOm6I5s8ld9iBhJnItPcFQTeCXCYW49F4E51WfPVGNXIu85ZDJ0+fqKAZ5WSfxuxvANvWVbOh6jJvkk6A/cZiikuw46KoLLmVMWRsZ5G3jlp/vzBsyuYtPMzrjHhX9VLuq0FcQAqLDPPspo1u7Xlkkj7N3FvhxPFxWmCJWFlyNCLXRoOAzUYkiP6Y3AiHDFVz41Ai8jmtwhjXfBQga6YxMyOj3IFE3pWQdpKIzJR9dyvI44E9Rd/Cfip+67DXRTgnBG4o2KaY0Wj3SboOcY/9JhomyaV3K98GTUbxyOrZEJfL9Rdvf9BdjyQPABBgwv1QDB4nueBpQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH 2/3] qcow2: Don't round the L1 table allocation up to the sector size Date: Wed, 8 Jan 2020 18:49:09 +0100 Message-Id: <672f5b3c7c6bc12548c72ec309a7b2a01d253a72.1578505678.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 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 , 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-Type: text/plain; charset="utf-8" The L1 table is read from disk using the byte-based bdrv_pread() and is never accessed beyond its last element, so there's no need to allocate more memory than that. Signed-off-by: Alberto Garcia --- block/qcow2-cluster.c | 5 ++--- block/qcow2-refcount.c | 2 +- block/qcow2-snapshot.c | 3 +-- block/qcow2.c | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8982b7b762..932fc48919 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -124,12 +124,11 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_= t min_size, #endif =20 new_l1_size2 =3D sizeof(uint64_t) * new_l1_size; - new_l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(new_l1_size2, 512)); + new_l1_table =3D qemu_try_blockalign(bs->file->bs, new_l1_size2); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } - memset(new_l1_table, 0, ROUND_UP(new_l1_size2, 512)); + memset(new_l1_table, 0, new_l1_size2); =20 if (s->l1_size) { memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index f67ac6b2d8..c963bc8de1 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1262,7 +1262,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, * l1_table_offset when it is the current s->l1_table_offset! Be caref= ul * when changing this! */ if (l1_table_offset !=3D s->l1_table_offset) { - l1_table =3D g_try_malloc0(ROUND_UP(l1_size2, 512)); + l1_table =3D g_try_malloc0(l1_size2); if (l1_size2 && l1_table =3D=3D NULL) { ret =3D -ENOMEM; goto fail; diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 5ab64da1ec..82c32d4c9b 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -1024,8 +1024,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, return ret; } new_l1_bytes =3D sn->l1_size * sizeof(uint64_t); - new_l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(new_l1_bytes, 512)); + new_l1_table =3D qemu_try_blockalign(bs->file->bs, new_l1_bytes); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } diff --git a/block/qcow2.c b/block/qcow2.c index 92474849db..e8ce966f7f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1499,7 +1499,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, =20 if (s->l1_size > 0) { s->l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(s->l1_size * sizeof(uint64_t), 512)); + s->l1_size * sizeof(uint64_t)); if (s->l1_table =3D=3D NULL) { error_setg(errp, "Could not allocate L1 table"); ret =3D -ENOMEM; --=20 2.20.1 From nobody Tue May 21 10:00:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578505916; cv=none; d=zohomail.com; s=zohoarc; b=DZgKuT2iRsDHu2hEytfhuy2pyC7jhem7NT32keR4nBgoVTlaD/danFnABfr7VTH34VafbbrYjGYugVJEEONjMOI43o8pyzODFMdUN7ZWuLf0WxPQY1mQbr7tPq2l9wfGxJ1rHZOEtZRcgVCqKyqx30CEn02SJZ18zvU12c1uGhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578505916; 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; bh=7obi6hyBg9iHOq68BveAS3HpKksoZeB2IapeD+aUG5E=; b=VEOxKZqSff6bovkY30XXgHyDQ3E3JKzIa82AL75eOwQVzNewmRsmpW575W9UFj+0oTI7mOKiVJ5/T4MA9HFxzNUobBNUzLaT9fc5bxL5R69cCZzVkZ3Xo5pKqT5xaR1WUhDNtIo9aJ9h2wMGvTTfrUwEpn7NhHMIDua3nHYbECU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578505916799619.6545505582149; Wed, 8 Jan 2020 09:51:56 -0800 (PST) Received: from localhost ([::1]:47450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipFUp-0006rd-15 for importer@patchew.org; Wed, 08 Jan 2020 12:51:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48336) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipFTL-0005SM-Tb for qemu-devel@nongnu.org; Wed, 08 Jan 2020 12:50:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipFTK-00015t-Nv for qemu-devel@nongnu.org; Wed, 08 Jan 2020 12:50:23 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:55161) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipFTK-0000WN-2V; Wed, 08 Jan 2020 12:50:22 -0500 Received: from [213.99.255.143] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ipFT1-0001HQ-NR; Wed, 08 Jan 2020 18:50:03 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1ipFSD-0000Dd-Ci; Wed, 08 Jan 2020 18:49:13 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=7obi6hyBg9iHOq68BveAS3HpKksoZeB2IapeD+aUG5E=; b=L1WHH9FwDvZ8jxGFAS1TjWgWB+hfQs7L+NLdpAkN552GzvCL5ZAq6AhX6EQWJgjTZZGPk9C5KxpLhYOdARzDQQiTRzZDXMiLbo/gVJfu6QbtFZcxfHpcC0cigq81dMSoHmV0pUibTF6FeBLjFhTYrPPvulEN62dHsegDQQzcsePPEFIymXUwijhZjFezSzXVfgdoZQpRmyT1qBxeoo3uVjDe5fVfHQ4+rHxjlSscJo154rxdfO0u4Tg4Oz7cxjb0Z6xR9c9QrMOjnNHhRJC0B3cNKhYCt93X7guhHtsmHHwMqyRCPPZR6GcfA+8t/eTTRn+TVld5aWTS+u2yhwfdCQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH 3/3] qcow2: Use BDRV_SECTOR_SIZE instead of the hardcoded value Date: Wed, 8 Jan 2020 18:49:10 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 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 , 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-Type: text/plain; charset="utf-8" This replaces all remaining instances in the qcow2 code. Signed-off-by: Alberto Garcia --- block/qcow2-cluster.c | 2 +- block/qcow2.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 932fc48919..777ca2d409 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -219,7 +219,7 @@ static int l2_load(BlockDriverState *bs, uint64_t offse= t, * Writes one sector of the L1 table to the disk (can't update single entr= ies * and we really don't want bdrv_pread to perform a read-modify-write) */ -#define L1_ENTRIES_PER_SECTOR (512 / 8) +#define L1_ENTRIES_PER_SECTOR (BDRV_SECTOR_SIZE / 8) int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index) { BDRVQcow2State *s =3D bs->opaque; diff --git a/block/qcow2.c b/block/qcow2.c index e8ce966f7f..6427c75409 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2175,7 +2175,7 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDri= verState *bs, offset, bytes, qiov, qiov_offset= ); =20 case QCOW2_CLUSTER_NORMAL: - if ((file_cluster_offset & 511) !=3D 0) { + if ((file_cluster_offset % BDRV_SECTOR_SIZE) !=3D 0) { return -EIO; } =20 @@ -2514,7 +2514,7 @@ static coroutine_fn int qcow2_co_pwritev_part( goto out_locked; } =20 - assert((cluster_offset & 511) =3D=3D 0); + assert((cluster_offset % BDRV_SECTOR_SIZE) =3D=3D 0); =20 ret =3D qcow2_pre_write_overlap_check(bs, 0, cluster_offset + offset_in_clu= ster, @@ -3283,7 +3283,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) =20 /* Validate options and set default values */ if (!QEMU_IS_ALIGNED(qcow2_opts->size, BDRV_SECTOR_SIZE)) { - error_setg(errp, "Image size must be a multiple of 512 bytes"); + error_setg(errp, "Image size must be a multiple of %u bytes", + (unsigned) BDRV_SECTOR_SIZE); ret =3D -EINVAL; goto out; } @@ -3839,7 +3840,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, case QCOW2_CLUSTER_NORMAL: child =3D s->data_file; copy_offset +=3D offset_into_cluster(s, src_offset); - if ((copy_offset & 511) !=3D 0) { + if ((copy_offset % BDRV_SECTOR_SIZE) !=3D 0) { ret =3D -EIO; goto out; } @@ -3904,7 +3905,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, goto fail; } =20 - assert((cluster_offset & 511) =3D=3D 0); + assert((cluster_offset % BDRV_SECTOR_SIZE) =3D=3D 0); =20 ret =3D qcow2_pre_write_overlap_check(bs, 0, cluster_offset + offset_in_cluster, cur_bytes, true); @@ -3961,8 +3962,9 @@ static int coroutine_fn qcow2_co_truncate(BlockDriver= State *bs, int64_t offset, return -ENOTSUP; } =20 - if (offset & 511) { - error_setg(errp, "The new size must be a multiple of 512"); + if (offset % BDRV_SECTOR_SIZE) { + error_setg(errp, "The new size must be a multiple of %u", + (unsigned) BDRV_SECTOR_SIZE); return -EINVAL; } =20 --=20 2.20.1