From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198334; cv=pass; d=zohomail.com; s=zohoarc; b=XJFQOSExDfFdDnVQZrZ9UY5kooWEbefe/8Wh9m50bHHSp3rEjnDmJzMbtbvGLWzu4/NsHwbmg7FaUSH5ujvdfHZ8KecavyxikX8GDQBwpwSQBUWmYqXXnTnLHido1AfEWwWW/D9KfRrFdsuXSQgPhCz0nuZIg4ncdbOgLprFt7A= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198334; 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=hngAEev1nxwNGEj8FBZJ7ONnW4yWK2eBr0gvAaO7spQ=; b=OgkSmDy6ABmcT8eGlahp+peQLrdRUAyNWI/zAdSF+yNLS840HkI/5cghrrD49QYfZqFBLMQ5acrNV+TP/qKSSTXOCEDiEw4kqcWokJQx4ud64uwCRU6mdAmIS7rVNi4owKPtxMfBceCN/vmGHR8GRCXZFt0KKOg6tJ4PBu3qlXQ= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198334920464.3451384900235; Wed, 5 May 2021 00:05:34 -0700 (PDT) Received: from localhost ([::1]:48290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBbB-0004Gh-NM for importer@patchew.org; Wed, 05 May 2021 03:05:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBW8-0007d4-5H; Wed, 05 May 2021 03:00:20 -0400 Received: from mail-eopbgr70101.outbound.protection.outlook.com ([40.107.7.101]:33297 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBW6-0005pW-5Q; Wed, 05 May 2021 03:00:19 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:11 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:11 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z/6Dqr4BqvNSY343A766J7vUrUtVy8J/rmYPOWIQrhIYqL8o5o47M39jKsMY5LBMgIrGNde0YZ5STbxV4wRj0gkprQnTYA4hlUIxkWP1NTh3EAjNzgs+EIrwbbNBDygRRMjBlvgfOI9L1k5oXCUFip7RF3zDZ//8F+/LXNR7DwQjVRo2UdhKkJrqsRNgliHmO81/sxhXWerZ+VS23vBOUPaSRBqsxVgX1IRqvRYXJAvqEq/uXmg5wsVXDiCrVotWorxy9eGf8wPjd2TvO/VhnSshhgtNx90tXPE5HyJf5bfULjhlg07Y+kYbJc1kXgFM9ajOFxpKrBtXQXsfxtxr8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hngAEev1nxwNGEj8FBZJ7ONnW4yWK2eBr0gvAaO7spQ=; b=V6lcO5Kb9qRShQgzosA2hqzutk+atj15Sswq8HaPBKh1Au6OIOZsvkmKYHvZU5f0A5TodbBQfSzbxHZiul+OpYxoMC/aMVbQTZyGf2oyWl0UTaodhhnfonXSOZQq7eGqUKANGIBbd6g46Yq8SKVrnsH1yulNq2hGYfGcIdwdJbueRM13eAOr9Y/E2/RpWyNEuZuX1J5XoXiUdfdUq27TzRnwF4rwqZ1lCSX7VkyxBw/Q8s8BxR2OdtJdnypUSSKdgvJUnhSNbf9NaQLufRxfLEV4sU2mN3aroLoZEOnfdsIeDvA3S9LzmUZdePiAJKmweraAnuqBaKv0OwjyIdTpZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hngAEev1nxwNGEj8FBZJ7ONnW4yWK2eBr0gvAaO7spQ=; b=mU1gC6/Ua+nIw0+zJWBgAm6ejwr/U+3GZviEwd6pc/zlhHVvypryty1jETG8yPHVmkPQDhIDIlkX84tHmcFMOLKT98DgkNNFrP/Enjq+i4681ONfW4uhulhE2w/mIoHviI23BrIZkyydRWg2y3xq+16Ua2PyJyOG4YDA6T/q5f8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 01/10] qcow2-refcount: improve style of check_refcounts_l2() Date: Wed, 5 May 2021 09:59:46 +0300 Message-Id: <20210505065955.13964-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9638c94c-d698-4c9f-b288-08d90f936cd4 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D3CYB5nYWobZKjtZEnZyAXQ9SUBXm7MRym4Mh0OKyeZq09RvRV1mkUPBjWZ4WLxC5BvkrNXqTyBNMgk5ksxJq46OCUdQyxhJcNByTv3cj0P0RLIi6KDPAl8+VguL+vgVs3L7pG+B34tzv1BNmuswHJkyQ/QetEizafbyCIe2E6FNSSeuQXecKz1iGZ+OC1hKUWuxdXBVpcUv1AArbkr2F/BWsc8QC5lwrwpxXK/AEbEUN3LX42BZ40XkehNGoPImAd+jCJYIIlIdWvCL/WZQjBfaU2m1xjMO9FZLkxKz4UtYGaBUDgKF9dVR+T0yrDGnGBVyI1Lc1ljfNveamuQk28W0h2v99j/WVHI1mVYZBpNqiql7ianidoWHAxbRBcD/Cm3+TZuQ0fCzPWmJeFvTKJQh90L98cUBnC1N2UoArUUKdGHeMxcDCKZbSqJXbUx40liFQnxCazrlGnx2l5rEWDdc+17XEUSK/kjwJhVhw0xfYo3mNGLbSiSl9fgxTuJDbKH4EBNdvuuUjdXk3xidZS9t7SOKRuWCdwMSoo8QZrjqW4srLLNOBR4eFR7iALWM9LfAAKn6eX7XeEbw56vdzZJ6hlfhwnVtojuT/xNRqAVzFSVv44aNl1f9iFKtiG8Wz0XbvPHXldseQN0y2MwOQ8kc9121cVQKnXHoIBZF9yLymj3oUGMyIu7vOJqs00J1 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ukOI5QOSBGXH1JT53nb/kGpR115iDVJu1b5zsZqaRoT5rGwk4a46WItZIx3j?= =?us-ascii?Q?TER0uBSif6ecUWviBiEweRufj+6uj6OZl0DifzOtitj4s4dseUQmCFoeEROf?= =?us-ascii?Q?63q2OBBYyU9yaifO6cgEh0YlBGl8uXmkI8Ctjj4QT0sncDZBv7SnFc9IU1yZ?= =?us-ascii?Q?lCL188u2kYcG4LwCpK4mLTYHdxuyLa9XfJFHVsOegtGCyOAW3SBmRqF7V62g?= =?us-ascii?Q?9xLd17R4X4cinFkarisLFeMseSEOsyx1m0JsUEQEihy3L/4MAgCH/QEBHyMm?= =?us-ascii?Q?TZvG6Zi4NU8ego8HF18N+W6i9BiTZgSW2XkQx2QzZSdyvmuY8Jf4bLDZ2mqK?= =?us-ascii?Q?wrPqxLHK5zLpzlKj6iCIuKnGZxH+I8hP+wF1lxyE+JxEZbQ+P4VmgGW0T95I?= =?us-ascii?Q?CQrbSpALVWI6Lj+aLvMbv2i+57Bnexf/TGwMYlkeRfMbXyHUpbE1csqY1dmE?= =?us-ascii?Q?ADt/H0wA3YfWZVGJ05fvuScywYIrkRoORIc+frM+rlpS2UJ5zjOSki3H1LBB?= =?us-ascii?Q?JmOgUafs/BEzEhuKpDyvmKPGgyXxCxyvSkPztn3rvgOXAg8n9v7/RHKasyxF?= =?us-ascii?Q?mqMw3ACoeuycuG85Xl6lrklm8q55YtRTVL/FIGxH9dHU+S3FdlNZEkFi0Ki7?= =?us-ascii?Q?D8sya3gm5b9Yrr+eUTtV9KvsJPMQva1+/LUFt2Upb+dHFT9M169jjk9g1Xj3?= =?us-ascii?Q?irQ6R6+fxhfgLv3qFnzxhv0mDVLUTr9mARVeMGulyWVEqwCMSBXcINZFpUmz?= =?us-ascii?Q?e9SeJbz7KpbzoApjSA5VGHqvhMjO4qPdTFFGboD/lyjaJX3WVDm3ZkbjIgbQ?= =?us-ascii?Q?hqCV8CynQhL3R4QIxTzm3UqwSIFjGKIHIBm8S6dF/yEzhLQIugbBHAK+Tvov?= =?us-ascii?Q?6v9UkguPd+dztuydyyK3EfpviHe/5UPhQF5RneWi2Ol3jR5A0lscyQRNudp1?= =?us-ascii?Q?zA49mgxre6onGqQdlbD3eBT/1YB13TTiQE+XlkMGY//H3HR/amcT/TJ34A+q?= =?us-ascii?Q?mDcBXgOtSwPPoN0gD9Nn7F5A5rRjIICIONLofiX9H/7Z0wwuJA+whZVmU1VJ?= =?us-ascii?Q?FM8uhDby2NutgpfMyqVh8YI9vYlpwQEYzbrdKbSGbvFASlDsDG/G8koTpsxy?= =?us-ascii?Q?sY+Mu9xqfQwbxS3+jI/JjlSdxDRJQCiWq6MX9rrsu8X/JBD6SUwor7Wpzf2x?= =?us-ascii?Q?UcgmiXRNqy4Cel+ZCbNnR/nStGsrRiV/9Iet9F5LR3ZwK+qquBA1OsKdTvZK?= =?us-ascii?Q?li08oxnk8kMnAolE7Ph8iuObeXjjo1wYPcHoN1YfxVtvM1/9pq8LVsaMVCZC?= =?us-ascii?Q?lbdM484lwTqG/m+A0b11Or9s?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9638c94c-d698-4c9f-b288-08d90f936cd4 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:11.1378 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zb2iHOoiQlwCOCsDBk3gHLwDSb5VOOJSCBGEK6bsZVTGHEr0ldzRKanWiL8+IbUvA0qTkredo1V/ayqTTdOoaVaE1+RxrQmgQlPg03yQj5s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.101; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" - don't use same name for size in bytes and in entries - use g_autofree for l2_table - add whitespace - fix block comment style Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qcow2-refcount.c | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 8e649b008e..2734338625 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1601,23 +1601,22 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, int flags, BdrvCheckMode fix, bool active) { BDRVQcow2State *s =3D bs->opaque; - uint64_t *l2_table, l2_entry; + uint64_t l2_entry; uint64_t next_contiguous_offset =3D 0; - int i, l2_size, nb_csectors, ret; + int i, nb_csectors, ret; + size_t l2_size_bytes =3D s->l2_size * l2_entry_size(s); + g_autofree uint64_t *l2_table =3D g_malloc(l2_size_bytes); =20 /* Read L2 table from disk */ - l2_size =3D s->l2_size * l2_entry_size(s); - l2_table =3D g_malloc(l2_size); - - ret =3D bdrv_pread(bs->file, l2_offset, l2_table, l2_size); + ret =3D bdrv_pread(bs->file, l2_offset, l2_table, l2_size_bytes); if (ret < 0) { fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n"); res->check_errors++; - goto fail; + return ret; } =20 /* Do the actual checks */ - for(i =3D 0; i < s->l2_size; i++) { + for (i =3D 0; i < s->l2_size; i++) { l2_entry =3D get_l2_entry(s, l2_table, i); =20 switch (qcow2_get_cluster_type(bs, l2_entry)) { @@ -1647,14 +1646,15 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, l2_entry & QCOW2_COMPRESSED_SECTOR_MASK, nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE); if (ret < 0) { - goto fail; + return ret; } =20 if (flags & CHECK_FRAG_INFO) { res->bfi.allocated_clusters++; res->bfi.compressed_clusters++; =20 - /* Compressed clusters are fragmented by nature. Since th= ey + /* + * Compressed clusters are fragmented by nature. Since th= ey * take up sub-sector space but we only have sector granul= arity * I/O we need to re-read the same sectors even for adjace= nt * compressed clusters. @@ -1700,9 +1700,11 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, if (ret < 0) { fprintf(stderr, "ERROR: Overlap check failed\n= "); res->check_errors++; - /* Something is seriously wrong, so abort chec= king - * this L2 table */ - goto fail; + /* + * Something is seriously wrong, so abort chec= king + * this L2 table. + */ + return ret; } =20 ret =3D bdrv_pwrite_sync(bs->file, l2e_offset, @@ -1712,13 +1714,17 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, fprintf(stderr, "ERROR: Failed to overwrite L2= " "table entry: %s\n", strerror(-ret)); res->check_errors++; - /* Do not abort, continue checking the rest of= this - * L2 table's entries */ + /* + * Do not abort, continue checking the rest of= this + * L2 table's entries. + */ } else { res->corruptions--; res->corruptions_fixed++; - /* Skip marking the cluster as used - * (it is unused now) */ + /* + * Skip marking the cluster as used + * (it is unused now). + */ continue; } } @@ -1743,7 +1749,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, refcount_table_size, offset, s->cluster_size); if (ret < 0) { - goto fail; + return ret; } } break; @@ -1758,12 +1764,7 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, } } =20 - g_free(l2_table); return 0; - -fail: - g_free(l2_table); - return ret; } =20 /* --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198683; cv=pass; d=zohomail.com; s=zohoarc; b=clKJpNL6oQ1EjM1Mqzm/g859KdW1fhqW56lNgt7D/gaIgLfEw+FOaHNcUnA+zz2utJVWFf8b/z5J2hTFNiBNMqle+Hy19yvnLQdUC1kgWxjRGmM1dqO8O62u/y3zxCOZLLNAKwPe+sJdy1yfyUfztWpvTXQP7E1Q+P/TrJscZpg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198683; 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=ffmEzwA0uINAiwdsXSGxI1/Cggk7sOwDcpdAjAro5oc=; b=Eyw0A8y9y8vdVe8h5zCjQIlBk3u+6toWLMVyjm0oX/zTnBhVHPkDIKK1GrOMOXoLHFKsi4eHa3Jw2PD3g+s5Yy/ZGRYXRQBwbaRs2Q3jDrmJtyIO0+CaZ/ZcZqb8i48c/sG9nVepxIrsG9ozubUOImLkztyMJ70gKcFttAmqO18= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198683969967.908184244257; Wed, 5 May 2021 00:11:23 -0700 (PDT) Received: from localhost ([::1]:37846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBgo-0003I8-8P for importer@patchew.org; Wed, 05 May 2021 03:11:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWN-0007yW-6J; Wed, 05 May 2021 03:00:35 -0400 Received: from mail-eopbgr70118.outbound.protection.outlook.com ([40.107.7.118]:64516 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWJ-0005yd-SF; Wed, 05 May 2021 03:00:34 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:12 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:12 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dlao3SOtX8xB4H7UMVxXDlI5rv39iTBvblVKuzc1QVwBohnxSUHIypxYaOCKZaUXf1kpqM+18okN6t854gP/pxEvY7AIXIe+FmD8YXylcoPKK4cQsIg6gwuZogJSbhtX1gl6kSkoWP+gyMzu7TqU7xjQE/nVugC7E0E6Dn023UfScwQlSiDu9A+WIAnYikmulS/jxXjpessZMX63u7cOo06Qt5wpurpnNOBgXm1AzIZLqT1/+jx4U5+XWylOx2zCLGRYGyqWFodzfUEE5pXRuWa7jEUoz0JSrviGjNOgcxIPQZt4N/kwbz5B7rCuNn0NGn+5Mxjnj5XKzVbn7deI/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ffmEzwA0uINAiwdsXSGxI1/Cggk7sOwDcpdAjAro5oc=; b=Tc7VJi56jpgp9mXQjiJJDyaGkjXZDZJFn39SSSZhJVYeg/LnDt4+5P3gx+pFVpMoltF52iCpdRW6OzVc1VuiyXykE+Cy1ygOQEkdDm64guHrbSkAvy2PHM5GUS29XX2f28v8xDf26reOn8jCl/LquzkRImHn4/xYJMnev7fALw1jFcg5UtnbyDPnESe4FC9IUIZ4IOAQ9O6JqF+A8r3Zn5AVWLndGkmwpm45G67I0TozajyJcnGpNk7+g90edAL+vAWjjbvDgmMwkklwB761Pei0IpNSpZLAUbJ4gAZucCkpXkCySRl5oDSMvHiI+sBfs1E2+fURDz5G0sK9BQd9lg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ffmEzwA0uINAiwdsXSGxI1/Cggk7sOwDcpdAjAro5oc=; b=OYRxFmcBELYzQciGkLhP4AatScNuCn3uZ2++6D6u4nTAh3GH8pgdFLF3dWWmrkOAARjeFICPGVXRtq4uXPWuWfssOHpKvbBJBg+of9f0EGSI+cVo9FMnTAfWNSckUuHnEmru3U84uiZ+RkBosw6qRFGlcTg10xneQfhglfW0WyI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 02/10] qcow2: compressed read: simplify cluster descriptor passing Date: Wed, 5 May 2021 09:59:47 +0300 Message-Id: <20210505065955.13964-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 860d7244-cd22-4a3a-37cd-08d90f936d8c X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1775; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qkSx7KdFMuxQlWCn5CMOi5Un1YsAGQRiKCHrtZKqh38/aRqNrl6BsFdB1tEp+b83fOytxpV0coB4fwxmLKFCfXCdzuSWJenj77rBGdR/bOBFZOUUjTKN5tjH7XkjiS2K1OERm8RE86Ymxbau5rV1cHwqL4u5Os7M2fECRum53zfVwJ/ATFy29yT5OwfthJwXvNFngZDbtjRZ6NFobMrgcNkpzn1R0Dz337i43WPZYPVXSIqj8CeuzRaMHSCZcrIDL+BY0xczkA9EwS69SI5TIqCkkuXDuhJ5XT6frCpLszMxknVjfgcoucJ/Zvs0bOnF8ytHcJ0a2G82O5IUe4qRLTXGDXKytFLyM7Dam1rr1jgZmQx8D+Yn5Xs1iJtK35R8DACQ9VnIkWXTUwuOCjUk7rLA5N/iGMshK/pPYnVC6+6fc2QDlfU6EHGolxb0dsGdPcLyYlCxfgaMfeN5HnNudPgGAdZu/2748mWm//PHytW51hYkJ0A/rJfInv5DYbLxv33NxtmM8UlNKMELrKiibmb2Zqycxu8ybmZMpGfg92zCRDsL3K3Ms8x4eCR+qzix0JL3eQJIuqXmr4l67H1gwJVTczegmgR8K7D1YOeUgHN7i04gikZDtdNIJC286pap3AUEA9U8DkTctOw1IbbOUlBYe1lo3a8c3piqhCEtsxGvbtbSRY0Uk7OD4s1eaC3h X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(19627235002)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?6pjiNo4Jz+sw0gvKooth59aRXtF+2mlHB++Vv5Yjyg3xrdCH82FncXXVjSl7?= =?us-ascii?Q?E1T/G9DUqH1j7kxDfX6Ki42bVi0IPUaMdKqmB/LnKGBCsOenVQwu4WMKpqbp?= =?us-ascii?Q?qyEkWNXskQoWZKGZcCXWrp7TC1p6HUsggsSwhiT9MA8GhXAAVB/fpRzBRhgd?= =?us-ascii?Q?nYDk3Ft1NH2VV10MhB9kXukYm/i8K7HPqVaI8utLWdHePdXPozRkUTNoDqi/?= =?us-ascii?Q?d1Ug9ee2c170DvXWCeK8jQMUGWXd7Z4lgb7gb+zfDggocFzsMAkPzi2A/Wlw?= =?us-ascii?Q?N8e6ECcV4OHdcnczNQcN3SU16vVtK+juslndpY9Jf/DRPrW4HkAYefi7wJYp?= =?us-ascii?Q?R01c6GbYzCTIMEZFcbALPon4PA8aXZ3afFW1yJxpT5plJLwVmkeLjFdee07h?= =?us-ascii?Q?ig4q6NdbC2osWxvoxF5ILmhEhUfDU3yaKAHAmsDSAePfA0rchaXQ1FvJa/Oe?= =?us-ascii?Q?ybiQASqepLreSwQU0Fs+9JckP9JV6C/u0XuVEyPru+xBA87PkQR7dh4lf3aX?= =?us-ascii?Q?l0oyKF2zvLIxW6kk06DfNl0KOWUWSGBhbtD71O5YyLXUhtgNEgND7cJzQnF5?= =?us-ascii?Q?YvKTVNf0ag23VieVIa/+R1Mrirj6Xqamn5a/EXr4VmOMaOHFf9f5QIsSBZTV?= =?us-ascii?Q?soISuVO/XDyQ8AfmoKlvVSx8TqeL+tgPdtQKRVvHgnzCyVSiUZK1NA9+8CFF?= =?us-ascii?Q?+Bfi+6ncmOVbke3Ebq/I6Q7rx0ig+/+YvgT1J1SPohSf2HavXUDF3tGY9VZN?= =?us-ascii?Q?CSDgNil49sy2QJ5BHImgleaWncdPRKYoh2wJfxUSPtv75MtHD41HYhkrBOH/?= =?us-ascii?Q?a9favLR0h3DxkP84lSmcw+PPWPsy4M9npeBeoBAoTQuBrq/lKnDd/uaywPTo?= =?us-ascii?Q?9TL/TwAA92g82GumaBWbnfe9j3SB1K4K7C0Bmf+POo/qKgZ2+ZAdRY8VEIpa?= =?us-ascii?Q?5BGUiRqIM0RvFS9FFmzvTjZ6rVw9LxeglT7frKEPzrRQgcH88KY4nn8Hj6/w?= =?us-ascii?Q?oLvGOTwMH+0mjOLc6Fa3pFhkkm48tvtL0HbL++gE7sUbGOKPcFBfmyOxPijZ?= =?us-ascii?Q?O47hYxuHeZQphr9bPHhdFAun2NylifTZCJICKY29FlJLbsxfhUER0mzm2If+?= =?us-ascii?Q?3N4F/eDOKtXkSKLAzCuViwCcffNSITTEXfDhkbbrj54rCzqcs8SelC2eAjHg?= =?us-ascii?Q?bqreic8c2rueLsUFXv1ChEPmMLw8OKsWjr79ZYvhUtbJPM3oFHuX0m/pbb/G?= =?us-ascii?Q?7aQiYM2CCy5r+oWeGEymOwymHa/+FwCYwjZgPO7pOwiNdd7riXF0Quu3JSuj?= =?us-ascii?Q?0CfG3U+oWteIqW+n+Dp9Cyz5?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 860d7244-cd22-4a3a-37cd-08d90f936d8c X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:12.3823 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ko+SCk2L2/8Mo8qw7hOOaEeYkXeGi96GNEwi8vuaUP1nIVsOuKvXPJViRIdnIA8t3e8btFXd17QxMxor4I1vp2Uq9EPq67nGdHEwiggIaag= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Let's pass the whole L2 entry and not bother with L2E_COMPRESSED_OFFSET_SIZE_MASK. It also helps further refactoring that adds generic qcow2_parse_compressed_l2_entry() helper. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block/qcow2.h | 1 - block/qcow2-cluster.c | 5 ++--- block/qcow2.c | 12 +++++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 0fe5f74ed3..42a0058ab7 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -588,7 +588,6 @@ typedef enum QCow2MetadataOverlap { =20 #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL -#define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL =20 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL =20 diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index bd0597842f..04735ee439 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -556,8 +556,7 @@ static int coroutine_fn do_perform_cow_write(BlockDrive= rState *bs, * offset needs to be aligned to a cluster boundary. * * If the cluster is unallocated then *host_offset will be 0. - * If the cluster is compressed then *host_offset will contain the - * complete compressed cluster descriptor. + * If the cluster is compressed then *host_offset will contain the l2 entr= y. * * On entry, *bytes is the maximum number of contiguous bytes starting at * offset that we are interested in. @@ -660,7 +659,7 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64_= t offset, ret =3D -EIO; goto fail; } - *host_offset =3D l2_entry & L2E_COMPRESSED_OFFSET_SIZE_MASK; + *host_offset =3D l2_entry; break; case QCOW2_SUBCLUSTER_ZERO_PLAIN: case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: diff --git a/block/qcow2.c b/block/qcow2.c index 9727ae8fe3..746ae85b89 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -74,7 +74,7 @@ typedef struct { =20 static int coroutine_fn qcow2_co_preadv_compressed(BlockDriverState *bs, - uint64_t cluster_descriptor, + uint64_t l2_entry, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, @@ -2177,7 +2177,7 @@ typedef struct Qcow2AioTask { =20 BlockDriverState *bs; QCow2SubclusterType subcluster_type; /* only for read */ - uint64_t host_offset; /* or full descriptor in compressed clusters */ + uint64_t host_offset; /* or l2_entry for compressed read */ uint64_t offset; uint64_t bytes; QEMUIOVector *qiov; @@ -4665,7 +4665,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, =20 static int coroutine_fn qcow2_co_preadv_compressed(BlockDriverState *bs, - uint64_t cluster_descriptor, + uint64_t l2_entry, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, @@ -4677,8 +4677,10 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, uint8_t *buf, *out_buf; int offset_in_cluster =3D offset_into_cluster(s, offset); =20 - coffset =3D cluster_descriptor & s->cluster_offset_mask; - nb_csectors =3D ((cluster_descriptor >> s->csize_shift) & s->csize_mas= k) + 1; + assert(qcow2_get_cluster_type(bs, l2_entry) =3D=3D QCOW2_CLUSTER_COMPR= ESSED); + + coffset =3D l2_entry & s->cluster_offset_mask; + nb_csectors =3D ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; csize =3D nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - (coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); =20 --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198154; cv=pass; d=zohomail.com; s=zohoarc; b=nOtwuZzmLo19/t+vy7ohDz6Tl0gJVmsJ+7FuxDEbW0NXfh+B1SABgAXzM7DXWIylaZMTJotW0fvo+gtTVxxsir2LUHGS2RGYBH1gjfqOZD/LqhJKcF3RCQwcyBUa+cAk9fCV1+nVqG7KXBmC985D9egFapa00tagXKsx2B/Zr2E= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198154; 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=UoZQ57TpdwrglEnFj/robC9eebGwtsjMEgEpePEUxic=; b=YDmYJYxLuYgrb/e1lheB13HANWtGyqS2ArrW/0M1vxTjz/eHvihEf5M6DWSFxKCgHq9WeheTiX/zlZ8mAyO/X63bvzdDYM7Q/PyuBa+z2f07BOGQU0fjDfAB6ah/zzr6qwD1t2qtZfXmqZzmWwsoQ2A5O7EYAAyzc/+ntk5otwY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198154356764.3204446202911; Wed, 5 May 2021 00:02:34 -0700 (PDT) Received: from localhost ([::1]:40656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBYH-0001Ad-6W for importer@patchew.org; Wed, 05 May 2021 03:02:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWE-0007oP-5W; Wed, 05 May 2021 03:00:26 -0400 Received: from mail-eopbgr70123.outbound.protection.outlook.com ([40.107.7.123]:51520 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWB-0005wK-So; Wed, 05 May 2021 03:00:25 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:13 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:13 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kNhbbQftrC49cRNRFCBlDBEA5rfe5AcD8XkMtIyPHmYt3hCJ53ouChQ17VOdke4W3L1HXu81OSPdGhPb3cOlXUviBOE22egZCrdKm2jCXah3qRDOWC5hFJIGAYZUsmeNnF+MhE0+cRdtKFXKbYy4ZlaK7XNxVrEYqDKSlZTiL8txRmRyJsP1dda5RX3OiatRdfMxAsIg9W5TWTJeavSkVhScBxbinaC6QLoT5XNX0/oJaxAdzqsDMYghrViPvqvo1l0luemGVpS0g2xW29APiTLJOv+/e7Dkz3HpiQ8nx9hAy3yblH5aJsr8YMjsAyGZBiDebrhJKFRrXbX4gA7KXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UoZQ57TpdwrglEnFj/robC9eebGwtsjMEgEpePEUxic=; b=CGN8L4ctbzMtG+GIRZPwu04C7FkWvw9/2wwjUos2uNYBMFgKTX3egqo8KoLQy0gR7graMDTn56KHEqYUQ1o4F7+LW6NAtsixlxadzu86PGowj+74k7EuTedk9EtJKJRi1JYtg8Mo/yAPQBFc+bTW9ex+OwaYFKgX3+3jF3NaojSBWiDLWfWNwqJAevBUwFmqfViy/gUlFi1iyWliWuYOeM/ZJ+SxFDzk2YO33WDv6pCdZ1LsFGLgTkqt8EqnJSgMNvC85D95Mp/i+EVn1aoKVKv4At8F6/DzQt7wLuTg8qvpHug0DeVam272WYHv478KcElgRkhmoSrDZMHZKqGhOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UoZQ57TpdwrglEnFj/robC9eebGwtsjMEgEpePEUxic=; b=cHw0+GUaWBdilQ4Gmwff05FKkhjncuL8Gvqro+nDfjGNRRvQM2bWUK7DCsU6cszDyFwO7kPMqCRU9fROE3H/tPeXmVqIBqeujG3o23uX2lqaPCLlSriDbcxrZmI7EzL00FDGEsZtnR3i/hxt69ay8naQ62oCic3RG7O7JQijWCY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 03/10] qcow2: introduce qcow2_parse_compressed_l2_entry() helper Date: Wed, 5 May 2021 09:59:48 +0300 Message-Id: <20210505065955.13964-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1ae9a686-936b-4b5a-cdbf-08d90f936e50 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1107; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uU/ALpn33OU6/72geEK/L3P1OWZQKsUuZk7eqMatWeb+7tEVsOK3kxzhxtP1E8Po9kFBPyrc2VjTAcsx8j9pP62rFPExPkmaCKI5wMyrfNoblpfOorRfCD8QQGuAZmdzrSux9xuAyDFkOHfQIK99e8U8dTLDahWiD25ot3tdMABtFjc5qOl3Yk6EEO+ZkYWm6UK+o9mQjE83wb3bXksKNFcG+hGybBFsgnPso7LXLALjfHm8FsUkUsS1C5YV1KhI3k6SRyxasf/Kay/CMT5mCAJZQWyk2/yPQRagf975zyEtQ+3HEwIvI4RBTMeEvic8IdhDH11tL2YRXxU8pkbggnaUqnKE76JoxGqa+gTp2BoB1jX+7iYNtHawUw0lOJE74V69/3eQKBBhHQlwzsanLmUWMCFo6egGFbLDbbkt+0ESnUqLm2/ngpjXDmftxjViOsY0xJ07TlWheEbm/fP1MXfo1HCcuXQqzIeRUbwkasyW67uLcXKF22B8k0wibOw1WUrIS3iw/QYgCYSTbJrqGKLBa3BoOXa6J4IKrDp0sZPUdG0i1hx/qYwKXKogBnO1Jo2jV2pjIf5te6T//KmJ2ZILO1/SpH2CCaEL3UknZLf6ZRVDQ+HYCMTNDUaiwsC/vp4pq9telA2IKMgppC5lsuSAj3zbwoBfhKyXgC53hnpnXSIzJiU9YQBQC5MvfCkj X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?At4bmiVavKjvCkrarQjuutW90fbeDbsYfY0pfEn1tIBKuL5FOI0N5Y9NakOU?= =?us-ascii?Q?qdTi/ycqbro6o6wwIEd2/eJOAUTtz4WX9eGUgpwUOqX9dU+HTV0Tb4FMNRb7?= =?us-ascii?Q?Rw03vESehxq8dbFUqPNVE4vd+rRi4Vj7OwsUBa5b2QD8BKOX4LsEkM7cxvkv?= =?us-ascii?Q?ZQrpAbm8YLWeXuS2X+qtKJG3TKmdO34GliZabxtntK4ytQxuAt4HrG0Z5aOX?= =?us-ascii?Q?Ck1GzpAqz6+QptS1o14A8Rq1DQnsxnpjShG2lSrrmstrKMXlbYr37FVaD6vG?= =?us-ascii?Q?8+dPOnAQ5iJhdRHBEK/xTLZTeGMlR7NrKq77K3AYrlSZGy4TG1Re3NfpHMvY?= =?us-ascii?Q?GBN0WDB+Ah8Q1MVw33+aVZiDDQJDxBUs8y/IpbQWtoY1O+cjRKRuZ2w/GFpt?= =?us-ascii?Q?SxMc1U8aJ/gDQyK6D3wlNW3OBiQP6UwvVHd0I7jeGE+2M4nk9VAQmXloAs4p?= =?us-ascii?Q?3Aec2GAT5GGb06OoxfUMXdfoJO44E+4HPaOkCQIlJfgIEYuVyTIQDerJbpXf?= =?us-ascii?Q?aDpeXIJclrmgf31wBRnvDdHeJdsWLMopngtG+kKy1iCU6ndHd33DDJJCT+46?= =?us-ascii?Q?QOw9lmhl6KJ0OozXvyU0AtfHwGB+ch267+Qshx2+vdUe5RdaonzzkkFNccNt?= =?us-ascii?Q?+f0mZLihL1ZG8TD0MDqViZWub2MaAyjBIp2LrEPhSxPA39RfzyI7vNz91gcq?= =?us-ascii?Q?sZhk9X1tLXnc9+uYBrH7oBpfY8FgM33VaQ5LeDcVuPz+fFMEEI4FO+O40NRC?= =?us-ascii?Q?I44Wt+1nGY8ww4NZDvG2CrBJDj93iHnSB+AaXKzgrJgqcTXAuaii/tq+XwR7?= =?us-ascii?Q?euSB3RiSUSeApEQrQu/2RHVuHIX48G76WaipWdLu9NpUSVydQmnEhEGk7VFR?= =?us-ascii?Q?33TrUG3FvZfPoTRAFx1+0igZqLh+jg1oNOipUf+664oaKpdl2RMoF8019XPE?= =?us-ascii?Q?kmHt5zqmWK04ifBUeogMjb9lKOu2/iAceyebINGQcrlhopTDXadI52OFbFbC?= =?us-ascii?Q?ouL1UOfuv3sLnG0AmY52dkzLEG+d9AcqzPdGscGek6puMfbLUXoeE4JMOkIE?= =?us-ascii?Q?qlZAZHXqL6RM1/jdeklf1Nluk2DDkLzvVZ1wHXrU0EHZ/FU/pqUu92kYJdy3?= =?us-ascii?Q?KgbNTUntX/bHtU5l+TmekkgTnXYxZZYQZubumTej2fpoi0MJnF+f0DHZ2uZD?= =?us-ascii?Q?nH5BnPuwgbJxk/CBVBZVtqajdXGL1N30adqr+S/XkKIckYzRsxCunpWpNS+/?= =?us-ascii?Q?XHUtMbV81UH0ybj+d/Zjus12D64XrJUhWtWHvns5DGeqZXK6NmAiGbq+dCci?= =?us-ascii?Q?0sgxx/oo+P30oOuf3Cdo/hE1?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ae9a686-936b-4b5a-cdbf-08d90f936e50 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:13.6358 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6hXjyOEEdmvyNf/eNoiLQXR4eanNoSCNhwU/AszSRBxqKHzr8+fZkf47YA7SMizBjUKlZPFD+FAucOPyoQEeCnzT3UmJ6/DM7ypG0o4/2+s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.123; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Add helper to parse compressed l2_entry and use it everywhere instead of open-coding. Note, that in most places we move to precise coffset/csize instead of sector-aligned. Still it should work good enough for updating refcounts. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qcow2.h | 3 ++- block/qcow2-cluster.c | 15 +++++++++++++++ block/qcow2-refcount.c | 36 +++++++++++++++++------------------- block/qcow2.c | 9 ++------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 42a0058ab7..c0e1e83796 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -110,7 +110,6 @@ =20 /* Defined in the qcow2 spec (compressed cluster descriptor) */ #define QCOW2_COMPRESSED_SECTOR_SIZE 512U -#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 */ @@ -913,6 +912,8 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverSt= ate *bs, uint64_t offset, int compressed_size, uint64_t *host_offset); +void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_ent= ry, + uint64_t *coffset, int *csize); =20 int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m); void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m); diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 04735ee439..70d0570a33 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2462,3 +2462,18 @@ fail: g_free(l1_table); return ret; } + +void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_ent= ry, + uint64_t *coffset, int *csize) +{ + BDRVQcow2State *s =3D bs->opaque; + int nb_csectors; + + assert(qcow2_get_cluster_type(bs, l2_entry) =3D=3D QCOW2_CLUSTER_COMPR= ESSED); + + *coffset =3D l2_entry & s->cluster_offset_mask; + + nb_csectors =3D ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; + *csize =3D nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - + (*coffset & (QCOW2_COMPRESSED_SECTOR_SIZE - 1)); +} diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 2734338625..66cbb94ef9 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1177,11 +1177,11 @@ void qcow2_free_any_cluster(BlockDriverState *bs, u= int64_t l2_entry, switch (ctype) { case QCOW2_CLUSTER_COMPRESSED: { - int64_t offset =3D (l2_entry & s->cluster_offset_mask) - & QCOW2_COMPRESSED_SECTOR_MASK; - int size =3D QCOW2_COMPRESSED_SECTOR_SIZE * - (((l2_entry >> s->csize_shift) & s->csize_mask) + 1); - qcow2_free_clusters(bs, offset, size, type); + uint64_t coffset; + int csize; + + qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize= ); + qcow2_free_clusters(bs, coffset, csize, type); } break; case QCOW2_CLUSTER_NORMAL: @@ -1247,7 +1247,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, bool l1_allocated =3D false; int64_t old_entry, old_l2_offset; unsigned slice, slice_size2, n_slices; - int i, j, l1_modified =3D 0, nb_csectors; + int i, j, l1_modified =3D 0; int ret; =20 assert(addend >=3D -1 && addend <=3D 1); @@ -1318,14 +1318,14 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, =20 switch (qcow2_get_cluster_type(bs, entry)) { case QCOW2_CLUSTER_COMPRESSED: - nb_csectors =3D ((entry >> s->csize_shift) & - s->csize_mask) + 1; if (addend !=3D 0) { - uint64_t coffset =3D (entry & s->cluster_offse= t_mask) - & QCOW2_COMPRESSED_SECTOR_MASK; + uint64_t coffset; + int csize; + + qcow2_parse_compressed_l2_entry(bs, entry, + &coffset, &csi= ze); ret =3D update_refcount( - bs, coffset, - nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE, + bs, coffset, csize, abs(addend), addend < 0, QCOW2_DISCARD_SNAPSHOT); if (ret < 0) { @@ -1603,7 +1603,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, BDRVQcow2State *s =3D bs->opaque; uint64_t l2_entry; uint64_t next_contiguous_offset =3D 0; - int i, nb_csectors, ret; + int i, ret; size_t l2_size_bytes =3D s->l2_size * l2_entry_size(s); g_autofree uint64_t *l2_table =3D g_malloc(l2_size_bytes); =20 @@ -1617,6 +1617,8 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, =20 /* Do the actual checks */ for (i =3D 0; i < s->l2_size; i++) { + uint64_t coffset; + int csize; l2_entry =3D get_l2_entry(s, l2_table, i); =20 switch (qcow2_get_cluster_type(bs, l2_entry)) { @@ -1638,13 +1640,9 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, } =20 /* Mark cluster as used */ - nb_csectors =3D ((l2_entry >> s->csize_shift) & - s->csize_mask) + 1; - l2_entry &=3D s->cluster_offset_mask; + qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize= ); ret =3D qcow2_inc_refcounts_imrt( - bs, res, refcount_table, refcount_table_size, - l2_entry & QCOW2_COMPRESSED_SECTOR_MASK, - nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE); + bs, res, refcount_table, refcount_table_size, coffset, csi= ze); if (ret < 0) { return ret; } diff --git a/block/qcow2.c b/block/qcow2.c index 746ae85b89..418779a43b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4672,17 +4672,12 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, size_t qiov_offset) { BDRVQcow2State *s =3D bs->opaque; - int ret =3D 0, csize, nb_csectors; + int ret =3D 0, csize; uint64_t coffset; uint8_t *buf, *out_buf; int offset_in_cluster =3D offset_into_cluster(s, offset); =20 - assert(qcow2_get_cluster_type(bs, l2_entry) =3D=3D QCOW2_CLUSTER_COMPR= ESSED); - - coffset =3D l2_entry & s->cluster_offset_mask; - nb_csectors =3D ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; - csize =3D nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - - (coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); + qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize); =20 buf =3D g_try_malloc(csize); if (!buf) { --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198154; cv=pass; d=zohomail.com; s=zohoarc; b=addTU9l/A4ul4sUr40mBxphJFg2Bxd/6dbk/gg1MBxjE/RpJLUQxXY01+2w8DE/sk80j+cGcbT01XA690qrcniwLYtj+5zsElo3w9OzCP4mba55brxxM3EvZNQrZdJoyp1obCd+1QFpZS+rRAloAP8i/0bAZ7Z2+9b+ZJA9gVZY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198154; 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=RZ5wxpZjo6CWp8sO9JbQAwX3ht0ArKOrRW9o8GTApMU=; b=gBRj0G4RAYfwAgW6r/iCpnl8aXNhuHq/G5phZoHiOL01vwcFCYZhZzPisBRA9qaYGLKHtVnwntsQsTEhtuvSzEpc82vDUv3seiXXS8gXbSrcMVcljrryJjPtnq4I+daG9KuJaD5KY708leTLBJ28zYd1nOwdkXHHJXb1B7w4m9A= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 16201981539431008.5962491070338; Wed, 5 May 2021 00:02:33 -0700 (PDT) Received: from localhost ([::1]:40676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBYG-0001BA-O0 for importer@patchew.org; Wed, 05 May 2021 03:02:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWE-0007pZ-Rt; Wed, 05 May 2021 03:00:26 -0400 Received: from mail-eopbgr70118.outbound.protection.outlook.com ([40.107.7.118]:64516 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWC-0005yd-KN; Wed, 05 May 2021 03:00:26 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:14 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:14 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UVNoXReqGQ7kGf3Wm16KbaglblYH6iW/3xbLVET+uxh8jaJLloctS0IDLu40795lqr+ZfG4dsj6vJkNZXIzzxByxsW8m10i3Jh4il4GlmEVD+YQdnHChi0j2fsRfsSDxB9LCL7hflZs3QwBSsbrLzTfBtRgICBV4PAoYfGm4TiXEzXRLaHDJvAxSEShCwqURwQIEraVaq1lruWvo0iTkbnGuBHGxSC6kN7E30H/5wzJPpeXKzXZVF7tMvAAnqKqb8T6JN/vyWeX5fiEzg/Mb1RYNvrzg6x+2I5dz3T0rkNjL1GIPSqnDDlTL9h6IZfBXDo8oBTYhII/hSXSZP+BBhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RZ5wxpZjo6CWp8sO9JbQAwX3ht0ArKOrRW9o8GTApMU=; b=T2znpbT+iJ+HqLJHEOMs+96yYtFc1ag8sanRn37ZsJ4h7sc71sNcNE0gNYaSlmYVX1s1C1IowEwVJg6yqDckCRoHUbPkfhrHZFkf8Y+halsjhUc9GpELpUeuOL9d5ZYPH+HRwCrAZIgLLRTq46a9FfAQ/LUuihm+D2yG8ub8ecYh8GyNqts0j9rJ0GXJthyPMKM6B6cWN5Ms0UEznHcmVElmZx4VQjgkfh+K4JkqsRh4a+aX3qOony0O9BtOpI4aXRk7IL0hrx6iOLyMcx3UQ9Vh/bTfRdgNHTcXoIh6RGoZZNWh2wl5MYaeltB7dYjs3zOe106ev0PZgZ6whSwObw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RZ5wxpZjo6CWp8sO9JbQAwX3ht0ArKOrRW9o8GTApMU=; b=Omc2uFSEloxkQj0zYiRTrPCyJ1P6faseHKejXDRG8oUgEhP3c+J64+y+FBwkvNg/6tDZhOQVzQxPAXpX2VC33+1A+NsM6y5vt/fBOP2oG6X/s+JWEym7UnmCe7l07e2sdI6EupW6e2FrSHPOEIUL80QRTrvzzWuE7Y98BQi1E3A= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 04/10] qcow2-refcount: introduce fix_l2_entry_by_zero() Date: Wed, 5 May 2021 09:59:49 +0300 Message-Id: <20210505065955.13964-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a9a54e2c-8331-4627-79ed-08d90f936f08 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jSblhS1GDhCflRlRIitfX5qPYe1PNRAVCKIYxM8Jk6zEJxEZB9cxE14XYUPQ6j6wGtVAJFP9vLXHlFDtrpIcz75K+/Z7FwpPsjUnJMfeDqYiBcps1q0kQTS4uw/WRrHsG+E62Nog5bcX5BvaGnBaEsNdtMB5DDXqC70PqEA8BOyZrv+WU/rScNvjOSVIGtGDaryHI0bVTqXuplJbtlHqmNqPZ+iVro9eLJW69j8JlBzTjXiQX4SzOZjv91AT0TangcVotPZWBGnsKVp06EE70zbeBwPj3M39Gay2W1uL061Piu+tSerS7TxVaaHok+IG31Drjk3D/AYdpLGO50WY/I3xbKIcjffRPKyagNp2//StObnBURngKY7zsxFSbgWCFmetYVh9rBHUzYYg1vv8vJzVqvUta1wqSujMD7YwDACqT2ER6ryDa0iC8pEh3O+3voU95Vwe9chnYuaxQJKeXMjuJ1soHqs65PLbSlPfxDwMXuyBE0AtGQL51H9bwGbb/oHOIvPqHQHOCjQGC+Hn3yDCiQi2UGS+7KamsALL1Li+D09TzkbTCcQP8tVz8iBLpX4IzJXoTOndcybzHPJvASArPbyRzwfXLIK5NgvPhWe07qWiwykLpI03Odh0dT+kO11r9UWcu36isF/I9xrXaMih0uozZur0tEEoIy0ndLZ63nnynnue+B/qejeuhlAG X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?Pzqv8tkakPVIunxBsitoVzops9FDhyQAjFb9TCYP99/zwTXUguMPZHdkngu2?= =?us-ascii?Q?lJalfAQuyMQwRDl2lOqU8dnNiB2rFBwx3bBhPtnQy31mYqWGId33bv1NiZb9?= =?us-ascii?Q?ph5tgQX4rMUHZaNWk7voaNXsJcXCZZdCWsfG9un8TyRq6/vYT7b8VwAMFo4B?= =?us-ascii?Q?GNV/BjCKt8s64eqzIUnprc+8WkL9Vdju7/jdSV5MxBLBcO0loK+MlTF8wI6w?= =?us-ascii?Q?N1Yxr69ZnitreJ79DbAjuyoOQqe5tIxZrzi5lXJOVdFyjfkxv4QnNc8W073G?= =?us-ascii?Q?uPTJPrNuj8GD8Eh93D57ambGwup78cn0SyzbXnQxZCloc+F8yFX3BXJDxQ9k?= =?us-ascii?Q?wOBm3s39/Vfc0eLl7zwM5uXgAGaxvjo4ZCGBYq7wWXoTcavfTu2VlbcOKl2U?= =?us-ascii?Q?ZZKXruh34XQEvI4nzomfAMuG6P0qZI636Tq3MstREBMZkrLiUmTnBR04wjub?= =?us-ascii?Q?UadVIjg9vCiUy6UWv7oMrTCEOXluDku9013jUdmeXcc5z0tU1nIZmBy0xE/Y?= =?us-ascii?Q?rO0FiMyEbZYQVZ7FAF/FJOpcQnlSZXhvjRNIkRNyG59JtA5arvABSpRawkZz?= =?us-ascii?Q?1jbtpHwB4UcZG9iikJfVM6KI+/rtaUWpEQ/8W1C6YYfeRM/3+oANXGTFP8HI?= =?us-ascii?Q?q+bjrofVOYr2b4E47Grs2fIUCpgzFnaOPfOApaUPloxz6XGV92nItyVVwlcK?= =?us-ascii?Q?Idq4qMTDg36i6yoQyBYm8vmRkO2OK0AVLI10frKLQl9A0XcH5InZM0Y9Rb65?= =?us-ascii?Q?N5sKbiE0dBYUm6TcHJoxvaduSZw0NA2h5fbUjgMneRonfiqavSJyOLqoB5aX?= =?us-ascii?Q?6oHmo4wIuFRc4sMEhqrxS5dJ+NMxfQcocvvSYLQRgiEQ6gobfFrW65gbXDqy?= =?us-ascii?Q?owiUevxXgdj+pSDkhECM3WuuMVrQIC4hFPjcWw71gzJjfm/n7jn1L+HYB/Zl?= =?us-ascii?Q?mzbiKRWwTBV78aV6k+tNA/312qDBtnfPO7j0W4Ftoqf1dX0M8/7RKWFWSrOQ?= =?us-ascii?Q?Rg8LfOUp7GYeULguHBEPtY0TAuNrUxbgkOkA0fu27MwSvlyGjIdN/r9Gdn85?= =?us-ascii?Q?Lx+UQdQWOudQcMEJ1uwLFTQ5dAPJUB/nLJZKjctwQGD+JOBIgrC6Z4II7p/u?= =?us-ascii?Q?EB49sO0TOhVv538WB+fLK6zzBHUhXCpLjGXdPxU8KZqW9/XBAi7BLmnWtcs/?= =?us-ascii?Q?qS1IlVPMLqJMMYTzYA51rTVMKJ1u44SVLJVMZai3+fX0+LONEjpLGsvygOXe?= =?us-ascii?Q?5VE5qQG1c2EjCrsNMc1M9SWUq4Hc/1b97ErBrbnIR8gtkXsoB+j085FZ9okk?= =?us-ascii?Q?dUIr0+DCAN9pBiMFtVxpTl0o?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a9a54e2c-8331-4627-79ed-08d90f936f08 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:14.9002 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WYC/2rts83GRgJHQciDzHQnkAboxJZNk+WPFNWqDXMSLdfRvry/uGOULZfL3IXrS0zY55hBI9ghMxYuwwPJx8Ex7zjPO851IseUJmo+52S0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Split fix_l2_entry_by_zero() out of check_refcounts_l2() to be reused in further patch. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qcow2-refcount.c | 87 +++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 66cbb94ef9..184b96ad63 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1587,6 +1587,54 @@ enum { CHECK_FRAG_INFO =3D 0x2, /* update BlockFragInfo counters */ }; =20 +/* + * Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN. + * + * This function decrements res->corruptions on success, so the caller is + * responsible to increment res->corruptions prior to the call. + * + * On failure in-memory @l2_table may be modified. + */ +static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res, + uint64_t l2_offset, + uint64_t *l2_table, int l2_index, bool act= ive, + bool *metadata_overlap) +{ + BDRVQcow2State *s =3D bs->opaque; + int ret; + int idx =3D l2_index * (l2_entry_size(s) / sizeof(uint64_t)); + uint64_t l2e_offset =3D l2_offset + (uint64_t)l2_index * l2_entry_size= (s); + int ign =3D active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; + uint64_t l2_entry =3D has_subclusters(s) ? 0 : QCOW_OFLAG_ZERO; + + set_l2_entry(s, l2_table, l2_index, l2_entry); + ret =3D qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_si= ze(s), + false); + if (metadata_overlap) { + *metadata_overlap =3D ret < 0; + } + if (ret < 0) { + fprintf(stderr, "ERROR: Overlap check failed\n"); + goto fail; + } + + ret =3D bdrv_pwrite_sync(bs->file, l2e_offset, &l2_table[idx], + l2_entry_size(s)); + if (ret < 0) { + fprintf(stderr, "ERROR: Failed to overwrite L2 " + "table entry: %s\n", strerror(-ret)); + goto fail; + } + + res->corruptions--; + res->corruptions_fixed++; + return 0; + +fail: + res->check_errors++; + return ret; +} + /* * Increases the refcount in the given refcount table for the all clusters * referenced in the L2 table. While doing so, performs some checks on L2 @@ -1606,6 +1654,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, int i, ret; size_t l2_size_bytes =3D s->l2_size * l2_entry_size(s); g_autofree uint64_t *l2_table =3D g_malloc(l2_size_bytes); + bool metadata_overlap; =20 /* Read L2 table from disk */ ret =3D bdrv_pread(bs->file, l2_offset, l2_table, l2_size_bytes); @@ -1685,19 +1734,10 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", offset); if (fix & BDRV_FIX_ERRORS) { - int idx =3D i * (l2_entry_size(s) / sizeof(uint64_= t)); - uint64_t l2e_offset =3D - l2_offset + (uint64_t)i * l2_entry_size(s); - int ign =3D active ? QCOW2_OL_ACTIVE_L2 : - QCOW2_OL_INACTIVE_L2; - - l2_entry =3D has_subclusters(s) ? 0 : QCOW_OFLAG_Z= ERO; - set_l2_entry(s, l2_table, i, l2_entry); - ret =3D qcow2_pre_write_overlap_check(bs, ign, - l2e_offset, l2_entry_size(s), false); - if (ret < 0) { - fprintf(stderr, "ERROR: Overlap check failed\n= "); - res->check_errors++; + ret =3D fix_l2_entry_by_zero(bs, res, l2_offset, + l2_table, i, active, + &metadata_overlap); + if (metadata_overlap) { /* * Something is seriously wrong, so abort chec= king * this L2 table. @@ -1705,26 +1745,19 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, return ret; } =20 - ret =3D bdrv_pwrite_sync(bs->file, l2e_offset, - &l2_table[idx], - l2_entry_size(s)); - if (ret < 0) { - fprintf(stderr, "ERROR: Failed to overwrite L2= " - "table entry: %s\n", strerror(-ret)); - res->check_errors++; - /* - * Do not abort, continue checking the rest of= this - * L2 table's entries. - */ - } else { - res->corruptions--; - res->corruptions_fixed++; + if (ret =3D=3D 0) { /* * Skip marking the cluster as used * (it is unused now). */ continue; } + + /* + * Failed to fix. + * Do not abort, continue checking the rest of this + * L2 table's entries. + */ } } else { fprintf(stderr, "ERROR offset=3D%" PRIx64 ": Data clus= ter is " --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198468; cv=pass; d=zohomail.com; s=zohoarc; b=gWeVUw5/EXmOIk66XLRnSS3naV7mE+ifJES3eJgLNredK0SttsthfdGevJIrFk9jHQNjhi2e25Um8B+1cj3ZjmXNNr9JRB1fE57zP/lIQYa2pPmFrkjzMNcmvHCkmhTQp/XS8GXNEGJefeapguWQYPgAjROr69xn4M0GAj9dMIs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198468; 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=tJSAqSMQChtTeR2gMDl2jR+cz13jXFGwW7pDat7i1tE=; b=T16+YGqjUATjUtFGmwj0GHA/ly6Q87Gzs8ExpinGTYK7ztBw4OoQ2fI91ufe/k8rS8/hGr6RJvA4M8EcaRuTEw5A0H2FuWC6hMUJTMLA8aOLYU7nhwBGEjYHLWKLaOrfOTNlLEHpcw9K0Sgoo/Bvch20RCjjLST+YxvP0vR+k10= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198467823259.2779694553785; Wed, 5 May 2021 00:07:47 -0700 (PDT) Received: from localhost ([::1]:41506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBYT-0001VX-NH for importer@patchew.org; Wed, 05 May 2021 03:02:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWH-0007tr-2N; Wed, 05 May 2021 03:00:29 -0400 Received: from mail-eopbgr70123.outbound.protection.outlook.com ([40.107.7.123]:51520 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWF-0005wK-1r; Wed, 05 May 2021 03:00:28 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:16 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:16 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zww33MbwRRPyOcwwu/5jv0+tfdAUPzf7fOv4e+LJnRELb61B6+la5dgRHI5+UlVPouJv/SyN1diJ9TcpQilWG+aqBTcNN/9ghKjgJsSD1yD3K6is8tPEXLecG5yYxH4rrXI8PMm51Ckpk4c4oszppzGk6E+HdhfLO/Qaos6Dboue9o+mUjDK3Y2tVM2JHflm0Ri0iL6dR6wY1g0ns4GU31IN1aWykKAfBSdBv9sHrBjUaVlW41rsJy3aVJH/6Y6OqOtKt9Gp9LirDzzp1MpSRQjFDdfVzLUx/GEK3g0VYityA3aCXOMMMX3Ivdt52QqMJEFTZTOh7Zd6zSyltyQqSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tJSAqSMQChtTeR2gMDl2jR+cz13jXFGwW7pDat7i1tE=; b=UYjRror4pRJaCgP1PuPaEPcwV+QTfKs+DiVpl3LXFWZdkn/fBmNXWTp1fIhY6p+88Q1Y+h7qeO/x1gP6QaDTRutNOIzlH6BFYxADpdDworv/GREAfD/9qVakYxtjq4IkzTr9VrlTf0kL9CrTOIIGJjaVi3jJZf+I1nwuJFKQmvtIUKqfGhlHaV7sczrtem4bmraLJvCV7AMx8Jr58oJlNIBU/HyOiyEjfzSvpuDQlwOwOtnA8ZXjPfzhiXM6WgHlt/OgIcPY74FzOvffctB4L2MMo8AMHJy0e7Ss0sE/6zHfFs8LovYH6uzmFyuhVF3tjokJeJGVGc8Z+gsO+zQYlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tJSAqSMQChtTeR2gMDl2jR+cz13jXFGwW7pDat7i1tE=; b=S2DugQcXFa7e7XLIm/nSaTtyMDB5LZ8w04Olawm4W4RIQ/QkqSvxT1HexzbBX064IFpmbsPntvmGvcVZ6qLTCvjoKrz8K2sMEbG1s8jf5pYAja9Dg8LJ86EeDXjfbr5NC/CniP7cDQXjSDyO0ORNb102+ns24BRAAUp9v/vXcdI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 05/10] qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry bitmap Date: Wed, 5 May 2021 09:59:50 +0300 Message-Id: <20210505065955.13964-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f6a7416-8065-4e52-f6b8-08d90f936fe0 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:136; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: THKD7Dh1miY0zQrHTuJXZ1oS3vlIVpu1h7APhlTkTZDxeTC7Dncig4og5Ftt5mNvUUF6MEAeWbUECHPdo5aj8myhOxAnMp1atQ6g6hQpoOYTSZaupGr1FRTDYacldfNrjslH1a70dP7cYI3mY4XKpl1DjJ/1AypTJULy0W15HsHY/iW6Dye8AxqCgsjY0W83QDlxwuIdofO5iKgyMkB0bcauuY80K0MQqyNGmUjQtKtTSG8rGVQhLb8WlDBPDBjgXRVSF16C6lH8mLLNxr61ps0hAi/Nh9tjGxZozc4Dp1pft6jpH328yHulwRwLbi8UNjOeOZoTTuVWUKZ2O1ER0vaNzwn50FwcwQVr4Uit67ZcvGIjZRyH9sSe1wmr61AJLj3MRzAj0l06CFKXPo/IZ+ZGRvC23jxHGAHOHkyH6jTsOn78E8nLSGTPKE9TRs/q5PPLrOrLbCuwaFKm35h870iPZY7AzC1FS+ie00K12pB5hbvzjRkPKdzhWyfmeCgUrD/x6UlkmCd6DtgUUH271LiQYxifY2G0bqRWCKUyaqQoKh9ZMx5RBX4MiDaYwRUTbGa7dDGq/JYagVni/D/SCT7fYa6U+OHx6xU8KxS686kUa9/O0qtXvcB0Vddh4MLdgHElw0YG2ZM4njqqAQX92G0JFECWhM2p2w2HUFlbcJDPh5s9JKtt/jBoCI37FJu4 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?xdeJ4WzIZWnDUvUwTXlCK3CSQ3nhM1weCNDjXnDJ9NPb/dT19iGRHodjucmN?= =?us-ascii?Q?bSxCt4xFwALsV6BlfRZwPZkwXz/Kc8TmJDpVN176QadVytdlgX0hCS+GdiIi?= =?us-ascii?Q?ef6lUxunspOcgiDxI2V2eRk1hoBChyk1QQyDguV0XsrvNJox8Xc7Rk7xqAu1?= =?us-ascii?Q?wSwdFs46hcrWo6YPbDqLumGr+DzOpnV0t3oR2NReL4pa081KsEadzEEr/MuU?= =?us-ascii?Q?KAk+DntYMFG23XhYH7WqtD++8+5hwUq449/8nkcHoAYW3tBz9apRtvemp787?= =?us-ascii?Q?Y8yilT+a2GBNpOGQ8j0wYmi1LgU7wZg+aS2lox5MuZQxqF6tYwcbztRfvlkL?= =?us-ascii?Q?qiQlYt/5JPBctpc82ZinsLm/vBYi8MN2+9Kr0AYFCb4DpAoPlSQAgB304CFH?= =?us-ascii?Q?3RyrgKQ8+TGji48HPxy9olIYIBhVHrNLYxGmabPnzL3Thh/k4M6pzuOw9n/Y?= =?us-ascii?Q?+IUJlDKLw7NX7D2Wd0Me+USq4zhUgHiISxsquVZU3LfNOTVrW2UVAJiuqsjl?= =?us-ascii?Q?BED/05zfCU0ZDY3HjPC/KV4EfBIWYUGmMFE7O4taIyhvOvgqSJ6eHgdBQDSV?= =?us-ascii?Q?qP0RznBiYPKIin+e3WG72VSSHKoj8MDf3unNKmp9h3qsN9FuOeT9nEii0hQK?= =?us-ascii?Q?s+hUiR+kP3jPegE0giwibv5+3SkvP46NQJkJYa3m/sUmiK1fhikHGXmOVIOM?= =?us-ascii?Q?KRsZ6Ew4sZwY0GhDA64NUzL6uYNVEHJ0eRG9tqMoT7rEL5gjLUtIu4NRpmZx?= =?us-ascii?Q?TVguwwveznApRCvhqNBtt4Hw+xyEzTaZaKYIeGIFuasd0kxELtr2GKaDKh38?= =?us-ascii?Q?XbH66FuhDVLD/LEzsdtAWrUQAkAOn4ziElFD8KEKCckEzuAklqE+ebpsrtBq?= =?us-ascii?Q?gIH7wJhNIh2Xnx5gTFGLHhH+s836gtW9PZ6KqKXxSEF06WG8dVLfMcKMZSdN?= =?us-ascii?Q?hgWk1LBiYW49dkmwzBtK2a+yoDlkI9KHXq8783oJDne1P/fA8xYZZq9V5uea?= =?us-ascii?Q?JkPcn2uPUnLJk7zXnO7DFMaC66T49lbNIZpiJ51DfVrrjqm9DXNainJOvaHJ?= =?us-ascii?Q?R8JOJrPYkNyu2n/Vi3wf1+tTVe6CkEopur16cGJWhPeo7x3qPdazfefd5NkU?= =?us-ascii?Q?7xgea3xYXt66vTVTJiAn/M15pBeFlUWpTGA8s62WV8bKM5CRJRu9wqkqL0UH?= =?us-ascii?Q?OVtwWyXN4EgDfvNSTZDcEOdDrvxocbEQLA0thKNKoZzBfuxHVBExoggZJl/t?= =?us-ascii?Q?x2/18ZzZt5mIvmFbC5Y6Li3j/TD4VGEUaE7ncctAJE9hYpxz5+UcOQqcINkz?= =?us-ascii?Q?FMh/5wlM84Izk5ZWBzv6W70I?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f6a7416-8065-4e52-f6b8-08d90f936fe0 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:16.2732 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kmDkJ9oLQW0UP1QqhKrGtO7HVB83RYJaUlw0wzxjQPlUx/cB0O9aGnydgS+TkIQnAd7qJPebgQI2mWJyuwcGjd0qsXeHlkOn+9we/ZGTmks= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.123; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We'll reuse the function to fix wrong L2 entry bitmap. Support it now. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qcow2-refcount.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 184b96ad63..f48c5e1b5d 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1588,7 +1588,8 @@ enum { }; =20 /* - * Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN. + * Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN (or making all its p= resent + * subclusters QCOW2_SUBCLUSTER_ZERO_PLAIN). * * This function decrements res->corruptions on success, so the caller is * responsible to increment res->corruptions prior to the call. @@ -1605,9 +1606,20 @@ static int fix_l2_entry_by_zero(BlockDriverState *bs= , BdrvCheckResult *res, int idx =3D l2_index * (l2_entry_size(s) / sizeof(uint64_t)); uint64_t l2e_offset =3D l2_offset + (uint64_t)l2_index * l2_entry_size= (s); int ign =3D active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; - uint64_t l2_entry =3D has_subclusters(s) ? 0 : QCOW_OFLAG_ZERO; =20 - set_l2_entry(s, l2_table, l2_index, l2_entry); + if (has_subclusters(s)) { + uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_table, l2_index); + + /* Allocated subclusters become zero */ + l2_bitmap |=3D l2_bitmap << 32; + l2_bitmap &=3D QCOW_L2_BITMAP_ALL_ZEROES; + + set_l2_bitmap(s, l2_table, l2_index, l2_bitmap); + set_l2_entry(s, l2_table, l2_index, 0); + } else { + set_l2_entry(s, l2_table, l2_index, QCOW_OFLAG_ZERO); + } + ret =3D qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_si= ze(s), false); if (metadata_overlap) { --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198476; cv=pass; d=zohomail.com; s=zohoarc; b=TMS/EV3+CbCn+nA991yiApt24Bk5VE+lGw/opfhGUH5kd7ozLSvlel+NdHF1OxPYXBEGWeetYa32YKqn8RAwwy5D7UiXgJWHGYx864Rf7iZT1oSNhinJ60PhzpmwaZ2LGlV1aWVaNKrV2p+i1R5NtBiVLlUJWpmRQcbPtFw3gCs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198476; 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=l1GsUaDfim50SnaIEID5KcE5RqXwxEjZIEX0ir3DYXI=; b=aLUMqFWNHo2F//paLw69H0MIofXTRuTWYi87ydnJIwvIXSL11UiwlheH7GQ1iJqWkHcEmJOS4BUMgn36ai0CL1xoD4HTBQ4NACJ9zj7d/uBP4gOj/JJjH/Wzw+uTeMdb2ChEA4eRFR7fk609p1kEDRG5lbKR2a3Q1Pz0Xy1B3CU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198476400808.6162413266279; Wed, 5 May 2021 00:07:56 -0700 (PDT) Received: from localhost ([::1]:55270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBdT-0007C9-Fq for importer@patchew.org; Wed, 05 May 2021 03:07:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWH-0007vN-RP; Wed, 05 May 2021 03:00:29 -0400 Received: from mail-eopbgr70118.outbound.protection.outlook.com ([40.107.7.118]:64516 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWF-0005yd-KL; Wed, 05 May 2021 03:00:29 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:17 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:17 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LMb0k4eMQb9fdRugDMIR04u/ZLwMNrfsZLgacFrxAQq07NRYtLw3MC316VFDOol/qMeuKG2k9whPQ1lOPxB5S7aI1Iho05Kc1vPnQkt/tGjAcIF9eX4aqyJNloURQ35hpnArJzK1mDORMoJvTp1+H1kX5wdbHm1BX0RQ8vOkt7ADka1hWSMUbyh2BIi7Lgj/R+a/xjt5VNE05yKL1SIM4VaVB3npiP81o8mTEvgB8rP9oU9D2aONSqnrVEC/pzwTfagRq6buuV8XA4eeiNO4X8NQgGlM37laVweWQA0XW0uINv6292WNIPX7FVbKMZEeYIf4bY37x1BTa3UdXPZOvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l1GsUaDfim50SnaIEID5KcE5RqXwxEjZIEX0ir3DYXI=; b=cupkjcm10jb9rcxHCYK2Aq6qVQmKYYvD/pQrtm9Xi97o0pa8tMmHqwZQEh9Yw8VSEImeCUCWQgv2S2Ds3z/4nyBbyfet4YZ8bzutgkSgg33NQiqReFKZ9exs09dNDv0gvi+4dQcvFoDm9wdzA2k8cEZv3ZZvA0chhSajjPFxCHUq9S49heA8X7ig3GjxyZyHm8/aC7jUYENqA/KRFISOqV8cF62yLwdOrKb9M+Z4aKplfXerqW4pBuMtDa6CLZ89P/k8suYouH78aY/FgJAahSpzp+Z34GMhLs2xUEEDz0S/uwlJzKVMmRQE1zel/Smo3rWatQpluRm6GesBW7hLIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l1GsUaDfim50SnaIEID5KcE5RqXwxEjZIEX0ir3DYXI=; b=pKDtW13m7uAEpKSGxSMr8F1vGiTeRPfRGYTYpgXF4nNFPBg2klGWHgWP7PljuV/7Mm3IgzNFm/nj3Oq/CH4jNRz40ms6JKn9Os+HFUuXzA4ij2Q229fKfC9Wm/ijT0hGHWYg34ABFZmV5F2DnyxduQdIhb5keJs9GcVblSHM6Fg= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 06/10] qcow2-refcount: check_refcounts_l2(): check l2_bitmap Date: Wed, 5 May 2021 09:59:51 +0300 Message-Id: <20210505065955.13964-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89ad73ba-19ad-4f44-9d59-08d90f9370b2 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:389; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7t9GabUcr3aBpLjW8A9MqJTtazBRlo7cgEL6/dmYRHNBVZo6ge2JrXWOGBFBA/QUC+tCToedHVrGKmQcFjTvXj0GlLpJ+ZhR6IhD62aP6oGsAMFInXzxPEcEC7o6B2NRdJkLPjbhHTlijCaraNt9cTiMiM+xfYmQh705RfYHo1+JNjGhY9OKJMc92cngx5L7vlsU4EdldWVMj+kMOIivDArDEqnsy/8marvVDtkkY0EKq/62iNLThBCnEAKusPH/31yVKfOIPENn5enR5JVb3d53e7LVT2Y8jMnJd5E35ZjLpL7Vlz+5EWfKkP3+m3pTPryij6Rr6RqVIJ2kZpdWnwDbztg09uJyGyAuYmqOrDt1z3qjk9smLn1Bepus89aMe8TVyI5tMbP8rc7MaqfjS2l5cVF4i+8T9sjTEVs9+G1tTXNcbZNDjGK1OVmmoD6K6O9InR60yNov1XaxDG6iICHorfx8qoBJqCa3MPOxoD29DfOk1hkXWFa3s4G8TYoyJ4kr20pZ9JRng6LD8hETGlOYc4zhA6mN0e1BPXBGI3yKNxsCSUKhUchk4rXFI573O/qdWxX/3htC45SWifL5X7goZ7H2hf0HcwEV4AoFpOUGCCvSMaRBqouXGs1Z4L1VyUVdaVH0O7eqZKQWauGxWFg9b9+XQ3SXbh8FzappsmgPuefMLrLuNTuF7xd9z+wM X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?8s/DvbgZHYBVfZrl8TQsxS1d702pH2eOlXmXtUvdKwqs079Mp21VBnxApyN3?= =?us-ascii?Q?AUgjIWSHBiyJ1UdQrnXCnFA+H09bU6inxLuUxym7NNvK7cadaLoJIlYVZoPf?= =?us-ascii?Q?LtwecrYmtKQ9TKGHUKFkQWhRfw7huvA6de50zgtA6R19B4tKdmPwPwNxj1th?= =?us-ascii?Q?Ibp5CR1CnZRo1kBM5b1CXFjh102etNvIleq8eSU99K/ok/Pd3wEAoZlSbbCP?= =?us-ascii?Q?fSSoDF+bIBy869LMwriAOAzou1BEMTtihQquNw08ryxgdkx2FG/gE9+Qhmyh?= =?us-ascii?Q?KcOwEFFmRXFvYgyEMz8XiM55wKPdWTjjimRiykucXZFpt0DB7UMHkxpv4dNe?= =?us-ascii?Q?x4x7tlL2yLbTlwDFc+A6NvEfi2bsCjhK7HIMRrZKOdKmnYlbKDTFi5AEF0yK?= =?us-ascii?Q?rPCf3trrstfhexQYxOxp5x4R7M2D2cB3jJWCglGef+n8/+kHM/WHnx0RDG+T?= =?us-ascii?Q?W1gcZMJ2Qm6RxAty606W+R1ErudVtx6qm3EJMWG/Px+cGwtsYkjdkl4nP6b3?= =?us-ascii?Q?4k1RQcj+eq4HMs+NXjH3PrEVkgku4YJ2JseWjyJdUIx/mSEgLVT9hhpNTTJT?= =?us-ascii?Q?q5BnDCczhyCKeW9BK/vt781ajo/5eUbiXpfa8WOMSI+JDfVYGCjUufsipV/z?= =?us-ascii?Q?NNmOzvx/y1GIFBvU8DjwXI7hRZJD4udy3JMiq8MYBEY6AB4iIa6OXsR6zQgE?= =?us-ascii?Q?TUY3UUPwtlR40IA5HALAU0qs05mZWmk39UyGXFlpZ8SvnCV1vHCZefTMZ+VU?= =?us-ascii?Q?txqYsiOwmeIG90L7UMOuyXcybY92BHTmC3vJZWw5i+cl7m0L1AFSyyF6oubC?= =?us-ascii?Q?PPXGLwnDE1aqWOoqew5Ww8E/3JjJShUjju474VdYiTCQSySb085wZiJEa9pk?= =?us-ascii?Q?rhXHACV1JLmat+WlqprdidgdWktPiNGE1d+KREJ3ZmKzNRBc8VV8kzk2dfcZ?= =?us-ascii?Q?TBkePjlhSAY2tSYSAK0xfPGSy6V4smX6qhqpzhn0+8bJWKLRFFkEBzBUyQ77?= =?us-ascii?Q?Co19UOHS6LxiWTyUOOvzjqS8G5+KWrTrR0NGSR3cQMZ/4kXQME+5BEjecSbr?= =?us-ascii?Q?toilwMhsVkeEaCWhRc7SMG3L1Zt5HTFcw/nTS7Reniwjh9/TmkDGn3MvsOMU?= =?us-ascii?Q?EsZUU/QKhfZPKdN5qyLWurPDKKMDRSt9+UQOi8o5G4kAHm/dKbuMD/krvD7R?= =?us-ascii?Q?C4E7aZd4TEjdtrGLAfIUxrhFAhCsZh6UrImg1ILigF60fmw9QvvyGRrIf+Dx?= =?us-ascii?Q?U9bBsFMyy6VG2H2ExK555yLkmqEKbEezBiYJSx4pN8glUc3NErED5mjtdxXz?= =?us-ascii?Q?GlkKSXIGwm/ZttShPjyXM/Yw?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89ad73ba-19ad-4f44-9d59-08d90f9370b2 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:17.6123 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zQ+mWG9L49KClv4tD3T7IrpBfJFIWyhMe7WgDbougLGxYiLwYzHANEKz3gAukoegV7BzyHjNNlkvleu3IbF2R4gKN9RIVdhabNf7kF/Tbc0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Check subcluster bitmap of the l2 entry for different types of clusters: - for compressed it must be zero - for allocated check consistency of two parts of the bitmap - for unallocated all subclusters should be unallocated (or zero-plain) For unallocated clusters we can safely fix the entry by making it zero-plain. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Tested-by: Kirill Tkhai --- block/qcow2-refcount.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index f48c5e1b5d..062ec48a15 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1681,6 +1681,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, uint64_t coffset; int csize; l2_entry =3D get_l2_entry(s, l2_table, i); + uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_table, i); =20 switch (qcow2_get_cluster_type(bs, l2_entry)) { case QCOW2_CLUSTER_COMPRESSED: @@ -1700,6 +1701,14 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, break; } =20 + if (l2_bitmap) { + fprintf(stderr, "ERROR compressed cluster %d with non-zero= " + "subcluster allocation bitmap, entry=3D0x%" PRIx64= "\n", + i, l2_entry); + res->corruptions++; + break; + } + /* Mark cluster as used */ qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize= ); ret =3D qcow2_inc_refcounts_imrt( @@ -1727,13 +1736,19 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, { uint64_t offset =3D l2_entry & L2E_OFFSET_MASK; =20 + if ((l2_bitmap >> 32) & l2_bitmap) { + res->corruptions++; + fprintf(stderr, "ERROR offset=3D%" PRIx64 ": Allocated " + "cluster has corrupted subcluster allocation bitma= p\n", + offset); + } + /* Correct offsets are cluster aligned */ if (offset_into_cluster(s, offset)) { bool contains_data; res->corruptions++; =20 if (has_subclusters(s)) { - uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_table, i); contains_data =3D (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLO= C); } else { contains_data =3D !(l2_entry & QCOW_OFLAG_ZERO); @@ -1800,6 +1815,19 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, =20 case QCOW2_CLUSTER_ZERO_PLAIN: case QCOW2_CLUSTER_UNALLOCATED: + if (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLOC) { + res->corruptions++; + fprintf(stderr, "%s: Unallocated " + "cluster has non-zero subcluster allocation map\n", + fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); + if (fix & BDRV_FIX_ERRORS) { + ret =3D fix_l2_entry_by_zero(bs, res, l2_offset, l2_ta= ble, i, + active, &metadata_overlap); + if (metadata_overlap) { + return ret; + } + } + } break; =20 default: --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198370; cv=pass; d=zohomail.com; s=zohoarc; b=cXGd7vTJ1Y8F8YruuOVzhnDd3dzNHCsmi0tQXPNyVDbli2h+fdntxO/r+NOvHsk+1M8m2VMywTLyyPcCJBwp4tXsCd4CpEfZ034A4PpLJrOck7POHJmG4CBg6JZJU1d1nmPjx9Xv+V0cvucrvM1IFMgfujF2Ok9ccF58x5jV8/E= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198370; 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=Yh7t0+Jcb7uOUCaU96d6uLUnxIJpp4mstPuBzzvRy28=; b=d25twlEKVsYxLOVnSqwRpaezSFstWdP1rkorCabJg5tdao8SwPHg2ZlbgvNij7x7jprycZCQF/Hxv/ShY0lWylhM2N7sdF6Rc9bTi2oowiDguwHkVe1ZUPCbSmCZyCBReN78ffWrlNHr5kr1ToZi+A+2ZWXs+IQDO3g86JFFDmU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198370756236.20080836769; Wed, 5 May 2021 00:06:10 -0700 (PDT) Received: from localhost ([::1]:50622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBbl-0005Dd-MA for importer@patchew.org; Wed, 05 May 2021 03:06:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45396) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWL-0007xa-Jg; Wed, 05 May 2021 03:00:34 -0400 Received: from mail-eopbgr70123.outbound.protection.outlook.com ([40.107.7.123]:51520 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWI-0005wK-0c; Wed, 05 May 2021 03:00:33 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:18 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:18 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N4NU+efsDHzNsoTozilJ1fwmXqrB050/rc6KV89pNwac16Tbj5gSLr3nqeyBbkI5RABQvVRJ9C2gx9a6Gd/IUgXtvHTzUXYNx5CfLcT5Qdnfem47cZGHP5m6kBWuMlRQGYjnhaGFfCXduZ0eh+AsJfsgXv2yGEyx+ZDySLY8S0f4h9KTox0F9M+gG0+7EMhsowPnp8hoS/65qM4nJEvYko+CF8o5+Q4+DY9FwObAnxeSF5cUECzzOI8vPigNE2LGmdf66+L/8YVoOtKvffKujADZjrd7X8uoSRzqQYDuMNvmhyeLLvy14DeMn264oUZXjifr9ezhTm1LDQKgL3kMXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Yh7t0+Jcb7uOUCaU96d6uLUnxIJpp4mstPuBzzvRy28=; b=L1y33FajpKV2tePmFU7gXzepwe1E8SJM1ZkU7RCEH9jAc3Uv11BFO2UbTCyip/LNcA/iZZHc/zdf1uCTX8se3qU53anozPBAPntPII9397HntDWHP/lIxx6ICbtSYgHjOhNPLvNevYP/DWFyP0qztNoCXgpgKSV6R8w7PKvgdD8B2BgcmfHgGmelNkW1W+Mv3vKjukOiOwizyEY6+edClRVhjBdkXit6QOzRENBQfwKulbuqQLmriIgOzMoeKqUIZTefDMALFKNrm0mPdUVgAcsKlp/yHzTpVEJVEJGQ/pyjKwKvVdccTb4892/94QUdBngR4F2+yp/zB9NSWa/5yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Yh7t0+Jcb7uOUCaU96d6uLUnxIJpp4mstPuBzzvRy28=; b=KR74qLdtSH5LTctxHDuih1dDK4hD4RWv812wXgBuRHiXPAiMtCuelflC/x6X7xB9XaOxVDmW+xG1Dci8n39Kvitvez4FuDIV31OyISXAWcg/m5iCbXupiCAyeRL8pmMReH+UWFamg+Qjj1AjN9eyY00jW9pT6HEvRaZYSDSAivE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 07/10] qcow2-refcount: check_refcounts_l2(): check reserved bits Date: Wed, 5 May 2021 09:59:52 +0300 Message-Id: <20210505065955.13964-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1de637da-2a3f-4eb8-be36-08d90f93716a X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:53; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JRRN/2OsQNs5GyW/mhzTfOvXJcXDc9yZ2vNIsmUEYsVUqM51LUsKKNJEiylVGTYjDUyZkwUJk6IdiRoe4a83V5TSYxPCvP3yIByNZ2ALEpgC6/NvltHFROq9o1hP3oI6fmltBu6bQoPRyb8sRWQods0SJFJ/NR4+wvB7cGmUz16pjdqiyFPfLNYC4iM610Pr4N1EkO8O+/GVhKrd3ihhNIfUkC9sJLNOuAeSNjs+hDpoT+sWZpbljOffmphCjPShQ/eDMqnjLToTFInXesVMSMdboOcgof5pAY7WDcmYUrANfwkRNo8gjhTArTglL8fZWUzjIp2j+rETaFez6jA8TPduPuyILR5vTEFiIlgz8Jf1HzGOZicn6Cvj2cMjob6kz3e4ogVB2bhb47+3dFSYKZIJMyQ7CuIkv93NvP2hjEKiKzOKEAneeTvasTM6SyDGGXOpEi7eAXt4eazJQtcjVhrz+dHu6CpP/R9HlwtQNTMdvfrPEvFRtb9TyVt+Ry3MLGz5oJUgI/xfHlAkuh2z7vL6haD3G4vz4j6idh8BMA7zhygf67uasbd32lqBp+oCNGptyuOukBOuP18SkUFnPGak0kyl8IUbwixkJ57dewJk6Oa5a5tpZhtMPyK8ZEjRdLm8LlbakHT8Y53K6XjRMP0Q9FWvxJA5oIZiE4VdqFg+ejVHBRv1gE6lkhjngKXT X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(19627235002)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?d9yCcraRkHWeQGhlfSAxCpkcifNS2/WA0iZOVHUUq3oSjGULZSRrpFClTr2s?= =?us-ascii?Q?lTYBEp3VFE2msaxb0mKTXiWAbQH7bvh5aGQVAQu+gVNk2UbRHtwhRqic5WQu?= =?us-ascii?Q?3I6xwXJDy9kuS1XA72+PHm3AK9MvusS2MpJIYI8Z5/KP3TOIKBo6WfjQFnKo?= =?us-ascii?Q?T21I/jFketl8awPBYRW50qoG//JpzcoR2bhi7lDQBQZnqznLCbhCMDRUybXS?= =?us-ascii?Q?052j5O2RubQ5k21+3CaAomWVs23Z5hlWaODYATfuyd9GZf82wu6Z981apFtF?= =?us-ascii?Q?0vGxoOZ241BLxNl7kDMfdXxooAmJd5jj5XXT2b5hzkzISWaiZzbI4VabOzbx?= =?us-ascii?Q?1PNOarajSvLSut99PUrpElgTl3EU8K9oV9JVot4D+n6JoDknROqLS41OrevA?= =?us-ascii?Q?PpN7aps0p06BKQj32D/du886E1+y6/uoF8E564VJSPUpKZgn+uVIEkbEf3yt?= =?us-ascii?Q?EGMJGjHyCeIalKhlVA5oBTI6DuMIcFx+LrExIVmYdl4imW0Ng/5zC6Zqd4xv?= =?us-ascii?Q?RWEydnGqVNU4FrJOQkxRDaRs5T9CPyBxC4+3irWnhe3kd/sk6NaY59VvTg+V?= =?us-ascii?Q?vjTCcsfrjmgYI8y+p2tolR6n9g6ICW69baMAKMU6IVMc7RVHVmKqCFWT8Fas?= =?us-ascii?Q?RPy1z6n8pP+X7JJcbLJl52bF4gLRfy2PYwGsdBW+pgRmXS6YkladnjgmHkWq?= =?us-ascii?Q?CmNTocNj8mJeVyWPnUhj9APXuvxBQY3ev14867wvnC2A33WaXh66PDpEFKEb?= =?us-ascii?Q?vvPazh8Vb9IQrwWySP2OwoifU2ZVjjHzwjgCOQf8P3XZKbjm/BzEoWw5X6Ya?= =?us-ascii?Q?bGuQ04GlPsuv9mEasQtm4Y/Xhh5PUy1PXJyrUWMfSAobU7i+Oo5b8+4ji/2a?= =?us-ascii?Q?WUW2/HwwrZ0P37aWC1pM4TJ6Ni+CBG6jnfdkXhWpzfY7s36ds/bZoBHPq1ka?= =?us-ascii?Q?B7LNOwAv9j+8DjeHUOhKkGFPU+HWcv2caKAsOJ5N6N9wPYXmkY33P6DZoL0B?= =?us-ascii?Q?2LLjExm4bjXcazBJbX2d4D8L2iCgez/Tmgi4Fq1ULvikSh5VInGgIlzhLGX9?= =?us-ascii?Q?HrU3QBlOU8zUT15nd5QomOZbhMGieL27RXREj8HOtL1L+snzeJnm75qxX08U?= =?us-ascii?Q?w2HgJrrAE5Dl6pmXzCYEU2qaHQhSYVTJ+/Ju03aO0RdeQSKvt1g+ZGkUcBhc?= =?us-ascii?Q?5D8C64GAaujZvs2JAQP41tCubX5S/7PU6RL5yQ9ujQtt/AKiSVhOvgvF/wBc?= =?us-ascii?Q?RJVXFSaTrV77YKmb1ZGUNUD/nUa1M+1NmV0m1dIzyMencROb5lZ6JuvhMuqQ?= =?us-ascii?Q?rTdxV5HRq4XiDJD5woKHSAeU?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1de637da-2a3f-4eb8-be36-08d90f93716a X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:18.8410 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZocvoLfEiLtlt6tcbyPkub8FCb3ejw/khs/7VcLkviu2o15ID+U1dlGVp9G1yvEKaRAjMgPBJBrygKxj00C3BoYOBCZip0RCC8GgsPu6v3o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.123; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Tested-by: Kirill Tkhai --- block/qcow2.h | 1 + block/qcow2-refcount.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/block/qcow2.h b/block/qcow2.h index c0e1e83796..b8b1093b61 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -587,6 +587,7 @@ typedef enum QCow2MetadataOverlap { =20 #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL +#define L2E_STD_RESERVED_MASK 0x3f000000000001feULL =20 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL =20 diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 062ec48a15..47cc82449b 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1682,8 +1682,18 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, int csize; l2_entry =3D get_l2_entry(s, l2_table, i); uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_table, i); + QCow2ClusterType type =3D qcow2_get_cluster_type(bs, l2_entry); =20 - switch (qcow2_get_cluster_type(bs, l2_entry)) { + if (type !=3D QCOW2_CLUSTER_COMPRESSED) { + /* Check reserved bits of Standard Cluster Descriptor */ + if (l2_entry & L2E_STD_RESERVED_MASK) { + fprintf(stderr, "ERROR found l2 entry with reserved bits s= et: " + "%" PRIx64, l2_entry); + res->corruptions++; + } + } + + switch (type) { case QCOW2_CLUSTER_COMPRESSED: /* Compressed clusters don't have QCOW_OFLAG_COPIED */ if (l2_entry & QCOW_OFLAG_COPIED) { --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198494; cv=pass; d=zohomail.com; s=zohoarc; b=GQD/Ec0Yl95Tx5bRCIl6oG3slKIhKwTlh55rdoGQfox9tw6oLyiPZzXl9Hy4k0jx+8wKuI01JsLs6RIQjgelRUf9V9uPuvy6Zlaw33pD8BZdZytxUztiS/O/1HzDBjJoPsOUUQgyggyKb28yA1g9G2DQlCuqgZqnKOxyXS3v3oQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198494; 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=9G5WyvaOES8B0BFYc4c2ilE8vSVWNgDmBbr9RbU8j3s=; b=FE1lEyloZpCBN6WtLPlzvjuQzoUQ5PmPNdbzZgUzYPc7Q05jA5w1SDWgO8Sr1Mfpb8uI4Q3voEBuIJ663b4/y+tqtCDH0aCFSN5ku9UlOK8VVBZETJg4LOp2FSfGdysnyxh+epoXubxxSR+jsMpdv+hV4rKnG37ItRsdIUmBdZA= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198494580268.94694736702354; Wed, 5 May 2021 00:08:14 -0700 (PDT) Received: from localhost ([::1]:56320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBdl-0007bn-SE for importer@patchew.org; Wed, 05 May 2021 03:08:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWP-0007ze-3o; Wed, 05 May 2021 03:00:37 -0400 Received: from mail-eopbgr70123.outbound.protection.outlook.com ([40.107.7.123]:51520 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWM-0005wK-G9; Wed, 05 May 2021 03:00:36 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:20 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:20 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VRsO884vj1xRiF5M2DHVEHSdEqqtUfcnXJoeXf0CmYeeRUVp6wXzzclQNaOuvki4auFbnHn7SS70+K3aNtweNTtqV8ISzFLjST8KTcJ5jcAbaM9fhHBlaCxswLjN/DxS7OjV/tG+KO741v6yBGUVtBtJoRElqPk4zHnv84XefFi8nL6sBK18vpmx57zMNHDbxWw8o6x06/+kScP87NUSqIttw6ZcmUp+TNz4fiKjjxpOgRd4DHe+a0hqCw4ZlU5FzqmXBxuur8kAV7VLgqj1vXBsyJf8Wl2o+rqWLpwS1HzDZtbH5xiM1HFQ5Z78OOKeuyMzcLGQ3v3Deu8B1Nsurw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9G5WyvaOES8B0BFYc4c2ilE8vSVWNgDmBbr9RbU8j3s=; b=EID0P05LBjOUvDZ252buSsgX1UWi10wK6SqY1LVnjSmjaiizZ1rsNSjPU6kHqh0EYk6fdzbJwoY16G1y1Dn+Rqr9GktDdvzT/X41zn94Efy9PJbocJ9OhbepFP9rW75xxn/KFBmAIj5sjFUS5lbP0NW7Noegf04UYX037zYDmqh46u9knBCum88ItgS3nEwNF6cyZBOiCh5mYGN2z1T5dWbTJBhNWCdFSmtZa7GBUHBfm2mRsdlliWmiVR6sLnWsNEhIwCX4c8b44ULUp/FN2u2egbL9ILB4L0aoBUTrPCTfmyQQx1IqB1cms+LjhWH8/PceZtika7twH0e2XPn0fg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9G5WyvaOES8B0BFYc4c2ilE8vSVWNgDmBbr9RbU8j3s=; b=kzVInrbJVLlRkaO/sipJpRIjUy87tcSfpcZEakadqAUHQpS056+bjfnhVH+Gx5+RcZRN5Oq0b8c5A1rmT3Xx7t1tYWAygBh+/OKJplMh8mRe0Ja1lwjcJAWpk7wJ8d759Va3+mO7wbN060N8yf0llMFUVHg9m8pCjEfXXRh3FMo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 08/10] qcow2-refcount: improve style of check_refcounts_l1() Date: Wed, 5 May 2021 09:59:53 +0300 Message-Id: <20210505065955.13964-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6f19caea-24cc-4b30-5727-08d90f937228 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:454; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c1CqgH7Qj0p8q5+0BbDARd2BXKWiaLAsrHyKKYwd4mRqdEr1X0MrW8Qvld49Pp1D9mL0PNhhD9uSb4ktnuMT1OIJhnQ50wIIS0zKle9LlkoYGu3p5xGBNofyKYMNlM+QbFiooQsFhZaDJFhM+02XCYZNRynUlLxCpwc9QzC2iDF+AgJ0mi51b8e9vvkXPuW8D76zUJmhP7utp2YS+oeembA237OkfGaXG3c0jjdPENpRftpWZSzIQFJockeYDmpcxlmfmMzvuEmB1nmwRj09Mpqy0izSE4J76ibDoWkEOqcRaG9MArLne0oiJ3gsE0JbixC2GXZCKr98kSdz9yD6Y5OfN6tZFnneB4JACGU0q5YZc1ze43JGI7qv1KhdociA612/kvzUmlYTMv5ZHTkXzFPj9dJcPe2vzzhBPmpCcc4G4uSPLugY39FVFU6fcawvKIeBhBHK4AXRZu71swYwLs1oDRpj8KwRI42nqxd+WTokyVIVbneVAFEiEbQINfjvi88q9lX+g4xLlT76Ts7bIUxLoFYGJWOC1oK5vvCMvs99GgiGHut0aP1O1FeIQ+6V5dbKFIUNvjME1Un9G7YKemiobIhAwxQXYLqrKCuVcqSxSpc7U+Pd+wvN19MR+8vMu/CUMgrCui7HGjRJqphsvKm6i5ca83272UNFsHWl7WRD8u0T8qqwTQQQmZOSnhMq X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39830400003)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?PnkjXkb7TCRA54IIW+Eq+Q//hi5mm2v0Q9fqo2Ekr4aNI1i/s+/lYX6A8A00?= =?us-ascii?Q?D1Iz2JmtyOgUc6myme26EEYkfjxbv7whHseooktdq6ORnsHD+G5yCC3M/s94?= =?us-ascii?Q?wzlPSD8y+plCPaJs2whhHdzoscqlhQg+fcYvsajQ0ctfkil5jITi2zFoAxL3?= =?us-ascii?Q?+rj3RL07qLENmPnnwJU7Pju+ELChL2sf0/AcM0HnS7UHgs++YfWqHQWjAHJV?= =?us-ascii?Q?7r8CtRNaFE1WiluKD9Kg95Ycikgzu5nSJBqmBZedHU/WgeQT3MDqtN/uPbKR?= =?us-ascii?Q?0Rf66AdAXiIU3NpgO3XkNneIZMzRy5C/UY6T78+pQQD82k3E2H9yYB77U8F5?= =?us-ascii?Q?XF0tc+33GrwIVQpoIOnosE29r3EiaHoDTDsgUEVO30jOh8hbm6OvB/ihyOcl?= =?us-ascii?Q?QxG303sa1w+RFI0dfT7/R2FuNEvJYRAvkCMkuW8xJf+tALnJm878Pid+hq1N?= =?us-ascii?Q?TllX7NZwyIA5XDOQHn2uYk4aBEXnzr1Ulest0iPNssIbjaslqcNoud60upRE?= =?us-ascii?Q?2Ji8ElFUqUdIeRwf1BlVibAeAzhrcy9yF6VHUtMWDH+cqDiVS+Q+tPLPVSa/?= =?us-ascii?Q?Jj5SCm+EJn+4NvN3CIq+WKdJCIws60xJdSbDWV+oiYI20fmImdIoed+56/8O?= =?us-ascii?Q?XJ+aHyFqlfQQtp7J7MMPILPF1bp7dHBRhDEe2iM9+WMQ7zbEuUEhi7IHbfSN?= =?us-ascii?Q?fl12HswtjSqSHg8ffnnK+leDXlVHAIj7UwTGic6WDa9o7Z5dg8NuVtLxwa0I?= =?us-ascii?Q?Y3un/gMJ9LuqqQ9Nc/J7s6TRbP2vi/cHx1sRZPHX1WH0bY4hBiultetvvCHb?= =?us-ascii?Q?NLUXvvTZVZGJIx+ebvL866BnxtMV456UJAuVzxkNqJJlHXcByC5gklY9MX4z?= =?us-ascii?Q?a6D08D3+jJI4b0woaJ/M+vDG/xdg0cKE+WWUNYWsP4jFmTVNqIT4W7rpzi3Y?= =?us-ascii?Q?TD9rdCPUxfLGQ2Ms4/4KT4mx4TpCbaC7JwRlWsFAcVxI7yjW/fr47Nef4Jxo?= =?us-ascii?Q?qPwOL0owv7C+TLEOk6rGKy0xSR5XSz30BpcvPxAtX8hkxBTjSVvfLEShO9tt?= =?us-ascii?Q?dgrWTQOtfE4ytqCKBT6cezuHIa3yuZdDRNMImeQSLJ143ZCQNjXj07VDAQpZ?= =?us-ascii?Q?seMwhx/yeRS5jJ793daVG/7j50bqBxLSfkEOPp349AN7CdmEr8HawgAW8j/k?= =?us-ascii?Q?aENOiPV5HfSJjuI2f4Oa8g2RqNfzeKaf8+s3LNVJfhBph6llqVQNm23cv9aQ?= =?us-ascii?Q?zmISBPukfHNMpWCzgEu9uv7rZIE1869aZjcyG9EetW0Hf8nLAyahccBOLBYb?= =?us-ascii?Q?e62f9ejbtXr/h9lfzizPe3dp?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f19caea-24cc-4b30-5727-08d90f937228 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:20.0586 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 29J3+5BYleDu+W7f8FJEGL4i7bVc8+KETGsTB488m5ShuYyNnrTviD0Ege9e/RDUcn9IuPx1nnCr268kge2pbvCcxSvAKQokpLPVdfzqogM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.123; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" - use g_autofree for l1_table - better name for size in bytes variable - reduce code blocks nesting - whitespaces, braces, newlines Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-refcount.c | 98 +++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 47cc82449b..69294a94fe 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1864,71 +1864,73 @@ static int check_refcounts_l1(BlockDriverState *bs, int flags, BdrvCheckMode fix, bool active) { BDRVQcow2State *s =3D bs->opaque; - uint64_t *l1_table =3D NULL, l2_offset, l1_size2; + size_t l1_size_bytes =3D l1_size * L1E_SIZE; + g_autofree uint64_t *l1_table =3D NULL; + uint64_t l2_offset; int i, ret; =20 - l1_size2 =3D l1_size * L1E_SIZE; + if (!l1_size) { + return 0; + } =20 /* Mark L1 table as used */ ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_tab= le_size, - l1_table_offset, l1_size2); + l1_table_offset, l1_size_bytes); if (ret < 0) { - goto fail; + return ret; + } + + l1_table =3D g_try_malloc(l1_size_bytes); + if (l1_table =3D=3D NULL) { + res->check_errors++; + return -ENOMEM; } =20 /* Read L1 table entries from disk */ - if (l1_size2 > 0) { - l1_table =3D g_try_malloc(l1_size2); - if (l1_table =3D=3D NULL) { - ret =3D -ENOMEM; - res->check_errors++; - goto fail; - } - ret =3D bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2); - if (ret < 0) { - fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n"); - res->check_errors++; - goto fail; - } - for(i =3D 0;i < l1_size; i++) - be64_to_cpus(&l1_table[i]); + ret =3D bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size_bytes); + if (ret < 0) { + fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n"); + res->check_errors++; + return ret; + } + + for (i =3D 0; i < l1_size; i++) { + be64_to_cpus(&l1_table[i]); } =20 /* Do the actual checks */ - for(i =3D 0; i < l1_size; i++) { - l2_offset =3D l1_table[i]; - if (l2_offset) { - /* Mark L2 table as used */ - l2_offset &=3D L1E_OFFSET_MASK; - ret =3D qcow2_inc_refcounts_imrt(bs, res, - refcount_table, refcount_table_= size, - l2_offset, s->cluster_size); - if (ret < 0) { - goto fail; - } + for (i =3D 0; i < l1_size; i++) { + if (!l1_table[i]) { + continue; + } =20 - /* L2 tables are cluster aligned */ - if (offset_into_cluster(s, l2_offset)) { - fprintf(stderr, "ERROR l2_offset=3D%" PRIx64 ": Table is n= ot " - "cluster aligned; L1 entry corrupted\n", l2_offset); - res->corruptions++; - } + l2_offset =3D l1_table[i] & L1E_OFFSET_MASK; =20 - /* Process and check L2 entries */ - ret =3D check_refcounts_l2(bs, res, refcount_table, - refcount_table_size, l2_offset, flags, - fix, active); - if (ret < 0) { - goto fail; - } + /* Mark L2 table as used */ + ret =3D qcow2_inc_refcounts_imrt(bs, res, + refcount_table, refcount_table_size, + l2_offset, s->cluster_size); + if (ret < 0) { + return ret; + } + + /* L2 tables are cluster aligned */ + if (offset_into_cluster(s, l2_offset)) { + fprintf(stderr, "ERROR l2_offset=3D%" PRIx64 ": Table is not " + "cluster aligned; L1 entry corrupted\n", l2_offset); + res->corruptions++; + } + + /* Process and check L2 entries */ + ret =3D check_refcounts_l2(bs, res, refcount_table, + refcount_table_size, l2_offset, flags, + fix, active); + if (ret < 0) { + return ret; } } - g_free(l1_table); - return 0; =20 -fail: - g_free(l1_table); - return ret; + return 0; } =20 /* --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198580; cv=pass; d=zohomail.com; s=zohoarc; b=WQghi99R5uy0UMTuRQWGRQ75z7hCiyj1m2gzXUeHOhZvrrNkxo3pEZFBzT5aMiQAx6tIHHndr3h5B+/MRNVw1pIIbz5sxl3dOH4v9DMc3wNN6cRMXzAqvPKbP1ZZT9WZqNK5uklQROP2mNB80ca9vCrpVcXD9PVT3ohNU4Spejk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198580; 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=QYpsKTlYtMDBxc92hcBHQaJSSzgdGhHnQzOqqmwnDiQ=; b=WOQQl6EMCgQ6pTeomRW1e8Ib6xQkbsr4dFVDgMINnK1XtiSDcfgK7UpufPXt9GVR/iFv996LcT0migpEDM4odzdqNChcubahbpAm8Tf4/KvKjQWtpyaJ9T2kdFZq9QHjcErA/MGFEaIIF04KdQJhuWzem3KdD8JVf8+NFpgB6nQ= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198580552892.2532915459929; Wed, 5 May 2021 00:09:40 -0700 (PDT) Received: from localhost ([::1]:60952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBf8-00015h-LC for importer@patchew.org; Wed, 05 May 2021 03:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWJ-0007wd-Rr; Wed, 05 May 2021 03:00:33 -0400 Received: from mail-db8eur05on2095.outbound.protection.outlook.com ([40.107.20.95]:22496 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWC-0005ys-Pl; Wed, 05 May 2021 03:00:31 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5493.eurprd08.prod.outlook.com (2603:10a6:20b:102::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:21 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:21 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJRHzo2OWwG4BWPKqShX72+sVNcN5wcQilMRNw/jDquHXt3HalkL8WP/JDiK7ZKsL3IKPjVqnxh991SF1IufYI0xcboVWKpUY20H0W0tmupobwTcEw0tF1QGy5TaBlAV6Dex1IGd6UeE9gAbk2WHKpqOwL4Kn9eR5ilwOoebxR+d+IAzvcr1AnETTG0PN4742+gDaFcFKsbS19Pun5C8ivgty6OkUEQRnqMqVF8y56oLfCM3hxoXkBAGeSteIDC5WZy5A3q7I09OP4za8FVyBvmDrCoXMzxQlIvRlYxjwd0S1mvfkEiRctUQiknbs5omh/CTv0jurgQMSDc4gN3GZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QYpsKTlYtMDBxc92hcBHQaJSSzgdGhHnQzOqqmwnDiQ=; b=HyblsqVTLs8LOBl6BDq1UR3xj1RB5iRTWSP/8SF1aIfLuBziimaV94BPDalhun5ZGWTVZAkEO8eINe2wWNHrpWlwS46OIxIdag0eHleshNbYvjWMS6nJgqnZWU44u4xyV1qn/2RLdNNF2v60/QImEqVADsl13gGxr6OQ3dw3NjXOGDf3u4akGKo7afEpBXFZEHD/eR5OnJ9VDy2JAv6Q0NoL92gQ9jp042DvO+Z+mXVYL9V8j1uwG++uJCl7S3/ok4951b15epo4w31Kr7MILtLwZ7SeQStGuaR4l7fB2nw428Vcs+f1L7GFQ5juU/pn8+CIIUh/6yPj9q1QqWYPqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QYpsKTlYtMDBxc92hcBHQaJSSzgdGhHnQzOqqmwnDiQ=; b=ObD41VeRcxUo6z0wtSq/S8KdnW611qyNQzd/p5XA47RDedTSrB/Ye9VlDbbbPrn5MO5ZMK7/Ab+1FZnqb20FNYX2nNln3o+VOqtP0roMGglu3i9dA0yqB2tkupwc9PGGDSUR+B/ABgcvVQDvcbS3PhVQPjk4x4XN0ntWNXEmf4c= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 09/10] qcow2-refcount: check_refcounts_l1(): check reserved bits Date: Wed, 5 May 2021 09:59:54 +0300 Message-Id: <20210505065955.13964-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 29f779b0-35ae-43b7-6749-08d90f9372d3 X-MS-TrafficTypeDiagnostic: AM7PR08MB5493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:257; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p4kqrZsDHStQUshyUb14mxKAo5Dg4mycW0savMXlkxDuHZi2fFJulxLlARkA+CUz5TSIN0FRpqZuN1xWWnjqOP0iyB7YhjpyUG9fSwrZphjKU4qbj9SfAXiOPosLHSjB8rh0qONnxz9Xteog1XJOWT0ZRUbqzpvznyHxFpZhhytI47LO82nLAX1g7+DQ8xT5lMNfm0czzB+Op9bfhmnpA+rYmfuKwJGq8XCsodjT7bkGvHdEcy71TiA4KLvYIEpTZXnCpYCe0uejH6FiCqXEyPVaeEqOnPpldn4dgS6zcC4jENRFdwCD13ITd+/XYyRH+KCAhc7b2FyzIp3Lz1RqLOZ+DFuO/0pUfVxa2uJQcnVYEI7MSwQjEgTqDES3h3OBaAoSBPSJvCik7H2DMTrbWu+iuNYsaD1zltv09uNLNX5eEiqEzOUU0K0dpoEZ5UDlJVlA6Pz02aVSflBQkRB0BD3ary4PPS/lidESdcPzoimHEDULMeueSn+6WpJW8BvGr+v2AXF2YQBnGY3GDqvf7q0LUv7ttHV7F+MZ/9be/BZcS9kLOkNwXGHTSqB41HS7PUONB5BiR4+rDh72wyEU5KqU7/41XS//yPMrZYWtpuQHiY3jjesNNMACnppu+JQAP4ZOwVYTAvJIDXuQgjm1K1EUQG0duxil7C/qDBf+QgCOXoUqMHr984w5SOKEQ0xA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39830400003)(396003)(376002)(366004)(136003)(346002)(1076003)(8676002)(38350700002)(2906002)(5660300002)(38100700002)(4326008)(36756003)(16526019)(66556008)(6512007)(66946007)(26005)(186003)(52116002)(83380400001)(19627235002)(66476007)(2616005)(8936002)(6486002)(956004)(86362001)(6666004)(316002)(6916009)(478600001)(6506007)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?SrcYCx84K5BPONL04rOKj1bR5IOBuBXXOD30zsAGl7GCpA/tvdtGGrvclJbz?= =?us-ascii?Q?VYaJDv3fcoR8BHPqua3wImeIxGkF4ttbocMVwgMP1HC5RGwI6xe4QxzqmfX4?= =?us-ascii?Q?MQfa8F7MsF5yPz/5PEDEuzOBdIdP60keay3e/b+T0Uona0T/ZX1YZgVjoK2R?= =?us-ascii?Q?0ureNqm5iIsQL5z1fgZapp7OiyIxXeoJZmNhoUwxqO3d/Q2iKfTSl3VXYOe0?= =?us-ascii?Q?kx4QUQYMGH+y5F/CZKaDhv2U6f0ChxN2xckV3+HHA0Ghvag4tV2cgHde9UZS?= =?us-ascii?Q?XqmbMlW5QPFGKLjPjEyavT+2E/r+7xxAbd0RutPqoMld11xetfWXYOH+gulc?= =?us-ascii?Q?U/UxKG/k5qt2xVB7HjZj1qa+LPT2lKO018mwzioHtN8hE6ap2ijnaHq6RuU/?= =?us-ascii?Q?9Z+IaZbY0lSiJjGDqyUplnMQQMuLIDTUlikO7sRMjp3qjdazdK2eniFWPiQJ?= =?us-ascii?Q?TEkymC6DCeglxU4PJPW7j5HVXu+qtXA5dCYOwh+axUkdBu5akzJKMGLCGAZC?= =?us-ascii?Q?LdPiIoiZNyQ/IYM2j2mCsdwSfT+UDnz34LufGlxqLvVUP033hVjx5c6HAux3?= =?us-ascii?Q?68XfD8tCv3df1w2lmdtzegkmCINvsFsQ90XljD65iALNnADV0Rk4EYHoe/KI?= =?us-ascii?Q?BjS0irMnCWAtaER1BmaifDe8u0uT1udededkDEyBtcPuN4syH2lu7UAy0kjI?= =?us-ascii?Q?mX6h6CZ+YDrLNkmhitxFvJn+6R6iEjmG4wsneUbaVkpdBcGj0KaLRBZq7Mje?= =?us-ascii?Q?HIXgfn7R/E/gZLZTGum8Fs6Hx5rfC76JW8sLDXbcDpNdZPFhzzZryCOsfs72?= =?us-ascii?Q?+C09G0V1BXPBnVHkQ0JkkpNRnWnLEHtUDk3HQaC8ccHyxYqw/pWs/9Q5LZcj?= =?us-ascii?Q?rHhBdMClw/K+ZXPxu3Kfi4CK6E+CiiHT7DQMj9z9Bk+I2WI9COruXHYVpF4U?= =?us-ascii?Q?MptevteHwZY8eAnYNMtQQFur3Na2IkwhaOVC+c4MgOj59efLDnMV9BAapF5v?= =?us-ascii?Q?FAe9plCEGOyPt31SFFCnUWD/Bx23dP/vZ6yMixfWSq5ssPsE9Bzixc39QD1u?= =?us-ascii?Q?0WAJZH5QOcwf3D43q1L/BeWT/zTdY2V5KWCeU7jMoVrOuAqbLnJ2B+59YxPt?= =?us-ascii?Q?8BYoR4ROXnQQKQEF1hLawDxc9tezWZ9bk9JPpP6kIqiq45TLvanv1dTaR0GY?= =?us-ascii?Q?kTniD6F0SmBQ4OwNlarn6ISryO/1TP7KwESf5Jjb4WduxcdsDBVoxQR+aW+A?= =?us-ascii?Q?kIPE+NkQB2aXhafpwUr2JtOqNKkg/s4nkm8Crcw6puVx03VqhRXiyVxD9TRk?= =?us-ascii?Q?4eUtCggDcZFk+S5Njbhh2jSR?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29f779b0-35ae-43b7-6749-08d90f9372d3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:21.3201 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rdl/zGAtj51njH6H6WEPuoYoIqM2ePAGllYeRiYYuPNzYGDIKDx36Jigy5yfcrro+LBWLqif4JDoix4dM6/0NjyQLWRQKAm/DtSAq2EzBho= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5493 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; Received-SPF: pass client-ip=40.107.20.95; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Tested-by: Kirill Tkhai --- block/qcow2.h | 1 + block/qcow2-refcount.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index b8b1093b61..58fd7f1678 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -586,6 +586,7 @@ typedef enum QCow2MetadataOverlap { (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2) =20 #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL +#define L1E_RESERVED_MASK 0x7f000000000001ffULL #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL #define L2E_STD_RESERVED_MASK 0x3f000000000001feULL =20 diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 69294a94fe..15c4f6b075 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1904,6 +1904,12 @@ static int check_refcounts_l1(BlockDriverState *bs, continue; } =20 + if (l1_table[i] & L1E_RESERVED_MASK) { + fprintf(stderr, "ERROR found L1 entry with reserved bits set: " + "%" PRIx64, l1_table[i]); + res->corruptions++; + } + l2_offset =3D l1_table[i] & L1E_OFFSET_MASK; =20 /* Mark L2 table as used */ --=20 2.29.2 From nobody Sat Apr 27 18:44:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1620198605; cv=pass; d=zohomail.com; s=zohoarc; b=kxuAfUaMGUvQIwcrz7eVdU930HpiV2gqZQSwkIEZ1jCrJ93NJUOhbR11aSyK7rEU0VF0/XFFyJBsDXxSzHpgZxaVM8b5xxJAgrNo1TTfqD8i/fhzbIBl/Kgi5hTv5dUhknSRKpM9QQuSyWM3eE14l+3rZqo8uiZU7lDGLDSlhOs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620198605; 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=mITfNRwR6VnM4DdBHnwK8EKwU+7oHqkKHfJG9q6oxEg=; b=TFbvlb/X41GYVAtuTYMhG0yZhf0XOF6yFBMRCGeR6wlRKqMDBWHDcJCBiIGLocWwCsQ/3V5C9O8Wj/bffjKJkUotzgaQc8D7AzNDuFRDgQrGwbIMhDT3TrwHseDCyEtnBeQoZAHYK78jh6tKlwJnjjcu+cMH/tG+7vUK38mucxw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine 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 1620198605881362.6602018489973; Wed, 5 May 2021 00:10:05 -0700 (PDT) Received: from localhost ([::1]:34234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBfZ-0001il-6b for importer@patchew.org; Wed, 05 May 2021 03:10:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWP-000816-P4; Wed, 05 May 2021 03:00:37 -0400 Received: from mail-eopbgr70118.outbound.protection.outlook.com ([40.107.7.118]:64516 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leBWN-0005yd-TQ; Wed, 05 May 2021 03:00:37 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.38; Wed, 5 May 2021 07:00:22 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4108.026; Wed, 5 May 2021 07:00:22 +0000 Received: from localhost.localdomain (185.215.60.236) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 07:00:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YOabiUTc1+sHPeI6BwiMX199snKRb+9SQglc7e2RPc4fOHVp+NJW7W70NAeyNLt3KVclcRe45/Do/rnCTPr+rzRObz3CB08PxPZx0wtnYCpn4w+t6RNcufww3Bs6pHiLaDYcM9UJPulgvQyn+JyGmHYfd9E2suZmTBVdDVhP9TTzSrbuBafdVIHg0yfRWvV7s+9cCVTTizzj4goyY/Zxqwv1TJ0j3HH0IdcJcKPdlHEe5qezUP4+cq/CG0tVEGxdEeHVhESRb6XSZgbkv8GblI0WQGOhzt2ranTLoyhANYetv6/NE/MqntoTJEwpJBPuwVVJ6EiiL3Bj/Nkqs3Mwiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mITfNRwR6VnM4DdBHnwK8EKwU+7oHqkKHfJG9q6oxEg=; b=DKnDH1ImlRjO/AA/K3i+R2ZePWiN02U2qVOlVRT+r4s35il6uiO3bjVnZewijdblBsKYmny+d8lRbOj6qhlwvjF8Ze6t67ykKHAGit0vNtT/eFqv35TlAecnQcp7X5+u345Kh06+HKJzPx8JhlyPbgWHk0hLf2vil/uHyGlkoiNPdoUGS/feDblaATl0HA62mOcK1Z+VQvNoipFU2EMOovj/Dqgl+gwACeVzQdPNCB0nSF8S+tcJyyDBTkekjbgKxJOoZLkdSHAqVR73kY3EI7fjALXXJaNisF1y8S5lWBVpqDQ+zJoXoXA6Aghc6/5MveARLJVXljSXTTWsk5uKoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mITfNRwR6VnM4DdBHnwK8EKwU+7oHqkKHfJG9q6oxEg=; b=OPUablxM/AVizPFQTvjeguab4xmzQJc2gP6VMeoVURoH00kr4ft7EOy+UQSoSbF4I3cGb8eFLFX3lw9DAvNDjuzMhMCh4B/JrzWHUwylsI7yLxEJHpH9HcJMGggjYXD+HKKJD4NjT4Ju+Cnn9bZMsBUPJgMnezk2/FIhNqFJoCc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com Subject: [PATCH v2 10/10] qcow2-refcount: check_refblocks(): add separate message for reserved Date: Wed, 5 May 2021 09:59:55 +0300 Message-Id: <20210505065955.13964-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505065955.13964-1-vsementsov@virtuozzo.com> References: <20210505065955.13964-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.236] X-ClientProxiedBy: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2a8df628-f93e-4c52-9c38-08d90f93739d X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:198; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kYuxYfGXmXkwqcDJ3BeQAUXfFTDRyzmIAGoGKWTdI5JrHrG8Vl2W4MRRaROD4oRN1yXq5Xx4Lc3/2KWKiES4dfroPSx3LrpSa6Nr46YzXgYNNcWPs8I5Hfm3HLEC7A9JcTXOPXa+LinXhpRHnFJrI419sbcI1m8q7JrRpcMnSnWAuh4ZMxxCkaOm9HePHUgilHuXjbrK0MP05S0lXsV9StD2XTaNx36BfjXmrFT4jpDoAFKoPsBKcAoqhn9VT+jfid9EkPELW9LWd9qc97KH0L91WEIVKj7NsdGLIXIagOKILZLAvZEKrRG4Qtr/SXepoYaWEhpPuFYSxymp9Z2z8yNL0FuJleuB9JfA5k9ExhtyV1Pw3hJBqNk9+43kTxO6nIvGKGKIxjQVaQewXiLRP3kndRFl/1X1u43MWkMVz+kERyZiVW4xa2zHg1re89jqOyuOoxTo7C/BKXqhLTq5hI17rWPSxcSVW2znsomv0JxY/ko7Zt2wwN5TAofJC5q/y/q66yXU9UfUZZPw3O1xXIh4glmCG/FITb1kn9MPDtn4eRIXzK85CEOeixSpwj1KD0baqHEkZWpZLsBNS1fYF3pXZiObsRgOSkL3x9DbMoFIrJQ20yasVMc3k2hecdgPkH/r+CNhyXpzwRDsX2n/05giZXc5oJhqwPLl5DiRTY/HyKRVTCEmKYm56LSSTZJA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39840400004)(136003)(346002)(376002)(2616005)(2906002)(956004)(36756003)(66946007)(19627235002)(6486002)(8676002)(8936002)(6916009)(4326008)(6666004)(16526019)(186003)(6512007)(1076003)(316002)(38100700002)(86362001)(38350700002)(83380400001)(66556008)(26005)(6506007)(66476007)(5660300002)(52116002)(478600001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?MbWL7ReUS263FwZm2+z8LoTQslzjhtstnCxVCjiFpdn2hMDNMd5tu0dvXKgP?= =?us-ascii?Q?VVDLblLyBa/2he/3Epd5CgUQtO5wYX5yiFUo6VU3PSUUr+vt7RLxzSe+HCPB?= =?us-ascii?Q?AA4D/J3o0Bf8UIQW5J1jBlIbE5dbZk2TogRwnlwS58qcwwDFIDDDK8Pfv8zD?= =?us-ascii?Q?+Ee3ZUkeCHgQ9NcAJIGES/GVmYgtv6VQ3YtuDYZLYLc4EEAwRYi9gn+v5fKT?= =?us-ascii?Q?ElfJr2mxKgRRkYRVHVZPF4LD2ByD+mh5E9HocLv+QHIkQbB0Wwj2O94gJrVp?= =?us-ascii?Q?6p7IpZaK7TgA3D7Lp/AysErIjPf98ny/qcxiKKSckARFwEgKP32RcUkcc0Uf?= =?us-ascii?Q?80qqw+7ZuQNcAktrqR6nGPFG/NEFiBN4IrLPMKxEKbMQzPVxCfwD3l7Q8P78?= =?us-ascii?Q?5BSDbwN996HU6oW8vfH2ZFow0n+cKWieSb0UjOhsoRwuXtR5+4Bbkuot6kCs?= =?us-ascii?Q?TuBgeH3wluP8FlYj+zaWrMK0t6WRfKef6WpfXTUW73SQDMNJ1ghzvPntZ2yI?= =?us-ascii?Q?xLlWU92mxC5I1x6ykIdBC/yP7w7NMmcEWNjzpoAa8zSklcbMOy1YzcWa+jMt?= =?us-ascii?Q?RiwWANYiB2WiJxri/oa2ilHWs1Zx8xlJWd2fhoal8mnUtSBRNsl/tuFskvT+?= =?us-ascii?Q?9mrYiw4fC/Z8zUAJZerDeDBFBfYCYE6psIKHYl3tQGwlp30CWf+RLfxA0lPX?= =?us-ascii?Q?aPcsESJrw4+8EBh31hyYVz9JeYYH+Pv4WLSGSnDQs4AsQRIJ24I2QHwJwTUF?= =?us-ascii?Q?qD9tJ7i0Wg5N+7GpUchVIPGoma1I5m2rto/UObdCWNZEu40nrWsZXMkkXufV?= =?us-ascii?Q?gSf4dbxda1TSestECu802b48nWU82S7htNDn8t+RjopluX4Rhj8vrZm+dYpU?= =?us-ascii?Q?5iKlwWXIJoWzdKGPTNc0+5bUE2yBORP3xm3OfBDR9v+hb/mxZ39Aax9IzbGi?= =?us-ascii?Q?dRBDlkRpxJbExzcuuheOPdfRZNB1ohfsfEWEBkmpyOaVz8+HRDU7xQ33QNrv?= =?us-ascii?Q?6lYKcifQfr2uNjctr3BMAGzuFX1u2fD/Fyk9PiZaJQ/QZYidpcga8a7xjtlp?= =?us-ascii?Q?ycj/acVxeYHdNrzpEGeIP4ggAUVC5CgI5Z/K43wIqE3g9HiKdwFhYmYvNIAb?= =?us-ascii?Q?irclgHe1JwuaavEVI/vcuccU+cSfkjTlOO+MibYU/a0Xkcl+2Eqjg6cawonU?= =?us-ascii?Q?2JHUNKTLhW4coOASsa5aT6BFf3P4lachhJtFTtVd9xTtmTmUD+hOjhruZHvM?= =?us-ascii?Q?Vbs6fyTSRsx431UMG3ouQRfQxlt08DqKlWTM10anuES4O2BYj9Oigu8RBaEx?= =?us-ascii?Q?05K5o6A4Ky6zGvAGLcPMFWG7?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a8df628-f93e-4c52-9c38-08d90f93739d X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 07:00:22.5168 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rTDGgAlGC3YItuO4VzPwcFV/sm5o3Wr8UNkaxCG6eVUAUQqF279GetoWKGkTVtDI5UNFIHvegn/e9pOdvsBs4Hopd+C9iLj6qw6wNorUe/Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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; Received-SPF: pass client-ip=40.107.7.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Split checking for reserved bits out of aligned offset check. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Tested-by: Kirill Tkhai --- block/qcow2.h | 1 + block/qcow2-refcount.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/block/qcow2.h b/block/qcow2.h index 58fd7f1678..fd48a89d45 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -591,6 +591,7 @@ typedef enum QCow2MetadataOverlap { #define L2E_STD_RESERVED_MASK 0x3f000000000001feULL =20 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL +#define REFT_RESERVED_MASK 0x1ffULL =20 #define INV_OFFSET (-1ULL) =20 diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 15c4f6b075..472a7026db 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -2091,9 +2091,17 @@ static int check_refblocks(BlockDriverState *bs, Bdr= vCheckResult *res, =20 for(i =3D 0; i < s->refcount_table_size; i++) { uint64_t offset, cluster; - offset =3D s->refcount_table[i]; + offset =3D s->refcount_table[i] & REFT_OFFSET_MASK; cluster =3D offset >> s->cluster_bits; =20 + if (s->refcount_table[i] & REFT_RESERVED_MASK) { + fprintf(stderr, "ERROR refcount table entry %" PRId64 " has " + "reserved bits set\n", i); + res->corruptions++; + *rebuild =3D true; + continue; + } + /* Refcount blocks are cluster aligned */ if (offset_into_cluster(s, offset)) { fprintf(stderr, "ERROR refcount block %" PRId64 " is not " --=20 2.29.2