From patchwork Tue Sep 14 12:24:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493025 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,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 A7A5EC433EF for ; Tue, 14 Sep 2021 12:32:37 +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 30CC86109E for ; Tue, 14 Sep 2021 12:32:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 30CC86109E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:52786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7c4-0002ok-8g for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:32:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7V8-0001mc-AJ; Tue, 14 Sep 2021 08:25:28 -0400 Received: from mail-am6eur05on2131.outbound.protection.outlook.com ([40.107.22.131]:32082 helo=EUR05-AM6-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 1mQ7V6-000628-6l; Tue, 14 Sep 2021 08:25:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JrYJ8i+QkKstSTA33umv24MZP3JTbGNn0XD8rCMXatTslW0296U3P6OkBt5UJjxGyuNpRk2AmqUUfzMXFmWqF2tDz0M34pWrQHMJgm4QIl8UlL6JIMcHufsQM0iLEOFoyn/U28cL3lLY0liykdu9NJ4Tl1VbIsBNMgHFMZii6kcnnfL/fVUVFRzWUKsO0OPEyGFQKC26mV2h0s8AxKyr6mflSWrC8CnZCSYDqeRSB/e35njF5Fj74NL0DOp9o2iR2Z/7IAqwvhCIhoKPC6G8gxn+0wIgOHjF5xtuElFJl4ImJZtRZ1mG0EMXQcAkONf39vSinb+3gkiBp3u0gvP2Nw== 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; bh=6QG/g/QYMS4kzSJh7+QPY7k5GWusMi3mZda7IANnMwk=; b=Who9BoyZ1neWqDUDppEjY7MSCjFrgtd4pAvl0dF3pR25dMoavyMUd1EEhTLJ1a9NqUQpUNdqoD7hthZIv2Kt+TD1Lg8OxTPxBPoApXD4tv/m6fxUtRkKoJQL1P6Dcn7geuJA/iJnO1CTn0Qp+iXDZsofRaE6UgUqcZnOUfYs3HEoiDRvEpIrGs+zlZcWPVbwusejBsgB7rnqqV5sSaKGaFIB2ItugCKz4S+jN/eNEtIvOubcoRkWJr3HPWT/CObbgNyn+CUU/YS5d8tCUs0lCFDcY5a5ulF6jpkZP1Xd5GN2zpOPC2n9v9uXZbV6y4LuLRjNOYBXS7b9rB7vuNWvpQ== 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=6QG/g/QYMS4kzSJh7+QPY7k5GWusMi3mZda7IANnMwk=; b=Ls4TFryEEFIFrCiSFgqQLBUSMMawVRZIdtvWmDrvJzLxrtgSTXSY095kUTSKJ8bq0BLnotC4EssrokYMiFx5QlXzeO/lzBOGet9ajormW7FSbqWhzQ8V5MUG1/NwSSRqwJRm6McEfPHUacwoBKVkeTfPIs07eO5xw5lYCSfYp/E= 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 AS8PR08MB6946.eurprd08.prod.outlook.com (2603:10a6:20b:345::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:17 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:17 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 01/10] qcow2-refcount: improve style of check_refcounts_l2() Date: Tue, 14 Sep 2021 15:24:45 +0300 Message-Id: <20210914122454.141075-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e21cdbd1-c892-4a10-d2e6-08d9777ab625 X-MS-TrafficTypeDiagnostic: AS8PR08MB6946: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 23jkMUAcBZBbMhXgNKJQXT8zxz0iowo4yYACviWhoHZaWxwTNRaGB2cCx1hJgKG2z5ln/i0x6s7A9tgya9FnwnAn8f3qqhOBDTzh/OWiizPh91OvrGwUw8bvsHC0B7Ym+rN15o98Eh5TEzMpKv7Jz1Tmrit3vFW0X4qxlotSTJ0sv0fkkcckdEJT71NNA3uuMoiL89/jTBtwlNIl3oAnBa2qdGkCW6i7I35xQR7VP8kvAodDyknkq73LWeI6Ubr9yWhqp1oqBtANTd2y8saPKa5+EHZlVZJcfffi78yKv3ik9xh76MAgRolvDox4jZoHWKQCgdRIZmyS5Py1RB3XhGDno/OvSUoX64H+C3TY2S9EwmMXwxn2NLxV18/0j/EKGIwMe4BuE9Wwb56WWW9HMNBxxHlqGUUhpB0FNhJvcvAIwkXLYH/YD/1Go67oE8/cFUmhyThTb5Jx/FSvX7KpmJkZdIOz+1okVrt1YE9DSzVnY3JgvbMRusj25MAP4iyaxQqRHEVT6+dHGpqVdL3K8RVm/zdnocxhyMhkWarhTgi5RmgbmyR3VPYOhZeskvFF95x3LHD+Ub6ZpHScwIw2ddIfp3/t6mzZJDpFrtP4dGI8gSHcjFLyWQvSn5ERREuR2B3jmzQf+PtyakAY/DEnCdGtDFUPId3SAqVhL0HkJvbeWel4vaff/hWitkCeQMML4OS8/OduN6FG0cMyJy8zeA== 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)(956004)(66556008)(66476007)(2616005)(38350700002)(26005)(86362001)(107886003)(2906002)(6916009)(66946007)(4326008)(508600001)(186003)(5660300002)(6512007)(316002)(6666004)(8936002)(6506007)(6486002)(36756003)(8676002)(83380400001)(52116002)(1076003)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lvxo20LWk0rLiTB/yZp+ReMoiR7gbcV/pE9wlEHxkkKP/+ua1KN+psH39rNNBS0W5uiLSXo/7VRpc/eBSdgiIU1+qWhpCtbruIvPRAUemU8XSBxfOF0jLC7aRCHqcWT3Mf6jz/0kWXEpkD2Hxu4oP7FSusrphKAc94WljiIOWDlz/oHVix5FDsyRJHfskTrJYC8fIdi+tFjACmfd9FEaL3R+WuD5JXxgDLZJxOztFxJvkwtnphrG01WQx7fOi1Lm2EQ04+2kPLRarhVvtcTjpp4ATHOnDbbXikPNSFjH9pRUE5lrHG0dMEFm4UFbgNM5su8QyvPMI6B1Log7fvIgqQG5qCdSONxHEENnmUX5zZg5eTJBpPZyLG0TBtf0P0/AYGt7k+ZxYKIQpAxkM7VzLe4NLdLuxgwio56T9zwp2dsGZ0v6FVq/wOXSUeR4CWydryKcUKkB5tUXJW3djqbNW+9mqZTtYSSuA7WAoHdFLwXlheyyKEr+BRWA0tDLFuHlRFCJbqr1Re6Lk79Pnx3fFoUdvlJjJq6kVNC7+UeCkIsul+GAMzPEBkT7l4BDqrkTnmP/nu+D9A9gghr5R9OB8EDZ3eI22amRFvOu0akIkAlvNgCndqLUqm3/OzbOlMSlBDGHvg42Uai9tadm18qlXCl/h8zjkA5d+gnucLa3ZDitGFjwYepTe+eDWBIOoKJY0QfajmCJIYd2oPF37oxU12ODcgM+VCIwwe3nL7BewThubVykEzMWHAUU4wuSMhR7s/G+3NfI1+oT7MBo6dlpGJhFyuFdgx1umdAzQK7wccTvTKA9xpJjwmmiAzA65tza4StbiRThNzAa6UAJUQeZJgCsojimrh+bt0nUE/qhUpl7D9kFaF/cWN+z323kdpPAkEanrGQtVglxfFzE2vUvLmxk9U5TdTmr9Zf/XxGWoI4yxY9Em3H5BBKwNQRGRv5jUPpjUZp+Br4bekU2WkBJ6NGer/0O995STItt8a1lj1KawDJ52FMIcTyxbbIFhTEBr/KQ1IDkezlXEHb8xlG4a1dgAL2ZuwuEa0DBzJNkaQaa4ouCKAVOpEj14ES0dh4nTFXZmSO+RzPKQrXo7RS3Ik13t/Z+MPdsTVDtnaU47qza3zZiS+tCvncKP3kQ4DzG8ftX4d1ZAZyZzVyuHE+Jh+kifi+I6hyAkIqnTQ5khFs9EVnzUEmfQ7ezdvHn++2t6AvlP8gP5sfu1XYQdvV4YDWpZXQsbPYewY2Xep/sAUShBVnLNq7N2qM0C8kw+0T4DoGI3tYiDJfSrkHc3LM5gjXdXsgjZRlb8/lNhwxgQPW4bc9qwUbZjXBn7IyUba5H X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e21cdbd1-c892-4a10-d2e6-08d9777ab625 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:17.6826 (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: zHEKVUjMnlx39olKmkcUQ1B6zFchtK6MqX9kNcDduKrzZVDU2IoGM/iaauP1YVhHcouUmX2CwZJwKFrLuf9B7DEfJfM2W3vzqPgY3XuwOJQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6946 Received-SPF: pass client-ip=40.107.22.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-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" - 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 Reviewed-by: Hanna Reitz --- 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 = bs->opaque; - uint64_t *l2_table, l2_entry; + uint64_t l2_entry; uint64_t next_contiguous_offset = 0; - int i, l2_size, nb_csectors, ret; + int i, nb_csectors, ret; + size_t l2_size_bytes = s->l2_size * l2_entry_size(s); + g_autofree uint64_t *l2_table = g_malloc(l2_size_bytes); /* Read L2 table from disk */ - l2_size = s->l2_size * l2_entry_size(s); - l2_table = g_malloc(l2_size); - - ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size); + ret = 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; } /* Do the actual checks */ - for(i = 0; i < s->l2_size; i++) { + for (i = 0; i < s->l2_size; i++) { l2_entry = get_l2_entry(s, l2_table, i); 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; } if (flags & CHECK_FRAG_INFO) { res->bfi.allocated_clusters++; res->bfi.compressed_clusters++; - /* Compressed clusters are fragmented by nature. Since they + /* + * Compressed clusters are fragmented by nature. Since they * take up sub-sector space but we only have sector granularity * I/O we need to re-read the same sectors even for adjacent * 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 checking - * this L2 table */ - goto fail; + /* + * Something is seriously wrong, so abort checking + * this L2 table. + */ + return ret; } ret = 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, BdrvCheckResult *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, } } - g_free(l2_table); return 0; - -fail: - g_free(l2_table); - return ret; } /* From patchwork Tue Sep 14 12:24:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493021 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,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 20751C433EF for ; Tue, 14 Sep 2021 12:28:49 +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 7D2FD60F24 for ; Tue, 14 Sep 2021 12:28:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7D2FD60F24 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:44282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7YN-0005QP-M1 for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:28:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VA-0001mk-Gu; Tue, 14 Sep 2021 08:25:30 -0400 Received: from mail-am6eur05on2131.outbound.protection.outlook.com ([40.107.22.131]:32082 helo=EUR05-AM6-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 1mQ7V8-000628-SO; Tue, 14 Sep 2021 08:25:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hN/YgegiPIZN6h+N0Bh47Xh75b+UC8dI3a0AoHPzVYoprDr+bn/NCA6aEKatFjQUZWC4pZ5ABtnVFU4XmQSBVzZ25l9+OYpttmDjBehDwXnzuXv6vWdtsDPci1LYU6tpQjJZx1HhMnU0BuD++SyAgycr2uUsOChstWWgmnZv/tGjha1StKJvFQblCXSmSxo5AnwXDrP4EYQj+QdXzBoJTcPdlMMRXEDfDgIbTrn1IL0bvrzOrkEts6ImYHzcNCaJ6BMUMu6oQ2M/9T83BeK2TFM1bAbw6n5Y/pPgsqYGW33vKVHNIfQ7lbSPcHowlgPEMhmQ+Xus/qVW7VJ1Uibcyw== 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; bh=2R0jsrKmMDSx2wDubS0WReXS8D74xpRF2RJ+UPHIol8=; b=iJ/SuYJ9LhsKb92yr9fl9ZGYlPSIsDnic7+qcU/6rJdZAESk4ElmBX17AeKZHaNIx8ikaYHUdMdwOQTy9G5v+z2zF9g1RyBaXNgIhv9M5oXajEC5OR2ha0sM27O1TdF9eZ22+W7Vj+HHPhUGiu0ZAI40DJUV5+d32cWPPvoL77o3hEIrCfCjAeQDDPI0RIvmVJWiZiq77+x77ACr+vsza7uu5EQ5xBCRfl4k2dFR59XnT4cc+uxjmzUD7RA+hbMWNNOm+nE9/TqCj1NDSUXP/WXEMaQD2H7xhPHWh5VxRJ338OSVvTKhxnb8i5QrBGhfr2HIEkIh39YlaHZ0mwF/xg== 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=2R0jsrKmMDSx2wDubS0WReXS8D74xpRF2RJ+UPHIol8=; b=cfxAVPKz6KSdrjzHTSyqrADkW24XI3x9+NEWhpLzvG11Q/i5bDTbwP4D0gy2jgt9rxRJDgvO0QZQ7vtSsF/vpgfJq79dJ25n18vixvw3AVjg9Wjqwuz9tHx5tRc2QzK2YpM4Mp7bCSDph7/uh1WqPcmT0uiHOErEmACXHiBw62I= 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 AS8PR08MB6946.eurprd08.prod.outlook.com (2603:10a6:20b:345::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:19 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:19 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 02/10] qcow2: compressed read: simplify cluster descriptor passing Date: Tue, 14 Sep 2021 15:24:46 +0300 Message-Id: <20210914122454.141075-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 903ca4d1-a402-41dc-2b53-08d9777ab6eb X-MS-TrafficTypeDiagnostic: AS8PR08MB6946: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1775; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tqJ6fq5I51cioNx6j2FWY6rLiUjkQdz1B7MsoJQ5GxhJKU65iBjCNV+BQam7uXaw3kDH4BFOcP3aKWD90yOMOu0VHaV3MqoaC/pPa9NI/Pvlf5yf1bDYwmB/DZHFe0akfGMztbS4C8ddtyFZo5v6vExfvOxnoAMeUYQGddL9OyByEFFCnAbcEKunpmTbg1z3Sl/k1+rmOOzCw7VqasR/FPmfU5S1w22RIhERHyDwCcKMYPu/WpJhDtqcgob6BgKOZL+hfPse4dxgOiTH3uMIBexqKJkpjZhBwEDUIOJcD1F76e2BbDkj5nJeqROub5u/kaubIBYe+wkZoWdT0tiMi9ob0D08VSK/M5kP1ZlBfRTsLSMWmf+V6VgBQpaQA00XxzRmcIXSTYaN02FfuVHfhz5w7jZhZB0NnKDBrsAgPuEPCuT5HUpptEDra3KPDpHHjnRS1KNTNIWTf9PePbP4aG3BjQCGjPBjbi4Eu/6qYRYKa8n31ZzzJyTlefZAG9v9kDnKuyedmZZNyjRxK7ULsggOuoCnKNsOz+16T9R9+Z8Tqb557cUTMhhnDGYpG3RKwEOfCWVQYe3nIANnNaTmFoxwSVkJGgEZQKpbTmCv7fuE3thsTlWSPzAidOK+w2+CbqRw1fY2QUrVv/VifQ3h1UiZLXkR7dHpECTUBO99/Ro6wh1Yt+Sv118xdUx4t4oLM63ftEnNTn2OXujyP6iJ4Q== 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)(956004)(66556008)(66476007)(2616005)(38350700002)(26005)(86362001)(107886003)(2906002)(6916009)(66946007)(4326008)(508600001)(186003)(5660300002)(6512007)(316002)(6666004)(8936002)(6506007)(6486002)(36756003)(19627235002)(8676002)(83380400001)(52116002)(1076003)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: URP5QqFGv4kssUqkbwwUn69vQQ6aHTTKqD3DnGMNNyKj5K6voasJ0rKAgA1u6CH0e/BnDV3bZpmWit15FHgIX+gczfTxDwsYkSM8RZzlI+j+720aSiOrJ0+VrERjFXPHMeYtFJGWSsbJ2wds45smiHbOOL/Tzgw+kqiWHgQGhIGl+8AxImcJHrG6NMeCoPBrWuCsUfYPy/9LBVrrosTiwaBuWsfDxe/YmWqoQZxgm0EN6CKzAjho5Hr0n+7tOI0k6HXnagFcwJAB5RgpMjgChpUQCoCNcvZOrukqcqrMdtPsaqIQKVYDDiqB/HSjdI3aBbScmhybgfNGjYqSDEYzYryvfDZPwp/mpemnOpCe58IhZIduBuGkgkSr5vpbfuNQArSmE4I53K3ttdeR2ug5ek04bvN2eRy/CltkcLn8/Vk833jllkUBpt/jZQ2qj5CBrCPDeYTrLBkfAXWWWwpCX7fAEyAIx0BBIcY8XDUOFopyEGGrUMWCLGpnS1BUVtfuFEqZrq+FLch6ns0UnaTaQlJmPqPig7WfgBy+1C3dORGKjt59d4+54nnvHIByk0hn33MXuXl0q5kjjQGPjsNZ+Wx2MfdDAhoTZSo5yxjC0Mpn6uif8ZFTciXT2+rs5ME6RPrIJuhRYCN5nR0+2Ujy9aZodq5TtQpScydKvQ6koauTHBCYF3x/H5veLE7LBPlUjJvlO23oihu0625Ihb3j6XT1XUEv4qM/tk6z75ssHwTn1OOGdSF6BFW+ThFKM/fZkr8oZMpJRotjawyaGrS+BoNnCh4MDLH4RR7NTGaqmklPyXghavYD/NLaBRKcaxlDFfNTQ5jhYrJmFIZpJRBe4zSuecX9r5FR5Rnx3gNaUjGZG0f2FUgZgdgjGOkQs47plCa2TI/UYyfVOv7VC1N2ZyBM4HAXtaZHV2vrzVmGJAFIMjJgNvnl/le+98p9TNbeXQPZv5T2IKrW/QrZmRTDSoFd5UMz2TSdbXiU6yI7BiB5xNcKs0/WMaer0vBaekrliFUnBxVU7K7+7mJLxDDMePdydtP+HzxFTD/iSK/0jiHtgArB1PccB1EmE6pLPeUZ2pb+J78Ko8y9zd4q7f7fbuKmEb9N4+bgSty0bzqvYYCqzI81cJ4QUwhxcXRA9bLBLcjzFy9j8jCI2JWpySml7KX1e2kRkOzoci+nSkKL0o9YvCsQdIrrWBJt4OaXoUsgcLsPyvMccRpWHaVu0Lwi5nm41/v8LnOoSwPQnUWwrDKJpBSkrruz2G+fgGYF/Qrxyi9n0MPVh8u6zDulzT0n4I6VAI6MvuoKEFeB7X9UkcCEdUbWvowl4kwFH/m3jBfA X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 903ca4d1-a402-41dc-2b53-08d9777ab6eb X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:19.0327 (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: hpMyJlF6LyindrdNvTTbk2e5e94snk+FmsXBCJ48AuCjyfmU4BoqZisfkB9PbaS3iZTE3QGbANba7rTG/YfB7eAKt0b+V+fQniW/160OgQc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6946 Received-SPF: pass client-ip=40.107.22.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-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" 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 Reviewed-by: Hanna Reitz --- 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 { #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL -#define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL 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(BlockDriverState *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 entry. * * 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 = -EIO; goto fail; } - *host_offset = l2_entry & L2E_COMPRESSED_OFFSET_SIZE_MASK; + *host_offset = l2_entry; break; case QCOW2_SUBCLUSTER_ZERO_PLAIN: case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: diff --git a/block/qcow2.c b/block/qcow2.c index 9f1b6461c8..e5d8ab679e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -74,7 +74,7 @@ typedef struct { 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, @@ -2205,7 +2205,7 @@ typedef struct Qcow2AioTask { 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; @@ -4693,7 +4693,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, 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, @@ -4705,8 +4705,10 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, uint8_t *buf, *out_buf; int offset_in_cluster = offset_into_cluster(s, offset); - coffset = cluster_descriptor & s->cluster_offset_mask; - nb_csectors = ((cluster_descriptor >> s->csize_shift) & s->csize_mask) + 1; + assert(qcow2_get_cluster_type(bs, l2_entry) == QCOW2_CLUSTER_COMPRESSED); + + coffset = l2_entry & s->cluster_offset_mask; + nb_csectors = ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; csize = nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - (coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); From patchwork Tue Sep 14 12:24:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493035 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,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 429C2C433F5 for ; Tue, 14 Sep 2021 12:34:43 +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 B9C1160FED for ; Tue, 14 Sep 2021 12:34:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B9C1160FED Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7e5-0005Dd-Vg for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:34:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VD-0001ov-0N; Tue, 14 Sep 2021 08:25:32 -0400 Received: from mail-am6eur05on2131.outbound.protection.outlook.com ([40.107.22.131]:32082 helo=EUR05-AM6-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 1mQ7VB-000628-5S; Tue, 14 Sep 2021 08:25:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bh+SX2HulcI+UTr47JDkZTjztjTo+iGcmH8OT1mzvR9uGmmO2CHHEMxhZk1ISKcEwrF8h1yaxPV0SJQEKO779Ezv3R/7ryajm4/smBWc3QwpOLPvfvRboD/rlYICSwHTinurfQWutO6xxK9MpWGvRbqxJlIW/kfw9TekEbTAZfNNFinXZkkBBptfRQXTpyt6y1dtmP0I+UJjyrYhzBEFxadmwacIWrwtldvVYdhiXIEnVJl3EqI9XSD9MCGf4m2ZPmcWfjyrStTWVW0BW+5f4kCOm2XAeQtPACIPVKcVoBBuKuW0HRzHL89cXgfX71rBVTVkTmYN0rkCswnqbbqOfQ== 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; bh=MSiABOFcH7Id9Tm3KGA/npPkxqsJWWGPN91EiMSTTMI=; b=STav1cvjmbmIy5fW9YAcyytdMoBuZN6THOKWeCY9CzFor7wUNflzqR+laInFHPR622uJzskTLtSkwKrv+2YJ13o7KLo33sZiw0e/dp5jY2Lhdhv6f5PRegr6Az88HB8ieQO74Spz9NO+COzAohq2qJtgigKUN8QfJdqjD527YBdVfiq5TxaTIGWYmB7VoTGsQSSWCHOnE1Ag0OWKSu2+yCKDNxn2W8sSIo4Q+BfEpnWFSmQGZf48+Tfd4vAasbEVzZ0VszqCPy/taABnKo7PqE80h5pyKBhc1UAYTjqE+errBk4oycfci9SRCwhVt2Lbo1+ib9uzREINRsu8HSuzVA== 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=MSiABOFcH7Id9Tm3KGA/npPkxqsJWWGPN91EiMSTTMI=; b=K0k7akYxwDjcsmxMN1gXdN20V17AAJJIp9IsmSL58TmsS7P4JHO/qoBLrCSET64cInfx8DDifRnBzUqX/5e9Hj0Y/G+jUTODdW3UbOHqg1Ly4RZaR63KEMIZZzNBjTE3ws+63uzUdS0lG+Ywg0/nrVT+Z+eX3AzRUZLK14kl5CI= 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 AS8PR08MB6946.eurprd08.prod.outlook.com (2603:10a6:20b:345::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:20 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:20 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 03/10] qcow2: introduce qcow2_parse_compressed_l2_entry() helper Date: Tue, 14 Sep 2021 15:24:47 +0300 Message-Id: <20210914122454.141075-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 59cfcd87-0572-44f8-49a6-08d9777ab7b6 X-MS-TrafficTypeDiagnostic: AS8PR08MB6946: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1107; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uJdVi5XiIpreymsPqFpO9jB157jgPP6a9L+7mdA1Z7jPZHZL/ibVdRGRrVj32lF7tsvFrjBncqHtupW82WILDH0mbIWWPdBgv5W/dXf7zxUet2pKXkL7VjKZokje7tQ28EHX/nqF79p19JkwCt0stfdxW2W+GdE6NcaJb9mzBeiqFAUFDjbcp4datjlWYXtBDYJehHCUIqHKy70JlROLe7GvPA4ZnnJTbzchCBP/CItO5FiUqgtGHTXTq86A6JsKcIjNo0OmQXq9Vbv7TfQRpdFezM4ng72aY/iZ+pmDh8MsF+jsqZoqyScxVle/sINsjUU2/HCsCZjzzCTUapJiz9LmxGOSMrqaFZnBoGxnXxc08qCta3phkV+MNYMcnC0b3XvkK1NM71uXyUqkWGv3FXkhK2ich1GCI+ivxeohw9hJW84JDUc2CKbvOPgNaqTCfPWq+6GFYwbGAgnjCV5GYZPgqCv1PoNn9nXYGYMcbVPFWwuIgP5nVbhAmqsLlxz7PSrG/OXejZDnTUTT3FictjWAUzyB2MGIudounRmkSheEOI2vos5mV2sLhuR2jyOH+8B9tZywouiwf+DnH0p8TPhfFyW2xzoQrxnmUkuzE9p5tm6TicrIVJwcHRPwM6Ys6Wdm0q/YbU+ZAECa1LkUdvqcan6KvGvKi3+Y1vNtA8scAARQRLxa/jd4Csj95/p3aP0zHHq6U627imaQQns4fg== 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)(956004)(66556008)(66476007)(2616005)(38350700002)(26005)(86362001)(107886003)(2906002)(6916009)(66946007)(4326008)(508600001)(186003)(5660300002)(6512007)(316002)(6666004)(8936002)(6506007)(6486002)(36756003)(8676002)(83380400001)(52116002)(1076003)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +jH+tAQbdvtiaeC7G7/U/Lk9ClRyuhXZx95Rff979pBWop0OJVwqMII1oiXRPsUCNwcZsbCXXHMvp34kNIIAwoj+4ngrDdllMikSOccqErQCD0L8Wb+XzMMfhhAAfIE2C5fMbjRhJVO4ElNbHpQPRFNXrbnscwWGmuaC5QOgQaSBi/K5WXCZm3ry+YE1zkGoqZZhrKKON1+991aZypShLLzyuWIiG+QxzwXpc5CKc1pD10aWs9CFuCDPssbGpbmD96gnhuBfseL0jjCLWQmV+NPnfMKOlhhaNa2gTC52LiQK/iWcP/BREwCj7AY70RELibC9sRWL48qYBEyH/o1c6DVAJGku62Ny1mzw5Ba5fsddks4bcpIMcQ9VAzvAfnGWBmtrHe7BE7Oy/0JT9tZCIudj6KO9JxXgKQ3SIEQ4SmIdB6sxQcinsY5dUVb9WbgRjYu/A4auWIJuQMCgI68ULxLjNvnF3MAE98V90l8dXTYNCEJCVjUerrGrKsY4kb/DW5rZ7otw4g+rHn03qhZScmYnR6PtW6nxs4mIJO9Z8WVEqlqTBaebYavZGvxnakuEdvMJ70spPGnecS7myLNUGreblPCPkCiw9ShT0lYzlSFMKIYep7OW4oKsJP9RbPiQtxXhprIfg6D6dlyAGhwbsU7ISbKne84hS2ILhHof6bQwPscGGwZL0NdC1p7pJ2k3cv0YVqtBq6rgOlFA7GAd0xrHcl4UZe59H3nwzylaKktbJaI8lpWxRKqpiSDuX+9ZPmTx53SBQVfFyBw9q7pUDhSZvIL9fm7FlReGno3kJi3S0SwEmZ2MMe5fU3A0pNIA4Cx6q7DLaR98bgenYEIs3MIs4nH6Dcswe0KEMO3TsqgNoSmLF/9M1Ooc6Bn79ORDXnXNLtwO4RJBaO7nfs8hS0SC2S9r1t2RRiDQjOeeWjDNFj2fIdhzCwFQ4zf+ng9uOmcBJIS7RQsaT1BxtCepUh0HOCus6Uou9UZWHo/F+ivBIlx+ecv8Z0FFN9mWZXLR+/KBZaMc0XXyp3bIt08eQrgxnNdFEJTkM3PAeLKc/CHeEKKlSsAeztTMTgXUJ88bkkGncA6rhM5Gp44qa2J/mtg8R8e+meHVFL0hazZhMJGi6NIV8Yny7OxMGV5xaiCYTyJoyQ+vC/zuvuclPh6p2X+uCuMeJOF9Oh34dEYeXXv6Ujwwn9pWDMMmiUgPxxMwNdH4OBxKYwqc5PgSqb3SCplPTK4lvahCYAUomWBLS8aM852H60XzZiXU2S9d+Ljsgc0H+mJO2ubyivjMPPk5F8nwupDKNiSoCfWj1F9IrueYSBks8IhKRi2aXwb/dT+m X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59cfcd87-0572-44f8-49a6-08d9777ab7b6 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:20.3658 (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: /ZnOrQndJCRIsXqNR7b08Q2Y/7eL1MhQsPY9CJDH8uY+YMtZw46h4Vkmscv1WOrWVZd34Ska6BdMVnzeEhjWT+avkNKMNvakqwsmxQEaZYA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6946 Received-SPF: pass client-ip=40.107.22.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-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" 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 Reviewed-by: Hanna Reitz --- 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 @@ /* Defined in the qcow2 spec (compressed cluster descriptor) */ #define QCOW2_COMPRESSED_SECTOR_SIZE 512U -#define QCOW2_COMPRESSED_SECTOR_MASK (~(QCOW2_COMPRESSED_SECTOR_SIZE - 1ULL)) /* 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(BlockDriverState *bs, uint64_t offset, int compressed_size, uint64_t *host_offset); +void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_entry, + uint64_t *coffset, int *csize); 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_entry, + uint64_t *coffset, int *csize) +{ + BDRVQcow2State *s = bs->opaque; + int nb_csectors; + + assert(qcow2_get_cluster_type(bs, l2_entry) == QCOW2_CLUSTER_COMPRESSED); + + *coffset = l2_entry & s->cluster_offset_mask; + + nb_csectors = ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; + *csize = 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, uint64_t l2_entry, switch (ctype) { case QCOW2_CLUSTER_COMPRESSED: { - int64_t offset = (l2_entry & s->cluster_offset_mask) - & QCOW2_COMPRESSED_SECTOR_MASK; - int size = 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 = false; int64_t old_entry, old_l2_offset; unsigned slice, slice_size2, n_slices; - int i, j, l1_modified = 0, nb_csectors; + int i, j, l1_modified = 0; int ret; assert(addend >= -1 && addend <= 1); @@ -1318,14 +1318,14 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, switch (qcow2_get_cluster_type(bs, entry)) { case QCOW2_CLUSTER_COMPRESSED: - nb_csectors = ((entry >> s->csize_shift) & - s->csize_mask) + 1; if (addend != 0) { - uint64_t coffset = (entry & s->cluster_offset_mask) - & QCOW2_COMPRESSED_SECTOR_MASK; + uint64_t coffset; + int csize; + + qcow2_parse_compressed_l2_entry(bs, entry, + &coffset, &csize); ret = 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, BdrvCheckResult *res, BDRVQcow2State *s = bs->opaque; uint64_t l2_entry; uint64_t next_contiguous_offset = 0; - int i, nb_csectors, ret; + int i, ret; size_t l2_size_bytes = s->l2_size * l2_entry_size(s); g_autofree uint64_t *l2_table = g_malloc(l2_size_bytes); @@ -1617,6 +1617,8 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, /* Do the actual checks */ for (i = 0; i < s->l2_size; i++) { + uint64_t coffset; + int csize; l2_entry = get_l2_entry(s, l2_table, i); switch (qcow2_get_cluster_type(bs, l2_entry)) { @@ -1638,13 +1640,9 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, } /* Mark cluster as used */ - nb_csectors = ((l2_entry >> s->csize_shift) & - s->csize_mask) + 1; - l2_entry &= s->cluster_offset_mask; + qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize); ret = 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, csize); if (ret < 0) { return ret; } diff --git a/block/qcow2.c b/block/qcow2.c index e5d8ab679e..02f9f3e636 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4700,17 +4700,12 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, size_t qiov_offset) { BDRVQcow2State *s = bs->opaque; - int ret = 0, csize, nb_csectors; + int ret = 0, csize; uint64_t coffset; uint8_t *buf, *out_buf; int offset_in_cluster = offset_into_cluster(s, offset); - assert(qcow2_get_cluster_type(bs, l2_entry) == QCOW2_CLUSTER_COMPRESSED); - - coffset = l2_entry & s->cluster_offset_mask; - nb_csectors = ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; - csize = nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - - (coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); + qcow2_parse_compressed_l2_entry(bs, l2_entry, &coffset, &csize); buf = g_try_malloc(csize); if (!buf) { From patchwork Tue Sep 14 12:24:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493017 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,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 779EFC433EF for ; Tue, 14 Sep 2021 12:28:36 +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 BDCBB60F24 for ; Tue, 14 Sep 2021 12:28:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BDCBB60F24 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:43364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7YA-0004oh-UU for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:28:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7V9-0001mi-NX; Tue, 14 Sep 2021 08:25:30 -0400 Received: from mail-eopbgr50116.outbound.protection.outlook.com ([40.107.5.116]:58241 helo=EUR03-VE1-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 1mQ7V7-00065R-PD; Tue, 14 Sep 2021 08:25:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UegPbjcE3eLbBfTMVpcpNkvgmnFnyWkUDh/ZjTGcClu3szChMcVlZ81PwfWQdrCnbElfQE8GXAFWZVGXfTB7fcoPD+Vb3zOjzoMa0jF6RQu95CoPc9oyCutfftF7CfEorMEUVqPAz1i1zMsGvhM9+R6v+wV1hXglKPcXkD8uAUXs+XKUN6mIR0LB1Fqk8BK6ipwp5pOwSPEHMLktEqokmTMvwt8wnLC7LMUD4PqgGP+lpokii5Lr+a8pptWmUzp9C+uq9L9EmPns4fH9aXha+RCB6tZHLBCNARmN3AJyA0F/tNyRvZmOS9NTLu2+OzFIeftQOHsrIgaHB/cGXH/xtQ== 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; bh=KWpJEs2ax9Fm5ZtED2XL1ytdm+DemfPtHxDHmT+2ZtI=; b=Qj4RosI/tH3n7VnMpETbTPB0KjAB53aGagIGpydMQBZjbOYWdW8LEbqSqMeMeSIYVHatNaz7kp8fxab9zvEXz/xLl3i5ZiyZNRsQqDpQK9ePrZZDb7X6mfRnWbBid3KXLSGGjiukOVYV+dVuoHLtvFUeYNvfWl5F/vKEPbAOzwJVw1vTAbJK/k1xapXOYbc4SoueQa6/ZFbRIh0bCbP83eDYVSeBacYSKRP0Hp5yekhDcZgJnBpu0fG3PARJfFY6oseMmtku5TQNQbjEv3UXIiP5eMr7TCtBrjEuR9rZJoc0VW7Zb49yhoeB4fMOfsZGPktAYjawc++Vkq9fI04FvA== 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=KWpJEs2ax9Fm5ZtED2XL1ytdm+DemfPtHxDHmT+2ZtI=; b=kD8EarMCbM1b/VLlvbLgowEtZj3j4GN2y3dBjc27VOVxpcrfcwMIadPsZEtglTQ+AcXTfCO+B8MJ3UkRb6Sr3o5O0V7kFkN8ctSGBrX41QYq6Xqg/Rw1EsLU9d8b1uAbq3jfE36w6444qDOFxuaT+YRu/LTiDqhlR50xKssQIn8= 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 AM6PR08MB3158.eurprd08.prod.outlook.com (2603:10a6:209:44::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:21 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:21 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 04/10] qcow2-refcount: introduce fix_l2_entry_by_zero() Date: Tue, 14 Sep 2021 15:24:48 +0300 Message-Id: <20210914122454.141075-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e58293b7-2648-4c6a-4af0-08d9777ab884 X-MS-TrafficTypeDiagnostic: AM6PR08MB3158: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JIPvY4zhKN1IbTahf9oJGYsxSf+1jCvz0VEypyaSId+HrtBhyWG//r5CNIAZi2e9moLhlEFT1R8LgkdXpn7B78AXTWy/jPwO0WfHGHSVUwAXa2+P1cAFFpxLKFeiPgaQUZclTEAjdHk6S+DF+1VMiNQyhmOMZv2rJTV/eP0ECzIirp2HqY900uEjHFKDkagJ/zJg5+qKXE4dzsEsKniCq8mboQ7upFqv1bFF2iiWQQSnaTTEEZ3l/zfEwetQuEM5kkx1G4d8jNUtdEMhxorRQh2O4uGD+8ULt22M585y+Y8P8LidIOChDab5XE7rfnT3cj/2isXFkm9/rZht7cpCAY47fxaPSin6Xzm/yItnU9p0nHWmQBXU2YGuwGPi/Gx5+pWJwZ50L5woyJEpHMdVxxgNBooENWxeEeUHalxMBqwbEQTZAk7KFGx8ItxHzKmeO3eSbwW/HeC/ElHeLt+k+Y5ukptqD24Ea2LL211TSruzX3jBu/N8xP8CMDNbt+bWgtzsyvxlPB7Bik4/26/kLaCExu66Fm1+tg3jiFR5q52FHaPSHpFVsn46dldfpTMG3EjFeQzBzM2SwxV3AfhzFJ9wP7+Anl/pxjoXhakKI84CtU3Yhk49kXybyIJbZxWLTKPL80ibKlwk2c232Omv0HE3v5mC+FbgDAdFsi3lHqrVQe/s+3yd3FQ1IyR5Gje+58CkGS33kpUFMFiqr2fMlw== 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)(136003)(396003)(376002)(346002)(39850400004)(366004)(26005)(186003)(6506007)(478600001)(36756003)(38100700002)(38350700002)(86362001)(8936002)(1076003)(2616005)(316002)(4326008)(6512007)(107886003)(83380400001)(6486002)(2906002)(956004)(6666004)(66476007)(52116002)(66556008)(8676002)(6916009)(66946007)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: T9ynxrHSGiCBeJ26KytEkRYiKFYKamdc3f6iL/934yrEvUvxXZgFN4jtEVNtRhaX5nByPzskx/Im7p5B2Y/tJI2BmdVhhgapnGl5yMyJQh4Trd0UXVGPZbFEhT7Vgp1h7067gZp234wt31Xdf1pZSLWL7+1ZTbHmIagbENDtv2VBpb67t6NQg+VyYXiBeuu9K7HpkjU7ODlH3GyBTCGbK1fDcCsUJL7jt0/2DWsbcVFboYWlQJSgeYxDVEV2S9QJlRRXWo5nahMlvqlbmxaLCvkIhg0b5DXIQGwlvcrxF9cK4AwPFHbEwizd1g8DpHwRHVPS4BS4gfS3Z/K/hvASQLtnd3Cwr9IteJebtfDMg8Ef1pt/MviN9uIp3XVm+bgW/kaKfpMTLVtfztx90ogekez2oxbZbJGpbMeo+OONNqLDLpw39nb06o3dpFUVsOKIqnteXZ+GTsyhVmAAY92bhVLluLZpu7FwuBkdEiQMR6nDaZSSVXi3xhiaK7JgGxcQDz4Mu3J4DgQoh1cncuCHUxKhWrPr9r+IXnP3Im/wMHBZc71HbhC4nAJSyRJ9iP2VdRrJNoXoQ4rVclLVG8kRwF81QeZ+Gfym5pzHlEFEbpOn3Zp8m9/TGz+lCHHjDgKah8mtxPyPlsvRqoNWUtW/r2L8zPABsf9fWl+l1oVnjq9x8G5GRWE4wuXZkWkI1IllvYF9YMVXCi33nyYET3RiLgVTc3XDIePiAhA3zb1hh6iu818JtLIsmj8HNE7nfTtkaAEvPMXvzK2PiTsDK1Gvpk8SLhxQSYUEH6uT3ElIxW07i6oLczVH0+5MTxRdpAoXs+XpHNsqdTOobaEqNAiSkTFXO93bgcNGHIK3kTze69MU3OB0HE0T12DEHyG8Wb8qgoH32onu6MAT/NDdcakzvIdimFOVUV3GwUTwo4t7ZAoZ9r4HBxLWMbRu0q0QCxyKR/VhotpnQ53fIipecPdhuH0UAL1kdsQ1MaCmrMv1MLKqd5MueLEDgmLMgDNkW1uRbZXbNZpbU5dv/2S1S5RJDzcMtS5UqqerbcKn8Z9fx7Xsmj0eOqihNmzPzV8/qikWSz/5y4tqFFAUK4uLdNyIrmBL4mCFVA5BxybKPBA5Ot4Rwez+xfUzlyCpvbb7g2i8xafB9bfNV7T7Qdmrs8cISYWtuXuC45ZaDEDIOXaJUnNS+f4itOuIq9Rk+EHPu+4UN/2lPS/rBwSPbRZtrnf19Mz6xRh8yf/NmezOeBpxEI9/Dega4g18DIfYq8BzEGaU1psa6qGDnii+tCHOYL8yYEYHGEZLQUwA/D3xhb8Q3Sq69gxyVUElKNMe+lRHaJ9e X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e58293b7-2648-4c6a-4af0-08d9777ab884 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:21.7408 (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: qJPsrDMbrJHeFvjD/W6JI2bav1H2SttajSxRGwEEUJkg2vimipZrd2dUwJVgBVOCJnPcC1sxNB1ZFqu/W/5YCu8aQFou54Tn68lT0yXt/+U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3158 Received-SPF: pass client-ip=40.107.5.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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" 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 Reviewed-by: Hanna Reitz --- 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 = 0x2, /* update BlockFragInfo counters */ }; +/* + * 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 active, + bool *metadata_overlap) +{ + BDRVQcow2State *s = bs->opaque; + int ret; + int idx = l2_index * (l2_entry_size(s) / sizeof(uint64_t)); + uint64_t l2e_offset = l2_offset + (uint64_t)l2_index * l2_entry_size(s); + int ign = active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; + uint64_t l2_entry = has_subclusters(s) ? 0 : QCOW_OFLAG_ZERO; + + set_l2_entry(s, l2_table, l2_index, l2_entry); + ret = qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_size(s), + false); + if (metadata_overlap) { + *metadata_overlap = ret < 0; + } + if (ret < 0) { + fprintf(stderr, "ERROR: Overlap check failed\n"); + goto fail; + } + + ret = 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, BdrvCheckResult *res, int i, ret; size_t l2_size_bytes = s->l2_size * l2_entry_size(s); g_autofree uint64_t *l2_table = g_malloc(l2_size_bytes); + bool metadata_overlap; /* Read L2 table from disk */ ret = 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 = i * (l2_entry_size(s) / sizeof(uint64_t)); - uint64_t l2e_offset = - l2_offset + (uint64_t)i * l2_entry_size(s); - int ign = active ? QCOW2_OL_ACTIVE_L2 : - QCOW2_OL_INACTIVE_L2; - - l2_entry = has_subclusters(s) ? 0 : QCOW_OFLAG_ZERO; - set_l2_entry(s, l2_table, i, l2_entry); - ret = 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 = fix_l2_entry_by_zero(bs, res, l2_offset, + l2_table, i, active, + &metadata_overlap); + if (metadata_overlap) { /* * Something is seriously wrong, so abort checking * this L2 table. @@ -1705,26 +1745,19 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, return ret; } - ret = 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 == 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=%" PRIx64 ": Data cluster is " From patchwork Tue Sep 14 12:24:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493015 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,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 D2107C433EF for ; Tue, 14 Sep 2021 12:28:33 +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 4478F60F92 for ; Tue, 14 Sep 2021 12:28:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4478F60F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:43298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7Y8-0004mD-CN for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:28:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VD-0001oy-Mg; Tue, 14 Sep 2021 08:25:32 -0400 Received: from mail-eopbgr50116.outbound.protection.outlook.com ([40.107.5.116]:58241 helo=EUR03-VE1-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 1mQ7VB-00065R-0j; Tue, 14 Sep 2021 08:25:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hwShODzvgDxQoGnqJlmD3XjJ4vICcVzaalr7vAx87FIMEfvPG50O+ghjUoRYXzVbzqWAzfeT+h9gKwmgvS1Agt6+YPRcWonHctzcdEhIQIMRNfUShv8+qrFgkuI63gGyNH63YntEmgjAq3Vgp8M7QsJRc3jkO99Y+k/AUzMhCeMKCwIzgEFdLoykgrqojmpS7GYREd1AYpLUebews31JcsnhTNxzyfn/eTUh67iXisUCJr1q2qvrwgBbB6P/vQ8OYIiwxN61muXGpQxXWaV4hpIB2x6Y4xlLn/F6SeZQtoykWRcrB4OS2qS3ADp7LQNHbQ/OsH9ziawwjOn547B1gQ== 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; bh=ywiWkJe2B1CPMO0ZMwLB/2a+ZwE2xpwlJy1GjXMWDGo=; b=GtZjm6924KdWwfMveqvG+7mG6G0pWhbS6+0FMMxoIIN+QlRutrAVTFb0L/OZR7lPBJ1IUQyADC1g2t1rCW+x8ABGVwxu5VEy4xiFzsPgRjMVLhaO3HirZqGzcUNRluw4Ne4B/FFnFCw3vr4KzIJI/aOLmawB9QnZaObWJIr4TyxNZK95W/XbosRn8Fq00S+X/MBP9GBp2KtLFXbMkvkHdnsMvpabr8sAw1WtwLSyy7FMbk+txRiV/uHfGXrywbO5eTToViSg++qe/Al20SDlTI8qGpXC1hv+8HIuNqc3zL/VteXoUkqef8T2padS+8aHwJW0XDcnlEvBED7IuvYWCw== 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=ywiWkJe2B1CPMO0ZMwLB/2a+ZwE2xpwlJy1GjXMWDGo=; b=Y/vOvnj0HPiLuGuBhGgCblBABi+1uS24uujfnxZKm3VA+kKXbYCbYFdC6UqL5gp+qwabTQ7NnL0h2DwdYwgjV1JF+er61qMpPrf0BJ0HqokETPsi/Dh1/q3Kxz3DXLReqJqSnPXViWAX34VYbqZGaE/oOk3jiTtDldJz1kdU7xI= 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 AM6PR08MB3158.eurprd08.prod.outlook.com (2603:10a6:209:44::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:23 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:23 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 05/10] qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry bitmap Date: Tue, 14 Sep 2021 15:24:49 +0300 Message-Id: <20210914122454.141075-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d584efaf-83dd-48c8-fb7f-08d9777ab958 X-MS-TrafficTypeDiagnostic: AM6PR08MB3158: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:136; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YCqiMFC6Ecx6OZis8ZcwdwbbsrrkfcRxreBbSFGPNKEkYgIALXCp+Ly58XypCUhCw0LP5aATZqhDn2INiBz8B/RLy+OXkdYgAcD5ZpwOAZ3UPtgq2UbUnUvTMKJmoH2cj1b/wgiYWp15sgQfjMLPO4GnXd9s25i2Av1pWdaIOb3kBx59wIDu+QROVQhGHYK7vs9eh/K5I2E04+KNDZpQ7sF9tnr8aNC8T1KGpQeHrXZFUOt5MSLPc8vcik54N2OhAfg2N/H2/UqfU/VRdElxefstM0HAmyby3Or+iIVDKzR+o/htqSQdkAYzVl8/0/v52HNO0Dk+2mpVJTMjrHngj0O765PHE+qiXtyRVydtiPoRQ0iv5bpw5dVlauGpCsWjM5uZA7BqJ/cQcunP+8PUADYDfbsNC8yvMSChPBjNHzmd7MK906jFlsTF/Kt8ag82cHMTQG/wiAWe8hm2JLkaLhkx/Py68E7WdjgUbACKHHOCOZRrlFEiLUeDpvWchBPd8RvC3aC1YAEa+19pG8K8VVz+Ql5ChYoHaAcFcuNaIwMlRPGF+qGBvDyb9bLIunkGLq+dVOr3Fu2KM5JJV7z5Pcu0rPtnmRGg1wfXVLjlCOMTQoytYKfdhU2bGHmN6zQ8KpgcCmfYeOoSPyT1+3i/MFelMu+M4JXjLrbsYgLyuQRrlYzLjjNNi+evj25sxdzdwjPyEiavQsDhdL35rauZjg== 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)(136003)(396003)(376002)(346002)(39850400004)(366004)(26005)(186003)(6506007)(478600001)(36756003)(38100700002)(38350700002)(86362001)(8936002)(1076003)(2616005)(316002)(4326008)(6512007)(107886003)(83380400001)(6486002)(2906002)(956004)(6666004)(66476007)(52116002)(66556008)(8676002)(6916009)(66946007)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KYOYExy3FVAP8CuyfqsJzGJBGqmb5dwLvfMyGy6mbz4FBJkrbHYzhQxMTVX11OgkgwhRbMaIJyWM1kELWPq/Oomz29KgIt6hEY+bmWnWG8kfJlJIcWyKb8WShEtovGEdN3CpFEeljPJ9oCe8n3v9SumSU9VfQdy4kzQLyftUsqalWxCY7yjlNAH15Xptu/+jY92+1Nwama6ZH+m5ngC2pngXnHvwuv1h+lz8rVWEgYA54TqQWoxc2WYuRxFjp7lV+ks0n1dNYtgGP1A21PM/kwCg//fYoohW3jY/wnE0O0ChiwYzdcuJfywhbpWkbdx5jpnMzyjTudPMZL1zsW19xYzGZyezHLnSqziivoa+KNPDxv0zxg+86SDJUTcDDUu4KT59sUBdsSoP2Ko/vBz123Fk5ckxAe7VPbUiS8Up5G0xJMxhQfzq8Zm2v+yLJ5JVNoX7x17gQbV5quKVA+SUWiVLr44KUK2pKy2RyVWU/oU3B0lJ0eaT5j+EiPvPRTo+etDUVbsgTZ24olr/mMBehEIsn8O3cZqaNjnCBEBUd+9XSckBbDhzC+ASKy7eXLZSXTRTpBifFYkJqmBFc52P2/5r4xKAHGn0zJycYTItLMfUjCEK7BTKOBt7U9vo0a9B5TxO8nUHcZBZ6Gm2IQHED6+riNu3DCyKTYYXsQK5hphShwpPqpmrLhst9WlszpArf8xyEe6svLZIYWNhYI7uqAOvIXe65rLnC10klByPXJ+uDpQ73i/uEhzM2yuS1XJSVrM7zhiGa35fNmTmLnflEmNbBm5ULawgkhCqEVLAQykR5FutYNH+ddcFju3+lFnMbRhQKrsoae02SRPoHuksbdesadhTyV8UpftDRTOlTzSDJ0GavEESAk+mBXhqA2jWkItNcKr+BmAmN080j3uiVhu26A3iHI0V/3yFqYll3E4394FfzYe3d92Sui+2zptkJtfDLmfVDiJ+Xoob43wprLOmOQbjDisUXSWww32rPnr4synJ/8ViutJg5NNEb2wmi5YChgV3JvWTn/cJGbxnMevJ+Nsyx2tbuNrD4xddpz+ZFKsXaBReh329ttbRNCUhsNvPrSMoJfP9F2q2qUEYvMdXUeLAHI8SyBYjczJcrEP+KBo9rVSWYUYTTUDP+LV4+wW+a0Q0b7aGI0lxUzK69tU+dcIWmZAJI+UA3GUmVrTZU3MdArm8PF7WOvN+6KuwhuhX+ZuVJJdlJR1wy5mnmOmc4U2EzJmnLh3jwZ17d+o0Dt730LFpk30E1cO+3s1P42m72hKcQGPM8PwkdfFSRxek6L/unhedcylTN6vX1bYJq8O51DpUG/2LX2xpuJc4 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d584efaf-83dd-48c8-fb7f-08d9777ab958 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:23.0401 (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: Emi1lU/6LJiBZfOu7Tyx52HcNdrP7PmkMySUoQZpkM1AfwT7yosDluxfS8c056Tw78NFnMapii/L/eTYXT0gcY2dtIM3Lc+fWhXmxM/ldqE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3158 Received-SPF: pass client-ip=40.107.5.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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" We'll reuse the function to fix wrong L2 entry bitmap. Support it now. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- 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 { }; /* - * Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN. + * Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN (or making all its present + * 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 = l2_index * (l2_entry_size(s) / sizeof(uint64_t)); uint64_t l2e_offset = l2_offset + (uint64_t)l2_index * l2_entry_size(s); int ign = active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; - uint64_t l2_entry = has_subclusters(s) ? 0 : QCOW_OFLAG_ZERO; - set_l2_entry(s, l2_table, l2_index, l2_entry); + if (has_subclusters(s)) { + uint64_t l2_bitmap = get_l2_bitmap(s, l2_table, l2_index); + + /* Allocated subclusters become zero */ + l2_bitmap |= l2_bitmap << 32; + l2_bitmap &= 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 = qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_size(s), false); if (metadata_overlap) { From patchwork Tue Sep 14 12:24:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493023 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,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 9E785C433EF for ; Tue, 14 Sep 2021 12:32:33 +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 3993460FED for ; Tue, 14 Sep 2021 12:32:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3993460FED Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:52610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7c0-0002i5-CO for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:32:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VG-0001sO-9B; Tue, 14 Sep 2021 08:25:34 -0400 Received: from mail-eopbgr50116.outbound.protection.outlook.com ([40.107.5.116]:58241 helo=EUR03-VE1-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 1mQ7VE-00065R-Dm; Tue, 14 Sep 2021 08:25:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AFEB+pkSEcF4Ga8i2yKdIAjULp3mVToXp4/qKZEOse+g1YI4nXim+CG89e3nlMT6DU4ENMw9f0ez+GLJ9lR179O05hdq5wjKTd1EEvCg9C/GrU1XCgVd5zBfke1h5jiHnlSr1Kj7OAkBh7UriEReOb/8xwCKCBb2GtIebDhVMo8t7N5J4U1WJ/WTNfN0r4Ry4MRQxnACLypfcsjUhbKK4ERIVlY55U4fRS2AJgr5oWlDJ8Sxv2NqRqr0O31Iu3Q3iqo9qEUdEzJ35d1+k74sVC60otCJegb7VE76YhpTyOb99h+TVJ1LOn+Nt5jstSdM4AM4FRz85cx9uah1704Lqw== 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; bh=8rdt9D164FRdKx9NBMPkBjNfXBaw8NV2pzs2lRsFwuw=; b=SC6oaDrq+/UH1UkBNPYBhTmleOnwQYawRqhqZlj/ywK9tIQT/hGmWuEHPy5inK1cN/dKMpbJ7Yfrra1NPgRoEXFKTeMmP8wo+bACuFUoFVwO9dZiz2Yu7yz8TolzIIBx44cCp1PW11BbFnye6IIrg+EhibkLNhf9ATEIBvLkU5d4vmD4IfYy6CmdjRs6vt1MbrgOMB8yBBOkPX4l8iBknLthlCQhX3vySx4TCiFLE7H7u+IpgKsPEUQ1nD9XkxoElwvz7+VOa6tx1I5FIx2hBwBxVteNee7eNvvsw0q3VxFrsHn2o/7H7EKoc7vUJgLU0AoWzdoxxk26FUN0YNobuA== 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=8rdt9D164FRdKx9NBMPkBjNfXBaw8NV2pzs2lRsFwuw=; b=nQtZ4Zu50Mr1cxOdYaJEoWy513oniXburhyIjOEoDusDafhZ0O4NxPZ31TmG1UBUqzHhZSRPFgSzlGcJVV8n/NYbpDAiG6sPYX76H9ieepPpsMoaVJiBYh9N7FqjDVVYkwqGf6Lu0D8yZqdGusdHyQ746BF6ClADVIRKeGUU8vg= 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 AM6PR08MB3158.eurprd08.prod.outlook.com (2603:10a6:209:44::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:24 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:24 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 06/10] qcow2-refcount: check_refcounts_l2(): check l2_bitmap Date: Tue, 14 Sep 2021 15:24:50 +0300 Message-Id: <20210914122454.141075-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7521419d-0654-4531-5083-08d9777aba19 X-MS-TrafficTypeDiagnostic: AM6PR08MB3158: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:293; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pcc1MOOkL5+WBJKZ3hGejmlXPHxf0oi30O0FGQQ1XgypOY+rUJpt+Kd6GXBMfeiLddz59khlz8xiZxpjgj2468GpwtTwyyzn3VUIt45EefyDwt5+SgUIdHuEM6oVqLhUw+C1JVf14L/JgBXgDnleW83DxKNdAWYwgwmkXF8MAt/H15Au3NoIMxINcoQ6GBsSTiKjY9z9gsCZu6Ojd2udpPRq+jAsNYdbyMtYlp73ti5xB5SLTcUQXL8IxRedq+VgwnZyn5o3LEIbTkyWF1t0T4a41fs4Bby62IXFcp9yadip9HEGGWxm2ljhzaW/t0U8GT34r9XyXlCeucU1efa1tyBwFtRy30do99qB5DLFw62lHWIVCEufAICAEQGdVMOxoyl+0vGKlQ6capvi0C4PvXxCVV35U7kvXMfh1eoyGAeU2lzz88wwi32ZfuLoGP+QD1o/Ncn8pIz2EM0rQHUWjRD9l8/ZTxFQjS9w76OJynAE0WCiR3UpcFAuRBCOmaJ9qf9YSEUBakM9r+vry/ndLeX/iaQ4bXTPaQmkl471cBdL2ZA8sH40RVULRZHY9Q7pPrVSZ5KQscXeVLC5ns4tRUylA1rsR3dWXGPuvG//8rjqYkzbqU2+CRUnwOtvVJKKSS7t0rMnuqTHAiETn7VlTMtKOUBU8B2ePhoiqqMiTZ+MNmRktI+Mj42TYK+SdGRRw3JqCjoh85jPOlQaaWfrgQ== 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)(136003)(396003)(376002)(346002)(39850400004)(366004)(26005)(186003)(6506007)(478600001)(36756003)(38100700002)(38350700002)(86362001)(8936002)(1076003)(2616005)(316002)(4326008)(6512007)(107886003)(83380400001)(6486002)(2906002)(956004)(6666004)(66476007)(52116002)(66556008)(8676002)(6916009)(66946007)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B2iPHNHQiucfZIZM6Ge1hqLmcYLd7tJPItvZmmzj6s4HLGHTrV+LLskbrChfN6iHNexoT8dYKnabuWOpM8iAKZhf+CJwfAmEmXO+JxTDXm5ZOJgb3e9gvx8JPWn1qk7chgoDYB0u/hBjbxLakpdhW13H9IkzeizBbYtz8v9vofn+3T+SYV6bdlhFJA5sFtYyMqzX59SsblbSvRU+z+/WCm2oKIKRlXuijAP4ve/4Q+8bn8i2C8cwdaoMRQp81cI9+cBjYhxYvkB2W1jvoNAHWSHtlSywrAd0Tbirm0VcYp/TBNrclmierMXf8n2hRK3VuN/CzQdb+LEb+tvBNES29vA/u0AicykVmPni6sM5WxWKZRJ3MVRcTxXvYYCwagAkdhlo+Jm//b5TSH5odI/k0KalxhKxghTtql2pbFxK9F8QYkc+yIYC3pGVHLMeitHSuEYBl2RJcCieaVpaNMQnuX0NjZORTjUNTsloNctY7ijMKORz97x3FR3GmMyV8GRFsUn8yLr6SrsbRFcYpcFeb5FiGTbfCt8MtfQD4d4zcGFX9n47wedGz7KVZfFU4trbKLgez2gj6Mi5n6OzcCatjMeAAcUAQDvaXX5J21u81JxYNt1FXRNr70iBB7qtEZjkYA+rJ2cV4tKJg9C2UVXOK4Wj8Og5B8+PS38syFr02gD1Q66yhR2cgg+1BbOfMWXSiYeMeqW8JdI0ko+gwPg2KK39WIDgVFza8qz2clBzCBxunNidYdRqSw3Q1V1ln3+v7hiWTYZehKeAnecm2MZmdRIP/D2dHRfvPcceUhi3uXsgoNydMwrOnw9kc13J2qqIoNWoz17A+3GWItimu/e3YRtX/bTjszLTFk2WpN2a59O6F24we2VkjVLqmdXxZ9UBe0vYUZ7xfvBfKbHj9bn0bbA2IikikMr7DdDxKaoqPsrR/1Hv5ZHxR/BAdMYn7Jh5KtttcaPHi/61+rSvlyTVc0SszoykONX+kxJ+6Vc0CJDU4JcgoQfeO4OIAve4gaMkn5lvZX2ZHzSlw02UxqfaFqCLK77jET1Llr3vWLtpIJSQ/Xb2rlH82SM9jyExhHbOVYYY3RB2gqJ8PEZpVIuFlKflouR9djSuFtPwzL1fu+4L59zCF5QDvxDeJBta6iLy3IFxzfS185Na83lmvFB0WCwaVO6LxHUACfKclTC0dXDIdCfiz9oEf+lcC4I/3ili+Su8vB1pdZVCziVvqk/Dmp9CgaAD0ger3EZBEBs05vtBQcXoKDBytrOEL7fGtsxlKsKwlHRpSFqaCDH8Rxsteq8ogrqNSoqT/wXDAHhUbaBFKnflUg83uhnwuGhUgo+B X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7521419d-0654-4531-5083-08d9777aba19 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:24.3404 (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: XXLC8QgBf1y0FMRFF6I+ToOXx8GiI+ndALpMBftUs9Y9+GY/qE6NiuCkPozGgHJn7hjlhFzUX56f3wNWq0Hb613hX8yXS/dKdkG8IQmDa10= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3158 Received-SPF: pass client-ip=40.107.5.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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) Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Kirill Tkhai Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- block/qcow2-refcount.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index f48c5e1b5d..9a5ae3cac4 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1661,7 +1661,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, int flags, BdrvCheckMode fix, bool active) { BDRVQcow2State *s = bs->opaque; - uint64_t l2_entry; + uint64_t l2_entry, l2_bitmap; uint64_t next_contiguous_offset = 0; int i, ret; size_t l2_size_bytes = s->l2_size * l2_entry_size(s); @@ -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); + 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); @@ -1799,7 +1814,16 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, } case QCOW2_CLUSTER_ZERO_PLAIN: + /* Impossible when image has subclusters */ + assert(!l2_bitmap); + break; + case QCOW2_CLUSTER_UNALLOCATED: + if (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLOC) { + res->corruptions++; + fprintf(stderr, "ERROR: Unallocated " + "cluster has non-zero subcluster allocation map\n"); + } break; default: From patchwork Tue Sep 14 12:24:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493033 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,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 5B304C433F5 for ; Tue, 14 Sep 2021 12:34:19 +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 C96A860FED for ; Tue, 14 Sep 2021 12:34:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C96A860FED Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:55176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7dg-0004St-Vv for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:34:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VI-0001zi-OW; Tue, 14 Sep 2021 08:25:36 -0400 Received: from mail-eopbgr50116.outbound.protection.outlook.com ([40.107.5.116]:58241 helo=EUR03-VE1-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 1mQ7VH-00065R-0p; Tue, 14 Sep 2021 08:25:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HhIhXTZSBgPcQrgVA9/jOmMjU9quh5B52KjEk1RMbSgcO37Ag0jWKKBeNAsHgAatHscFcJeT9NVdHlR3P4kuQAexkjmdxZqm3ZlZJiPCmh7NoLdTVdk3X0omnGiLoxhor6fAcxj44CNydXlVXl9aDliWMyuDWef9rVjaFmUT1aIL10WdAg6v9Ppz32YibZqmerwT99CsfihnB9k9kNNKriFDrqfay7n9qPrPtLeCzQH1Bad3490GW1Gql/ATl7dIdODLfa8aPo/Kbiiu5aN/jN/jaL6xB+paBf+Js568MrgMwGhMtyNjg9mgNd8uLGTmdz9r3vfAnO85K1wxbO1yew== 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; bh=C0q4bVkTdma+8RnVvD/WZadTsoKuSpYIff+f08Msc6w=; b=Uff/JQPB9NRgUax/A6jLuAKx+dzTnuPWlHLhmHyDxtfo4qMKkChQ4k36LlfluTweD8r4B9/O0VN+lvBSpDmBHfwmjGk3lj7PduZUm3SbUUZx3qe2tEprXC2/YTyqlDOAmZLTO64tNOGW05kb/GuD50eXwF26n4fVY0HzdTh2WnCwiUsN+qYrc5/zpsFE55QDuOK8jfeFWO9Lhk280dBOeyjBWgDyOUTyBZk6wSpYw6MJdCJmKvYLKX3Py4laGEE2w3gDfl89LzWOlapYHKTjVIiG6pdI8vPwxpVUqNqAuQ15mUip+a9mUxExnQBYC9MiaByAIR15STb9c3cWORb15g== 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=C0q4bVkTdma+8RnVvD/WZadTsoKuSpYIff+f08Msc6w=; b=wER/RY5LE/ardRlmdZbK6RkJXvV6p8LwKlImIvqFXm96drGURwT2oBz0jZsWVyGY3ESys8xw/0dbT8af2Q0qR7Ro0NgcHBYD/X3oT3qkalo+AWBVJoLsPFC+rAj0Sg5dDXDIVSFKzFYwM2N0R+mOPYU89YZpmf+GBOIB9gZnP1A= 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 AM6PR08MB3158.eurprd08.prod.outlook.com (2603:10a6:209:44::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:25 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:25 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 07/10] qcow2-refcount: check_refcounts_l2(): check reserved bits Date: Tue, 14 Sep 2021 15:24:51 +0300 Message-Id: <20210914122454.141075-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 70f9d469-291d-4d2a-e9ee-08d9777abae2 X-MS-TrafficTypeDiagnostic: AM6PR08MB3158: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:53; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BlmeTCQGUdrhgk/Qh9VPAorOnAjYgoR3g/sFD420gxB/6Tcro3bwpQScc+rI5nMSOUuXKv9FTSw1E/tB3YtVx0RYMyIiqaqOr/sKW0ir69ec/9SmQNbl3zRm/Uzykz4TSxsx5pflsJzIQZOKqNpPNDvQ+c+RsFnn2D24FFxDgkn9qMgPAc9jGruW1pEfDI6WcDY17F9vMGlYtif4waIPWjzHGYGna6yZuD4yRZdl+YdQL5mxUNhNXeUJL9pySZbm9QSrpt01sy1vORaY4lHMHMMTuTEd/nTukyyMFzNymJgeQcRyI2yjxiLxizGp6f+QIyyX2qQVq6iq/ZQg/EDB5/mOZ2OtOFC3wED78I+ozElfUuJQsZQJH0L5grky2mC+3C3BbrMtBDnZznyeq7pyZuQXnUZ758SqBMjb6C/GhwKhsxegLQ4YMQMk6KJ0FkZI3pk5IJPaPgLYAzE52JjwTWSIqdbpTj4MHTxp+TirsHoNumF8xDSgwH1rso+NPJ9AMdKjM3jCn1cEnQzz7e1/Mk/WBsx3wou6XUi5Jmv4pkLs3ZeMWFfm4kkFNM0OhFsczBcOrlr4s0/44DIWvZJs/ordlbZ1NnGcVyhyKLrTcy8sBtu95reJR+PZRZKMYnvvUlwmNEmuPaJDIR93T9gzJdeCfHk6Qmp8LDrNwFaQSdPmfyQye8OOoiyJRhY5XDFM10c1zTgUM5BEFHYNTJsuRA== 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)(136003)(396003)(376002)(346002)(39850400004)(366004)(26005)(186003)(6506007)(478600001)(36756003)(38100700002)(38350700002)(19627235002)(86362001)(8936002)(1076003)(2616005)(316002)(4326008)(6512007)(107886003)(83380400001)(6486002)(2906002)(956004)(6666004)(66476007)(52116002)(66556008)(8676002)(6916009)(66946007)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q9EGmDYaJEfi6pKBIDvKMk/4brkZHpEFJJCp0T9nEcHvTeYpZIqpYXJkZlZ9UMvW4quGq/7Wfz5kGMXFkTTiDXhmfe2yQmyH83gAMdOAsdXwPRHA4sgSFJdreO54qzquktZPNI15M5C6vw7E+GMBL9BkI8f0fJ6f1sHIZ1g54NJkMu9ScwwQW5H+20j3CnFNojdJq5debwazAEqmQ/BOFoonXuITrO/jX+tS4GEjKnmutRUXMotEppRFaRLB8xR3etjji/dRr++UUhVvId4OAsICrbWJM2cT1am/lhxEm/e9cBieaD3s8cVvpGUDYU9rnBMZyL0L2s7Dx1q59D6jlFFpB4vUwPhCe/k4jSXeikje7RW+MVTkswnPvsKofGrpokAo73BvYL2eeFAfFEhseQyDQqXuwFw44ootuGtFZ94EpL9VnhMYZPGQFxvF9VvdbtuXDByJyM7aWkFpOHjyPThdC+u265WK2Pr+p4BEUtzGA6W3EcE2mPV3a4SlU5zwesZqbLLJWJ/CB9rCvLfjO3HTN3+PX3v1DKCUdl7mSjUSElzHAAhsLuup2UXslwpTRt7hc8ndvN5jC9yVm6jsf3u9vCaX+l2LDP464gIGtkxMvvE5VPBgN7a6o+W3tU3Qs8J/7E1t6zvu/KiaLySA/vtnWEhw3etrTT4x0mgsdjgsRFd4PeAH8HT8KMAS9PoVjmbstoFDzSd0FSjs1WLU+DZt3irrYRsi1y2fSBHs6KWEzqp2k6/U4+eqVDTlSi7kbQuE6kO0I1S6gxUhIyVrc71AZsQ7Qf5jTpB+NkSKK0kiyAadi99VLvVdOJAX8DsEAja5S0uEEZnExASCO66mLTOnZk2IHcwTDI3296piiuzPfsdOpItF7OiDgyhBPIJ8DGCJImcAvOkElJ5x/dIKfysdpdpEr+tqYFDanSsw1tlHvnaoqLag5LDzGD+6BYER4NiyvHSDxYQTqbyrJ0/P0WQWyYZ/uIfoqS6BYy+aE3E5S2bXK1lF/tBE5ec+Y7WtnZh9uus8b22b0rAsUmeAsthF6VqroGrLj/BSp4+VPcw9kEiWiMsiOcJwXmFQb/afe8nr7lpQu9vfaV0kF89ZQveYo9qlquEwsG13CkWyzTq7AKLbX4cWYEwi5FUCqQPa1tQlVr11uLOC+JnFqikB+icWBOwPcHqBdGN8dt3LKEWaoOdfoubLspEAe6TJ427pbXxr0eclaAL3VQ32T6dr3QgU61EwTJDZukutlsPwKa01jhGNDddvOSUSs7PiY+rf+uKMGjOzZlyroQsHo8wxUNoUGnx97ApjnPRPkUBta8i2supiSlNzlvVbq0CviGFV X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70f9d469-291d-4d2a-e9ee-08d9777abae2 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:25.6447 (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: N1q9G496M72jiJYI6iLYLXqBeFpgex7zMppmTbAGWqJeSBA13FgiYYdXUbjv3hhg6D1pEdB/xd8UrdQa7Q8azsBblQFdXa83LWmY4dthEYY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3158 Received-SPF: pass client-ip=40.107.5.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Tested-by: Kirill Tkhai Reviewed-by: Hanna Reitz --- 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 { #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL +#define L2E_STD_RESERVED_MASK 0x3f000000000001feULL #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 9a5ae3cac4..5d57e677bc 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 = get_l2_entry(s, l2_table, i); l2_bitmap = get_l2_bitmap(s, l2_table, i); + QCow2ClusterType type = qcow2_get_cluster_type(bs, l2_entry); - switch (qcow2_get_cluster_type(bs, l2_entry)) { + if (type != 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 set: " + "%" PRIx64 "\n", l2_entry); + res->corruptions++; + } + } + + switch (type) { case QCOW2_CLUSTER_COMPRESSED: /* Compressed clusters don't have QCOW_OFLAG_COPIED */ if (l2_entry & QCOW_OFLAG_COPIED) { From patchwork Tue Sep 14 12:24:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493039 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,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 8E4AAC433EF for ; Tue, 14 Sep 2021 12:37:36 +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 1F36E60FED for ; Tue, 14 Sep 2021 12:37:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1F36E60FED Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7gt-0001vq-A7 for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:37:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VL-00026u-5H; Tue, 14 Sep 2021 08:25:39 -0400 Received: from mail-eopbgr50116.outbound.protection.outlook.com ([40.107.5.116]:58241 helo=EUR03-VE1-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 1mQ7VJ-00065R-Df; Tue, 14 Sep 2021 08:25:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hr8yPPOsiyoEJEhgfBo/btT3TP2Uil4THlCK2NFZlQLJ8SM99MF39xdJvUGSGfBz7vX6+HmKXqMf3vW0t6zYkgJoh4BDo3RJT49pIQtLkJoEkD3gncSuUsw4gGwm/SSVGgWM1aBclnTsKCZdw8ElBKm+qfSwqHn9sOihGx/cmkvDNmlauQHA/OrtbiKjMKbdfH0CAzA/OuvGJNCqVdvquoM89RYB9JhV78xihq0UBdozkORPRIFY5GIA9SpbSFEHs8TLXG5saMBAewgjsZQuo+/g7ckePHsQYnAH0wzEiThkwYaERFsjW4fo5bsFeMaWSIaMMT9DggzRQzQwxyeQSA== 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; bh=uNBRu4JdIVBQ5ZsYPNqSHtqtZIR0iNKK6ywR+Zpu4A8=; b=n8ariuUjs9gM4vd0162ZX/NyOV69pa0x+6RvDaTj9NUG7VFgnCr9Ma2C6wyyUYhSvG9/BQ2+WyFORpCzesCzZupde3UzBRY0PRUJWkZ48k/8xNbnlL5dQBCihQ4QR14BzZf58zE8qpe5pE4iS1xGH9aaEKgfjeLCWrwFKS5jAoe+S5tzgGLi6bH2asDRtLPrNj5CvlQp7dLRJomptpRfboyqm7Ymp2xeWoeYuW0fgPStX0fcE2YPTS1sO71rQFgPFE0C2I3k7DdxYDnbBNfq+0PhqXjLECL+7FecV0RR4YEHq2NXUK0064XVFxjuCQwrTaUKAE17waY3aicgZNkrLA== 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=uNBRu4JdIVBQ5ZsYPNqSHtqtZIR0iNKK6ywR+Zpu4A8=; b=nV9pEzf5shjcwjobjGnZ/wFtxjff8y1Gv7S4HheZWxftfliDV9Th6ee82ExhUjxAoCp688Mqr0tX1t6lITZNgmBSeSC62MuI0sV8CxJIca5Z6IzwBgGcpY+4RY4qeP34qd6i1l1tJlsvD6cP02uMJIrVsprV96n6oVxRb74WWfU= 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 AM6PR08MB3158.eurprd08.prod.outlook.com (2603:10a6:209:44::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:27 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:27 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 08/10] qcow2-refcount: improve style of check_refcounts_l1() Date: Tue, 14 Sep 2021 15:24:52 +0300 Message-Id: <20210914122454.141075-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95bc51c4-7f19-4cd9-c3dc-08d9777abba4 X-MS-TrafficTypeDiagnostic: AM6PR08MB3158: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:454; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eRrOhqgYt0tGO7dSq2aWoNoaFgY6NxveFjYInaeBBZd3z/Jz57lBZqda6YP1YwctooD0Sce6OVjA8rwC+eng3lKP2laq74SS3CoWVdfig+9eWwLWDpiByElX34I3B/yONUvot+7lluGs/gO1jGQ1wZk3FHTb4yQktC6KK4XpmqSdqYlXAqlxriZ8E/S7riufseBcVQWkpJwyBRvDv3/cSzC5AEi/MNEn2bgGoq1BMnKix6ME1kNrAqbOWJ03ZEIaap+RlNclF38qsuELj1BiKODkfWG9+A2m53sN2BJkjwGKKUMz3HIwlW2bGlcj96Trla/rt22HrmFydhoyU+EmCfvLHczeA44HuWojddP1IADNAPoGmVOPnq0weF6oeaUu0Ksz/T9MBhntYFBhKhVP+DBMZcGcnhqH0E5QhjxMMqV2RjWBQu8JEYbooo9SXI/gKH+Q11m/nXnXO437GawI4lChPnznN0IyRMSZXtG/gKn/pfS9UuzMeNiaLBNIN3NlJU+Utxz3Rja3OOpokSfulubwmDuERQcaWtoDKKOIECuNUkTVTqwrZhD5xFpEzYTa6Zkfvzd/RlcbqAtuh+DpejjnqqQXhGso4ibKVbUU1LHVBTzWuVxqNcRL+CnTT5jOWAcdkguLgg21LuMHduIXIPMsB5uQupYiYT0EEIB5Vk2wJqU3lYU0qyDM5rwuqD29PtnDfiMlaBDSKSgxS58obA== 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)(136003)(396003)(376002)(346002)(39850400004)(366004)(26005)(186003)(6506007)(478600001)(36756003)(38100700002)(38350700002)(86362001)(8936002)(1076003)(2616005)(316002)(4326008)(6512007)(107886003)(83380400001)(6486002)(2906002)(956004)(6666004)(66476007)(52116002)(66556008)(8676002)(6916009)(66946007)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 796lCJK7jjVnNzao5Zq8sDMHFSdoDFIZobpdjqk3kB8ORlJpNZQW/d/Pa0c3g77E+Fr3vDdyzwuz0mmoRY2cK4RwuBtBzAZ5hRq+ARwoV5xrCJ2WTcgVi+J50BmAgZ4PVljBWNJRl+SLTtGWKoMBeHH3/mcJE/lu3p0To3YpFr6ZwSo4kPpSRDLi6YKcONxOd90j4PYdUSQHdbqZwAvzHC/QDDzDya/mfj5q/Kf+rzljS7//6rsfGnnT5DATW+aHwBWh6C1DJSVl78I5cuDWXxy00CEnWe0SCr6WI4SD/cxADdDkWVWYHlrMRcc+bjVq3sicMKeveGSoSZy7pD7Ep2OENkIJ3QFqY7D9HG3HbD+Vf1FCJBKjvRbFaOppPByYaALj7Yb+Bgn7uLSFpHXu8yx4AKqvOt0ue0bNxtAIqguXG5ain5UzZ6DrFgRtAnl1r+cJ3J3RIp9pbMUEXqEyFKOZ4vtipk6jZjXZL1rkJhx1O47JIPWKmNUlCdoCWxCdFKgnL9Xv9zjScmj6Eh5M6t2f0VrYoXxIpQex6AUFPZpa4kXWC4ddpiBz/aTCB3WWeJsrGp2JUPhimwNsUkDNx8PNzajHRXGFA54Otqpfj+QQiliAY/xWCdO5m0JZr1wRSaOsBjeKxiY3dILlFpBvCThjHki1bcja4p0YHpdcBDhkVeguxoy799RNEa1wLsCXQeA6NDVCbZy50mu0RPZSNex0gzJR4Xxi1ATah+Qlb0XbvuUYEFGR8x+KFzVgHJxU2ENE2R8QHvar8zveBlthCj7xuOI4XcfAATNl/RrHP9Zm0klD29Uj7J1NeLxsC1BCTQFilvAU74EE7gUOOpVc8jZzrdUW6qYD0rhPqWiBTAU6j8n7oBBiGQXKS+YFeqoKhMiRVNU3R5u6c2cohy7eERNZUOEZ0lS0y7YMDMP4/q9wDHwAsV6LEaYbP7PWuPeFx6dPJ6YFI/bOlX+lxV1iYQaUWLMH7Z1M51b/hLbbIgejf0Li+anQINE23STDT9Gihm1tgHQadU1yRAGst8t+EqdHCpb7AiNJ0gUo/El5lOkZkvsLTQVMdYgQUyKwCrly1rbjbrjCkBX3/ldP3EPFfsDRb8geEDe03yW9M1bo5ujXH+CwL5Rw9bAHsKwm48XD5brGEm4Gcfkt+G0K1flwc5shW4a1wTt5bbBQCPCJWIc+eqs3Szy+HebnFlGdA8JFR9Tia8JmVsay8ulU57r2zlBZLAr3tGYNP/q1Wd1H0KO4B32XZVydAzJvEqi8rb04O/vXIF7N4duEHDCJd9gdXDRo4v4NXkqQUXtqgBftDeEBhF9L7vSa4yK0a0OCm+rz X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95bc51c4-7f19-4cd9-c3dc-08d9777abba4 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:26.9241 (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: BXyZg4tMWk+pLPixfrUya62rm/r/nBKOIp1J4qv5Ls66T9owoVwHrOcTogshtPo5As7fO/YBejsQSBfgL3pMV3bJ7ivloSpxYoBed9bz+hM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3158 Received-SPF: pass client-ip=40.107.5.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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" - 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 Reviewed-by: Hanna Reitz --- 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 5d57e677bc..153e5ca087 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1860,71 +1860,73 @@ static int check_refcounts_l1(BlockDriverState *bs, int flags, BdrvCheckMode fix, bool active) { BDRVQcow2State *s = bs->opaque; - uint64_t *l1_table = NULL, l2_offset, l1_size2; + size_t l1_size_bytes = l1_size * L1E_SIZE; + g_autofree uint64_t *l1_table = NULL; + uint64_t l2_offset; int i, ret; - l1_size2 = l1_size * L1E_SIZE; + if (!l1_size) { + return 0; + } /* Mark L1 table as used */ ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_table_size, - l1_table_offset, l1_size2); + l1_table_offset, l1_size_bytes); if (ret < 0) { - goto fail; + return ret; + } + + l1_table = g_try_malloc(l1_size_bytes); + if (l1_table == NULL) { + res->check_errors++; + return -ENOMEM; } /* Read L1 table entries from disk */ - if (l1_size2 > 0) { - l1_table = g_try_malloc(l1_size2); - if (l1_table == NULL) { - ret = -ENOMEM; - res->check_errors++; - goto fail; - } - ret = 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 = 0;i < l1_size; i++) - be64_to_cpus(&l1_table[i]); + ret = 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 = 0; i < l1_size; i++) { + be64_to_cpus(&l1_table[i]); } /* Do the actual checks */ - for(i = 0; i < l1_size; i++) { - l2_offset = l1_table[i]; - if (l2_offset) { - /* Mark L2 table as used */ - l2_offset &= L1E_OFFSET_MASK; - ret = qcow2_inc_refcounts_imrt(bs, res, - refcount_table, refcount_table_size, - l2_offset, s->cluster_size); - if (ret < 0) { - goto fail; - } + for (i = 0; i < l1_size; i++) { + if (!l1_table[i]) { + continue; + } - /* L2 tables are cluster aligned */ - if (offset_into_cluster(s, l2_offset)) { - fprintf(stderr, "ERROR l2_offset=%" PRIx64 ": Table is not " - "cluster aligned; L1 entry corrupted\n", l2_offset); - res->corruptions++; - } + l2_offset = l1_table[i] & L1E_OFFSET_MASK; - /* Process and check L2 entries */ - ret = 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 = 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=%" PRIx64 ": Table is not " + "cluster aligned; L1 entry corrupted\n", l2_offset); + res->corruptions++; + } + + /* Process and check L2 entries */ + ret = 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; -fail: - g_free(l1_table); - return ret; + return 0; } /* From patchwork Tue Sep 14 12:24:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493037 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,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 F3C24C433EF for ; Tue, 14 Sep 2021 12:37:09 +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 8981060FED for ; Tue, 14 Sep 2021 12:37:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8981060FED Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:32934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7gS-0000L7-OQ for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:37:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VE-0001oz-Cr; Tue, 14 Sep 2021 08:25:32 -0400 Received: from mail-eopbgr40107.outbound.protection.outlook.com ([40.107.4.107]:50377 helo=EUR03-DB5-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 1mQ7VC-0006CE-Tb; Tue, 14 Sep 2021 08:25:32 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fmwt0Cm0DVkfyQnu302nl3CjnmLEz/qnu9DzDSklYGuN2wL5M1lpMvcKIMlN40ZiKX29nPZNEyn1bT1y8UepSi+ZMWyt8MFM4UzvFIjsDDiD7oQgyX8ZpLy8BVbKjuv/eUAchWwJDt6329EcOHP+RgMmXjZsV/IdcwgIJZqIpcGTK2Y6RpzvDNar9YrfUo7Fz07uW1WIdbv6KyQluuSFxLl779ML0qTTtgf4KsWvbFsH8AG8yKIvnDZhVLLQv+Q+tbL0kEw7xz0JL4e9LfioNp9BspHb7cqAn9weLW+G+pV5e7TDbbphDIJSyDvQLayHg70/3gG23lVPjVBUqitHjQ== 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; bh=8yrEBm5IwizU4eb9IdbXAjqEIXmN6P/F51h412eUtk8=; b=RSwFWzT8j7yt3pDMfFL/7ajtDDUI3mdlX+scgS1vbL0PyfBI/alYSpGhM5J0HSbFQnkb7KXw9+XlAtM7g6AHIhDz0d9i13ycTGTyzHunf8lki4M9yzhsoDh/SsHZxQ4nf4Z2hGnFvZLAeBpVCkIIngYIIBrS4bY2D8o23LXbufu6OFrEnpunFHva0l3nt41JSuVcKDkghb6tcw6qwgzyjaxaFMNJp7vAKIp6rsiEZdjMyN031w/YlanwldYMwOurU7BmjPbqXghU2Ad+K8eXO6rISAKwDrM3f4Fjsvie7Yqu07IfW7URTXbMy/SABkiByrYT+oOZ4v932EoEfHNVEg== 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=8yrEBm5IwizU4eb9IdbXAjqEIXmN6P/F51h412eUtk8=; b=Aw5NWJmrQQHjjfqisuWRBy+fS5vZ0kGorttE0GX40ehiEB9/RmHJ7gpHkfi8X1Iof/z6jsuoSvVQrPypIYdDqnzf7PT0qbdFbAPRJj7EYrObk1FWBwTF0IbCcVZNR+f/jfiWp0MhChdGQu2htN9BBAhlX0XweKoJO01NSSehbq4= 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 AM6PR08MB3157.eurprd08.prod.outlook.com (2603:10a6:209:48::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:28 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:28 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 09/10] qcow2-refcount: check_refcounts_l1(): check reserved bits Date: Tue, 14 Sep 2021 15:24:53 +0300 Message-Id: <20210914122454.141075-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 67471562-3c4e-4aed-d856-08d9777abc6c X-MS-TrafficTypeDiagnostic: AM6PR08MB3157: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:257; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ym2+6Zmg80GDKGIacGWPauHv1onQYy8/nKQPHG2whLOvl18j3ir3I0CTpGhXN6bwcKsrvNEAwSmdXX3RCOJvodDubf6e2E7NUcbKsAOjFg45MbbFGXLBiy9KaGEbixlvz9a/amH2jtCkfDvhKhhrI5xrk6GVlguqdJ+Dli0ZU8hHGCp+39SVZfa1Y3e5NY4sld4ZGjLekG3uNYlkRlIO1KQC0O4rZ6Yi7BZA02GOKT4iXMBuis7cszoMCyCOz9nIK4Y/7gy0fn/qWq/db+dgTpsVQdvZg3lAOESQ2fCS7Phz8Wm/D3LYhrl6TF8geX8ZyNDdVDUN3ne1eRstyj51PkeKvB2lIBht63eExLmI/13QJg2UkGKXG0hAvMQve4cZLB5CODMvM5fQsLKxTmQRdgzbuJoFarO7gjulCrpY6Dbd+Ln+jRVXbXfIUB+3XrE/IuX4ykFO0HRi7hkPQQLeE8RSISqq/4yMMciPsQr80FkMbcS+VVjxmbhall/nzLVwgMEHjSjdaYhZgFHy/kVxn9AeN8M8S6ykTAAuHzkSTqcZilaUieteQfr9nbcSsBs4uHWDZaB33WpPz06VEitj31/D+6aY1EAtRe6v9KWEQHBRWoJNur9Om3dbr5M3BlqnobkB2zgCDnihyS0Jl7samHMpzpl5l+oYp+0Xk70y5ITzvijwdP7agwbMUPxQDW5IYjpMARx2v+ETGzWFoW12gA== 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)(136003)(366004)(376002)(396003)(346002)(39850400004)(52116002)(2906002)(6486002)(8676002)(38100700002)(38350700002)(2616005)(1076003)(5660300002)(6666004)(956004)(107886003)(66476007)(6916009)(19627235002)(186003)(4326008)(26005)(86362001)(83380400001)(316002)(8936002)(66946007)(478600001)(36756003)(6506007)(66556008)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pZMyHnb+pm77+UEEa8Or2O2xWaV6QN11jvyizs/RLX+JjmqnGsRf2p1XWcjuLjQhCYkgr5XYoaf22nuRZ+XGF2BrmR2TeNJMrAEITZ/r3kr92Sgyl5sACuotY9BiwoCErNyhLcaa6Zd1GpwrePVdyxf0sf6WsJKiSiMOK31mlzAVjRn+6hWf9KLgxf73XmoI86z5VBqnPasTuxPgxYP1CgzMFa0+DiLrrQlL0BRol6Ng2qrwTuehcU/gJrMlypFMhBFMUFEP/sBL7jB03yHAB61vNvlf/zV3QhzlPBqrsUplTLT2QnvU6EVsf9h0sujkfr/oPy7mXJLB6WMuhON6K+Lv13hFIDtMGocAt5nLfczzriPJO9mqpNVIeGoWhvXSzjDCYYO9FH5Dye6j4a6YBw0rGAnDU4So5+2PJ3aAU/R2nKONL7A1uKtq0rlQuM5UuZX8/mVBml+6ZWWcgost9g5EVTy8WkR6HzDuujF4o6yen7xy6lRKSf/W/r0kBwC/sHXU8hh2xRZETLS7N4qR3MXuR/KgDNSMUvZCGMjHNDZ08Ec9/KQhB4jt5+2b9i/eGQnF4mU2VTaFALl5+sFg614M5vfAJ+7Ds5hXqWM2I1p7JKG1oEgQnHaZHMk1HjljwzgqEXHtJShH2olG29IbZufk8H9P/WeyR0EZ8F3dF2Z+iuLeHZtGbRBya0g1Ayid3Ip3dTvsxqPCeybHkN277zI23kgKxm5T+NoPAfzLrvxqlDRiALw8fh7lpiKWh9dMulbZHAulPCYZQGptpbDfYPx06nQ5zpQMcdHwTnsXtyPvJtznE1dbCGKw8MsOnfNFARUMPuum9TjkZ3O18QCEl/MD/Kd98uRlf51AOwGU+19NH4XtvgEP01VTTkf6vSn42pGYfIY4JIJor55Xwlu1i3a5znwFSP+jD9MEn29DJKNe3VSQ7SSw4XFG2W69BzG/ZTcgeHHmOAER4ez62kDRubQ+z2bO0wmCVQ8s1Kqg9HKOQTMPW70PFsbqZVWsy4WPsuxkQ8YRbbBQHAeoDGQTW/EAyVyj5VbkrO+jVL9fochcmT6OUxdT152mhIZV2l7Wsaap9eO+/Llx0UbV++SdECvK7AkktzpEi9oWmbEHkrNvKRnVfN09ArxH5/+z9V1ada4I+4BWULqLTZyrBDcqPTPYFdgDArgXVfWl0UDu8T1JU++vv8GAFz9Tx2nLEQwc5vsl3nb6i+AFPrvLote7m3PbM2/uRjfq47M+T5OZty62gqM+UwvhUD+X4fTjJx8c2Y8ACCcHSBYOMIIpMw7pshlqQ8jZ3Q5SuGaL7Fh3vMZLhH5JfpnfrvSjO7mzHHZm X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 67471562-3c4e-4aed-d856-08d9777abc6c X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:28.2263 (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: uBnE/ICf0x7oslFlElVbs+uLCvjN5s+xBaRNw+7UC1I/ITt4tUxMjXJVuCNKvjLK5RZTG/jgFQieEGnKBnxEyLF8FAreDlffsw8MWKeCWfI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3157 Received-SPF: pass client-ip=40.107.4.107; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-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" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Tested-by: Kirill Tkhai Reviewed-by: Hanna Reitz --- 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) #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL +#define L1E_RESERVED_MASK 0x7f000000000001ffULL #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL #define L2E_STD_RESERVED_MASK 0x3f000000000001feULL diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 153e5ca087..75751a0181 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1900,6 +1900,12 @@ static int check_refcounts_l1(BlockDriverState *bs, continue; } + if (l1_table[i] & L1E_RESERVED_MASK) { + fprintf(stderr, "ERROR found L1 entry with reserved bits set: " + "%" PRIx64 "\n", l1_table[i]); + res->corruptions++; + } + l2_offset = l1_table[i] & L1E_OFFSET_MASK; /* Mark L2 table as used */ From patchwork Tue Sep 14 12:24:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12493081 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,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 29646C433F5 for ; Tue, 14 Sep 2021 12:39:44 +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 86C966108B for ; Tue, 14 Sep 2021 12:39:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 86C966108B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:41202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQ7iw-000626-ES for qemu-devel@archiver.kernel.org; Tue, 14 Sep 2021 08:39:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQ7VG-0001tL-Nw; Tue, 14 Sep 2021 08:25:34 -0400 Received: from mail-eopbgr40107.outbound.protection.outlook.com ([40.107.4.107]:50377 helo=EUR03-DB5-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 1mQ7VF-0006CE-2i; Tue, 14 Sep 2021 08:25:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e/6zjeueNTUJQYqB4NvyzEXkdZ0eTtx33lVVp1yVLndslbGIqfzFLEiLGOg69eKUcOHhxhwY+qdwRaApXo1hBzmHPZmS1K3dKu8FBRGAXLga/z0npe29MlIaLaduTYxFzZ93WEHMsiB/S91cYntPNwJMYincwfsrKkVmSatkl7oG26ikyMIjQNQUwvhFcte3rh8U81gnRcbF49oWtnxHCfRGK0Ng/mzSfUMgua5wRfPY54vSGkS3qJnNQH1tpN7pJGjhwT0thVJlq/uHY/o6U5gzcugNK4XMxKYo161hT3tfqegf77NTwETQp0H6OXHt1TyYVXhN/3Ex66FCeLGYVA== 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; bh=sVYOQZk3gziUN9dQYhtd0Bz/6SDcl90B4K8/9cgY1j4=; b=V4xb8On3NBim7vNKn4pDua9vi6B08DlA2/Eb8kiv0xgFVC5vs0IqZPYoFaR08Bwdcy4rwRYcYHYKSbDxwxGK/cbdbvPR5yMVOP2sRXDo8I0y5WdpIVrsbUAgJtMgbWGXZ3akcH5m0PVlnWBxtJy2pfJkGMSDaa6S6S97VtDLrfVw8Xyicf9x1hILbJT1HBdJFVfnre6Zn3VOkISrsG8z8m0f5ZTLjOywJtFvwHg4YCpKiej0Xf3Z2akrZZju4uO3LmC1zwqorJrXK1wJVtBHJ/1BpGeXy8eZVEil0/JEevjeC9Xe1t+OPqK89ge8pTQSVmLdrXZB4v3f+mHatRa4Yw== 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=sVYOQZk3gziUN9dQYhtd0Bz/6SDcl90B4K8/9cgY1j4=; b=HQGT6YsF4qjrTEO2M4CrfnfdepIMb2nzcafUptVGhmaKU/KLb6t6hNnvLQ5tQxQ3Nm1EJ3cepqJpaxL/pRLbmniOs/BxntfR/2Frf6txVg4WHYDUSmUHQ+DlfvN7WEiE+2PvAGGdxNc3JgfhFTWP/+4QtBqSA39vgiU6CvKyWCQ= 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 AM6PR08MB3157.eurprd08.prod.outlook.com (2603:10a6:209:48::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Tue, 14 Sep 2021 12:25:29 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4500.019; Tue, 14 Sep 2021 12:25:29 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, eblake@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com Subject: [PATCH v4 10/10] qcow2-refcount: check_refblocks(): add separate message for reserved Date: Tue, 14 Sep 2021 15:24:54 +0300 Message-Id: <20210914122454.141075-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210914122454.141075-1-vsementsov@virtuozzo.com> References: <20210914122454.141075-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) 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.196) by HE1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 14 Sep 2021 12:25:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04302750-e05d-43a5-5e14-08d9777abd30 X-MS-TrafficTypeDiagnostic: AM6PR08MB3157: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:198; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ixZnYlmG4OgqjJYPKLk0Nke3P6gMB3lyPVjlOknhggd9+8CmOfAOFyfXJxGiyEfDwOi5tkqlfTyO/N/J2WwwYVOZTT3BMsyBHF0gfPH8PcAQZk1QkBqZQuUNAVT57axplYJ6CkgK6Z+kSiRMBNFw5gvE0gt+sPOl+uNCf8qFC6cLEB3r0ncp7nIGu+NoBoWn49q+nbA7yY4I95ngZ54YL/ohoU6SyY9RwAAvX9EFuKWD3VNBcgGEgync+J/Hydgx1GokNRP48n/JUFrNQ9yEnM/kmy42O9QtuQfPfA5KPz9+2SlLFl0bHa1YbR4oV4jcd1+CqZR6+/yvY+fDzdJs/JWlD1LH2VpNKXLSp+19yWnyuRqmYttdzSKElpoWVOK9ZW/EfWi5WdXM64iz0qTq1WDcdE3k60uPWAAt/F7Fic9i+7kiBcamaUlYozCMm83R4O55cwjAkNlq/x4yu3ompQ1yUMLc35VlsZ2K3axdb5Z/p+Sn1kSYjdEUAsRwc5ZX3CCGxOKX8wQCn8p1vAmIuELWYg1jzOwzO7RVcQnthG+SumQibJJkmI9og3mxOUt8tQiD7fN4UFPY8cIHnCcJsu0RXrxdDeoCZ5TvpYhMYIuMc+aBGGe4vPLHkSL7DwCk0SDTzZp/yAT0bMPUKGgLYJrNlsfRwCj/gzaGO4VNaV7YxszqfXJRcqmD+hTNCevA20TWXvpF4ZX79JxOcLLnZQ== 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)(136003)(366004)(376002)(396003)(346002)(39850400004)(52116002)(2906002)(6486002)(8676002)(38100700002)(38350700002)(2616005)(1076003)(5660300002)(6666004)(956004)(107886003)(66476007)(6916009)(19627235002)(186003)(4326008)(26005)(86362001)(83380400001)(316002)(8936002)(66946007)(478600001)(36756003)(6506007)(66556008)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: x0v+lV4Bsskhk51nbsHOw+uizJt4/v5E9TZIVMKsyqhTwEoNrI8XPQ+pHxUJNkjkyTY8D6RB4KnPJEtr1IfJKrDdRGZhgrYDuBHxwVboG03XB2uJvEGd1+5bH6pLMpBImcBI+g8NYQawUqXNjmxGiLgUEmgMtidpdOBfYxVIptkJLuyPdQmlW54WInHYjv0BgCmngAqokSH8ceRlVj7i5zua+DauDBwRkGJR4XgzoO7TU9SzuRZ2iZ5gfL6WdQrrccmbEtzFKPb1BIXEwsjGXffdPkoTi+mFT0FYg563GmmXpeoJ57EX6/weUgptXe16N1A/yt7OXEHDhg/InD6Yc7Xx/FTx5ieubLORo0y7uh6FUP7Qwgtw1mcpJRClb6dgWyabXm8SJjRVTvAunjfAtxS2reUq2fCKTVKjDXHVufaXqk7mzG1hust9fZ1zL6cvzYcZ+tRyZp//l2Z90thFCrTYybDy2R0GPpsM3PIIa3Hf2NV6vQqi2o/lM54D0GhjC3FCbXco/yRjrIzwkL9tfu8XkwZ+UKzVnUCGgV9V4IKAXJtsuG8xDkVbUd3JUJchbIeNVyNFT1QQvxVZG3QDDPbh8HH8cz3mzTh4Ya+tpnpgv4DK1Ik0nHo4xLz4uAIXzV28n0GYXtbFC2uK/wtqHGsYhYSVUIW5eBgIqGHV+DDTTlitsUMJYE1Rt6tO4ac1wKVlsW8TyCYaXxZfOeZQvfWgnYMvfe8V0mxPeM/jtV05YlTOdduGhntxfWKrZO2adYIdYlpGu1IfQpXC0CWKEXcNJREBuu+cREb2DmBbJj1Amv+5zzsbKYeBdunbR1BM7GZ+uXxCfqmt2uJHAeZnYeMBb5ORyOEmKUbmlPf7Sc8uyUdl8bm5qcWITKkpUnj+ndeYwnyHd6EkzMSnW3MyP3qBjNCTq6ilNNIajtpxQMdSYJo5FUQtpIWqAcoQy7mg0fVw7NgViFhnPq1I91dchkIGvdu8tD7laeBfgxc3FaDI0xnRiOnSX/4K2sVcLazzY3cAwIm4v7PSUSlV59UOvGP24yy9ruJWTZFJVdMdtEadkSVyrhNGEVlNy9dB6DeSH1UzM8x7Mgbd1GZ3uT+uoYo9FaqkeoHZiNALMGU1W0JI+JHusEvJKO8LfJf4umXYkdae0pyfZXB1/UZDShjG4+dv4vCROOR1Fs9TPHp88mGAegEHNmwfkxR8LJPLo8ZWtbFuBqObNNpWSq4/bot9DdLsGgReEz9aOyt9CDE2tvgBFm7tK7tju4F6ZVuIDED4HMJegObdYASFQ9LK/7RqJlhEGP0s4gFIiQZ7HGTOpO/uj8DA6gmw1Hl46qzeDLIC X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04302750-e05d-43a5-5e14-08d9777abd30 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2021 12:25:29.4948 (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: /GSARRdGXosnfIAoeYmyq/vMmakdtt0qSnsOnJN8qJOXoPzB3BKdU5gOqnJIf3P2mjAIUiKVVHAdz2gBMrdkDf76I/u3EU1mBhV+K/ytc8Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3157 Received-SPF: pass client-ip=40.107.4.107; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-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" Split checking for reserved bits out of aligned offset check. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Tested-by: Kirill Tkhai Reviewed-by: Hanna Reitz --- 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 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL +#define REFT_RESERVED_MASK 0x1ffULL #define INV_OFFSET (-1ULL) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 75751a0181..d70667916b 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -2087,9 +2087,17 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res, for(i = 0; i < s->refcount_table_size; i++) { uint64_t offset, cluster; - offset = s->refcount_table[i]; + offset = s->refcount_table[i] & REFT_OFFSET_MASK; cluster = offset >> s->cluster_bits; + if (s->refcount_table[i] & REFT_RESERVED_MASK) { + fprintf(stderr, "ERROR refcount table entry %" PRId64 " has " + "reserved bits set\n", i); + res->corruptions++; + *rebuild = true; + continue; + } + /* Refcount blocks are cluster aligned */ if (offset_into_cluster(s, offset)) { fprintf(stderr, "ERROR refcount block %" PRId64 " is not "