From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EC99C433B4 for ; Wed, 5 May 2021 07:07:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6D23B613BE for ; Wed, 5 May 2021 07:07:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D23B613BE Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leBdQ-0007C9-5v for qemu-devel@archiver.kernel.org; Wed, 05 May 2021 03:07:52 -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 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; 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 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: 8bit Content-Type: text/plain 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 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 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+A6NvEfi2bsCjhK7HIMRrZKOdKmnYlbKD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kmqEKbEezBiYJSx4pN8glUc3NErED5mjtdxXz?= =?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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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, BdrvCheckResult *res, uint64_t coffset; int csize; l2_entry = get_l2_entry(s, l2_table, i); + uint64_t l2_bitmap = get_l2_bitmap(s, l2_table, i); 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; } + if (l2_bitmap) { + fprintf(stderr, "ERROR compressed cluster %d with non-zero " + "subcluster allocation bitmap, entry=0x%" PRIx64 "\n", + i, l2_entry); + res->corruptions++; + break; + } + /* Mark cluster as used */ qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize); ret = qcow2_inc_refcounts_imrt( @@ -1727,13 +1736,19 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, { uint64_t offset = l2_entry & L2E_OFFSET_MASK; + if ((l2_bitmap >> 32) & l2_bitmap) { + res->corruptions++; + fprintf(stderr, "ERROR offset=%" PRIx64 ": Allocated " + "cluster has corrupted subcluster allocation bitmap\n", + offset); + } + /* Correct offsets are cluster aligned */ if (offset_into_cluster(s, offset)) { bool contains_data; res->corruptions++; if (has_subclusters(s)) { - uint64_t l2_bitmap = get_l2_bitmap(s, l2_table, i); contains_data = (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLOC); } else { contains_data = !(l2_entry & QCOW_OFLAG_ZERO); @@ -1800,6 +1815,19 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, 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 = fix_l2_entry_by_zero(bs, res, l2_offset, l2_table, i, + active, &metadata_overlap); + if (metadata_overlap) { + return ret; + } + } + } break; default: -- 2.29.2