From nobody Mon May 20 01:02:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1616791743; cv=pass; d=zohomail.com; s=zohoarc; b=lCQ+I313ChqPcBpaZhwPyWC1eZ9dDX7/b5oeMOnlEZ4TwrHHy/BYt2KUECJds6BiEiWBvtDn0vaWdJGyqBqH6gbpu7eN72rAu+tf74Fxqpew6o7xJCtkmHdU5QFwFOvoDuIHIoJlDDhHAdy1L1nY+dEShPJJP3eLdSAsw0Ue450= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616791743; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iXZs9GFBvUAXNvJ2vlQnOgXar2kFLPug2NV9BHHGUJM=; b=ZeiPSEyCY0J+EuToLqc+mYgCPygr1qOLO5keuBHicfcs6OeDS2UyZrBJoHAHTW2Jc+b0XxRRrli/vAUM33xFksp7717c4dAJzIqGAgzwcgpJ9ng1Cq/10RJjs1VumWfhKZGEtAoP2E6sUF36PNo3xHr8Lhr125tPT18ljLArcCg= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616791743817695.8111771313875; Fri, 26 Mar 2021 13:49:03 -0700 (PDT) Received: from localhost ([::1]:43406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPtOA-0003e6-IR for importer@patchew.org; Fri, 26 Mar 2021 16:49:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPsdy-0000YK-22; Fri, 26 Mar 2021 16:01:18 -0400 Received: from mail-db8eur05on2134.outbound.protection.outlook.com ([40.107.20.134]:9409 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPsdt-0006bj-7y; Fri, 26 Mar 2021 16:01:17 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5877.eurprd08.prod.outlook.com (2603:10a6:20b:291::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Fri, 26 Mar 2021 20:01:03 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%6]) with mapi id 15.20.3977.029; Fri, 26 Mar 2021 20:01:03 +0000 Received: from localhost.localdomain (185.215.60.202) by HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Fri, 26 Mar 2021 20:01:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eg7k7EHeCPGCMDFVSuok7WeXZEzbioA+x1QSi6Pp9iW4meEi2VCIWuTee50hs3gx0pKuGOr/w7ImVikcQty8OKZGL5Qv0yF6ZREZVDc6XlBCcmPVs0wXp3GV75k16GgIPZ/3W/Jw71WDJwwgURB1QwFIkdfoOduguNz1FFM2X7VhOc4/14gK/iX6qnh6cygTau3rUbcBHf9Ln3Fhff+XbZFoZskOhLIoyZJjv4Caxp9200VwbqbdeugxuECBTmvvLts26PwgjxJ7/ceCq6XPVPaEt9dyG5aQeM62i57Pe+6T6fJo01p8pM7jlTayDx+ees3Mx+jWE8MARzowOfNNUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iXZs9GFBvUAXNvJ2vlQnOgXar2kFLPug2NV9BHHGUJM=; b=bKLrH9vKIyRcqe8ykaeFVbyxcQXPiH+8+8q5pirjj9aUO87gGFFaIxzlGpVvnlLVaORUPwOZaI2Kmi5f6gK7ktdHX/XRsfV6joP7pk4RQxFzWj1Ni+OrENSUjb1CimWeT9kTvQ60lk0z+dCJpV/BHgq1RAPsykp9hFsr+jWZInbFCuIchN8SrnbYHeDWGN92DN9gMSdKsMXdJVU1dFN8omrrKFdqGjay0sL000SqQCQqRBGWW5yItd2HzGHWTAOlc7/Ab9LZID6939fPtT9lzzq7JNZ+NRZuCH156rjgICH6zV4AXvUxnFxOWF14Byy9jVcEkl/LxhpbtQ+RGPfVTg== 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=iXZs9GFBvUAXNvJ2vlQnOgXar2kFLPug2NV9BHHGUJM=; b=nQaiVc8aijUDZvB3Mu4gXKx6JMB04TEif1zZ3WL2h7Ce8Inm1eVFWGGEzlaHCgKpCWaACiDDPsdqijyIlGA/Oa1xe+6hVg30vjO1vQEi05CDhL4jaqMU1F+mh9mKWz9oZK9s8Hnxep+PbEKJliy7PeFQL2uU6rNh6xOflCnEeWA= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v5 1/6] iotests: add qcow2-discard-during-rewrite Date: Fri, 26 Mar 2021 23:00:40 +0300 Message-Id: <20210326200045.363290-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210326200045.363290-1-vsementsov@virtuozzo.com> References: <20210326200045.363290-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.202] X-ClientProxiedBy: HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: de419a73-d137-478f-f884-08d8f091e236 X-MS-TrafficTypeDiagnostic: AS8PR08MB5877: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7APkokag4HAT9/C1eR57/IuJRHzqMmgbbGY3ucHmkh34RAWQlVjy/kHfA2tyWMe04i2ZQiX5IOWL6asjGl0x61H2z5c0mSKxEw/Cv2zitH5r1DQeDgwHwOGX4fP79jos4qM1137g5cRketKI/bipdPETwt+lyj4hgJRW9OGSTQV14HH+0vUQOKDFtocp/iK7R2lyyOD5IARZBl4G3JollKU7HMfiXpZMmDO/m6JosDCToIId0DupzqeLTD0t878PkOcvwRdrln9XrIqgVFmfCXlx/noJF2QBJH6YxIhz8oCGmM9fGASdFDGY3eCDkv6/IaMdQr6lz+fAH5MABBQdA6FHPWOuJ3/n51Gd0YaMhy6AjNj19T/Ij7YJxh5mUbTVcBGsL2ptkQh038Y00I0Q7fJNm/9aISg6fXyarLGoYxapitWwetrkIMlctY7FXF0b2DYRbWfi51qg2t+pog7Z7kMFM0LzIYmjhKBghPN+hIumMNffdKYiuufm/0gVIrzN1cANhKargw3Mret1oqI6MaeVMT+oSfmNlomn8uPQMH5zDA1cJGkMDlSTUipZ/KPeZOvi+XwdacG8qPO+6/snU2kGoYqXNvsiDjLTUvuaIkmsQ3QsPaPtvDtbopIEV66YnxjT4aRUFJeNr1AYl3qIcnvpt7UMHIuxjEtk4uR0gDGmhfv6+xrkZiQZh1OURJNB16y+hQk6Rb1cf6cL/0DePyZ1JjU4ctCVb+oRVLVMWWWvDzxQDmksvicDYbcfycH86ydqis6ho6z4GoRos2W4u3djp8odP+C1SlEAzDVmsBblRlLk1/E9u8S/gZO8efIt 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)(346002)(39830400003)(366004)(376002)(136003)(396003)(1076003)(316002)(6486002)(52116002)(36756003)(6916009)(86362001)(8936002)(956004)(107886003)(5660300002)(2616005)(4326008)(26005)(16526019)(186003)(83380400001)(38100700001)(6506007)(6666004)(69590400012)(478600001)(66946007)(2906002)(66556008)(66476007)(8676002)(6512007)(2004002)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?7FVie/4Y9T/LOPLMczQY5vgrgZr3DplNKZvGpne0jaRCJZtl3Qv3nxhveeJN?= =?us-ascii?Q?VV0w/hG89ASJtXMcfALsc9lrB4N6U8vklQIu5qN9l4bAG11XXtfTYWNKFBlZ?= =?us-ascii?Q?0NvC4/6EtqJ8zaLW6DqV+XlxBoYJKafVcrNrmGOirDS7LSqVHMTVuXB8tH0L?= =?us-ascii?Q?3ZNqe7LMUfX+lBfodDC2XRdrOxQYLXJxFn27whs7hlvb+CeSVweosN4VbPFQ?= =?us-ascii?Q?BMVI0W/1fHp2LVUDKQFBZq/E1zYIGrXcfDdvPgW8H+fiLKf4Ow6cmueuia7V?= =?us-ascii?Q?EESUkgMAx6LagM+OwFWCBpNv4K46FTpposO1ymimQJU+LnrJcBdIdZzThCgt?= =?us-ascii?Q?Juijnd3XtwYB3vdD3kfJbblj2A2cm3AT5Vn2FtqxFx3fEARuCCv9Pq6xFjdX?= =?us-ascii?Q?I96uabkBrKIlK9jCXpiOQ9rGkpNfcApICOGDTEOQvpS7nV9M5Av33JaKqBvI?= =?us-ascii?Q?FA8NX0Q1MGku5GfvrSC8DDJhqy1hJnaj8QjeZQd3Rso+X/mQSfWUJ2ohfAFL?= =?us-ascii?Q?QOtLtLCpL7tRPYOOb1n/1579f/M6NRxjJ0TOVqVOe1VeAhzUIjUF2sPqpd5T?= =?us-ascii?Q?bi6HGR1AXJ+mgexKm97ynAveM/6+iquVYCgEqjoKqS9kTfJvRImGoQzIBNxQ?= =?us-ascii?Q?/Kb5G7ZEqCchapoADNPEXZ2GOP4pwjsSwlHzjGBQ1g9y2W0V4Z4pK+kThckB?= =?us-ascii?Q?nEWrCSi6mq0DwOhUd2qRNv5uLjIHPZRwHyBlqh9nsTmgQEXK0GQyXLdG03OX?= =?us-ascii?Q?mDyMbDilNBIMLvtazgY7DujsKnJdMfCNgsyfO3WTkGBHOOlMf/Y17X/QC+5g?= =?us-ascii?Q?O61tca1GEytqcbAmZ2BE7pDoSe0q1vKUSpenG8ZdEN0+5D987QWvB0dSknMc?= =?us-ascii?Q?2XLHV8wIF2a+maKG0po9gBdY2fATM3qj6eAc8PevuP6ff4mF6gCO6HqQMiW9?= =?us-ascii?Q?+42WqSbWXvJ5Pd0NhSixp1XorZJcI0k1rAQwvFOFXHB0YnBqz2IilzMTzuXD?= =?us-ascii?Q?PH7oh1SPfFEmVX6wFS1ARo+7GlCfIbtrZ8MKSeGldwVioGkJdhwfgCa4FOMm?= =?us-ascii?Q?SddHiOZq+xGMjd+gNIe4yb2a5s1xDN7BYs8DPXRg2Rc/lHxlyxrCkHtgfr4S?= =?us-ascii?Q?ivuPAltRcZf8/656rVsl16N65+zsGlTpNcLFqCP19uaJVTCRuXC7F1wV6Cv1?= =?us-ascii?Q?7hT3j04GOJtRM94wBKGBWFrCUtCo01PAfmFE0sx0337m1T09LZva5zXQ0KSx?= =?us-ascii?Q?QlauDpozHuHtQmd1JqrO3A+/RjN3K7gHeb0eu9xddEPV1hjB71+e5wW/1SX9?= =?us-ascii?Q?hWodmow2ZyyoNXUEYYK23g+g?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: de419a73-d137-478f-f884-08d8f091e236 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2021 20:01:03.0576 (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: 9EwVa6oS3FK3hZjtyjYfDMR/q5lbRyBv5UOLaFteEzCDD+ry2dcGgRKBdROIPcUk/ZogCSWhop87/8H2s+TgjBjt/UUd6xarKiifCT46ApI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5877 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.20.134; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Simple test: - start writing to allocated cluster A - discard this cluster - write to another unallocated cluster B (it's allocated in same place where A was allocated) - continue writing to A For now last action pollutes cluster B which is a bug fixed by the following commit. For now, add test to "disabled" group, so that it doesn't run automatically. Signed-off-by: Vladimir Sementsov-Ogievskiy --- .../tests/qcow2-discard-during-rewrite | 72 +++++++++++++++++++ .../tests/qcow2-discard-during-rewrite.out | 21 ++++++ 2 files changed, 93 insertions(+) create mode 100755 tests/qemu-iotests/tests/qcow2-discard-during-rewrite create mode 100644 tests/qemu-iotests/tests/qcow2-discard-during-rewrite.o= ut diff --git a/tests/qemu-iotests/tests/qcow2-discard-during-rewrite b/tests/= qemu-iotests/tests/qcow2-discard-during-rewrite new file mode 100755 index 0000000000..7f0d8a107a --- /dev/null +++ b/tests/qemu-iotests/tests/qcow2-discard-during-rewrite @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# group: quick disabled +# +# Test discarding (and reusing) host cluster during writing data to it. +# +# Copyright (c) 2021 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dvsementsov@virtuozzo.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./../common.rc +. ./../common.filter + +_supported_fmt qcow2 +_supported_proto file fuse +_supported_os Linux + +size=3D1M +_make_test_img $size + +( +cat < (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616791881030510.95734457217884; Fri, 26 Mar 2021 13:51:21 -0700 (PDT) Received: from localhost ([::1]:48532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPtQN-0005mf-UB for importer@patchew.org; Fri, 26 Mar 2021 16:51:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPsdy-0000Yb-Oj; Fri, 26 Mar 2021 16:01:18 -0400 Received: from mail-vi1eur05on2133.outbound.protection.outlook.com ([40.107.21.133]:54454 helo=EUR05-VI1-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 1lPsdt-0006Yw-Nn; Fri, 26 Mar 2021 16:01:18 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5877.eurprd08.prod.outlook.com (2603:10a6:20b:291::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Fri, 26 Mar 2021 20:01:04 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%6]) with mapi id 15.20.3977.029; Fri, 26 Mar 2021 20:01:04 +0000 Received: from localhost.localdomain (185.215.60.202) by HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Fri, 26 Mar 2021 20:01:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PNcB5liyv2b/z+gB3hUhpkBFLa7z0w7WY6mm24+A2+ibdVmfreMjP4HZDyzTB/AWGCb/5Lt2UWrdYvCZX8yOMAbW17XBKRyN2gVUJRoTr9pgsHxmUuYXeZ5qRh9lDx7YNEhpeEwoHjHIdVwKxzxYw5DWe3jtB6mr0MA/iltCHMwN5C0Q4otFk6/SAaLxrd4CADSTt6NkUKfO7Czksjbk/JZOy6GivsaTD7I85Io2HPeEBi5NzKemzdYDruwi9XRTeBtYkYhtUDH4Dok0xnbBUjy7Wjr/B7gWrZw2FPHC+PV524zeuYXbr8lllq2bYDq82A05OlNmA6jOOzH63ndNUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fBWNHREMp+DrTjs0IlaNUg3+8U1Nq//1jBxyeP0IVBY=; b=HFmCLRJqDDtDUSb4Yy5lrtgtWpHKlLeu4EieUjZY4UhEOpPN1dbBSbAQMpwR/hi6FMj0Kx6yGuzf+RHQedXh9Hz92/bkz97nclBH9fFnBJwaR+XntVql3E6LzoDVWEhfqarBCuM8JVhMNoWUvwc5FscRbZe5EA7/clostCVhjnS0D59uDqEn2UBmk2U9Q8z8Lp+RrvI8Og88DegHt8dBFewNnEnf+ac5pl38lulmBr+Lmcc/9O3HvCQJX/R88O1Oii8rA2TgU0oKXJfDAVe6MSSMDzqH0nIW5OrUEl3tOdNd2gtMMYsbRNMc/PMnVe1qflGd10woj5Zdliihi8D11A== 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=fBWNHREMp+DrTjs0IlaNUg3+8U1Nq//1jBxyeP0IVBY=; b=Uj2bI8IqrBghJ13dI4p4cOFshQSBKw1uxFOnMVxAxBeGocC+TGyKRaYFi6dq/UGPfm6mnSH6Sl7BsC4IMYAFFtL5aJcwt9YXVJ+J6RMCDqzPqGB1sBVDCMeYgwqYqg70psRamDrGZah/c7SR672pD4QRPIIWCl0rFphWNp4aNfE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v5 2/6] qcow2: fix cache discarding in update_refcount() Date: Fri, 26 Mar 2021 23:00:41 +0300 Message-Id: <20210326200045.363290-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210326200045.363290-1-vsementsov@virtuozzo.com> References: <20210326200045.363290-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.202] X-ClientProxiedBy: HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 19488822-1fd8-460f-79d6-08d8f091e2dd X-MS-TrafficTypeDiagnostic: AS8PR08MB5877: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:173; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zvHTSLCZinIG3Ha7Tzq6l+p+fZNrEH7pCq5Z6IQzM8dfIu7Xm/9h2FDkyJ1264HpQj1pnun0q+/DINQcsum5HHKyqJXZ+8bbIGzkX8zCDqc0HWPvvSUdFAcbBOkZjun/ZDcai7pbeheB5U5IQ6CNDRAgFUWlI1zqI15NsWG+BcG/GPC3SzZL1FAYMAt1lgccLedQR1YqqiR7h+vxOV/VMTwwwmqJS84YAE+5AgDw8l/wO7GSOqdbiOYRJxejX6Uhhiutq81DCQRFt9A1fE8ZBL3O6wRdF+QgaM7z5Kggm2mC3LbDZrQ71jX8ARjg7oIRP9oiosyTYI2BZTNqtHTXb4qOsMKt/DHdxE3aYcA5+lFZ+2JgJUYRSjfsGHbIUekdZ0GJ3bUJsrBL1kGVUcRSJG2TImgUX/sWYoCgmKxWJzfvcsSTJhG1F/HvDuqotCGIPMMOQwB/4uZYfNM9V677q7TuNVe4zSU0G5+tTXiyjEArT1lwUuzklZHt8hFHtfc72JnVQ/UBqamv2FQJAjvJz+ftHgTXDZomj1PYEwrdtrZaa06xfjD/MM1nst92SUe2DuxNXHHX4dPas4VFDICTaOa4lvxcOB3H7QjuqjXA8Dz0kbMFBcoGQKb6Zj0LGW7yhyBpUFjv70KOSUnVLNr00KYAzzjrsqTHruioZ6g91XB+DpaUd97cHy2fnOSy8+gr 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)(346002)(39830400003)(366004)(376002)(136003)(396003)(1076003)(316002)(6486002)(15650500001)(52116002)(36756003)(6916009)(86362001)(8936002)(956004)(107886003)(5660300002)(2616005)(4326008)(26005)(16526019)(186003)(83380400001)(38100700001)(6506007)(6666004)(69590400012)(478600001)(66946007)(2906002)(66556008)(66476007)(8676002)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?WXQFD5kbhuAsF8YV/E3Of5IGCTnzi2vql7n/ZBIjndntFZubR6L5y56GaVzF?= =?us-ascii?Q?kddTdogTwDLh1E0x3FJTBHcV5TdU05km1EE9RU9vHPDlW7LxhSw5eXGl9TKU?= =?us-ascii?Q?0RIh/wzU/IqvJv/P3Mns3EmQGb1ggruUAnxxmpZ/TLjiNaM7bTiNXOyG2WJK?= =?us-ascii?Q?89AHXXWtB4DMfFLszeruFd23doFqFdQ/2x+EXhi/q+eMQAx836wPmp+LsyLZ?= =?us-ascii?Q?6hkJ3Zp7pJbx1WA7hjj1+W+YQzHXRO/3xc+uBkj4UvHYoRwNo/aVI9Rzze4t?= =?us-ascii?Q?yWJwj1xPmq8S8lLTDhSs5MEJUFIWXIS4j/mYT8Ke7XxkVD8CsR5XHL+83UU1?= =?us-ascii?Q?QikUKxWYEoM6kO7KnXezmPB8ehYqAyNDgkzwhs4Lzw56EuisFO5rLST+Aksz?= =?us-ascii?Q?Hl4RhH9QX4A/zMr+LhLS/Jjr7bG538UJ/r5egBWicAhf/4wm9JkqQsdlwcl7?= =?us-ascii?Q?1KueJBuWXAuME0s040mbsiz36lLaEAL5QWdlQY5vnW9kjFGlYwJWvL/pXr4h?= =?us-ascii?Q?JY+CI52gdQyrwto+QbggSfr5JenqlTSMJSKsn1cbi+x5rG3Lbelw2T2cORTD?= =?us-ascii?Q?7BQ82xZO/mk6Yp2GZi03bHBEwjIVBYPE4+g3xhOqmN98iprIkYh0zAvwz2UR?= =?us-ascii?Q?9mZM1buS1IDkqQ9vQn/HKi5pl77uySsf/ZnI3s5SaV/BKrqtjwWYkrvD/jxz?= =?us-ascii?Q?I6FfzEM492ZAU93cZFopxTSwswBrZH856CpK0h84L9JDNy96c2gPgXb/agIy?= =?us-ascii?Q?fwy9NOuiBGceNlsJJ62Vo3BuGVqgFpa7xEf7le9kgAxyYshL5C52h4znS0o1?= =?us-ascii?Q?ylrTlisiSdNuG7kNRhQeZtGOM/UBisKBxEkZzOKvL31cwG1BlS77q4JMpn75?= =?us-ascii?Q?VSvD7z8EOuaPjmXGSB7veLoHW/WtX9iUaY4Mvq+okJVlKwAmZflPGIIJNVvn?= =?us-ascii?Q?EFnJtzzyLUeN6YFFvoKjqpYzsO/R5sLBjnN/BrGHhtU5CLW6o1lyLhd5dybh?= =?us-ascii?Q?rPYFBIzZLznG0GjBIcGURceqNHf/mJFZhRM4k/M0+gPG5H/EAT+5MpC5IXar?= =?us-ascii?Q?7S0932GhmJMeLnEbB6Wz/Vmz2eSepuEMB5n8N3Od46iiekR7yujalRvX0X+I?= =?us-ascii?Q?D8UKRMVOouPaB6GMA02RZXJ+WiPn2gB7CXEvN6pxWU0pGz+rgWwomeB1baVc?= =?us-ascii?Q?jooKPVZa4vk6jC9aOYR6z6fKssfC7uwC8x0JN4dDibaDO3UJRPsuboBrTttu?= =?us-ascii?Q?KHlgKFtBs4ffZgyPOQSHSrE0Ekkdl6kRrGZ6g2DgNYRdORuT1YNMiGTyCg8x?= =?us-ascii?Q?D+8Rm2lOpegjLUnasXjLctSe?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19488822-1fd8-460f-79d6-08d8f091e2dd X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2021 20:01:04.1707 (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: qnlM32FY+A7wln9zSMYmv58U20iwig9m/C4nstTkuf0ICPgDwVRxXxCFQpJBlOuddnNoQXXnc4igZiXDj937b3omjozO0wkieQizfTN0Xlk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5877 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.21.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Here refcount of cluster at @cluster_offset reached 0, so we "free" that cluster. Not a cluster at @offset. The thing that save us from the bug is that L2 tables and refblocks are discarded one by one. Still, let's be precise. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qcow2-refcount.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 8e649b008e..543fcf289c 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -887,14 +887,15 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(Bl= ockDriverState *bs, void *table; =20 table =3D qcow2_cache_is_table_offset(s->refcount_block_cache, - offset); + cluster_offset); if (table !=3D NULL) { qcow2_cache_put(s->refcount_block_cache, &refcount_block); old_table_index =3D -1; qcow2_cache_discard(s->refcount_block_cache, table); } =20 - table =3D qcow2_cache_is_table_offset(s->l2_table_cache, offse= t); + table =3D qcow2_cache_is_table_offset(s->l2_table_cache, + cluster_offset); if (table !=3D NULL) { qcow2_cache_discard(s->l2_table_cache, table); } --=20 2.29.2 From nobody Mon May 20 01:02:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1616791402; cv=pass; d=zohomail.com; s=zohoarc; b=TjvdIQloZxi0rV1Z/85lPDmuoLQJxdDHwtBNrgvYpQ7ZBMb9dmf6zxwbz5YrjAKNA+dcGKF84+9Uk1XlW9Tr8K7SdHAwDkxb4k8MZcA1FQR8EsMAft6/b9h2PiiJoq5B/ZRrhqJVErUJ0otWf9A2axgxs0nYa4wyEijXSCmi3o8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616791402; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f1R6YBn/tIIM3NCFzA+f6AReKsjIpB/lkO9dj8svUs0=; b=SCl4lex2wISzI+PBZ1CsuQ24pAR78VcEhkkTP7irWL8BT2ZyodYkdoA/rtwkw6sLIwO4s77vbDO8Mqd9F1awRVzjOrJ4ymHTs9fBh5ptKYE03OciUzfaJY2AaqtQS7scW9JsxKzs0Dg5UtU5fvc4cE1R4pLy1eryHG4LaIuxM7E= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616791402211218.25980052036812; Fri, 26 Mar 2021 13:43:22 -0700 (PDT) Received: from localhost ([::1]:33466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPtIf-0007lu-0b for importer@patchew.org; Fri, 26 Mar 2021 16:43:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPse1-0000bb-BD; Fri, 26 Mar 2021 16:01:21 -0400 Received: from mail-db8eur05on2134.outbound.protection.outlook.com ([40.107.20.134]:9409 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPsdy-0006bj-TR; Fri, 26 Mar 2021 16:01:20 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5877.eurprd08.prod.outlook.com (2603:10a6:20b:291::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Fri, 26 Mar 2021 20:01:05 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%6]) with mapi id 15.20.3977.029; Fri, 26 Mar 2021 20:01:05 +0000 Received: from localhost.localdomain (185.215.60.202) by HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Fri, 26 Mar 2021 20:01:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i2ERhUOvtpYcFnfRDGaYDHbu90EW+VKdXitI5mE7C/EzhBLSPfa5bHX068iU2pyf9aaAm/ko+IYzGO8xPDBYQitgLMg2H+PVc81vodDsUuDZXtChUaxcWNXhP3Y7OZm/rpSSKyFiExq/meSjtZxo4xjr9TKClSyNMMEHXEcgB+sRq4WZIJMFUVQdcySU1fhNotLjeCvt9hXtuuh7GtrZ1NuXpl/UJJdnvXBYu1UT1v35AnzQvA1h7q9GG3lUQS9JobuKNSfQtDArEJAgSRoPs4jhzMz9ffoEFyjZ9JYWsUgGnAdBxNEWMUITKLD9sgKp8AdgaSqM2JzW6Mii+jLm8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f1R6YBn/tIIM3NCFzA+f6AReKsjIpB/lkO9dj8svUs0=; b=En3IqQPt+yifOtf4e2WOhH4q6Q5delyHZ3yb5m+xzQ1Kd6XEbBd2xhcZejWulSsYmP5Ois2u+TCoS7E0dVJcnJiWXPV56Lf5P8xa1tX+HAI/UkQMcKNsvqahDinysX+zLBxZyKjtJAdN2Gz+Es2gvK2uQt0kGJuy6lEFt3L1x/EA1a0K1r+FZGfGMX//QEjkZO/vvLY4uFz6qEEtYHUW3zRAyZmw5T2PVQey6qpfSmG1Lnj69q+f01p0Lh98il/2urr0DO44o6uf5BGZPy998I4q33l2Z6A2tycS012G3ylwugA/kqGNPEMnQMayFuYmyhBckC4OUVogtBqMg85fVQ== 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=f1R6YBn/tIIM3NCFzA+f6AReKsjIpB/lkO9dj8svUs0=; b=TlScyvUpJsM6S2dQeZ8pld76nCvr/8eurPOb4JuGMY4MDkbBZTNB0KljWseDthGwtjQNel+8GxZ+9BaAUJ0MXssCP2zSoEDP94MTGmT4jRb92fIje5A3ZKOfg/RBqLgDfHbfenl1SR7Mqf2Y9lMaLFN7XW6XZnFhpWbtBYu1TRE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v5 3/6] qcow2: introduce is_cluster_free() helper Date: Fri, 26 Mar 2021 23:00:42 +0300 Message-Id: <20210326200045.363290-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210326200045.363290-1-vsementsov@virtuozzo.com> References: <20210326200045.363290-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.202] X-ClientProxiedBy: HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ba47045-e476-4ef3-3f98-08d8f091e38d X-MS-TrafficTypeDiagnostic: AS8PR08MB5877: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:873; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rExNEqYgSIHzxY2/Fh7g2pp13iZCyfvX5Gombbvz46qw9o0oGxM+vTYb6aZs7clyC839LWS9QlYoLMK/oT04DrbRhabYqNScDOB3G/9s757CKF9cKTJsGeo73VR2Hk3vbAMgJHxNxPSQu1YnpFGEEVAya1JeB49IZmfHltmYt3RUdjRU1oRMn/ePXPLJvSUn6rOP1mIsS1qVuNn4nTUgjgHGo3lpoqdznBIi+jgplz99PbHCp9wKyOs7kJWZh6FNCgrnRdq/UsRxagJprBujagC18sNC/l4FaX6eBIPjSgZBBtyWIuKmF8a152dFDwrcecbklzX0E6kZONGCG42UQFdVKsdHZR6eRytabHyvEc5QQ1zHX7mO2LKhe1s3WWPst4i4VeN9BO6/rvEv4G5U3gpqlDtyZ3tmAAyGQ/YKlgVhE07Y4pgHi7ctpATTp6MZnsXEGmULXUeFAxPvXPGuh8NDWFo5zxrbV/9jyQgh3/vYmr4MGMCm3R4+VfCfkXMrxAP9ixpHLalFguC3WoQVBiPNwUWLNeaV4228vZKbK3HrfG90FZ14UTkHvCHx1KFsEboQHDafQIFeNm97uOjEZpnpGq19m8+x0YzGSW/83tdiPGErt/Xb3oX+DcDK0KDuG2T7lANxAZOr6VcHFyD7mDzYsRww67mYamRwGLEezsjg2lNMOrG3Pgvz4UplvPPx 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)(346002)(39830400003)(366004)(376002)(136003)(396003)(1076003)(316002)(6486002)(52116002)(36756003)(6916009)(86362001)(8936002)(956004)(107886003)(5660300002)(2616005)(4326008)(26005)(16526019)(186003)(83380400001)(38100700001)(6506007)(6666004)(69590400012)(478600001)(66946007)(2906002)(66556008)(66476007)(8676002)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?MGQ/YpEYQsywEt0QZSQBoCIo/hfXUaVugkNZ31Bqb2lveq06tYvinK4sGfjV?= =?us-ascii?Q?+m0rd4BUqdhge0VCAUcrO0tbcroCfhgHP/r+sGjYNUre3LJ3DqR0RCLJcXPg?= =?us-ascii?Q?busAsOAsoheDGt3x49jqaSc0orF4hvtCLNPHgJuAEtvPJS6h7VwiGZJMBA0M?= =?us-ascii?Q?NRNJCrfa8HL48XEUzqxD/qFnTo9zHdSe9KSA0lBKspPHlTtHZ/UOiNRE6sj1?= =?us-ascii?Q?qG14jUxtABPKm7J//TtyL8OhTCAjJ4useVxA2MM+Mr7Z9n+BSWQN0k6iKULR?= =?us-ascii?Q?70GYvMcs7ojP20hO8DDvsdN3iTQk4fVmq+0sO2EqD5j8O0oG6PQ2wYSJ8BZH?= =?us-ascii?Q?IvVcrkBJgJ/Z1LPshiEf/jziE0ZH5H2Y9xPGGHo9pErvQS24S2ybsCk6um8g?= =?us-ascii?Q?5mIBVUc+Krngf+WLWJXtyORodgeEI5dDrb3FIcxjZNniDfo6vvS2GQwcwQPc?= =?us-ascii?Q?JNjsX7FpiByS8GugRma8msUFyKQY20OTBqprQe+6NGHEkcIFJ3Kys18k017I?= =?us-ascii?Q?1WnanUcxe1JsG1gNzVKuy/KWKQMYovSnCFyJ+IIVU5JHOa/5+zgSOes8QR7b?= =?us-ascii?Q?rWy2hvzEar0QOHChZs4QztUfGTrtePK2KmcSvX+qtr6n1X76zib7zX874ygo?= =?us-ascii?Q?UMEiFQl6V54+wLIa+GhR58pLf1vx4QrhUyM1l2PjXNed0cyz7/qmQQRGVtmH?= =?us-ascii?Q?4xVhLdKt/my5qdyFdpmYlmMfrCBDb1Irfwi2J2c2ahPKo0Bul9zJO3Qvqv0P?= =?us-ascii?Q?TRO6BGDGNnLUirGAfIsjmnh7IW7jXWRG+abqCcrYDBr4Ylujy4qtL6WoghFL?= =?us-ascii?Q?MVJsR8KSZgQOIFrzKmjdygm9cfKsnGwjDw/FSTDQprz0tdEbceR+I4/jTBRF?= =?us-ascii?Q?CA1ikj4YG4BiHV5r35aNL+OCzhq2Zmm4MuxYHVrXBzE92q30IRHtxTlYZ+n+?= =?us-ascii?Q?motMOXiw/XLBzjq2Znq5GLUUtQZ1/jHuagWTbXw2i3GDOCxy/9pzbTABskaF?= =?us-ascii?Q?O+pB2ZHSrwwEuZj8Zk6tvFh14Hzy5YGB2bHBPYADPAtfXDRYQGdVL8o3xDDm?= =?us-ascii?Q?sfrIwLCKL5yGBPUf/0Qyk7/7bkHARLaT+EKZVjkhHnY5SNvQCSF8XpR7aP6w?= =?us-ascii?Q?PfWgm0m4K0zDopHtT+rLTsSlkpxJAJr/42lpgyRkyPXAUAoaNb0eN49mVYHf?= =?us-ascii?Q?Kh3wF1N/Rrt/MMAFXGSHvpvE4f5O2+M2OHoD10goGGNC9TTgXg5tegeUJiyo?= =?us-ascii?Q?ZP8RaZ3DqBG1zmCWJKfOqagtBWpG83rkHT2pfxUSYhP3g8mWPDEE79Mad7h7?= =?us-ascii?Q?jiEviQMyZI7jN2JnwvijI07L?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ba47045-e476-4ef3-3f98-08d8f091e38d X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2021 20:01:05.3316 (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: zLybVsfj1PUe54HOAPXGOfR95JMa+sRmler7Ea9ud/swtM/KYJbXwtIqYeNUIAEz6qTonPYU5FDnOTLLPBUtpF7A1XvNeRN/kEWPXv0GP/I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5877 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.20.134; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We are going to change the concept of "free host cluster", so let's clarify it now and add a helper, which we will modify later. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 543fcf289c..1369724b41 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -962,13 +962,32 @@ int qcow2_update_cluster_refcount(BlockDriverState *b= s, /* cluster allocation functions */ =20 =20 +/* + * Cluster is free when its refcount is 0 + * + * Return < 0 if failed to get refcount + * 0 if cluster is not free + * 1 if cluster is free + */ +static int is_cluster_free(BlockDriverState *bs, int64_t cluster_index) +{ + int ret; + uint64_t refcount; + + ret =3D qcow2_get_refcount(bs, cluster_index, &refcount); + if (ret < 0) { + return ret; + } + + return refcount =3D=3D 0; +} =20 /* return < 0 if error */ static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size, uint64_t max) { BDRVQcow2State *s =3D bs->opaque; - uint64_t i, nb_clusters, refcount; + uint64_t i, nb_clusters; int ret; =20 /* We can't allocate clusters if they may still be queued for discard.= */ @@ -980,11 +999,11 @@ static int64_t alloc_clusters_noref(BlockDriverState = *bs, uint64_t size, retry: for(i =3D 0; i < nb_clusters; i++) { uint64_t next_cluster_index =3D s->free_cluster_index++; - ret =3D qcow2_get_refcount(bs, next_cluster_index, &refcount); =20 + ret =3D is_cluster_free(bs, next_cluster_index); if (ret < 0) { return ret; - } else if (refcount !=3D 0) { + } else if (!ret) { goto retry; } } @@ -1031,7 +1050,7 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *bs,= uint64_t offset, int64_t nb_clusters) { BDRVQcow2State *s =3D bs->opaque; - uint64_t cluster_index, refcount; + uint64_t cluster_index; uint64_t i; int ret; =20 @@ -1044,10 +1063,10 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *b= s, uint64_t offset, /* Check how many clusters there are free */ cluster_index =3D offset >> s->cluster_bits; for(i =3D 0; i < nb_clusters; i++) { - ret =3D qcow2_get_refcount(bs, cluster_index++, &refcount); + ret =3D is_cluster_free(bs, cluster_index++); if (ret < 0) { return ret; - } else if (refcount !=3D 0) { + } else if (!ret) { break; } } --=20 2.29.2 From nobody Mon May 20 01:02:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1616790367; cv=pass; d=zohomail.com; s=zohoarc; b=jIUHokAa98hX6OVUlpYsNzYAXk8dl4ztTojDNbFhJLGD1DD7Vx75S29PKWviprwjZWYS1WrLFMt81Joc9BHC3arGMOVqK3Ipa9TQnfSfCLMRyX6L9JXVaQI35QZO0qp12wdZelYV6CwKhqompDHogD/Ng16rFltXUBOqIN58dPI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616790367; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Udo0lvdE7fqNfuTvNF1H2PhumtJnPOyuY2Fbm3iNj5w=; b=HT/1s9rWy7gAV87ESWUOoiqUx73DreOwrJcs5LLNEGQvj3alLNVjvjh1nPV4zgSlWCUtkVJHfriG6190lDPQXlA8UW+ieVQmKDIR4sQA3ZMbyWAsQQF3GXtYTZG3s8mGZzmvu+xZMFFNxy2WfcjxjVza83KmooWgLXJ+nIcdr5I= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616790367395986.0500617508135; Fri, 26 Mar 2021 13:26:07 -0700 (PDT) Received: from localhost ([::1]:43044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPt1y-0004yt-Ap for importer@patchew.org; Fri, 26 Mar 2021 16:26:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPse1-0000bf-Ti; Fri, 26 Mar 2021 16:01:21 -0400 Received: from mail-vi1eur05on2133.outbound.protection.outlook.com ([40.107.21.133]:54454 helo=EUR05-VI1-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 1lPsdz-0006Yw-Gp; Fri, 26 Mar 2021 16:01:21 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5877.eurprd08.prod.outlook.com (2603:10a6:20b:291::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Fri, 26 Mar 2021 20:01:06 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%6]) with mapi id 15.20.3977.029; Fri, 26 Mar 2021 20:01:06 +0000 Received: from localhost.localdomain (185.215.60.202) by HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Fri, 26 Mar 2021 20:01:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OQWlZxK/GTY3XLRUnSm3RFRT5buDbgwUclucx2LjEMXo5g4p7BzFYDXv+MyXw+9dUR5Mw3sQvMHw7dEmCahmcPplYthgJcWbS2EnzXpkllEIOJD9/mtzl6njz6aqlhz+ZdOLi8ZD6IvZKxSDKMLs22S+7BOdqVxC8aGk6i6MI9nKjasfo3x8iSLDxX3xR3pP72QsQjlK5ivcAO19N8DOoz/53zh5tNIuIRaz4vbU4DxOqxiIr7r0UycgBJAtvUqd1CP3zSQKxscPoarkKBU//f9hjDVIAuC9+Us1bpDI4Po0E2zpeZKcU/1NldeEcEHAFoKPsEQ3Nuh6IWXtVx/vgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Udo0lvdE7fqNfuTvNF1H2PhumtJnPOyuY2Fbm3iNj5w=; b=E0oZrumouhEwsX8gwi4RwQkrTLUpE6m0v8gcGGOuX6Ab7SpUnP5ifjTsJaiaZuUi0EAYGzz/S7KwN6nypT6CV0UOIeCLeajkpdV8mvemTNzYS3iG7uvBKqW9HAV36pI42ZDsMfTOFAy3rZc0kH+1hsw56vI19fn1Y70OObRwllHEUQFmtAyhDc9U4lXocntSHM6Wig+rCu9g40H5FNcbkx0dQT41KZIx9L3HBKchwUk40dXjfj9n7ehE3IHYCgHn7ocEVQqgvOUJ/7uxejX6qdtXJVgT95C1mJzi66a5bvgXkjS9RscxbqNT2r5L2WmmbVIBkmojJYbJhT2UNwbjGA== 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=Udo0lvdE7fqNfuTvNF1H2PhumtJnPOyuY2Fbm3iNj5w=; b=aaS4dD0QfPuZN8Euhh11TKdIyruZI7xIAaifu/Z7Do+TRAbQtmsEZTQJRyhmyRnPBgUFaVlc4bJLewk3cPO62U1EM4FVEq3J28KWj+YVjAoF4o1iR3N0QS0Wpeu0xzUjLkK6IhUJHajMgqbf/xG6WgB7OO5uDiYNU40n7jZEgnE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v5 4/6] qcow2: introduce inflight-write-counters Date: Fri, 26 Mar 2021 23:00:43 +0300 Message-Id: <20210326200045.363290-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210326200045.363290-1-vsementsov@virtuozzo.com> References: <20210326200045.363290-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.202] X-ClientProxiedBy: HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f1fc27cd-37e7-447c-b12a-08d8f091e43e X-MS-TrafficTypeDiagnostic: AS8PR08MB5877: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:232; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MmAoHLcQPegW7I7ARf3TVG07uJuXypPQtCqr+ZfjBkhhiqN2DHOqJz7He1ctCjYZoFT6axN+DALAcpGrwS/ptxfPBnSC+a2d4rm8mDqj93kdCSZvSvE/UpxYUMb1NCoQLsJ9wAn3f/UygrpIyAdfOfDmLKzDlsUDbwTBwYgrhjjd8RigYMvYGcgDFnwuG9npxWlBl+JoHBcxSAH8It85t05gFUdorqtOeZ3YJSTvN0SCl3EcoQ6aBnz26oTmJxG1dpVvKZSvMI3Rle7SWZasr/BqXzpiQm9ePejW8G5PQfTjtOQ/ccZzUfyoLwjmlEj1+i/RqBipXS911xY1LQ/7Qwd6r97dATJLvzqlAdL1Rkac82E5irN4SW56qZm4w6lMi2qAco/ubABAoESh+4PTSLqM1IeirFDcr+mW3KHBxIpWN6+z5MsQR0HW75JP9WTf9r2iyrtiOz68e/jFOikSbAG7WdY/3wPZblK5FGUHb5OTCEz/h8Fzg160NCZ6QR/Cok/Wcr1gBSaQNuxkWBbtaEKawtG/m/UtJKhGkCczhp5fEWUYK1aeynl0jHpS9ODHojj8f2kmZXFy0Q5U1jjXt1HS7aA8N2e0P7EXARM8kcRT4go5R38t6DBWjMVlWmQ3ThBoAxyjk7BqiDJ21tcdVFEAzDcvxdfscHYYCMrkeY3EGLMnTY+kHKeyymUddELrTOaDdGEmWhjx052SoTN96A== 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)(346002)(39830400003)(366004)(376002)(136003)(396003)(1076003)(316002)(6486002)(52116002)(19627235002)(36756003)(6916009)(86362001)(8936002)(956004)(107886003)(5660300002)(2616005)(4326008)(26005)(16526019)(186003)(83380400001)(38100700001)(6506007)(6666004)(69590400012)(478600001)(66946007)(2906002)(66556008)(66476007)(8676002)(6512007)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?MRWFTnlMQTtxzllFn5/TguLisl8VM28JOLBwROblO67jRaALvdXnArBbAEPK?= =?us-ascii?Q?VyLQwhrtsHbOP30tTh96k041Rh/n8UDXZudkoc8MVR7inFq5zyElAR7bDQkm?= =?us-ascii?Q?zo5LggxAkF9OKrP/MdvXFKY7uALEMAHmKf7OfVQD7EzWB2Reu4g/spMxeuRs?= =?us-ascii?Q?H69zzyVF3X1nscccFwzHPgB6xYU6M97AjhVNmI/YmWPfnnddVZgG0tSKhxD1?= =?us-ascii?Q?tGWlYjMAeM2bb/Toncx3ZCGuJBMHBwmTSmEzDXdljYOyegsnpDedy86Cw/cw?= =?us-ascii?Q?kbxCEI/CZ/2SAAoAg+/ADogJWBOjnqnrYXE70tb4AuUnAEErMpCWG/UCMXO5?= =?us-ascii?Q?7W+DNpmU8n81gPEBb3WJ0Kv72FZcjidfr41pdXQ7Be5teUHdsdIKTs/6vqhu?= =?us-ascii?Q?5iZ2Wrr1gBCOjhMDQ2k7zlXAtQ2EfrbmebxzMRQ4jrElador1FYcSuq0uY/l?= =?us-ascii?Q?9R7ANWOqsKHz2Cj/vj+eloBQOAeAvK9UkVb8VMzNfaVrL5dxu2YmZMTrovOx?= =?us-ascii?Q?kNd3CVb/wnSO+Mmi5lh5wv/sIyCatW8osH6pSLzeATl16skRrsTFrHRKPSGA?= =?us-ascii?Q?v0kvrM0wr8/hFC2BD6djZ/FyDbZLj9SvV1Qfc17LZLUgf+Wab0ahiS3UF468?= =?us-ascii?Q?Apet/UeCUXw2oK/+JTECs91ywrSzMJ0zPBjTcEjKytXpN2+eH5rLyKFFjt9x?= =?us-ascii?Q?y49larUEjJ/0uwzOev1UCIkzc/oK9YlVIGrZeH4WSlwuE2zCZzjvWXgahQt5?= =?us-ascii?Q?NclqbWJMjsWHmDS19jwykntoZ/xC9yBs4kuZwQQIw7FnIdEtM4XFcczCZ1Y+?= =?us-ascii?Q?D2CxrpX7NLqLavRSq4trOjZz9ysiBqTSaXyqXygdZVmGNqI9km9jk8nB6DFc?= =?us-ascii?Q?0918yzDBI7KSQGyYnl4xohKmaWnMYU2Plk2UHEa2lBvQYgWlR7qWJDpBVoXg?= =?us-ascii?Q?7h/0FkVWjjAdWOjzX/SILGugToVrBrt6VUQ+7WyrMhbtPh+2rt1h0t9lGjjp?= =?us-ascii?Q?UsI4OROIVNxeOTHSHFfMX71vLFut0xXtfY0V0WDzclsYzGCq/nOrW8RVu3W0?= =?us-ascii?Q?8YE2nU3CJMJ4R9mZdJxn5jvZ33g1BwXoC/b9jL0f3DAfs3T4pm4ptzJtjY9A?= =?us-ascii?Q?E8f4uPt7kqIFKaqSTKvIPKD8YHlNtK+2hkmP/yW8K4C/2cpzpbtRFhDNGAXx?= =?us-ascii?Q?Qnm6I1z3+oqEkEfKxEJyZcbbEBYuR6A5pE39lGxd15rwyQTyRzMCYPLljRRh?= =?us-ascii?Q?ws/WrF3PWijQqkhSqYu1lFJ8RNWQr9jZsbBcL4hBBghHbNkbrILsX6ADf7Ns?= =?us-ascii?Q?b8Enr61olX7IrBd0ifLEvVWE?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1fc27cd-37e7-447c-b12a-08d8f091e43e X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2021 20:01:06.5482 (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: QbxlvpAm2LC1nN8oM25vaWgMI3QGsaerC0TudbIUfap5S1+CsJG5rtyjVMLXCG5vQVUu4iGuYNJV6Ki4kGkexFHM5mhsARjvZxZDEpekJz0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5877 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.21.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We have a bug in qcow2: assume we've started data write into host cluster A. s->lock is unlocked. During the write the refcount of cluster A may become zero, cluster may be reallocated for other needs, and our in-flight write become a use-after-free. More details will be in the further commit which actually fixes the bug. For now, let's prepare infrastructure for the following fix. We are going to track these in-flight data writes. So, we create a hash map cluster_index -> Qcow2InFlightRefcount For now, add only basic structure and simple counting logic. No guest write is actually counted, we only add infrastructure. Qcow2InFlightRefcount will be expanded in the following commit, that's why we need a structure. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 16 ++++++++ block/qcow2-refcount.c | 86 ++++++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 5 +++ 3 files changed, 107 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 0fe5f74ed3..b25ef06111 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -420,6 +420,17 @@ typedef struct BDRVQcow2State { * is to convert the image with the desired compression type set. */ Qcow2CompressionType compression_type; + + /* + * inflight_writes_counters: + * Map cluster index (int64_t) -> Qcow2InFlightWriteCounter + * + * The map contains entries only for clusters that have in-flight data + * (not-metadata) writes. So Qcow2InFlightWriteCounter::inflight_write= s_cnt + * is always (except for when being removed in update_inflight_write_c= nt()) + * >=3D 1 for stored elements. + */ + GHashTable *inflight_writes_counters; } BDRVQcow2State; =20 typedef struct Qcow2COWRegion { @@ -896,6 +907,11 @@ int qcow2_shrink_reftable(BlockDriverState *bs); int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); int qcow2_detect_metadata_preallocation(BlockDriverState *bs); =20 +void qcow2_inflight_writes_inc(BlockDriverState *bs, int64_t offset, + int64_t length); +void qcow2_inflight_writes_dec(BlockDriverState *bs, int64_t offset, + int64_t length); + /* qcow2-cluster.c functions */ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, bool exact_size); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 1369724b41..eedc83ea4a 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -799,6 +799,92 @@ found: } } =20 +typedef struct Qcow2InFlightWriteCounter { + /* + * Number of in-flight writes to the cluster, always > 0, as when it b= ecomes + * 0 the entry is removed from s->inflight_writes_counters. + */ + uint64_t inflight_writes_cnt; +} Qcow2InFlightWriteCounter; + +/* Find Qcow2InFlightWriteCounter corresponding to @cluster_index */ +static Qcow2InFlightWriteCounter *find_infl_wr(BDRVQcow2State *s, + int64_t cluster_index) +{ + Qcow2InFlightWriteCounter *infl; + + if (!s->inflight_writes_counters) { + return NULL; + } + + infl =3D g_hash_table_lookup(s->inflight_writes_counters, &cluster_ind= ex); + + if (infl) { + assert(infl->inflight_writes_cnt > 0); + } + + return infl; +} + +/* + * The function is intended to be called with decrease=3Dfalse before writ= ing + * guest data and with decrease=3Dtrue after write finish. + */ +static void coroutine_fn +update_inflight_write_cnt(BlockDriverState *bs, int64_t offset, int64_t le= ngth, + bool decrease) +{ + BDRVQcow2State *s =3D bs->opaque; + int64_t start, last, cluster_index; + + start =3D start_of_cluster(s, offset) >> s->cluster_bits; + last =3D start_of_cluster(s, offset + length - 1) >> s->cluster_bits; + for (cluster_index =3D start; cluster_index <=3D last; cluster_index++= ) { + Qcow2InFlightWriteCounter *infl =3D find_infl_wr(s, cluster_index); + + if (!decrease) { + if (!infl) { + infl =3D g_new0(Qcow2InFlightWriteCounter, 1); + g_hash_table_insert(s->inflight_writes_counters, + g_memdup(&cluster_index, + sizeof(cluster_index)), infl); + } + infl->inflight_writes_cnt++; + continue; + } + + /* decrease */ + assert(infl); + assert(infl->inflight_writes_cnt >=3D 1); + + infl->inflight_writes_cnt--; + + if (infl->inflight_writes_cnt =3D=3D 0) { + g_hash_table_remove(s->inflight_writes_counters, &cluster_inde= x); + } + } +} + +/* + * Works both with locked and unlocked s->lock. It just doesn't touch s->l= ock in + * contrast to qcow2_inflight_writes_dec() + */ +void qcow2_inflight_writes_inc(BlockDriverState *bs, int64_t offset, + int64_t length) +{ + update_inflight_write_cnt(bs, offset, length, false); +} + +/* + * Called with s->lock not locked by caller. Will take s->lock only if nee= d to + * actually discard some clusters. + */ +void qcow2_inflight_writes_dec(BlockDriverState *bs, int64_t offset, + int64_t length) +{ + update_inflight_write_cnt(bs, offset, length, true); +} + /* XXX: cache several refcount block clusters ? */ /* @addend is the absolute value of the addend; if @decrease is set, @adde= nd * will be subtracted from the current refcount, otherwise it will be adde= d */ diff --git a/block/qcow2.c b/block/qcow2.c index 0db1227ac9..0a5bd4ea4e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1833,6 +1833,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, #endif =20 qemu_co_queue_init(&s->thread_task_queue); + s->inflight_writes_counters =3D + g_hash_table_new_full(g_int64_hash, g_int64_equal, g_free, g_free); =20 return ret; =20 @@ -2709,6 +2711,9 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); =20 + assert(g_hash_table_size(s->inflight_writes_counters) =3D=3D 0); + g_hash_table_unref(s->inflight_writes_counters); + if (has_data_file(bs)) { bdrv_unref_child(bs, s->data_file); s->data_file =3D NULL; --=20 2.29.2 From nobody Mon May 20 01:02:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1616792036; cv=pass; d=zohomail.com; s=zohoarc; b=E18uz+jQy0T21j8ZQLtcGnTd6VGTns3Y9UPcOsAK4DlNqV1bg3dXjfqVnak/zSi3S0UG9jvdbMxIaxmPH/hzd0b93H5/lJ5fZQF4paG8sVcemcb8xpAHkiDDlC/ilryk2MDrzG9iOmcMujmymwYE8ZXfIrOvOejNE8jEGmK+s6w= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616792036; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m6ijyMV7owrdu6Qudm1dmU5n0V73jH0NckzEGrJpVJg=; b=jO0hT1ACziA6VRrodQhjd1yUpXJSOjT9orvyb7ll4KK9KjdR2ikX72vclOUns4jIOqoi93aUERSdmgAWM8uj4krvO/EowqsStwtgfns5sOMB+drLkw7HYRlQtAamVTe2xVLG1nbmaO65WOg3WUYBBoVbylWkYdIta3sYO/ogWrY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616792036213823.4333669181457; Fri, 26 Mar 2021 13:53:56 -0700 (PDT) Received: from localhost ([::1]:52194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPtSs-0007W0-5a for importer@patchew.org; Fri, 26 Mar 2021 16:53:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPse5-0000eD-24; Fri, 26 Mar 2021 16:01:25 -0400 Received: from mail-db8eur05on2134.outbound.protection.outlook.com ([40.107.20.134]:9409 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPse2-0006bj-2m; Fri, 26 Mar 2021 16:01:24 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5877.eurprd08.prod.outlook.com (2603:10a6:20b:291::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Fri, 26 Mar 2021 20:01:07 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%6]) with mapi id 15.20.3977.029; Fri, 26 Mar 2021 20:01:07 +0000 Received: from localhost.localdomain (185.215.60.202) by HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Fri, 26 Mar 2021 20:01:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fR2JSeCPO1AE4oSQAucNWa0hgniH0eBH2tsp5Z2kcMBrN+B2W4dYvhmvji25ElETW775JnWYXKf0AzcdPy+I+dGmo4Z5FIiyq1zPq7T0nOIR3SlUG2jUQZ+su7FPrbN39vG8k55c3Q2q5qe5YHNLxNlrMz54sM+ltan9vGRp4U0WhgvCVUPmEKSybSJRQB4BEcJaTuyBnWmO116HoIow5n+R/IyKLOH3ZW+oWHaxXz91kiitLY0H2WU4HQenMmln+g9VEPtGegmdsvZLe1bcxPnIUTWyEZOToQmOZlDJOvVdWTy2lk3UAijOeHgywODYF3Mee3+IzwZXMo28iOKNqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m6ijyMV7owrdu6Qudm1dmU5n0V73jH0NckzEGrJpVJg=; b=Lndf8RjFhdAYMQXoWlz5waQz0mRkNiiraOzwaso4Y7hxDRQmVQy7xfgVhi4aPwokRSrXaNyNBp/fnyVr/+2iNuNNP6rNmVxM5ASY+I2INpRn2xcYqvAOjI6hHyUSh96Dl5XkxZizhACkiSomkNcX7yaKAbYdfeA+eYs1VDsTyTfzSi9f0zxFnuqxvErC2OhkK0ofDcrANYPMYrNicANANLEj322wlVjX5gbO78KzwHYK1BMtjNKVXgN63ErA2JL4R4U540GhEsqapxxUuoBgEtD2viDXZrmglbsBuRwTmf4q0QGD60rLGfNB+95cD1PJg/9XfU0lGVCQN7xcLs69Aw== 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=m6ijyMV7owrdu6Qudm1dmU5n0V73jH0NckzEGrJpVJg=; b=F2DYdcLWLFg3THhTbtP+sRX0DAzAgZDjDV9Xs+t9Ppyq3gcXiRN7t2TDArNtE9O1nOXaVRxn85VxhvodDwOe4LPPgzalOgj45zRW4zi8MgDKYanZrzvvGzRDCiGn4L2XSm3yjqzydkXi7j9aoMsZEcdJ8zTIrlIMIYtFQdCChhI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v5 5/6] qcow2: consider in-flight-writes when freeing clusters Date: Fri, 26 Mar 2021 23:00:44 +0300 Message-Id: <20210326200045.363290-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210326200045.363290-1-vsementsov@virtuozzo.com> References: <20210326200045.363290-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.202] X-ClientProxiedBy: HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 282cf3e1-ef7c-4a1f-97d7-08d8f091e4fc X-MS-TrafficTypeDiagnostic: AS8PR08MB5877: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EafrZdyHtXbTo0uFUHNke5br1qmVGCV5qY+fWmI+VsVrYgKr6iR+WPgpV9wAf2ZGuLFn1gCfU3HQ6laKDwYIz05N9VHLQOyanskjTescb916OhNITDsFhYcwmmuEWf3GJKDUBAseaECP4sWSYivv5LA/+/OD1QCJ6IhWCRGipANbGVMLrJj8edJSKhEUtr0tVpEX5NdvVUgw7CcNOgwwvCKGICE21d4GB4s+pJy9TTRo4Cwit5fibxksZf3CUT/v7R137PBttwR9Th47TAdPXrTVEz0eMm1K6szu1UtVU0J6qYpX4588fS1+LXV7ks4yNTG04HhFNqnrempM20bZx0GpPaVVL7FHVLodsAd881b18Gmo04L89MGJnacK9qfDkTZEty+rO/7wMAVO7wSVwPaAtRBi5gw7WW03kuc9MzqNCQJtoSrno1I/YYlBCmrQFf8htg9P8/AckynKVAxv/aYRFYN+2l5h/UCg3Ju1PsIjKhh7Gj0QEf3uDCWH6fbeBl2LsaYhUV/9s5suNfjCgufMyFui0/UwzqWXoah6hmSx1NEnQtfPBPMOekr101SLjptNngKBuGswdM0hG1zpD30+yuBl0UAQy9Ti8MI7jzOi6pvrsZeEhcnzTgN6vCjnUUE+Tsbx3kV2UVJHefYMMC8jRPR3CXeArPFmyjZagrMr06X0EKeN6eFM2X0rRnj+ 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)(346002)(39830400003)(366004)(376002)(136003)(396003)(1076003)(316002)(6486002)(52116002)(19627235002)(36756003)(6916009)(86362001)(8936002)(956004)(107886003)(5660300002)(2616005)(4326008)(26005)(16526019)(186003)(83380400001)(38100700001)(6506007)(6666004)(69590400012)(478600001)(66946007)(2906002)(66556008)(66476007)(8676002)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?xpeG7hzO3sAczYjyN/7/WPote5+KtCDYkK977ZTTsAmM252mB3fbR5W+PH0J?= =?us-ascii?Q?cNTb3Cu4T9p7xn/9JyX9qiiXJzigpUR4D4gztfSDKOcqtP56bXodCvzLcZdl?= =?us-ascii?Q?P3knzNQ8VZFxGbm7hAaOiSNRT6xerqgQ7lX2YXGgVsnF7LOVGAHkqmwgZUAW?= =?us-ascii?Q?YRO1vm/SCVOWb8WF0Cr4gyw+UjMtSsqu+lrdpKekqp5H0iGp4/Wvt5AjuIPb?= =?us-ascii?Q?/81Rb5htBNlOgu+lJYE3n9NFrRzBUK9peyZITbAd/PCb8TgWWAfe6vEC1Z6+?= =?us-ascii?Q?Z9/SwEvy8vT33ZY1cMrXuugGAlrvynzgPj12n0xvrr9JzWPkddftjhwf8SG6?= =?us-ascii?Q?BtE7FGT3h1so9v04sVNHjzsB4AXG6HCJsQ9zPKRwGqgd4wxRMySSN6WN/b3+?= =?us-ascii?Q?aWMIGFHNx8u1nOeGLzbrgWcz1vajUKe2OZ8XKMkVVUWRjSwgh6WzTcizg2Qz?= =?us-ascii?Q?Ny2v/UcbV0Vdhv4cvlBOXaRrQlv4i8tUsWCE9kgW+Ts1bp2QqM25iGZfBKKM?= =?us-ascii?Q?h54/7AU6bTs2LhyqrJnEVi7lI+hfVaCXN3sG6Zt4xa3b70Cq98mKd31zsbFN?= =?us-ascii?Q?SgHFf8MsMag/MOzLkp+gXc13VOZj9mt4+yOsozN1/df1RoQKAqBkK9WRWN61?= =?us-ascii?Q?uKPWTk7i7yCfAbn/j3rnPZaBCmcU0tzmtOIQBUpAGChNro9vBsKPT18DrEI3?= =?us-ascii?Q?QDNJbALETO63yWFXnWLGQCWPlQ0GLWhFh2WP+kHt2JMXHGeK/bd+dbUjny+/?= =?us-ascii?Q?Efv64izw3ymzYi0K9JCWB8RhpUCj4wDps8P+9w/PXjyuQJ5XLzQU+WXkhyt5?= =?us-ascii?Q?Z4Ep6UKLJAAnO992A8GoQKA7COIAU1fYSaQcUvqyW8UPmhwgY1uboygCVXUe?= =?us-ascii?Q?VvWa2Y/GELlQJPYcsHE4beEeOxAgCPBpK1sbl/zBKskaN0/Hjf4iA4/Bgkfl?= =?us-ascii?Q?owiLDJNYpTqxSw0RvN8LLTQw94pLrU1NN13mB2ryt3T8G1MxsxeSZPOEdSEA?= =?us-ascii?Q?QksABgcwzQlnmHiPd1o7xEmjcKuNBEwx2oH8gzbnqKxpAce58/2uHYB/cCiA?= =?us-ascii?Q?VflHSoxJeo2hdyykRkyAN62oFtU1/C6XawntKA2KPETE/pAwjMsJ2pBXIM+Z?= =?us-ascii?Q?EG9id2fQ+Tz6VzUnDY9fJmiCYHhzujmibLTHlc/0EIiurb1VsQbWOJA/D8vF?= =?us-ascii?Q?HGolVkjJ2CPqoIFzyB3j4PMGH+TRI4JjF6VCgT3yBwa7fKaF7QJaJs+bImAk?= =?us-ascii?Q?9Bqc1a6Od7Sjrxg4KgyCGJbrTdVyS/rjHMbnuQOBzLnumrFGta2d/tJ3ItoF?= =?us-ascii?Q?9Ax1SakdoOtYVBMrJriyreZh?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 282cf3e1-ef7c-4a1f-97d7-08d8f091e4fc X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2021 20:01:07.7470 (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: YWGuWY47jN5v6k6GCW9Q02s2w/9782vQPP71dlESjSZnPnYNaRAyG6zEezSmoXYMI2rXKNsMj1Ga5Kt3PNRISCw7q1Qniqc7rYg46ifKW7Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5877 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.20.134; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We have a bug in qcow2: assume we've started data write into host cluster A. s->lock is unlocked. During the write the refcount of cluster A may become zero, cluster may be reallocated for other needs, and our in-flight write become a use-after-free. To fix the bug let's do the following. Or better, let's start from what we have now: Now we consider cluster "free", when its refcount is 0. When cluster becomes "free" we also update s->free_cluster_index and optionally discard it on bs->file level. These two operations are done in same s->lock critical section where refcount becomes 0 (and this all is in update_refcount()). Calling update_refcount() is wrong. It's ofcourse done sometimes, as not everything is moved to coroutine for now.. Still, it's out of our topic. Later, we can reallocate "free" cluster in alloc_clusters_noref() and qcow2_alloc_clusters_at(), where is_cluster_free() is used. OK, to correctly handle in-flight writes, let's modify a concept of "free" cluster, so that cluster is "free" when its refcount is 0 and there no inflight writes. So, we discard the cluster at bs->file level, update s->free_cluster_index and allow reallocation only when both refcount and inflight-write-cnt becomes both zero. It may happen either in update_refcount() or in update_inflight_write_cnt(). Consider update_refcount() first. Here we update refcounts metadata we must be under s->lock. So, if we catch a situation when refcount becomes 0 but there are in-flight writes we change a behavior so that we don't update s->free_cluster_index, and do not discard the cluster. This will be done by update_inflight_write_cnt() later. So, we save needed information into Qcow2InFlightWriteCounter structure, so that further update_inflight_write_cnt() do not need to load the refcount. Now what about update_inflight_write_cnt()? Here things become more interesting, because we can avoid s->lock. If inflight-write-cnt + refcount is still positive, we don't have any yield point, just update inflight write counter and we are done. If inflight-write-cnt becomes 0 and refcount is already 0, we just need to keep inflight-write-counter=3D1 during the discard operation (if it is needed) and then drop the counter and update s->free_cluster_index. Note, that at this point we only implement the whole infrastructure for in-flight writes handling. Nobody now call qcow2_inflight_writes_inc() or qcow2_inflight_writes_dec(). It's a deal of the following patch. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-refcount.c | 70 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index eedc83ea4a..9a0d6570a5 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -805,6 +805,15 @@ typedef struct Qcow2InFlightWriteCounter { * 0 the entry is removed from s->inflight_writes_counters. */ uint64_t inflight_writes_cnt; + + /* For convenience, keep cluster_index here */ + int64_t cluster_index; + + /* Cluster refcount is known to be zero */ + bool refcount_zero; + + /* Cluster refcount was made zero with this discard-type */ + enum qcow2_discard_type last_discard_type; } Qcow2InFlightWriteCounter; =20 /* Find Qcow2InFlightWriteCounter corresponding to @cluster_index */ @@ -845,6 +854,7 @@ update_inflight_write_cnt(BlockDriverState *bs, int64_t= offset, int64_t length, if (!decrease) { if (!infl) { infl =3D g_new0(Qcow2InFlightWriteCounter, 1); + infl->cluster_index =3D cluster_index; g_hash_table_insert(s->inflight_writes_counters, g_memdup(&cluster_index, sizeof(cluster_index)), infl); @@ -857,10 +867,40 @@ update_inflight_write_cnt(BlockDriverState *bs, int64= _t offset, int64_t length, assert(infl); assert(infl->inflight_writes_cnt >=3D 1); =20 - infl->inflight_writes_cnt--; + if (infl->inflight_writes_cnt > 1) { + infl->inflight_writes_cnt--; + continue; + } =20 - if (infl->inflight_writes_cnt =3D=3D 0) { + if (!infl->refcount_zero) { + /* + * All in-flight writes are finished, but cluster is still in = use, + * nothing to do now. + */ g_hash_table_remove(s->inflight_writes_counters, &cluster_inde= x); + continue; + } + + /* + * OK. At this point there no more refcounts and no more in-flight + * writes. Cluster is almost free. But we probably want to do one = more + * in-flight operation: discard. So we keep inflight_writes_cnt = =3D 1 + * during the discard. + */ + if (s->discard_passthrough[infl->last_discard_type]) { + int64_t cluster_offset =3D cluster_index << s->cluster_bits; + if (s->cache_discards) { + update_refcount_discard(bs, cluster_offset, s->cluster_siz= e); + } else { + /* Discard is optional, ignore the return value */ + bdrv_pdiscard(bs->file, cluster_offset, s->cluster_size); + } + } + + g_hash_table_remove(s->inflight_writes_counters, &cluster_index); + + if (cluster_index < s->free_cluster_index) { + s->free_cluster_index =3D cluster_index; } } } @@ -970,6 +1010,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(Blo= ckDriverState *bs, s->set_refcount(refcount_block, block_index, refcount); =20 if (refcount =3D=3D 0) { + Qcow2InFlightWriteCounter *infl; void *table; =20 table =3D qcow2_cache_is_table_offset(s->refcount_block_cache, @@ -986,8 +1027,24 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(Bl= ockDriverState *bs, qcow2_cache_discard(s->l2_table_cache, table); } =20 - if (s->discard_passthrough[type]) { - update_refcount_discard(bs, cluster_offset, s->cluster_siz= e); + infl =3D find_infl_wr(s, cluster_index); + if (infl) { + /* + * Refcount becomes zero, but there are still in-flight wr= ites + * to the cluster. update_inflight_write_cnt() will take c= are + * of discarding the cluster and updating s->free_cluster_= index. + */ + infl->refcount_zero =3D true; + infl->last_discard_type =3D type; + } else { + /* Refcount is zero and no in-fligth writes. Cluster is fr= ee. */ + if (cluster_index < s->free_cluster_index) { + s->free_cluster_index =3D cluster_index; + } + if (s->discard_passthrough[type]) { + update_refcount_discard(bs, cluster_offset, + s->cluster_size); + } } } } @@ -1049,7 +1106,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *b= s, =20 =20 /* - * Cluster is free when its refcount is 0 + * Cluster is free when its refcount is 0 and there is no in-flight writes * * Return < 0 if failed to get refcount * 0 if cluster is not free @@ -1057,6 +1114,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *b= s, */ static int is_cluster_free(BlockDriverState *bs, int64_t cluster_index) { + BDRVQcow2State *s =3D bs->opaque; int ret; uint64_t refcount; =20 @@ -1065,7 +1123,7 @@ static int is_cluster_free(BlockDriverState *bs, int6= 4_t cluster_index) return ret; } =20 - return refcount =3D=3D 0; + return refcount =3D=3D 0 && !find_infl_wr(s, cluster_index); } =20 /* return < 0 if error */ --=20 2.29.2 From nobody Mon May 20 01:02:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1616792144; cv=pass; d=zohomail.com; s=zohoarc; b=cUTBq0ynWTla0ujaDwW09GKfjuLf1CI6HZ2i5Bz4CJiakr0hARMWirboUxt2B/j832/V4Ij/P4hgU7+NAuEdKlq/VVvKt592tsx7pU3dds16c3L/1GG0b3xvStHgxZrKc0Gil1eCnpG8sEygp+ejVIJvdCvrp6uVAyv2XmdLUFI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616792144; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o8nutQesDe9eA/HMXAa+hRoGEk58wVXnWzmdLiomi6k=; b=ltTblS7ioSwtFRWsYnp81T/Lc4l+gSOFw0ic9ayz/jh+YdUzWetWNGj0BA3JZW2qSrtpjn3S0QEhO8pnfDYkCZbHvuPqo0LVh9wSp/iHPs1euKkh9UX+rwtm0XcqFbKDUkA44E0OoYig2ySxvnfbY7UE9pwDoNBEhF+tepS1R3E= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616792144754147.08246535975059; Fri, 26 Mar 2021 13:55:44 -0700 (PDT) Received: from localhost ([::1]:54554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPtUd-00005S-CU for importer@patchew.org; Fri, 26 Mar 2021 16:55:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPse8-0000hE-5l; Fri, 26 Mar 2021 16:01:30 -0400 Received: from mail-vi1eur05on2133.outbound.protection.outlook.com ([40.107.21.133]:54454 helo=EUR05-VI1-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 1lPse2-0006Yw-Ou; Fri, 26 Mar 2021 16:01:27 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5877.eurprd08.prod.outlook.com (2603:10a6:20b:291::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Fri, 26 Mar 2021 20:01:08 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%6]) with mapi id 15.20.3977.029; Fri, 26 Mar 2021 20:01:08 +0000 Received: from localhost.localdomain (185.215.60.202) by HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Fri, 26 Mar 2021 20:01:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SOuM2ulre/DctLfeOCdlDQKzyZemUxqQruB8GQbQBboQaYKZbIE2l7IWOqtTDuDitjUvj4eXHPlQjy79d+usiEhGCEzcucJA83IHqgpr6ll3ww/NNbUDI4FS4V1+gnuZP0D9rZkr4UAUb6s16AzQbWgoegjE4sjHk4n/X+ZGfbale2TJB908oTXLfPnNc/1E+WpMeonVAqXRQkphOaUWhXbigkdzMIfsL7ggcIkHQlN87+nyBhkRrSysUsNXpQsxa0zKlf8+NuhAS3fL/aiB2MiqysKZWqvbnayURRNfcUz30/tPwgT78H5yKROjSELeAsroujeYAro8PyZYkjJVfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o8nutQesDe9eA/HMXAa+hRoGEk58wVXnWzmdLiomi6k=; b=DpV1a+1PkpQAGReb5eR6qzBN6sCkMCRnbNAEU5M7cyiKVVZ+eGUs+wz6RuQhofv3/d13PumOkHTtB6UqnKDn2ejSGOdRYqLOQJqtm+fhQxCJ88a6FxKHdXc7mHC3U3IbbhjBVh48dBzzgif+h7HdXFxYhE4rIvP0TNmh8UZX9DspxLaKBvoV203O140uiSAmRtUts81wbofCMBYDgVvhlTuDIQJI7xcJs0W2UK9/uaTwYpgRWCgceAP0dbN0gEZKgEJKql3urO5W4uxfFfprLqhTSQcXEUZ/enBwjoKuLQQf+74FUbcJQqbay8Po6i74wvB/HqXXIUUkX6o0R1zTvA== 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=o8nutQesDe9eA/HMXAa+hRoGEk58wVXnWzmdLiomi6k=; b=BoRhcNGGHe24DyZE9Z4F+gxPxm/9PqmwkIoBudSjm2aOSoUZXKLmXyAxl77elKRWAnWsndWSxl1EjpY07C8SEtX2/QGTsGnKL5oO9XMZCMWyl0lAV10SzyJL52oWcUzx8yg7C7E8CRbk/WPmIQsRBlFTaS0bQtW5GGKhAKCssws= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v5 6/6] qcow2: do not discard host clusters during in-flight writes Date: Fri, 26 Mar 2021 23:00:45 +0300 Message-Id: <20210326200045.363290-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210326200045.363290-1-vsementsov@virtuozzo.com> References: <20210326200045.363290-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.202] X-ClientProxiedBy: HE1PR05CA0166.eurprd05.prod.outlook.com (2603:10a6:3:f8::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8589224e-b10a-4f44-e577-08d8f091e5a6 X-MS-TrafficTypeDiagnostic: AS8PR08MB5877: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HaKQ/EVKMaQRzsQYS9TfClQsZGQnSOPcu6XJ+c/nK84/Tsh93mtasOhXHAblj3/AQqorCSq5wv7xegGqLhUEKPkJtNiC0rY/sCxJEm0670lQROcH1FYXrr8vKxaN6lVGgS80oHUxPA9GoutgvytwqWy44+7yiYtIKnx+L3wWuF9g5N3wMZ/bYf2Hl3ufLJrqc5XPVd0nRsOikBfJXlhg0KhRyrDJpyCh/a/ZatombJcMIsDEwa9uDP1m6oaaTBvKne5LnUCnNgu/vY5AC9OxjeoQZsy6oA+gY5TM1DPpUzWW2qBYtEZ0zDDhNdeNnNl5eoU+x1HhZUKuZBsJHmj9Z5UsiBRGp8cMWSe0mnvkxnvKmzoB0s6PHpQ1BMnzYqZW8pITaiPxWziiUMyznAaqwAE62ZKPJny+DfLBhMxSlxzQV24BXnCZKrmk4/kR98mJyrxtxUFdfFmU1rcPygd98Pe9likCRYDHgVD29+Ebkji68ptM1bqL0RuOWeIr83+OvoPteLNBPwsL9UQa1/r+mGSCv0+AD2ax7+5JDYi277uqId1GTqdBTQTCeDzo0meCh6cYbk0TNmwPrUdxNzLcI7LQMSxQIuHWjt+uniX1Wn0BnHELctIyDW+v1yreyvLB3WpqNkRsPZGWvbDoO96i2sMlv0vMV1HQjOEm3AMd1AxC+NIdb8M5Uk2FbLD33EID 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)(346002)(39830400003)(366004)(376002)(136003)(396003)(1076003)(316002)(6486002)(52116002)(36756003)(6916009)(86362001)(8936002)(956004)(107886003)(5660300002)(2616005)(4326008)(26005)(16526019)(186003)(83380400001)(38100700001)(6506007)(6666004)(69590400012)(478600001)(66946007)(2906002)(66556008)(66476007)(8676002)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?rlX9B5udantUnfch3wHXtyvCeCgxYAli48jBxUaZnEwyQxQaI087/6i+ZDeO?= =?us-ascii?Q?+5ZQs39das2wgzdUYOWkLtNu/ZESrzxGYWQCWFcgyiDEL5dy7J0WOpYFKAHA?= =?us-ascii?Q?N+kOfN7EQqNJhQT3fiJuoM26h2bHV5ntQxZeXDcIA+14bsjg3kWGqNii4qa+?= =?us-ascii?Q?2InCKv0qut3k03X62IXzHBTavOd47aU2QbWzc4PuvFLHs7oiI8TC4p/CPqsH?= =?us-ascii?Q?xlLhXkECPWnUf9OpqtkJJAHCqmoKqIRdVAcqk7Xf5Tb6DW8m1kg17uhshx4+?= =?us-ascii?Q?+vaTd/7c6h/A2sVIivOTqrokWM/dHdMlqa4+ckYMApOW+rw9WCiVcqUoAB6E?= =?us-ascii?Q?rDvmSzOZZoaqgWaE9qGOzHeHdhpd2raaz9yQ1wtOJozrcv4jk8JCEmOIzDv+?= =?us-ascii?Q?o/ci0tuWHU5QCu7znzFrXsQLypmHGQxX1rE9E0AzKKW4CnqS0oV0safEX71V?= =?us-ascii?Q?dIW1ZsclxCVRM6SPlGvOsqNnvc5hVaIg1MOdWs+jlAOaFqjGOwXpc1oz7xRv?= =?us-ascii?Q?cCPpB14h4l95DuFb4BBkInXab7qgS9VrEaybS65Hw+JG2zd6cleprHJ3xXRY?= =?us-ascii?Q?AtrqDwYIUBhi5MoLNWW6ESYoEx0kAXBF6mXgga+OW0vu60eoEGAeo1Kb5T/c?= =?us-ascii?Q?RxU0BqxX70TXg+bhTvpH5MVJeN8hf/HJ05AsyZSthoAfSbasxAgnQlBxWdj9?= =?us-ascii?Q?AxprCFIgBWIjUZ+Rjai0wQ86VvRE1NlD7kmopGsJftmfSj1u8WJ/YCp+vGie?= =?us-ascii?Q?slUaRwmx3xqHbw7o7hSYMPFhn48izZBemOZnQzl4NoM8DTO1NPDRu8nCmXuA?= =?us-ascii?Q?5vZJfPQUYFMR06z+oZae+c8liuGsc3+CYAa2pkXZ/amCxFHQLJToB2oAtGak?= =?us-ascii?Q?n6uXTZG2RsuzGeysGo5PKwVjPdI3uIm6OYSWFr1a8O52EaRQr3ChtVoqbShE?= =?us-ascii?Q?+DFtYvB++O/qK4obIOMg6Bn5pxTDFWKt5akTzqE1kJOK9xPjcw/0lpvPAlWH?= =?us-ascii?Q?+XbedRvn4PHVHYP2ul+jOCCfk2Ot1WpwV6ePNVs4aBko6cKk9QT6wsxGdG7v?= =?us-ascii?Q?ZrzZQXiA0uKruKxbUCmLf9Tg3S2I7hKApw7ItklTHPAhfyL9ajLzFHzwP2xT?= =?us-ascii?Q?9sQoQpiCfwEG4CfzGUaLx0GN9e3P9tKBWFXH3wD73kacJJ/3zD/0oA+RSLiA?= =?us-ascii?Q?wW3OAUeD4phBW+TruPHGzgkX5lgp5g9tTQumK4nFn1odomrsfF18IzOPq2/o?= =?us-ascii?Q?W5lrX578aJ4oGw12aPgPwQP/4BxzDLuJc+ofyJEHYparpevr85x0fKDIhEVo?= =?us-ascii?Q?TqZ6ulxjGAToXQNdzgO34sTI?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8589224e-b10a-4f44-e577-08d8f091e5a6 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2021 20:01:08.8292 (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: pH+jkZ83ZvtN4tjiJ9S2r84ZYixbFR6379Y+LSsFehhQCd/VdugIIDYrl7BTTSns0qrzQ77Nerk3TUi87k0P5dKtR+SWgsd5X6Q4OKkz908= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5877 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.21.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Finally, after all the preparations, when we have the whole infrastructure of inflight-write-counters prepared in previous commits, let's fix the following bug: 1. Start write to qcow2. Assume guest cluster G and corresponding host cluster is H. 2. The write requests come to the point of data writing to .file. The write to .file is started and qcow2 mutex is unlocked. 3. At this time refcount of H becomes 0. For example, it may be due to discard operation on qcow2 node, or rewriting compressed data by normal write, or some operation with snapshots.. 4. Next, some operations occurs and leads to allocation of H for some other needs: it may be another write-to-qcow2-node operation, or allocation of L2 table or some other data or metadata cluster allocation. 5. So, at this point H is used for something other. Assume, L2 table is written into H. 6. And now, our write from [2] finishes. And pollutes L2 table in H. That's a bug. To fix the bug we now have inflight-write-counters, which work in a way that cluster is not "free" (and therefore will not be reused and we don't fall into use-after-free described above) until both refcount and inflight-writes-counter are zero for this cluster. So, we have the only remaining action: actually call qcow2_inflight_writes_inc() and qcow2_inflight_writes_dec() in corresponding places. Note: both functions don't rely on s->lock being held or not. But we should call qcow2_inflight_writes_inc() in the same s->lock critical section where we allocated host cluster (or get an offset of existing cluster from metadata). Otherwise we risk that discard will interrupt at s->lock unlocking (it should only schedule other coroutines to be entered on next our yield, but let's be absolutely safe). Iotest qcow2-discard-during-rewrite is enabled, as it works now. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 21 ++++++++++++++++++- .../tests/qcow2-discard-during-rewrite | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 0a5bd4ea4e..d021c9d3ac 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2550,6 +2550,9 @@ out_unlocked: =20 out_locked: qcow2_handle_l2meta(bs, &l2meta, false); + + qcow2_inflight_writes_dec(bs, host_offset, bytes); + qemu_co_mutex_unlock(&s->lock); =20 qemu_vfree(crypt_buf); @@ -2609,6 +2612,8 @@ static coroutine_fn int qcow2_co_pwritev_part( goto out_locked; } =20 + qcow2_inflight_writes_inc(bs, host_offset, cur_bytes); + qemu_co_mutex_unlock(&s->lock); =20 if (!aio && cur_bytes !=3D bytes) { @@ -4099,10 +4104,17 @@ qcow2_co_copy_range_to(BlockDriverState *bs, goto fail; } =20 + qcow2_inflight_writes_inc(bs, host_offset, cur_bytes); + qemu_co_mutex_unlock(&s->lock); + ret =3D bdrv_co_copy_range_to(src, src_offset, s->data_file, host_= offset, cur_bytes, read_flags, write_flags); + qemu_co_mutex_lock(&s->lock); + + qcow2_inflight_writes_dec(bs, host_offset, cur_bytes); + if (ret < 0) { goto fail; } @@ -4538,13 +4550,20 @@ qcow2_co_pwritev_compressed_task(BlockDriverState *= bs, } =20 ret =3D qcow2_pre_write_overlap_check(bs, 0, cluster_offset, out_len, = true); - qemu_co_mutex_unlock(&s->lock); if (ret < 0) { + qemu_co_mutex_unlock(&s->lock); goto fail; } =20 + qcow2_inflight_writes_inc(bs, cluster_offset, out_len); + + qemu_co_mutex_unlock(&s->lock); + BLKDBG_EVENT(s->data_file, BLKDBG_WRITE_COMPRESSED); ret =3D bdrv_co_pwrite(s->data_file, cluster_offset, out_len, out_buf,= 0); + + qcow2_inflight_writes_dec(bs, cluster_offset, out_len); + if (ret < 0) { goto fail; } diff --git a/tests/qemu-iotests/tests/qcow2-discard-during-rewrite b/tests/= qemu-iotests/tests/qcow2-discard-during-rewrite index 7f0d8a107a..2e2e0d2cb0 100755 --- a/tests/qemu-iotests/tests/qcow2-discard-during-rewrite +++ b/tests/qemu-iotests/tests/qcow2-discard-during-rewrite @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# group: quick disabled +# group: quick # # Test discarding (and reusing) host cluster during writing data to it. # --=20 2.29.2