From patchwork Thu Apr 22 16:30:35 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: 1469305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=TLR+Kyb6; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR31r5D1xz9rx6 for ; Fri, 23 Apr 2021 02:35:28 +1000 (AEST) Received: from localhost ([::1]:38120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcIY-0002zX-O5 for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:35:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcES-0007HO-03; Thu, 22 Apr 2021 12:31:12 -0400 Received: from mail-eopbgr60110.outbound.protection.outlook.com ([40.107.6.110]:40766 helo=EUR04-DB3-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 1lZcEP-0003u4-Ns; Thu, 22 Apr 2021 12:31:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kI5AjjEBI2khaMrMExPnb1q2nuys5tEwQr5BYZJzFpPvxEk71AUO3qNhyqeCLHKs552JhYDjF7Brkpxycrwd/w5v3qSB9BVM0PlOT3RL34nztAXOAX8S0RX0GXlcvDLkbEHf0cPSqd5FTVMCtu9O8llfbmPCHatwgwWa29yRJwOsDiD7TH09ZqtLeqVEdc0mGQ3Z0Ve78AhlxTdA/wj7wa3f9AgQLTekS7RQxK3akV9dDsMBI5QG5vtcAoimX1lUsqfBqTFMzi0EdsCS/m9sLDIzTMyyMRr3A34GKyn2XTxPwOYBnp0wFvWIrSpEkx2m3GNPQISueK7NwEbq6bZW/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iXZs9GFBvUAXNvJ2vlQnOgXar2kFLPug2NV9BHHGUJM=; b=IrigYfy0whQVHB6HGpw7bHli1Uv8SYzQYwrlxegT/Uxou1njKFcUwvcjxqQzt3F8ahmcsfNtKYzVFbgzKK1n6yXLWo66khCKuphJhh+19gndOD7jUeF8KC+oC1/kVfLKATDDyzxG0CNRZc+Dm21/MRQubKE6FDgr2QNUJjCWiqWtFBkp+5cZo5Y6yKDYZYPef+6hmuJxqw6JCcHmx5Sa09mbXVnP9CC1hPe3B9ePwtOQaH+uaq6CHYkC0PBXItAbxSY21Fj7kUG2JTKiYLM6VL4Ak7vHnbZM6CPtRsnQr3LR7lHR013iNeobmOFkrVPOn3UecI4byJII060Oq+QJEQ== 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=TLR+Kyb6LVajb/9eD0fFpjEBU3J4asmGklH+q2uMNroOsg/9JVYEQYOpy/z88KhUtyt0Lsbm3MB6LD3gYncLv5ulFANXKw9CkyrvdlbLGrtIoWaAmObLebtOdw7ynP5+w3iJJq7JknthLdGhsaC9Rsc8Z6GN3ET6lfWc8vMyLGM= 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 AM6PR08MB3447.eurprd08.prod.outlook.com (2603:10a6:20b:44::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.24; Thu, 22 Apr 2021 16:31:02 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:02 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 01/12] iotests: add qcow2-discard-during-rewrite Date: Thu, 22 Apr 2021 19:30:35 +0300 Message-Id: <20210422163046.442932-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a2304b72-701f-496a-6f2c-08d905ac04fe X-MS-TrafficTypeDiagnostic: AM6PR08MB3447: 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: VaufMrKpnj2X0Qnvmz9aquL6h+N53+VMWKkdLzLteNN3CJbdLjJGWDGluM11ivJ2M1XUaJpCxR6Dqw0gQCaGM6GTYkbVYBg3RuYjPvr/5UvlmJjJMuOoJSZzbsPQRJIDw1Bvilh4sN8OBQPASF10h0O6onC8qurgP3S+UM1YdsKIDpO4G6ldYfkXK/GCCxT/BQUB7xiqB2m1sg7o8rNe79dBUVQ8Ho1pa6MSa4tSW9+ntzoZU/fid4btaLmMC+2vf4gL6UpUbSyVlSkj/tBZB4/kR/z9mbUQXG7xoAU8mpSJfHRroVKQ9FCkJ/hrnIY31BKxCSeshEReVvtKuCRp/SrDHVkrftPo04oRGBwCpvZly+zkU7IFPgC7CfFivuTozgUlW+Q+qssuXcDbQEMMQ0/aeP5i9pNOYoqlUjHo9z9MAdyUYHMYRm33eRJ796O5ByEi9Zgt6sZAr71H7digaTSEi1VqGf6R6Wju2w6kaI3wO8DwEQGdkjJFAq+7+DTFM7gYNK06titCjB/l3M51RuldX2ZVSYQ2r5+BnLXRhRUaVZB6JKA7+v0ZkY2DxlKtmItjpmscC2ptRnRa9HEmYRvB3llZNgewr/zyuH4IvxL49Vla1MmGcNKKkEgrP+lJzMUk+2S0uDPsyhIYlsRDuArhA4lYp0G8eQOKuGWtYmtiR3YAEHEufuCSAW3YgkW8kAtQ5kZBpBjnEeAw8RiVpaGdb6swj1RC97rNll1SO5VgeeAsjyu1qxiLQ8nadJKVLOclettiBPe9nCd8xdjKNvq/wbeG4hh1E2BfuzzBjKDu+2Lvvsg+pw2hztt3peIQ 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)(376002)(136003)(39840400004)(366004)(346002)(396003)(8676002)(38350700002)(478600001)(186003)(6512007)(38100700002)(66556008)(2906002)(5660300002)(4326008)(26005)(86362001)(83380400001)(316002)(66946007)(52116002)(16526019)(1076003)(6486002)(6916009)(66476007)(36756003)(6506007)(956004)(2616005)(8936002)(6666004)(107886003)(69590400013)(2004002)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: ph1bvPDBGfQwyk3mrSibbPXISpGg1Z7naJM3dkGLIEmUlvy04uzay5/fCpfjmV+utdM9Inf6r9c/U4rQznNkbzuUdQNGGgKBtBdvU7Kpa7SLapCs8oJLUGIL8TXY6gKhzCMF74Q76IovwfAZgftlG71DYOw4YFYUJdPnjSHav11ELvhbudDEZmGphhDISsnKdPm43u1zEyuxCP/r9w3/m8Rtn9r+sFjRiQw3tkl7b54lJFbcQIm+kDvhQ4LhVjdMJ33WfItBuNrczBoQbfw2F99xxvr/ggZejhbduOv0JwI3A0HmpquVWm33Dj+mmOYVXGmQPNZOWlprIxkRAYEsm0hBXkg1XpV8vBSRASIyqYFfEIghfpvBpt7/eLUmMCBtvIgOfvJTOlu5DvOraQp6iSvNypmXYaanE3hV6ZHSbvdqyXlTknujmADqnsMtWdo4YK2ajn3iIfyo1E7z4dEKaIz4qKP/HoTy3LULk4sMUpMgXPmoQr0kyzandiDq5siw59NZPqpdf351y4e9GQr5V5wPxBqslqjn3Xox8wUdy06glVug05Q0salDii+MzaDdz8JJSOeBAYJ5F4REC+uScUqDFF6FcyA4c+sK6GfTmm6JkAy3OCcrXxOUTzJSo93vz/eFKtAfSfVZ9t84eHUGn5I0iQElUoIGgjPymO7ZyBM/k71UPwEejRQb46ExJUVUqfcc4H5Wc33p2aBlBLGmwNbf0bstBGti7ciuFsag6KDyS3Eq5hRLcDxQ9zVfwVgOVqmOyCJzCcxUqxp7IW1DuYy3K7ZQoS6VB7tI+XwPPOlDSWQPXiHhoA0G9Uy2MvWj3hQlnhn0aKW4hwQqkqXtIsalld4Jz8RUgZB3khzPGUSxVcUQR6Dx0aNs2aJdIDj6/ac+awMdpbYdkrShf1ddWVU4DSDdIljRsTSDAPx61Lnbb5VrV+snQBS7MYvenBYBb4/1Y1FBD2Rve0lJL0yGjRZ7lj7+rAKjBzT/8UuvPc1/E7d5SWV4beHBC4aw0QNq6rNR41/X7xZR8Urws4lV6heWN8WSnRL3j/jqPfHI95JE5z6Ktck9YHQUnIeffek/7ISf7DxyY+u/kvB7VCyL1Lo4C0oqZ7R56Kri19IXa/txaCv7ZalUJENpCct7FmnnnWpKvNfX0LuQBqPAS5G93We8zYZDGnPpGiMMur3BJI0mG8/T8Kf+6AO5ISD5lVU5JIxphBSb7zk9qt90CgN8n/no6NJ6EArmxStw5WqZaOhwe2W/EvwvyQUdgnzftDyTuc0XTMZwY4EoJJEu3DEylhe5YLds0jkTWE/Vw3jDlR0GO0BdlLcOgTfQVJ/VfPuj X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2304b72-701f-496a-6f2c-08d905ac04fe X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:02.7546 (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: IT3AwQ2Hrsq4aLLMO6Lp6LQFBKNQBYVbRa7d4IEHQLEBhu9VRebx7F/NLxTFpbpkP/uYTMa9cySPi1LoNCOpB2skpldtzwtQRUxOGVW5CR0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3447 Received-SPF: pass client-ip=40.107.6.110; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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.out 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=vsementsov@virtuozzo.com + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # 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=1M +_make_test_img $size + +( +cat < X-Patchwork-Id: 1469302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=BPt+g5MY; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR2yC6GYCz9sVq for ; Fri, 23 Apr 2021 02:32:19 +1000 (AEST) Received: from localhost ([::1]:57020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcFV-0007dW-TM for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:32:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEQ-0007FG-6a; Thu, 22 Apr 2021 12:31:10 -0400 Received: from mail-eopbgr00116.outbound.protection.outlook.com ([40.107.0.116]:34309 helo=EUR02-AM5-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 1lZcEN-0003vI-CL; Thu, 22 Apr 2021 12:31:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gUmYLLte4g5lNBj1W0bMeWn+nTnGA4akmU4HHx4Pprppe9Ktji9+GlpehQs+0SMNbLXh1mfVqCOsYA0j2mRsb8Ul4WPol2UWVzoHDHw0Pz0fox618kKdf+KQSeSzzWxVjJczRkZA5E4f3p7waW6hgEI1QUx7QFdYPkp7DJeR5TRh3qca+PyR1Q6ANxHZQmdqocagDsnR0eQXaPbf/sFiJpWOuaUmZM5or0yYRkg7sF9O1HcD4TqZLLVkutV8Is1zQJl6KT2wY8OA8Kp7vwBLRxbYjvklWVzVvTN1DNY0YH7j75RsYo+sW4mRZgLcOk2V8+b7Oq7b9JaGmWUNDRvL4Q== 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=npxNJiFest1z8IJPxdmXyA8pKlwHD2qgBk1aiTw34KM=; b=bjIkkkqceemP1ed3Vi6rj1yByu2oArlswpOiDz961UxOvsME2xk21WMPwuHrOtWPBYoKS+wL09kGeKAswwqw2IdztFIuptuuulQxUP13R32J74po6LjYhOPyUEqGVG0CW+oCBSrBeETY9yj0GxpIXaXSv9xhi77uf0f64Ym1wCqkPdmgu23EvOJeeDT21xd8lNTBAaciK9MPUDZz3IeeUeYudHLkmUGb8ngeKn1nneonJX5HHawImSvdxUan54ierVj3xYJbjh8PXScehOAl0ZNW2j4h7RRphaTDA55JPoE4jKLrkoYllJ5Fdi5c/8ermrkGswWWoEFABd+QzExDhA== 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=npxNJiFest1z8IJPxdmXyA8pKlwHD2qgBk1aiTw34KM=; b=BPt+g5MYO1EYRBit/jh2CRWGztbBsZrSQybc5azPBkZ9Byv0EkyQjMw1DnfhwWz0IV6bvo9qMIkcRlNtLB/E0XXjQ+oipntqOsPOSCTQe+g1jouE6uwJwhAG5aiEO1yXYCho16D0QLQlhKPrAqrc3fJABbovtoA2c0V9regifpY= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31: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%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:03 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, Alberto Garcia Subject: [PATCH v6 02/12] qcow2: fix cache discarding in update_refcount() Date: Thu, 22 Apr 2021 19:30:36 +0300 Message-Id: <20210422163046.442932-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 97de162a-d349-4db6-c8fa-08d905ac0592 X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: 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: HUUY+y7NnwII1kU2bOYp+qknHr5w0qCyCNfEI11U9m3w3MP7LAavKWSI37M5ZQQ7B5CVE1AEOY3Cyi3UmPjoFLWjTbheQCO5yt2uDmRfarQG2po755mTm9zOobb4jzcbBMguIcQz+bajkNLRr9tBgT/1vIDbfF0XMfX8eNTTiGv0VYjGSCyqZQZtKdlIFnxyDRbYvUuNAMGd8CIW1khH94pHOrJvgBpIk3bXs8umqzOG5I6Ea7nGLVy77ZimsMVkNWcclqGZtqFTFV/igNgECyOZoE5I+4BS89d5sWwiGIBMuncKuddfuxfDtEQsRUoG2bn2Xdi9H6Fp19M12kT8otb76JUo2anAGwSrz8UInU2Nkkh/Q5yHbUkRWhvc0/+pUQHrI8IeU/CeF3SDYG+2u0kdNT6fxLW8OSeUTkX/6IrVimJ0kVYYHtaIZp/i9WmLoI0fhlKn9eXyeA+sikga20Eer99evUZx485XNepUMkvugMXfRpw6pDOryuDVV/sjA2ztZznCULA3Ln5MUycaBgtM4VfiGH6qZQE05MJ5QuzYb5JVkYxJCkt14MwV/8BQ+y+8G6HFbKTeepFzIzWff/v9Dvzklcjg4UmiZYphCXBy/EPVC1mJCDoXn+Llcwpju2QtlL/T3MrZ/4Yx1fvk7I5Fr6SQPloKzu+D/UetH+b7Vg6+LIekOCon+G1kR+3B 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(15650500001)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: GMiGFEp9Zx3+7VZ5FUAKMzo5J8SFziMp6yMLUhWFjnvlRHCc3Mg3pqfNegpabU7SLq/r/eP2YqrPxGGlnDL9j21swZFcKhBnjFBAo0615l3KUKcNUht+VmBO6EML2/6E9wxD2NITM+NEIgyEuuSM/U07dMF3fSnV2yjLm6pEuy6Gwin4L27qKwNYwRjJ3pEKjWNPdaevlXHLtCgpu+WpE8lTJKQ8t4vCK+U5DoIXgJ+xeWOZ4w9B9XGLELlJNfTQMexVP8Xm5WiaAOdQrUUHdHYc01f+p8QmWO80ZonR+X0UdqavQjAgq6GZ2BdyEt2qjkO+yZi7BFU3bA6X04KXNU8dyWCULIsCsG+liF/OY3J/8iTwtHiwygcYNBC3rBSZzskKnw+78fG5gc8A+2Bst3acjW9ZUOe0EbVDfTkhkIoi2LinnF1giPyGY/i4LfhBMcPmTWdxoThv4XrC2fudbaeRyY+aDqzEXdoO7il6bFRZwSkmdoDOXRIAZKan6/Md+Rqa36s1rJqoX3Rr9GKTWw+kQjP6D71kIGScgHLkCoASh1FBy9CfI7CppfK9z45UAuw5OdSRXQMh+pZyTeN5jy/HL2z62lXUuQudu62RtgXD89Mt7jsAiAixXeQgHm3iWJIv8HmsLPv5BHojaMW/cnYCaSVfZCKRR750g4JrNq9FijejIDIPcXkOUwMlhMH4yBdqlbcM/L+IVcpS66MKDMd7WWcyJtE8e/oIUdipS6OT9ErCzvlgUJwzV8WIKT5oIemf+VlgvDxOGDoEeqCait4pURK1Bi5g/JNMAKMUnG0egqq75tdkU2uDL5uOcY1+Y40qecSnN6RB6WVVR9OOCMd5mz08Gfai5oR6vEehZmXH1j/WrBtGJhEEgx2rz2cYY3qzHrR5DToA+xrT19ZyRq3M1TLW4jWZNB2dgbjpNsW5oAOsF4Zkk22pM3Q8H2e26XJWImlX/jK0J2U2WBqovsn9CJDZYpc3fWbxWi2bL+xtOW4N8oIzdEG5QJ4pidwYwSsZusmkSMuCXrDm38lGkyTyIFu2WWzwF+Uh3cS25q2l/A/uQXI0TVqL5SVDzemX9jxvPXwDzNrUyLaBXCAc++LR8Ats6s12qp1ZOroNrXcJNNsduZsdaHOBz2dgEub7qHVyaWUkinw/wJ5phTIRZn6ILVPxPz9W+d8V8w/1EYvTXpiVfLTImNCbkAhU+tNMg3RWfm4ThvIYt2DnWL49sYGY94KTxz4DT5HMYhDmzBe+FjYKYn7Y5nCLo5quTuKHwHVslSclYMWDC7CX4a0gHHh3CPgKTS9CvvQJDswN9I7tlxalt3KENFv3g5z+D8j7 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97de162a-d349-4db6-c8fa-08d905ac0592 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:03.7208 (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: 9PdMuUCsg+SnNGjF2S/cGIu0D52RlqGyM77ni7zzQtdie9DlJ2b+urOq5MBiOm2/RYJJtyUeu/+uWiqW/DavnYwFKsU2h4vuLLQufv5csnM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.0.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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(BlockDriverState *bs, void *table; table = qcow2_cache_is_table_offset(s->refcount_block_cache, - offset); + cluster_offset); if (table != NULL) { qcow2_cache_put(s->refcount_block_cache, &refcount_block); old_table_index = -1; qcow2_cache_discard(s->refcount_block_cache, table); } - table = qcow2_cache_is_table_offset(s->l2_table_cache, offset); + table = qcow2_cache_is_table_offset(s->l2_table_cache, + cluster_offset); if (table != NULL) { qcow2_cache_discard(s->l2_table_cache, table); } From patchwork Thu Apr 22 16:30:37 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: 1469306 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=k4U1Av7g; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR31s1F5Zz9sV5 for ; Fri, 23 Apr 2021 02:35:29 +1000 (AEST) Received: from localhost ([::1]:38164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcIZ-00030q-4P for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:35:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcES-0007Ig-Qi; Thu, 22 Apr 2021 12:31:12 -0400 Received: from mail-eopbgr00116.outbound.protection.outlook.com ([40.107.0.116]:34309 helo=EUR02-AM5-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 1lZcEQ-0003vI-TE; Thu, 22 Apr 2021 12:31:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OZIE3ekLvmxn+vmpzI6Q17dkxijn+PhUYCgFiZKCeMebdRcQ3kEGa/91nbB3SC+Oj+00+TI9mGUmPU0jlm9pwfKqbkjwhVRyBV8xV0V3iZejES8WCpsvQa+nBscak2pLXDwm6/GOdkU5xym/rAvegtOMTz60LRzfVVKGdRk8YZNCLL56GhLjHa9cfUBN6jM4QoW72NxUjSgAHbbVGdSg0QE4/eflxf+uOgHWVU0vkrR0kWtJPM+/aMpw3UNqry19qSfF5xYI8JfT62K3KGOl4ClnoPCB3EhTlmFmw9jFRr7e2RgWA950yZw6S8UHxPIUFlNvlpPSk34OxifpwBe0xw== 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=39GRkmJDllTgdVI1SRKlrMHJCYsH3ftdbT2AG2zoeQ8=; b=SaDOXKobZ/KfFbTqNzCOg5cJzAhKIK+ebyTQH03YSpdO5kE9WvtIBT7cHAvqrzssfSx1fuZvTUwPCL+pFmMUvGF8O/NPKXfdtR0qmI6IyFbtdtjQEPWoGdrD0iZzAYIT9w2T3Pzlz2WTWt5OycK0HW1/yuWLSlzMFnLxrF54m+0dQf0I4eSYce+Hi1k7YVEx6GJbh0xrnUK4cA0rgm5sXdFlm89kqcobt2CJV0xRtBr75q/0flFWpbA3JYx4wo+Cd4tXDLBkfCgT5ZpBG/ZkQzRqxq4lnlo0nk3HqWpEYvTVPef9RkK5Feh+ZFRM+h6MfOD+gCYin6iO50CEE//i/A== 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=39GRkmJDllTgdVI1SRKlrMHJCYsH3ftdbT2AG2zoeQ8=; b=k4U1Av7gkPIpdVkMgoPB3vzWS4NN/PeNq/JRPmbzDtaU/i9YkdcO1Mb68kQ/2VyMMReGROtHX1rbdoZOM6ON4iuaxmmt9Xd/FkOaFjZitK/Fx1iCPWdfo4WnjmFRT+OlYrhrb9xG274XURWZFpa7lzjyuJyGL3x9rLOjqoxvtcg= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31: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%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:04 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 03/12] block/qcow2-cluster: assert no data_file on compressed write path Date: Thu, 22 Apr 2021 19:30:37 +0300 Message-Id: <20210422163046.442932-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d90a732c-1a06-4eee-e4c4-08d905ac061b X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gIyC5f6Md94xu2tZBNnUswoLNDioI9ONwun8zC0JTrmhFg6DKNffFmvOXvC2CWQEZqQCwhX53dbbCCfpmFkuN8kCp24X7NrBbcxZI+ZR5OWqMo56nMVfqOfuJSEiqJrf5Pta3vz2p8i37Oy/nT54CPshGpJoaAvvN8Hp6hLE1T6gPN7xxbs3ySqiwhikjLV75OlWwdNyPqNaHEYZMJNkkmldBszKYKzw8MMA5Q9su213lGiLxTidMyyYNaHl6Edw+Rh5hGhkHXOq2pmPqhpFh8sSkkcNMRt6os/r3Ke+vdnR8vUt+MuWAskwzAxJmtrFR4fViO5LYCM8kvCczDob5Y1CK4QT9hj+57IYYRhrwMrXMZZRcw2UZqkMuK7wrRCYeD8okZO06m5OyYYx7UPVpNu4i5ULTEA7mAAWCXTb06sj3QMmtdPgsO0cp/pdHGNb84sGM2QIzgPDAMEmZCwuuQ8iBk6/tYIVV0t5NVsMWhLp/sivrpk45j3MPDs70pl4kY+whuoMqLfjoZ/OIC8cD+PNzm3fCBU/ohcCEz1WFohFamTDXy+rH3ausWBVJRbhS0m1TZBMh38EcOIS0WoSvKMxt/XdMKdoGsNabp2Nn/vZaCHYdZtk9Zo7euE0mSP6XgGNtB45J0iLk8zh+pEPncPIa0afPOH/Yt20UzOSEVau0eTLOfVh+w+D5fQiUgpu 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4744005)(4326008)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 1UP4SW8IjT1KSy6qPD4ftVgtkIbyM4p48NVX4pMFOfG2tWDvGvQ76PHQvPmZZ1GYgCEQVm/b4ltAr6vGH491oaVxiwiiOJYX8x6w2KzQ6bqPwhMQ7lDw1NDXTXF/eiwokAV5s0vIJv0/dxSk79KM+wyrxA7pM6rUw1NSAcU9iStBJ4turd5UfQUvsq7stVELTxFA0d11NoZCqiEgnzG3Iq9d/91tsODeZB0zTwFFO2LRz3gCrXXZ+FH0Lc4D0ZtgqmS7BR/OjnzBZaFmI9j+gAj2LcnTy0xs8pcgO9LJ7Id7ICT8abfbdBsegJ4UpEvOTl7RGvpnhaFRL2F5KuB9bC0F5VZizB0MGbHyCPVm9PMkEDUuW701IhPoQUSVa1AynsP3d/avVrbk5fOY/I0eEzPh1ZCZs9+aemaN+ssDLDnwv/sEDn7KpyIFEG6DHzK1lwZBOA6kNqgYIoo5xjiofdvLpqH6yxjWLld07E3cJGwx4mF9/BFTyTWk8NB4Ifug4iHPivfPgS+u3pY9xUfYbb6tcmGNPlBJbVgr/FiLBbt52nNp1jbf/+eS/sm0X03XXf4C6xdu3TnqKmwFHe9Q21wxgF5y5S7Y9mlE0l5O3xMOeS9ji+ii+FokQb6C2C+VlONdJGbIHKryZsNKfAPW2+m1Sj7+z/pK4qbfddAEio2vrWeYQ2eP018c2YHRbsd8EJm4kCdIRaAEE9xMOlpfyHEws3324Tw/KVe3fxP+QjgYsJGAcdv8M8MOEUzLbYSgsr62ekgZaBKbX0Yk6lPgYbIag16sH9j8MPXJHB2PkSBf97QqkNuMFaDbU67Jd1N3LLs7dzrdC9LZv0nxpg6g/KUVMly6TbsyXDaUvuieP3mAMAuprIq24L5zfY1TwmvZbjxuclMkDl6pAuq3TL6v2sA/FSEJq5LqnqFKuH0IWbKvpQnAPUX6t/emvJzOVKNWIYHEiaDi069+S5Nw3gNXjrE6XL1DZ01VEMiPafxRAFrjhps2aI3lFIlyRkxUdiu/6wl3HQN57420Y4y2TrZ2BQeLhx2wOWMBpf7BabpNMY19fO0lDQ99CUwcKddlZGuaSHjiPhpJtOFKtB8vTVLcqNCyGvNuQMjFlud+tTgUFflCAJRNe6yzyOdlbtNnAbA0yjr6aq8KlIlsIpae5mHaccG1vsA6qPgeFtIHoyFPBPxqQzJy7QqaRW8ktXOairNYPa8B+G5WN+RHQGs20elRvkL7Cbl0ByD+mOvrAHgyHXXCmVzdcitlPHIqqYgR2WUdrloOSE50WlrkC/rLSH9yXSHn9Qlj/uQyTRSQhAeDc5cLQkOwEJZOW7BEXuCooQQW X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d90a732c-1a06-4eee-e4c4-08d905ac061b X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:04.5995 (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: ijFTJx/bzrat+VECp0WDAXCtbpJDhPXx8qorcv1YgfZkeC/ochESEwZvqpImNCuzO81kJdVsjyv5okPBgUczJrSKOst4i1eCha0Q/MONZlE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.0.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" First, we return 0 here, but it's not a success, we didn't set host_offset out parameter. Next, it can't happen, as has_data_file() is checked in qcow2_co_pwritev_compressed_part(). So, let's just assert it. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-cluster.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index bd0597842f..6105d4e7e0 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -821,9 +821,7 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, int64_t cluster_offset; int nb_csectors; - if (has_data_file(bs)) { - return 0; - } + assert(!has_data_file(bs)); ret = get_cluster_table(bs, offset, &l2_slice, &l2_index); if (ret < 0) { From patchwork Thu Apr 22 16:30:38 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: 1469311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=W4Vfv2lA; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR35f20Wlz9sW5 for ; Fri, 23 Apr 2021 02:38:46 +1000 (AEST) Received: from localhost ([::1]:46684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcLk-0006aw-8D for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:38:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEV-0007My-QA; Thu, 22 Apr 2021 12:31:16 -0400 Received: from mail-eopbgr40129.outbound.protection.outlook.com ([40.107.4.129]:3204 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 1lZcET-0003yB-CT; Thu, 22 Apr 2021 12:31:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DWEvKv7z5YQG4Qp0lkzXdMuSGUv/6XbvHMittULCoWTXWSL5dYlqXrrFGNVo3PglzydiYrk6KhEI5aDpQoKNwB2K1RUu8v1bcL7JaSDHEW2cIIYO3mn3DFlppnPFFwObcJVjD71YJUXl2j3aas1yP4yPV56tu4ofjCkJIdeKTAZD9pwtFQJ9AP3K17Dp7TtVrfhQzBzy9TB2OTxllnSUJPAlQtQN4jKZ4SgfpYCNncRdPTqTxMiSqpTTGNA71DzW+dpaG+xJ12yfcqyibQIy2RWhnffe5gars9fxdHTpZUUYzfW5qt9E48KJ9prNDqiq4WfThWkbk7R3sByK11FzPw== 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=YqjR0mTXFjFvP0QqJzujV2aBCbF5nfVUnPA5uiK8img=; b=kchnl1XKTwzMLpvKuI4jAOsjtgBV5BVg0VkQ9eX7OWB4NL/0VlnRbk56sAHnUp1bdb6QBggMxXLJ4tF3hJs2XdXtKf/Fq27VZPVlw9zm1SO8zqvqtfsYyPjfMoKh3N+ErhDXMFc6EpxqHf7Snebb+ylAcKMrStfiZ8gD5ieRgMqlQcs1j6Oq/firo2LNEI8EyS1emXC9xTlrEYSe/UPd11oxFcDmEP4Cw4f2cmJQz5llRO/fVOR9Yy+UsQ8UO5LiSjhP8WYQYBGTCcDrQlxkgqLAYavaisrep8QtfQHfavG8pbw4LG6uAaqW2Z0OEJvbGp4FdD4o8HkFaKg5q93vbg== 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=YqjR0mTXFjFvP0QqJzujV2aBCbF5nfVUnPA5uiK8img=; b=W4Vfv2lAFTxAJHWxDEaLgtMKhXspmX09LsG7bNhH61pvInmmm1xowAqrldROieVuXFwuPslnG+vilJG37HiQRF0coXnJTKtLiHZkgTz0ZGwFpT8vbYsOOPIpKKZPbNv/sw1bQl30l0eZPRgEynENdCr03j2SInINxJlFD+ylx7g= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31: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%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:05 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 04/12] block/qcow2-refcount: rename and publish update_refcount_discard() Date: Thu, 22 Apr 2021 19:30:38 +0300 Message-Id: <20210422163046.442932-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d1e138c2-6683-4539-273a-08d905ac069f X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:231; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RAY95FT0SmdUgzqOKAY17VPUckjHWm86osswek2EG8asr7HBZul+SiVLg2AKW1H35j+ZYTFX+7O40mQ//j3Gqjd1ZbO4YPq7uLWHWM7OLC6M7eyKnHNTe6S9dvpaUJp6NtlS6uqp4g5QKQjuDiQ4yz/QeGLsbNtt73gNvfvQ0uwxohYsNboc+DcbIsmMaCytwi/PoKj4tXixpwjwGpZkNiagjh4rYLIDWXF+pDj7cIyUOtsJo5/FhFwSDO+AtuIKJSvOh1Q3ZsytslJVFDcfnnOYrlWF0Bp5ITnpIbCJF0jqyV+bTOX4wgmBEjXCABsNYLHG0soIHtclx+TUpbGzb+bL7RkLCY88l1g83MFS0FYmayFcIYUI9bNpCDkoI5iRgC5bxDecNVyPzqHxqOnKB3MV1iw3GmBcdMLQxLWXdKvUOSi+2UxzUFRcVp1hUuS504ewq+GXz5MpQmbyWcCbkgcDs3ES7IHgoDCnVwUVfc3STczGuwIrGdShgUJ/Xw3LVfC6Y9WeavdJFaGkgejpf+YVe6K8IlSbmq7wsHz4y+3QsqpxVGeEIETkUUccSaFdDPjMYlAHoRYSvHCgrH0vlPj6xNhEnz2OFhjLsOT31NbdLNBVRBWvkwXT+qcTx3pcpxLN5Yd/oI1MekzZq5G29gHmk53Yo+MrCchWoOeYGo++hujcz20k5V7kTlobLENv 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(19627235002)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(15650500001)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: TcapIHQEywc3YGscB+63MYgX2jFAl1zR8O2w54t31xRCJupT/8tINMoKUfHGDNOYx0amQtPN6iIWu6OFaArZep1hZMWrj/eDUwbO0tIkwB/mlb1GKYNcMv4+8D0AQFIPLQZVB3N+DakKfasO4Oq/Nhv4lOOAXOvh2JG4MbHuoRwVgn+Kmr+Cil7yVb6rlu4FZgYspnpuNUTkubwgSrxzoAQMMf2X8/QK3Ns9rkpYON4rnQmqcNSmCbEsOOm5//m7s8Jz0Cc8no4bgtjXyoH7/0K29OyWSot3thVzOvuNksKCA30SDa8KxjP1Oq7Wm2q6szlOWkjmZdP7dVIpAnwZskTMQad2DTwbzEvl2fdeaRsxVT6Yd2fSGHbmFQGvjDkx6fAWDYddw3JZfeD6rMI818TTi1/6IyLtOm4V+g5c7SbCXjr0wEozX1NruWmMZ55RgECgZQlvtTBODfRao5DeBCmWKeJhQY1xTHCxfPFM8yB0XbcbQDmjBYHuKJfi2MXPGbAMYeBMovBBTLL7stzCpjOEMTsxx42YX84ywCKZ9sidbYgMhBF3LIf7kA+GGET0VYXNL2sQPEL0oGpwxkh7ndwiFc1B1dMfFo40Q40z44pAhxGqlRH32sYXW0HD1Zico+YPMb6f7u+yGH6wR7Ug3weM2Y8VzKXqeCJ7cOTchJpPrZ73dD7wa7R6aP0geCKkFypVgSgy3PBTZrK9oARWsALA2y0PEwbeMGwQ420JJKrfegQOTlsagHcbZxp8A+Kasry7OrG1QFkJPAzjQQszjn1Tge+DXKjXjinUJ8gj8UOV+8sNcwXotZHs/lJAC6DOVEfDPB2Wx2c7fdgH2yg8i6i0lq6hDCvywWG1jQ5BJPX/TCveMc4MdnGP2+p/VlNZvcjvGCBo9TC2U06ISF0NAyCRX1ZnELevIxYOtL/nJjvbX6XCkd7+9JzwXxm6w53KTteyTpMOSwxke4/fljS7pRaS8Vyj9r4U6g1w+PqHcuqX/ZlgTmeTQZ2sZ3qY6dpvX9Vur/CEOZa2DgRgi5dpn9yp5Ek+9+/RZ9+j78gUFDhFFr56RKWExiVcsn+Zuh7Px8LM9qxJ4lcydWEbbEFq3zikcXIMYqmSfBO2KQL7vJ8BRUdhYF7sfacI5+aqfseeyiohNSZX+bCBwam3jlOKS8M34qNSdAGfFt0Q51CQTGdIq7PMNSO8xVcxZx3DZb75xSsuNYWAOeotycsHbSXzLLr7c/YkFwxl2H4rG34FMMpW2IWbnZs5iDEYV+J018JClfTlRzfOchJIrtV25SsqddukeM3z+vpfSGHXS+AqA95bLoOMJu2FOFa/s5YTW96F X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1e138c2-6683-4539-273a-08d905ac069f X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:05.4791 (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: 4Hm7RdoSLnuM9LeJgURwqvwQo5hH9Q0jMSYuVlJSs/wd84Og9WMTTVCSMIvBRtXpYGTHY1v/PwBP9ym0CBPnCQnYo20vXA5pnHp/JV+iERg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.4.129; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make the function public to be reused later. Make it's name to show what function does instead of where it is called. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 3 +++ block/qcow2-refcount.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 0fe5f74ed3..95119876e1 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -896,6 +896,9 @@ int qcow2_shrink_reftable(BlockDriverState *bs); int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); int qcow2_detect_metadata_preallocation(BlockDriverState *bs); +void qcow2_cache_host_discard(BlockDriverState *bs, + uint64_t offset, uint64_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 543fcf289c..ad021aab7a 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -749,8 +749,8 @@ void qcow2_process_discards(BlockDriverState *bs, int ret) } } -static void update_refcount_discard(BlockDriverState *bs, - uint64_t offset, uint64_t length) +void qcow2_cache_host_discard(BlockDriverState *bs, + uint64_t offset, uint64_t length) { BDRVQcow2State *s = bs->opaque; Qcow2DiscardRegion *d, *p, *next; @@ -901,7 +901,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, } if (s->discard_passthrough[type]) { - update_refcount_discard(bs, cluster_offset, s->cluster_size); + qcow2_cache_host_discard(bs, cluster_offset, s->cluster_size); } } } @@ -3369,7 +3369,7 @@ static int qcow2_discard_refcount_block(BlockDriverState *bs, /* discard refblock from the cache if refblock is cached */ qcow2_cache_discard(s->refcount_block_cache, refblock); } - update_refcount_discard(bs, discard_block_offs, s->cluster_size); + qcow2_cache_host_discard(bs, discard_block_offs, s->cluster_size); return 0; } From patchwork Thu Apr 22 16:30:39 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: 1469319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=CfXCiocE; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR3Ky1J9Kz9sWH for ; Fri, 23 Apr 2021 02:49:26 +1000 (AEST) Received: from localhost ([::1]:35998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcW4-0005qQ-6s for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:49:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEW-0007NX-Oc; Thu, 22 Apr 2021 12:31:19 -0400 Received: from mail-eopbgr00116.outbound.protection.outlook.com ([40.107.0.116]:34309 helo=EUR02-AM5-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 1lZcET-0003vI-I6; Thu, 22 Apr 2021 12:31:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hLd5a01cgi+9IYePnq9ZcLix6m30F8Tk72EZ1XVNEzUf/9WlE/dD6c7+SZeMgDPCza+migfMuCekmC+5EqJw6PUImrfspaN3GnJoetX3NV+shdRJpycb/VkmfvqZN45krKdg4Jo77YloaPpPdTY6zAMTjglYh6VdH59iaOODPv3S5hloapMsxAedOSrygM2ir05QbuagxaLv/3JcqzLqGlhBwOukrRVmqskyPbZo3vxQvhH/QTfJ5Ctan8ooqTFRk3Kc7W0jFtRf7izkQHLiVNsasXHDf3JeP1iFqFFWam7RwxaXaQdME+YrtNpzk992fogTe9YEylULCt+8KI8/KA== 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=OYgVMg7h+2BhVYYndWY5FAhLpal7BhUCSUt/dLZqOCw=; b=OfMSO3AXH0tM75vMmI+8VVG3YguZdhnD0SHVHFQVDYY43tXJVQeV43PL8FqHLYiwN+Okv/zxwLP923Gk+MORUoVitDCgNlLi2/fiTusUo77UD8YkEh5qKpvBu862Cr/+R95KEZf4kw2AVOaIm9JnZzizItwJ5eRwxoXUy2frL/j6ru8DzLc08sPYWsiVlsohyrnfb2ZJJ+Q+koxE8jxG5Me5eszEAL28ugo0xqi+Qz7+T6mda2SQzU3kFR5ldnNng1VrJDRmwMnlfgwYSxBBQlI0/C5OGcKGStNWM0zgRFF1dAspol5Bj+ppu81mYujq5HqcyjHmUIF5sKschSaNpw== 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=OYgVMg7h+2BhVYYndWY5FAhLpal7BhUCSUt/dLZqOCw=; b=CfXCiocEE/Z2wUpDLEhnO54vZ0ZQe6K0dLi0av73dzEzgYnLuL3FWykQiVgAU/BJEaI/o3kPqycGsjBnU+vLWYgP+b32NlbN1h3XOPOqhB+D5m/8e7jSMc9hLAgsahA6GVyYCaV4XWEzRzRdzMq4nshH1o/+kuBUQOvx9oYlFgg= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31: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%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:06 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 05/12] block/qcow2: introduce qcow2_parse_compressed_cluster_descriptor() Date: Thu, 22 Apr 2021 19:30:39 +0300 Message-Id: <20210422163046.442932-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68c5ab0f-cec8-4d37-8730-08d905ac072b X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:148; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k/67qYlukPkQqSzQTr7PtNOU9i2/G61z9fiE9fhkkibrpwz9tt2ItRzekRcUBYLVJESvRRh6weiLqFjTOTpBgcaM3ST652Lj1oPt/shU1QOkuaLRs3m9A5Fi/RecquIwzpOL5ggulq+ut8txiZjHZkYBI3ngRdLS0DkDqGzAPpUJADJcQo3BSrfAsJE5/cfRx2Rbez39uYugb7zYfnKbZB5D6s05LwoSQart+mpfVJDRiXlc7dKT7YyW+Muc1tKrb/NuXcXaZ7gx/Yrc8qdS3MVwk+0YfrUy1qVMY4/AaVdANcqIvT8S8J7MCzS+ukTYvXPJFZD/Oj2VGl20nOcc1OgmKBBfSI2bdolcQjyweAeE+S9ikLNIJIwk+Lfz+3zwt0NSHOPzcZuwZDlAALqs/ckagQ4i1TCPBtr5QRZ5CZG0DVEe0Bt526I+olhHC0TCms0gsk+FAf5SkhkzecUO11NbOc85cG1R93xkgWwkKUn13OPGQ4yv+Y09jtm35NcnNc0vEK3a/q4kFadH7UV1J2lS9FrzDaebD6JJGCc2NNKQtxTWY7de29pd7BwzlP3aYpjbcTQ8ZlC0AQ7IbrHD8RSSlEspzXXen8fA+PEExoOxXpP/MNaUoxntdnVj4cihLpeiYRmlnmNstSgpwqtKHx7B82p9JpFVZj0rVdmCcVwJoIOtxeStAyUly/HkkQXo 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: PW5nZpzNAGKazizFqaG7yI6JRV4bNBL/o/SFJtpD6vdh/1IbF4f6k3qjhD0O4kZADbwfeDLP6RgvS/pWmSkWcVeFDmQw97oL2HbzC4bjZcgvriZl8vaxUEJzgkJaLmyUwZjvy591Zo4dtw9z02TyDoyDS1SR7JJlps6zavUcmvFbQKoEQ13hRGXmOJIZo77yAa5Riud29zHLK4zQfXRoIzrHKjyIrEnhp2tNq4I2282impAj3XxdRnMZf3A6UUUIBqv/b1GRsIzDekvlvsgt8DMqwg6W9kDNdLgMtPoI/2hMN6fquzNOUoYNAHONhXmlYSqF2S35GwFl+Zj0G0WcFVdN2CyEKGrRsS0DPsWDVSyWr5/cwAyQlkFZAixAIq6KhqNmrrvJy7siUalFIu5YhkTBtNUED60wJf2jglzoq7UjRGQNN9hjhCf76YVyHMnsa0BmPCyyt9sYQCpP5EbYUNr1gIRhzsN8ugzZ3EniIN6k4z4CtOA3E5TdMds48U631WIC9ntcxOuv3WM1sAvZjtjI/7lQC9N/QXcfJL6Jv+JKqJ/ds+2QuNWQVnqfkcLWccWek7T+x5Iv+ngdTkgIJyWlikhY2rMGV7tOFqKWoG+Rt+f7UlogyQm3nYk1+CZ269upX8ErefRc1bHY+F+L4nGrcXpC0xlqYDPvxDMBNj4EFk28jW8H7KK77OJrrP+lKA08vaHB/iqDQYb1J91cJYzGoeR0f5BEu7RH8JckL8shkDw5wQ8q9m7i8L+qNLbC2wF2b7mP+KFM2e2ZLQyJyeUaRCFafytyXwKjkkUXkn4cqfEzRCugMR0Y8KXdKrXpDS5H3/uJy3emZEBznCSBn+SCRHiSxDPyEIUJgKjhBbUXr8Mw8VTh7wYHsJJg480sKk9Rjre6BHvUGtAylxjqm9sK6d7TEI9uTZtxTlKQwaXNPLoKbotJkyWEWWLl7+VOEscB771SPXSubNN+dV7rhwnpwyD+zSZVI2QSsHIuPn21nnorAig8XmarykxH3ms4MLGbfDQp1uZqDrf45pbIN5U4MAb4wxw3deuW1332mWptyvzKst10lsppOk7Han1tEoMl3Hilgle8HiuFa/eMNsVgJB5ZFoJqTEX+PyTCGAaFwPjj2Wdys/vFY08iJSetbX2ypWIW+4nKTjRD8ufj9/EmfR26HIiP7AvmxNPf2uLg3jh6klAgBN30yqMVbokqLhmYM52Std5RKnqNLX/SurJxB4Jlbor0HFt35BfoAo6glrhOORDszE+LgmRiQi0SaBAFe+IgccODYEmnoErX5He7zYdSReVeWHaejIOrOsNwr8CIoW6OXoQWPV1KY0F/ X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68c5ab0f-cec8-4d37-8730-08d905ac072b X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:06.3886 (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: ewh0bq8wCN8fk0usx14z1oCZvM2ljZeveOwF7vVf+0ywvfYgdIVkgbqLwm67m38adUUQRFz3Qdtcz6fbGEWCaWIZLSgsjpOGicb2WPrrDw8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.0.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This functionality will be reused later. Let's make a separate function now. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 4 ++++ block/qcow2.c | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 95119876e1..511db948ec 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -917,6 +917,10 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset, int compressed_size, uint64_t *host_offset); +void qcow2_parse_compressed_cluster_descriptor(BDRVQcow2State *s, + uint64_t cluster_descriptor, + 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.c b/block/qcow2.c index 9727ae8fe3..7049f7fc3e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4663,6 +4663,19 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, return ret; } +void qcow2_parse_compressed_cluster_descriptor(BDRVQcow2State *s, + uint64_t cluster_descriptor, + uint64_t *coffset, + int *csize) +{ + int nb_csectors; + + *coffset = cluster_descriptor & s->cluster_offset_mask; + nb_csectors = ((cluster_descriptor >> s->csize_shift) & s->csize_mask) + 1; + *csize = nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - + (*coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); +} + static int coroutine_fn qcow2_co_preadv_compressed(BlockDriverState *bs, uint64_t cluster_descriptor, @@ -4672,15 +4685,13 @@ 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); - coffset = cluster_descriptor & s->cluster_offset_mask; - nb_csectors = ((cluster_descriptor >> s->csize_shift) & s->csize_mask) + 1; - csize = nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - - (coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); + qcow2_parse_compressed_cluster_descriptor(s, cluster_descriptor, &coffset, + &csize); buf = g_try_malloc(csize); if (!buf) { From patchwork Thu Apr 22 16:30:40 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: 1469316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=DlN63HwK; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR3Bb5Bw6z9sVq for ; Fri, 23 Apr 2021 02:43:03 +1000 (AEST) Received: from localhost ([::1]:55394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcPt-0001vH-P6 for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:43:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEb-0007QM-R8; Thu, 22 Apr 2021 12:31:22 -0400 Received: from mail-eopbgr40129.outbound.protection.outlook.com ([40.107.4.129]:3204 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 1lZcEW-0003yB-Du; Thu, 22 Apr 2021 12:31:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cwKu9go6LbS6K/B6g0KwHZwnuUg8nLQpmxjJiIboDKL9OZtmh96kvGASMh16n3Gs40mf4Mzenty6LaUF+TbaxRtv+Zg0LVi5HmlJR4PMClEP71zr5VFMHvWu6a7KfyXgHZUQpYcuLOy7icWoC6QbcxHEdJWs36wWkHVAPOXCAaj8ok7ywfAVU9dINW5sMxf5CiWf+ynqNKSkbDwNvjCq1Ql6jbQW7NQ63cKJOr2B25LdQGrWXcTnGIt/0wbMGukGyoTY5r3Q6p2PzuSUYiYgCwQWLMBEDwVUlig0OJCbc8lomxvV/tniKtP+KimcEqiRCTbITl3KU6KWZAZ6UK3KmQ== 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=IytXGJ9WJOemtPQ9ezqfHE1QEDITcp6UTkqeQQ1MR5E=; b=N0f6aWJWDDs+KVR5OnSrrYcvDpndOxdB+fPDdKsSo/X8xhJvZRuG/5MJDoRXjztBFol/oc22AP0lx51fCpL3cuaXZYxQ5L0JOmufHXM2hDUbxrwAn4EjYIcsHSreDVe98rYlRa+MFtg74p2r3WQBloQu5YsAlZynZsFOPZ6mV9ofPGZeZoeCjsMakRqkXJyLDKoAe1XXVpW+mAuDpEkB36ij4FEnAz+avM1Mwlg/dDeRHljG96YeHlXisqLCL+vgVDMz9c9eiiXi58rL4WW525KVeKX2Ci2k+YtrhCqRcspQK1GttqBzLjXL91xdboypoYOQZL3f8RsKKgnT/cThaQ== 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=IytXGJ9WJOemtPQ9ezqfHE1QEDITcp6UTkqeQQ1MR5E=; b=DlN63HwKiymjgp2vPaI/CZmF5wUIKypg98ZnpviqrGyo9RHgLavYKxyFt5RK04stlMswr4YkZPFVr68MDbBEd95LiBB5jQ5/WRbyMq5vPuzpFYwTFLP05nN3DpagzRwzchXCC89b1ifMOJd+PwsgYWyjftSe0GmIqii69hk5Yd4= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31: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%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:07 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 06/12] block/qcow2: refactor qcow2_co_preadv_task() to have one return Date: Thu, 22 Apr 2021 19:30:40 +0300 Message-Id: <20210422163046.442932-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7080c447-16f2-4138-fdc5-08d905ac07b6 X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:376; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WRjCT2YvcND38aY2DcYLhHEW17eACFeJIu0Uif0X0dnHz87OcI7+iAfnFpBagu+P7Gi6AzIdD2it2pJSAMSZnWioPbntWKGSttm7wxKcNQt7QnZSu6bWs4V43oSwMTa7dcrgreyDvfh0ptYbk45eXathtYfQYKDPKxVHD1Euin9JuzHfsCRXstekpt7JkZBR0uzaAt9kLAAnlDSHsHsh6Pguqm4B0pnJe0xqyjS+yJGeDj+ks9auGXA9mJl8GsHftxnbVhUH5w7GRQy8UrVDKIg2sN2ROOcnXy86HMHl73GQHnEs/hvKekEJjBhwhxCTYlyQcKmI3E8/RzGQW61AXa0OD7ddgl0yUpeg/Kh2Sy8MPQseq2XIW23glPLCKiZFs12fHS/An528av6a8zV7NjfscRHdlWi2IR96J0tKwaEl1sCxS3YJUe0hHKs+yyFcvyyI36lMdZdiVSygqY832VF8EolD3jAmHEKvkkpdw11iHiCTi/hZQnzV+qkDW+RT5R4Vg0AaAylRj6EmwFhHzfd7HoSZEacYeqK2oNkQ3DgFYenqpK2j7EFvLPmZ+pIZWGLKQ+OQXDSWDPKBtX7chCWGhfpsdjFhzigVzT6cR9OHATwykOVpAyaDYQzuzyNnQnnDXpNHMgnzWuVeb0Mm1lxOb6dE0pNHAjVWDnSjKazRPTfK10uH7FUb5oybdTmc 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: kzM3NnwCBNoDhBlVvQ7NL2GjH8MYypt0dtvty+qbposlWn7wLHKFftD9Nrpb9Rof9xFJgT8AN12OGTVdkr0jm0PkBO9JsiOHgV0Vq82YJxai+mwCrKciEpccXL/qxWhKybq78jOpwlfl8WavdnppYuUAEVsWhXnwdhhpSsmizd6tRzjlcK2wW5Tzk1a8H3ZBFnwqRZhOScy4f+5kOZFpGeIzRtcTtllfK6LZKA4H9Vv5bdMBVpg1vIJgOSqUw2Ug9KMJTCf/R130xAqLoibmZmKudx0NtKXeoNTbSQ9i/WG2NH5C/uC6huVfDkz6OSfKYdzs0X6l+V1w/w1jpg4T/tWA9MckRYvZDBBuZe84XNlnMIC62GWAlLF+zbLWIYYb14P5RwrF9U9LxBmIqMb0X9KU6gEXWZMw3qkDp6mQVV7SRI9+9MO84SaBynxtEyuKhH88Dfp4v3BmQ/7t+PKh1fpWDwzjUCmrhxrdQ3VRPGcsWbdWMuVBOjdnZFu0sjXa0iJHmfFySYZhyuH9+RXRLP183o53jQFO2k3X4lxQOq4ElAno9Jj8m4i006cunCgNymMrKduqSCaoXq4KENjelpHcbmYvgBHerRyk2XRKffm/MhNq6pjijSDB6k+1XftsbuMlDTdSfy87qV/ZjkTnejV5dC5znwhKQQLNhGDmvQGBJRQ1Y4RwLcWjiQq4cMVwG7oa4Jj8YaGTVCMWY1G0VaKe/xDp0xjGS1Lm7SUmxVYWm3f/ln9Qw3W9CIx5dzAYR3uynRBdutgnWVTFvFU08kPQ+0NmddZ3rrzXKYvJIRhkPIUlvOi5mAbOHMMlaHmUDEAgG4LHwsniBdLryfAl3nDio21KZ+c5RkOI2wCqU/C1+mC6O+5OySh2gaDXpcIaiippJDNrEFdnicWnlpkau+F9dJdNZFegh3TMu4qqhU8NbSCsD9YqceyrkcupN3gKxKDFSzUzlN8DAu7gqJJZWZZGPj2tJEz+5vlKIBgcaCP6AjA7tnZcXnB0tumjdUPnh9HTrQYU+zpoIm5au5Tbdxn1t8rz/Y22Tfr01q19SEZJRDJfG4A/yR7wRGixcaiJnCUm1P6K2Djcspss90ie/Wh345/nYAYEN6WBAh+yBg0reqUIJlkpuXbSHYSFm//8ooYgJ3L1L2EPpMurx41jOwBzOoWwk94u0/1kNUoG1uQ7lDvkFazXFzd4jRgOfvy9/cM7ZNmCQYFfLv8u3u6TjgLJ1GLKgbSiKAD35hwh+KJ1LExd3CnCJUey0Lyo1mlAq1ORCXTuwoyKum2poJjBHvF3v5+5d6y9uel7wXQPwIsuhTkKHbVuEsd+UZgv3LZu X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7080c447-16f2-4138-fdc5-08d905ac07b6 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:07.2966 (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: T5xo2uI0Av5KPBfVvom+SPpUbCCbx8wy/7PYdJrtDVoNnjcvEENF/qGGcR4L4R778ltVSmcbAftTZ9D8m7axYT5dFXJHBlcZL85dLOMsARM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.4.129; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We are going to add an action before return for this function. Refactor function now to make further patch simpler. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 7049f7fc3e..066d44e2be 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2234,6 +2234,7 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, size_t qiov_offset) { BDRVQcow2State *s = bs->opaque; + int ret; switch (subc_type) { case QCOW2_SUBCLUSTER_ZERO_PLAIN: @@ -2246,28 +2247,31 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part */ BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); - return bdrv_co_preadv_part(bs->backing, offset, bytes, - qiov, qiov_offset, 0); + ret = bdrv_co_preadv_part(bs->backing, offset, bytes, + qiov, qiov_offset, 0); + break; case QCOW2_SUBCLUSTER_COMPRESSED: - return qcow2_co_preadv_compressed(bs, host_offset, - offset, bytes, qiov, qiov_offset); + ret = qcow2_co_preadv_compressed(bs, host_offset, + offset, bytes, qiov, qiov_offset); + break; case QCOW2_SUBCLUSTER_NORMAL: if (bs->encrypted) { - return qcow2_co_preadv_encrypted(bs, host_offset, - offset, bytes, qiov, qiov_offset); + ret = qcow2_co_preadv_encrypted(bs, host_offset, + offset, bytes, qiov, qiov_offset); + } else { + BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); + ret = bdrv_co_preadv_part(s->data_file, host_offset, + bytes, qiov, qiov_offset, 0); } - - BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - return bdrv_co_preadv_part(s->data_file, host_offset, - bytes, qiov, qiov_offset, 0); + break; default: g_assert_not_reached(); } - g_assert_not_reached(); + return ret; } static coroutine_fn int qcow2_co_preadv_task_entry(AioTask *task) From patchwork Thu Apr 22 16:30:41 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: 1469307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=PmM6GX2a; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR3231MGbz9rx6 for ; Fri, 23 Apr 2021 02:35:39 +1000 (AEST) Received: from localhost ([::1]:39032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcIj-0003MO-5U for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:35:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEf-0007TM-HV; Thu, 22 Apr 2021 12:31:25 -0400 Received: from mail-eopbgr00116.outbound.protection.outlook.com ([40.107.0.116]:34309 helo=EUR02-AM5-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 1lZcEX-0003vI-DD; Thu, 22 Apr 2021 12:31:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxnKhXybJN6BYQkVfQ6MGL8Zr9OXvAXaR8V2NquikFdnnNs5meK4E7jXjFSLxYesKMImFMhiShWYG4KOHqfz4hPR420Jq4s3H4muHSw0ofPsjDzrRh4FdmJ8xOcyIWh9ffiMU81mvbUQ18oY/kcUNhD6QIbNwmX3X90LSWgUjQKbPrTjCwTGOsZeOgP86HVz6EKkZsXBu2Jd3lt6gHYibj9MASB7T0tkZ34znJH3AbUXbuwCUyrdxnuB9g3LBoASH0rUm/B8+jpTNtragow9q4eazZbYw47LHyO8AFfBk3wNixzAvyJm6vH1Q+cnO0EMaJrfYPeJWjA4RItt4E8fhg== 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=8m5bCo55moG9oA9KkUl8MhaONF6dHB1WZCrTUrcdHiQ=; b=O6wTqU/LwO7aV9j/cUnRUbn1NMWoaOKKcBJan1J8SF+GmYMCceyMydHUaegFOFjBnTh0K+3OL/pbbfS9U1THLET/7whWh/ZOGG3Jm0LNfRJiLu2horw6/Pz69y3hcR3QoTQySSK5lll25h2FCjNUEGjSYW6GBGKd7GVSped8YzaVJZBfZ/t1SUGs/HbW3TMA+Fmh/NmDV2nI6u/iTr3p9w5giMzwG9rOEMegVWU2uM40y2CcCQgaJmK+ZVHxlOTWMLBBvLs7Cx0AATPVtqIozK6hfulxUjvqzyAjzn+5nP/xZ8eDaHLm+tmnk3Yzoenb4p3OokcP/xSJT4b7wfgmrg== 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=8m5bCo55moG9oA9KkUl8MhaONF6dHB1WZCrTUrcdHiQ=; b=PmM6GX2a4AwMleIt+rShdr9WH/ZpmSGuGYYLc/DgpoccZ4Nk+RApFu8vnkTRd1iat0q0GCB2PMbAn42dwIQa9DeLc3zv3v0KDY8RVVkySMatBailNWSKzxZ+rUs2Pyu6mVVW1R2pUO3foyfbrNDbAt/p9qR2mRy8/mWldOyiE6I= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31: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%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:08 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 07/12] block/qcow2: qcow2_co_pwrite_zeroes: use QEMU_LOCK_GUARD Date: Thu, 22 Apr 2021 19:30:41 +0300 Message-Id: <20210422163046.442932-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1fa9aba-0fc0-4e85-7df7-08d905ac083f X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:287; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UMO1QZ0ssImuKvnPK67pD7TE+lGrx0It/uhqXHeQ7flQdO9mKu66QRM4aYKqwdT3gxmuvEShSlpOeGqDuyNJrbZI9uAxrF1dok/vde0VfMB0wN0orGYL6jIoheWB0bkTC7s0ueYtQ0/wAMB7QnA0d5pwWPriTJc65cqazPV8YPIh08U1jwmoCs8BOgPxoDMPSc7ye6KEGdm8undGjzMxLWhj5D6vMkh9x9LVTxCuXhU+vdUag1BIaaXUKs1oJVjctqaEDljjqvje019rsccXiSGzO6B8BpPSNgj0fioZEPLlhvuSmTfjfWDo+qnrXQZ3trz98iBruIkYY0GiDdF6lVOaDFvSrx2UuBOaS0U2GNtOg2nduLDLl0zlinYfgAuiy0TtLD9BEJuK9iAbYF+RD7DUrj0plmFPkSoTicPvmX7N8O7wGo6OxfocnSBFZX4yWVGAFf19VfjQbxmyGF39xNEzyDF7F58w3niMGJ+LW4HC32BWvwqRSSvBJIyYIjKmMEA2fpd/ZhkI+txi89WlmwiSib58xKNvQq35CSj309r+O67gwmTHehaZkxboG8NnKKnAx+DXq32IdYiTrkEfMYaKjIvhyjlf0Q//Zj4QB+2Wfq99Qjf52+/1cF6j66riZgUEtJRh9RPRsal6epLv87vu09tf80eTO3fPyYhyurLmQ1wslyxB165bFv8uCnx8 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(19627235002)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Z/XsERihMfI3uYIl1rl+mLQCHLvN4mnbSwH2p3aXTFWEH/wXcN3H1myhLc+da0QgLfgVXlc8AWpt2SBZv7nHs8BuBVEfYpGGJixo9WnOyosLfHLwd90w0yv/9ak2YniNpRzXyixcrdPYJt+f30zz6o3V/HQ28kNzPcrgNIsQ3Tmn6LDSKRxJDZxLN1f8X/XFVuxbFle1jaWfvvFswiLZd6IPSpCGnKC2TRnGbFvwcJij32dkUmJbs/Z59iK3/yXs3g7CaZGv1elZHddGL7H+LyzRvuVEiQWmkUv3BgMKeVjh3rWN/VAnyT0uEO4okxRpeRywfspyHF12qRvKYA2YEJzuatAZTgQ3jEfiglPAfi0TQ3SO+xNhv9+3SEnoFyPf1RG0KDdxq9UuDWj01xf3hXPFdQYakUhnTFVmbmVkwyrzc9th5wCOVHLYYoDmDanboIlWCb7mYadIPl3Ob3xssBau3b6loZdNeNs9iPTq1R6BpJkR71AhGNGXq2qMyW8xHGZZTsT1b+x4Rh/GbLROljDvPx2ICu2zB7L4+8MSe1DTxDLqeVwHRUOj/LeYEK4ODjSJfLQllGFr/e7XzX/9xU4qhaMFsfSadB9qNbbeU1J7rQAm90aIIFyWm0SQBnKOZnLEiH8l1WWxq3ny3r6feWmDvgBEE5kjnTtXJfKHrnE5jByMhMjkoqVziyzm8tgAsp4DoFslwOyiJ9R0boWqacm2rD2gHKotnWkPkW0fq5r2MuYXkD8eybWpusO6z/Je8fBA0jMj0XXc2wpUqr27oQIealnv1Ay+V7Mu/rj6siNWAv4SJ4FEOdtU0CRDMLkJkEfwCSfiwtkKdGeSOPIV3GjPrF8wmKJwvAAqb/+ONTVd2MYOw9/7Y+ByVdnq7ZNVDBUpQJg/MobflhQP08MqcVomP1AF//C5g/QARzCM0uVwwxgAqPnDIf9tIID+tlYawIlWu0EaI4EEAKC/87ReBB3+winyt2+X2F5dFLR61SQQnRv7/eTvVfWuFNcEivrv9/FvrvGCy/VMKX4C7UKWisJb2J26FqBpf38N5+Eb6rRojzvVtzHqVvp2mqtBk11ROpS7P6wjYoLxDG7X6lrvKwN4RFPHbenvaiNMPCx5fK5TBIYlPuQEO9wyzAzJ1EG4u4y7eu1cmBy1OtcE4fcngU652ihLuyq8O9hwdHSKYn8yZEvUeP8s2ZVmoQ8g3TNvveA4Xst6p8ii1q20NZJfh326zjeD8GO+bvGVQ+6qkHSbtm5gpFnUSMHFdjz9cM07/gi1SrFItwI+nMaF8DRJ+oevZAkvoh8t+LUVQCljd2Ax3X+wL0NpEP/C5ViLOYR+ X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1fa9aba-0fc0-4e85-7df7-08d905ac083f X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:08.2041 (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: 7oxFMJREB5Xo+1xfDt+rEo5lT1/Hk0UrFliGacp3MOmA1wHuqImWz+++0cSU7Lw/mRsL8zrrxomO/oelJKMLLPfSPm+kkOApe7f1so1JLIY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.0.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We'll need to handle qcow2_get_host_offset() success and failure in separate in future patch. Still, let's go a bit further and refactor the function to use QEMU_LOCK_GUARD. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 066d44e2be..be62585e03 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3931,10 +3931,6 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, } if (head || tail) { - uint64_t off; - unsigned int nr; - QCow2SubclusterType type; - assert(head + bytes + tail <= s->subcluster_size); /* check whether remainder of cluster already reads as zero */ @@ -3942,32 +3938,37 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, is_zero(bs, offset + bytes, tail))) { return -ENOTSUP; } + } + + QEMU_LOCK_GUARD(&s->lock); + + if (head || tail) { + uint64_t off; + unsigned int nr; + QCow2SubclusterType type; - qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ offset -= head; bytes = s->subcluster_size; nr = s->subcluster_size; ret = qcow2_get_host_offset(bs, offset, &nr, &off, &type); - if (ret < 0 || - (type != QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && - type != QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && - type != QCOW2_SUBCLUSTER_ZERO_PLAIN && - type != QCOW2_SUBCLUSTER_ZERO_ALLOC)) { - qemu_co_mutex_unlock(&s->lock); - return ret < 0 ? ret : -ENOTSUP; + if (ret < 0) { + return ret; + } + + if (type != QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && + type != QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && + type != QCOW2_SUBCLUSTER_ZERO_PLAIN && + type != QCOW2_SUBCLUSTER_ZERO_ALLOC) + { + return -ENOTSUP; } - } else { - qemu_co_mutex_lock(&s->lock); } trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, bytes); /* Whatever is left can use real zero subclusters */ - ret = qcow2_subcluster_zeroize(bs, offset, bytes, flags); - qemu_co_mutex_unlock(&s->lock); - - return ret; + return qcow2_subcluster_zeroize(bs, offset, bytes, flags); } static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs, From patchwork Thu Apr 22 16:30:42 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: 1469318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=bhq1psvb; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR3Kf0Fhpz9sVq for ; Fri, 23 Apr 2021 02:49:09 +1000 (AEST) Received: from localhost ([::1]:35814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcVn-0005lL-CD for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:49:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEe-0007Rc-B2; Thu, 22 Apr 2021 12:31:24 -0400 Received: from mail-eopbgr40129.outbound.protection.outlook.com ([40.107.4.129]:3204 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 1lZcEc-0003yB-GI; Thu, 22 Apr 2021 12:31:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PBbBR3KDnQPnHraagRXonaEl5lPlIRcwwIfAtHPnmQdSPoQ5yjza8dMtVCPiU+Xa1NQyszJx5sQSNLJVe30DBM95CcwiM1mZdbRgXrECIqKY6XdDeXqfPr6ntWOU9KzsL1PL/GwTlGJzk270oETuZUd5YvpUO1iUyTzgTMmM7KmxJiQcRpVyCbI2L5Sz8to0x5b8HSc9Mu0fJuoU7US0SfIoEjAJsrjvz7EqcEu8JmHxC57D8A2qboHIX5YiBMglRiIfsxNsfrykBQtn7RAwVqW45InGG8ezCfaCbS53Q0nh3nAFCMRDPZhY0kJ8F3DFqRVvKf5n0yu7Yf/QBki2YA== 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=JVPrbCXOLoGPkLQN1znGuGj0mBCvZjATpgjDjqHUy+I=; b=h1/4XYs+eWfgsFE4jjYS/8WZVCzemgyXV53Iz5tVWvo6zY1CWzx7BsVVijPGEo2h9bkLa5BTG061wap3DaFhGcd1ViIpKxIjMkskVJB2bI7/xQCqNE0oFfP0iWwP/b4kVtHSRKoTCDtsuQOBN+n/ED2eXqKAhO4z7Ynf3TrZJlHZYx1n1FYLeqZXzYl6PqceHwm6xxv+NqXVmL/mzcb7bbMKbTY3dUBnHJfp2tYrOR+TZmkE5Z1RdFsc9jZLmqPZnLnZdczMvUIYzSKDtQH/CsQWTBS25YhymD/0UQqGpQ3syaJbpSj99afJFWcm1+65eOQL3FUJzH5ex28gvTujqQ== 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=JVPrbCXOLoGPkLQN1znGuGj0mBCvZjATpgjDjqHUy+I=; b=bhq1psvbMLDNBszJ43MTg+JLS5vhfcMkOzz0TLpVH5GKsWjCAIVq/AgmN4YlE8j6zPvh3Uo0phKEDjjf9hsGj5pYYBx4qB7+daAhzEFYzqIcIT9UtiQgUlnKa/3WNIWVOcWwb1h0aBHLHkyKodFyyP2mZokxTgNeaa56naqhtWI= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31:09 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:09 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 08/12] qcow2: introduce is_cluster_free() helper Date: Thu, 22 Apr 2021 19:30:42 +0300 Message-Id: <20210422163046.442932-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31add05a-d114-4c52-1b7d-08d905ac08cb X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: 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: 4ZG3pDIbdFwGloimivqAD+Wzc2PW6EAJq4LjVZRWKYX5nJkh87WZq6tNqkj4WPv9bZkSjo/mOBMDPBFeOtuL/7pjESV7FAnFCfrgj8gQvWsVfGXjUlPT9SHQd+2NEwKCQo8ryl4Ly0gBVqJcH035OCfKn4WshSTcobkN0yComgqJuEtWoZoY74ShBPfK1CchHdkgYvMrtMkibM/i+lb8N+P7qZj3gSaEFFA+Li7QnVgB1LgvMzdWpeFzjFSpHPAHzLfDAOixjZRqvlE4WswzT4Gos9fdvRThTTh9e015HFusUmn/myILIHd5Th5zCXvmMuetzUmFi9OOmQdzbRN6TkkAGei4OsrRJRwOlvkyu9+MrHQ0fG9vP26Pwt8e67Q9Dz1UVchnVq/MSv2eE+QCDrBtFHQOpSAE1KnceNf7IhfDKeD2ldhby6DHGAB7SztZ0rmwZxAloUB3et2cqWU1h45TtrvfvLjbvhnTGnASC3BWnb+CJ/zgew2rhnriGF87S/FmatRxdgh5qaeQsjtu/PfufLZ9307Aj97f8KKpSN4ffM+R1bk+IlTJVmphzNOnAY5LTtqPTSsGifEW7EcDHXPWTvpo8lBXzcPF3ENHDHkz6vbfLn1IPLPW0mnJgKh8hGXAABfBN/EK6wtkBYqASiJLbNLTUjIzTavrQMj965QMudYuOsTO3dsUbbhvXVIm 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: aKs4qWuFZ+CInrms6+kRI9PKL3oYm9nIrktAI32JZf+Puv1uBM+FdyIpk6Qf15Vku7UBUPMKvwtx7cx2kVuJPHRvwne9Eu3AhXqKJcBVeKI+3lCEN0BtMqm9EGGuwHd9cWoRAjNJlPO2TsHvwBv1Qfqhh8WsL38Q+SvBg3I3scckfbInFhBxohxIduyIj4fGgmD1c4emD1YBTbO+qWdVUkxcIQiTxQwiL2v+BEgTBL+dRTkrEGQKfJhaHMhJAwiD3ywAqV+QCqg/cad6Tz4Qvu+NJtJWJBw0sNeVM71ZooQ1FTDZN/2q08lOxLseS/WCUjytRTnNDMNF2d2Fy8zn6se8HnPTUq2jwQaMPKz6dHqRPUZeqL+DC8dxjR749Ij8ZWdf86Q4yF26o8B2XhZSev4dLnbk1FKqp+rhzIflMaHltjjvluF8aevONQfl7fVhQO6+o5dWnFqodPhrChnYkJtq6BGUom1jbBtuiHE7TVtyTIp71yYxe6+ZJZs0/wT/8yCPtwi44f12wQd2hnnoi9UhcX5PO41rMfMFl3/a9K1vAytYyiPENF//Tq9bIJep2K1pobmJj7Et/zEuFm+2TCkPRkwb1oYRqVQmgxHqtaeEBY2rV2SakDZXA2dKMEO2S5RDuM5kPnsUsuLtnwWt6XnVi9cGmDO4SwMW3IfSoBl+u5ox3YCyivE+xwfuLa+5oqqRDW+PBxW40tt31ZitQz1pVltNr7lBeqwVs7R4EQbdYVizFfbK/Z7Xz5N829qPtg6ZxwfJo+yq116Av9Z63GGYceETIIQcG8ZyN5asiu/qpJpFEjm50OFKRw72Kw6zEL1k/kw743BZSp4KqU4MK+L+WX9woC7+I94aLFIi1onN0+3d1u2rYIFYGAdR64mBsvdDnUH25SpDZ+iKw4cDHdHxAagqwVRLUOs8022QnU6Mi4jF0OE4Qj2QGfD6mFMGnujIUBk1b2VilhpYszYGHqrnam656OwXrPTw2lbJYOsH7cB7K801NTSIcpdzzsTFUPaZ8mKlZRAI8CrOoFh4iJmvJQHEcj7eLdRD9O1v71F0x7n85MHBorr9RWpDdHXDWQMuRDTlIsNL1t/kRMvTE0mS1QkbJbSDXDCYFCycRW54gZ4lApOwux04GAaA4YXZdqMbZHPtO/lkSfo0Lj+AI1dsRspcIM7JkaXvmofKZoKsGK1ht7G5cKMuEnnLyuDZss7T6we0KvHJxOUx25pG4i4hrmMoItKm5D+ygR0MKywCUSeEm5oYSZUQMU7VBSHIvzlUFA5oKfTtIWAUfpzyiCfkcWwCtSbNuicX0WQQJvuodb/viSxvUdLc39DGBKu3 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31add05a-d114-4c52-1b7d-08d905ac08cb X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:09.1072 (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: DExefTgXcySTH4Dw4r9sr1xF97rK3EWUw52WBWUj6SUy862vivGDs4rgYRL82KV17jfTIydMWS+r6Q5BkbvIe9pAa1wN7wfrUloz54b7tK4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.4.129; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 ad021aab7a..72e6d1efd7 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -962,13 +962,32 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs, /* cluster allocation functions */ +/* + * 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 = qcow2_get_refcount(bs, cluster_index, &refcount); + if (ret < 0) { + return ret; + } + + return refcount == 0; +} /* return < 0 if error */ static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size, uint64_t max) { BDRVQcow2State *s = bs->opaque; - uint64_t i, nb_clusters, refcount; + uint64_t i, nb_clusters; int ret; /* 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 = 0; i < nb_clusters; i++) { uint64_t next_cluster_index = s->free_cluster_index++; - ret = qcow2_get_refcount(bs, next_cluster_index, &refcount); + ret = is_cluster_free(bs, next_cluster_index); if (ret < 0) { return ret; - } else if (refcount != 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 = bs->opaque; - uint64_t cluster_index, refcount; + uint64_t cluster_index; uint64_t i; int ret; @@ -1044,10 +1063,10 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, /* Check how many clusters there are free */ cluster_index = offset >> s->cluster_bits; for(i = 0; i < nb_clusters; i++) { - ret = qcow2_get_refcount(bs, cluster_index++, &refcount); + ret = is_cluster_free(bs, cluster_index++); if (ret < 0) { return ret; - } else if (refcount != 0) { + } else if (!ret) { break; } } From patchwork Thu Apr 22 16:30:43 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: 1469312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=h1Kwhllh; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR36V1pl5z9sVq for ; Fri, 23 Apr 2021 02:39:29 +1000 (AEST) Received: from localhost ([::1]:48392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcMQ-0007J1-PS for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:39:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEl-0007Xn-33; Thu, 22 Apr 2021 12:31:31 -0400 Received: from mail-eopbgr40129.outbound.protection.outlook.com ([40.107.4.129]:3204 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 1lZcEf-0003yB-QX; Thu, 22 Apr 2021 12:31:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LPvAnOFWy4xtK3wLY1jg/oWSK6vyFhLn9BzwkLEBkg5crHkW3ICyoP9RRtorYThkKMTWpWYTP5e4HPa8QH+tit45E1lZuttPRIbGK4Hug8wN/XG24dFoQ6aaCpTbGBHhd7ZUZW7NGHWzb770v0hlua7DnmHZUExTmkIYS6hoyXFRy4JZ1XlnxyDdpO73wB4cTvrYs+5HqxEettGY6jh9dSr5klrbFarw6SrD/dUOsSnZBIvGakqlLUeDyt7wT3ufIEv/junSJ+cHF2NB19g0PnENVrsO67qZhtEs03nilvu96UCkVRmCwhtod8RopLaR5nAsQIN4L7o7wtE3ZnjDJQ== 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=Bj4labnwvQrnwJQ4BNr7LDuBcGJktYmuL7QjRTR6Pjw=; b=GQOYPVrmU1C2Kz7FfUpZV0rovvyYS5fFHFdbpyeodhKrnwEMPtYy0PejF2xhdzZIM+WOD+Ii+vT0EtA3GJV1QzYlSO1ZwW6wdY4FxXDakX+k8spnsAb1CBN++yqS/fua6fCvmtRT51R6bBTEF7buAOO49+y6kfoWgeoDmh3hS0BDDNgL1i5jc9/F3K6FxpX/4Km/bJaSHoLfqvxUcw+x9Ffjc4hZbtf6nerA8Lb2zCRUjuIhttZIUhMSTI97cEwPlVALHxLJED6lOPZEQGO04nVDSBKySmOnXV+t9MzSPv7h/gQMJorn9VwNkGX94uhBat9CZ4KnqXZqMJDTrFgPrw== 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=Bj4labnwvQrnwJQ4BNr7LDuBcGJktYmuL7QjRTR6Pjw=; b=h1KwhllhOnvWNNmtVASLLjms7qb2/hey3WRNR0oA5bP5v185q8UG/TPyAtuAV2/fGcMSwzVMPpSH0cUJJ/FiuuCDqEOhFwpmaDAIRgJeyptByC/rUC5t6kHH/rAG55Cfk+qgpTvFXm11CFP/mQMqpXtSlM7FXUKrs+ooIcKmxOg= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31:10 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:10 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 09/12] qcow2: introduce host-range-refs Date: Thu, 22 Apr 2021 19:30:43 +0300 Message-Id: <20210422163046.442932-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 85d3cbd1-61ff-433c-e7df-08d905ac097e X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:217; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: saWOGiruVQx4HWvRarD9ZAfTLqVasCLMHTSZclUL4YM2g9RJETcEyD2kROdsyYI4SnOrxRFABkTJnYFXXIS2JbyH7MHF9/ZlrAa5dnaL19S4MsqG8utF3ze43v9CouE+Eo/w4JUBL2mf9fK2Q62P9Ud396htRYm93aZ4vmPH6awWQRYeCOdMduWl9SsYg+B1SRr9X6OjuMnIsI4zGJoF90hg6mysb7k5xri1AynhkecyE7YkPrrEYb3PgkCyUnGUw5F0A6klOHCZw3IrvywPr/uPbVMFTnFtYgKP416SQJPY4WfR9dtSYYxltMLj2AL1PcNV5y57sQIWFHofh74dtHPlmicvIk5Ez6/p6ZR/ECED90iouruPzOelVTXwzs+7pG4MmSwQ+G/9gmGM8s011LSsO/gRAKMDB7wJ1ROKitvWLOsZseF9DQAVUzD//TD3P1hodzW14ct0fyxQF52Z166abj5jct69tfGf2dEls+YvxgH1NKpC2HKKta3fP7OG2RYw/DoIAZQ3n3ZK1aJX/Fi43mc5ckN7wuAa7SNNpVuF8pdXjGk/8G8aiAkux6l8DosJfqwj/+aH9gP69DpaPxmxJ/EAxqtXL6xDoZnhYt9MyDjJqkhnaK9zqyUjrfzPc9/Czx7/LO8rd08gsSBjxR5h4rvDWp9WBYxIrvf2S0m4t2NIL1OK3C1E5ZTRoqNb 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(19627235002)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: YDPtMbtudC3Zfe6fLN0TqgFv1U3C9Ri9IPzfUWpFBrKDccuILxgyvo6I/0xQsbj/vfIy1+dnx/z4sdxZYO2OqsFvM0drDgLQokerGjvs3DYsyEkayua/HwPE3AWVpKzg2jjYBFSUxx456hOIY31GjOB8IBZ9VzUhwL6XMiuoqGfrM59oXu3o3ui4HZ0ZMBoCaTisoEf+j8c2srewmGRY6ldtwZbUTijKvoKuwIdqDGeHN/OV6BXLlTLTEtKuHbr/aNme99+Hgr/BaYC3Gg8p5OAPydlBS8Zor+U1fJ+FJ6VGLBHsHiHRsIK1ZoRY+EWnyf0sz8DqL+FY880+oiqqv22SH4z59Qu6AhISa+i3E1fRsvSn51Vhaxzb2K3FPXSjceTBuGFJ528GI6Pv58BFy0UWTztiMR5lM677OGeaMHBO6aynCrVBISvGwF9fhUjI850KBKIb7JzQaJ2eX8yzf0bNEoP1OsUG9cM9sZ5RFXs58PfFbVAdXElVZ5/4QwGhawhC2MPurpVqzGCPV/VG41nR2Xb+lf8vXtFEvcXzBfjg0YT2V3zdVvZ2InHO61rXoGdgFPWFOKKb3tIykUEhK6jeDrgOW+Syq1ThqNOtMZ0RR7NfOFnezl8KdVJGi7dUHXlCdUq0rU8KsHx1UxU4l2U74a0u/gApP0TB+EZPWN6Euxm0RhO+S8jMip8uSGdophj4handXDeILDc58rbDXwxWKBsWfMNcjxuCZKG4MocH9T/ZXWR3EwPgXrp5ue+E47PUwzxtxKEFNdQB72Mlp8AAV/dV79zPlkd1uJHDBZr8SyVUX/cxAy3Uw3aS/HPvfGyBKeOUPzOb4lWwEOQSZ6pABbCqjrFHbDpCgO1O45DRmIF46jo0Lp6XSkDnBkkbSkF3lqQSZ77GJM+M30fCAviMdO+hMdV4B2FfCWF0EpDBCNXmVe78myg84KsQs4H4U6olUiQquulFAiPYRvLcTGbsbP2svguKSRGA7mvnBiKxYnNNGFPIkp/bHGb8xwrIeDMh9Aioq0WibmWiPeHJoVxIt007r0qQOk8ypoPiJx2wXjOMNNwJnil8zNUmTnMgckHVLjesxgFbBuisiPuDqtYHsCoxC02pHoRUyUFmhRQMnxw934TqlCuGHJPDE2zPgdhxe+kZ6+UBTTODzBMwepjGYE28rBnhHyotrTHsb907HYTQJcwQbgH26Y75DW5fVhVD2AcxiLRrc+TbUx8m8/FpkaNcSfez2GHAIFlmNeRT1QFZvU0+OD/pklwfDE3SlPwv9jGkcHRFQX5Iz2WR84/uBMZPutzpw1MHjBEc9njgwyFKQqGP3v74tdf8j5d1 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85d3cbd1-61ff-433c-e7df-08d905ac097e X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:10.3228 (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: gnaXBXztDSNuqc39rOorgZb1oBKTQTOMfoKqsahQ4fCi6PgMMZM71Sc1B7+2bOKBx/rnn2ORzdol4crqbDz2a852PcA+5E57c5VHqVO5Xjs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.4.129; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 and other operations. So, we create a hash map cluster_index -> HostCluster And for each HostCluster we calculate number of in-flight operations on it (which does qcow2_host_range_ref() of course). Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 12 ++++ block/qcow2-host-range-refs.c | 127 ++++++++++++++++++++++++++++++++++ block/qcow2.c | 3 + block/meson.build | 1 + 4 files changed, 143 insertions(+) create mode 100644 block/qcow2-host-range-refs.c diff --git a/block/qcow2.h b/block/qcow2.h index 511db948ec..d6de9543c4 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -420,6 +420,9 @@ typedef struct BDRVQcow2State { * is to convert the image with the desired compression type set. */ Qcow2CompressionType compression_type; + + /* For qcow2-host-range-refs.c */ + GHashTable *host_range_refs; } BDRVQcow2State; typedef struct Qcow2COWRegion { @@ -899,6 +902,15 @@ int qcow2_detect_metadata_preallocation(BlockDriverState *bs); void qcow2_cache_host_discard(BlockDriverState *bs, uint64_t offset, uint64_t length); +void qcow2_init_host_range_refs(BDRVQcow2State *s); +void qcow2_release_host_range_refs(BDRVQcow2State *s); +void qcow2_host_range_ref(BlockDriverState *bs, int64_t offset, + int64_t length); +void qcow2_host_range_unref(BlockDriverState *bs, int64_t offset, + int64_t length); +uint64_t qcow2_get_host_range_refcnt(BlockDriverState *bs, + int64_t cluster_index); + /* qcow2-cluster.c functions */ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, bool exact_size); diff --git a/block/qcow2-host-range-refs.c b/block/qcow2-host-range-refs.c new file mode 100644 index 0000000000..54f0be27a4 --- /dev/null +++ b/block/qcow2-host-range-refs.c @@ -0,0 +1,127 @@ +/* + * Block driver for the QCOW version 2 format + * + * Copyright (c) 2021 Virtuozzo International GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qcow2.h" + +typedef struct HostCluster { + uint64_t host_range_refcnt; + + /* For convenience, keep cluster_index here */ + int64_t cluster_index; +} HostCluster; + +void qcow2_init_host_range_refs(BDRVQcow2State *s) +{ + s->host_range_refs = + g_hash_table_new_full(g_int64_hash, g_int64_equal, g_free, g_free); +} + +void qcow2_release_host_range_refs(BDRVQcow2State *s) +{ + assert(g_hash_table_size(s->host_range_refs) == 0); + g_hash_table_unref(s->host_range_refs); +} + +static HostCluster *find_host_cluster(BDRVQcow2State *s, int64_t cluster_index) +{ + HostCluster *cl; + + if (!s->host_range_refs) { + return NULL; + } + + cl = g_hash_table_lookup(s->host_range_refs, &cluster_index); + + if (cl) { + assert(cl->host_range_refcnt > 0); + } + + return cl; +} + +uint64_t qcow2_get_host_range_refcnt(BlockDriverState *bs, + int64_t cluster_index) +{ + BDRVQcow2State *s = bs->opaque; + HostCluster *cl = find_host_cluster(s, cluster_index); + + if (!cl) { + return 0; + } + + return cl->host_range_refcnt; +} + +/* Inrease host_range_refcnt of clusters intersecting with range */ +void coroutine_fn +qcow2_host_range_ref(BlockDriverState *bs, int64_t offset, int64_t length) +{ + BDRVQcow2State *s = bs->opaque; + int64_t start, last, cluster_index; + + start = start_of_cluster(s, offset) >> s->cluster_bits; + last = start_of_cluster(s, offset + length - 1) >> s->cluster_bits; + for (cluster_index = start; cluster_index <= last; cluster_index++) { + HostCluster *cl = find_host_cluster(s, cluster_index); + + if (!cl) { + cl = g_new(HostCluster, 1); + *cl = (HostCluster) { + .cluster_index = cluster_index, + .host_range_refcnt = 1, + }; + g_hash_table_insert(s->host_range_refs, + g_memdup(&cluster_index, + sizeof(cluster_index)), cl); + } else { + cl->host_range_refcnt++; + } + continue; + } +} + +/* Decrease host_range_refcnt of clusters intersecting with range */ +void coroutine_fn +qcow2_host_range_unref(BlockDriverState *bs, int64_t offset, int64_t length) +{ + BDRVQcow2State *s = bs->opaque; + int64_t start, last, cluster_index; + + start = start_of_cluster(s, offset) >> s->cluster_bits; + last = start_of_cluster(s, offset + length - 1) >> s->cluster_bits; + for (cluster_index = start; cluster_index <= last; cluster_index++) { + HostCluster *cl = find_host_cluster(s, cluster_index); + + assert(cl); + assert(cl->host_range_refcnt >= 1); + + if (cl->host_range_refcnt > 1) { + cl->host_range_refcnt--; + continue; + } + + g_hash_table_remove(s->host_range_refs, &cluster_index); + } +} diff --git a/block/qcow2.c b/block/qcow2.c index be62585e03..aa298c9e42 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1834,6 +1834,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, #endif qemu_co_queue_init(&s->thread_task_queue); + qcow2_init_host_range_refs(s); return ret; @@ -2714,6 +2715,8 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); + qcow2_release_host_range_refs(s); + if (has_data_file(bs)) { bdrv_unref_child(bs, s->data_file); s->data_file = NULL; diff --git a/block/meson.build b/block/meson.build index d21990ec95..a9bf6fde0c 100644 --- a/block/meson.build +++ b/block/meson.build @@ -25,6 +25,7 @@ block_ss.add(files( 'qcow2-bitmap.c', 'qcow2-cache.c', 'qcow2-cluster.c', + 'qcow2-host-range-refs.c', 'qcow2-refcount.c', 'qcow2-snapshot.c', 'qcow2-threads.c', From patchwork Thu Apr 22 16:30:44 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: 1469320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=iGXYTxWN; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR3PZ470Hz9sVq for ; Fri, 23 Apr 2021 02:52:34 +1000 (AEST) Received: from localhost ([::1]:44608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcZ4-0001Eb-Fr for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:52:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEk-0007Uy-1j; Thu, 22 Apr 2021 12:31:30 -0400 Received: from mail-eopbgr00116.outbound.protection.outlook.com ([40.107.0.116]:34309 helo=EUR02-AM5-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 1lZcEg-0003vI-3t; Thu, 22 Apr 2021 12:31:29 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hsh6UcFFHubaONnOIZeNxzx4R9BIvNCBnMNHo/X73LrM9KCbOebYMa9wky6x1cHgva3oTsNGERS6b7XVAs/FGk//7zrEiotYLjTvhTx2FTM0q9bdUBKKROgRb16rgropNtLNp6W73yc93aTJo7tuMZNgBHxE6Ru3Gi1zXzTggjBG+OfSgSDmeWyFD9cd9g76TCYhhSc4Ywskun5tWXtKwhwwe7lY+XgmgqfvTqAZF0H7vER//LoAfGEYCKzUkDG5RZ77JcvkUO8KwZoRUjIlGPjsHCzftmflk0CYxefNd9Vj9Ggn++y2UT80ctPk1pvJgGleJF3Z++LfsNXScQ362g== 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=rv7/OtbdWG3EbhVWssajxwiy60oAc+13NztIjp34s2s=; b=DL9P28ewMHh3BhmtouGT751mVCQ70BDnzDxJICA9C2joli2mI5rtnTiJawQJrGzFHv2HAD2d1XoGa7T/lQ+j9E3+rqkwZez64CffC6vR5sAZ6oT8CfrN1Trcr79R4k+4yQL96H9SJHzES8nXS+WMCmwNGN2m7FdHEyp74ZImzBZxS4yPNewfasysnJbL9Yv1YwExil3F71bSZmQnrlHpb+tjbYB1dOtKYG8WW/T4c+wRbJoMmWK+ivP2N+rwICfHT4iVXXMYQYOyAuhuf8h6s3R9VAMqOwM/s+7PJNa02+7ikjXmsC3zJYuU3wt4vL85r5lqDOzhjhtb4xoqMjXTuQ== 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=rv7/OtbdWG3EbhVWssajxwiy60oAc+13NztIjp34s2s=; b=iGXYTxWNbJDc8rE0xsycHR5cmECcS8MR5WnB5ug9niNfou61aSAk9RtEnr4Vtygy7Lp2bH6ZX76pWsIKp5azqVWVlRWpYGbqRAW/w09fnyBoe8VGOuVzkyN6pm+t3HGAJ0no8TT89npuTp1eFDPtjtI1b5hv2q3OyA4prWqPKLc= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31:11 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:11 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 10/12] qcow2: introduce qcow2_host_cluster_postponed_discard() Date: Thu, 22 Apr 2021 19:30:44 +0300 Message-Id: <20210422163046.442932-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9dbc1996-1b0a-4384-6854-08d905ac0a0d X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: 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: wJGqmh7lxd9zlxaf8qbBEin0BBmLUcEIZJyNRda+Kubezsi7ik8tJrA67oCxpZNcD4fEHuvfmeLPj4eaSQD5r8B1JXp1w+v0uCQD8l6WXHPOLvjscAsh7y+zI9qRd6HiWgU5RipWpRavZhGolctdAetEwN3fs1YIttRf2//dpHLwe7+pjd9CarQbzmLOvCZ2y6eTWwZZk3o4wLfdkGED1oVfVpr3ccfYCRhJ94Cq7T+mbKQH/yHixjjN514s3wgKTauRWh7wpZw+rcPbRGhVbjjVg27xu1l3LdYDCpIQfccQ6eTMs7SWSBASyP+3oFUhBxQ7rBpCiqAfbFBGRi1C2pb9r8PtkEUe0RCqW7gvOyVequztF0rz0zY1PydXG7D2cVAChgkjdmTJMgrCDIxgrGlNmsqdUCS0i56LtQSRbIuvWa2ukNOmyLIzoH/kJKR4ORVMKEt+exkWiiwBANMoTd7BtkCL3EGsDSPgZaAyz7Vv98+fnMClbCoKWmuON3aG948ERLybKvWQVqG43nVYrt5mwM8xhFnUDcuG9hmjqsQFMYDfHFe/8WBmm7Yv4+1y6s0ltXJLCh3HpBEJxHkdgpJvLVTv5aMAM7IwGmu6yUCbBTMFa/olJ9W0NG0gf6WjoGIW5IeTm76SppVATXVBkQa+Cg5IY8vaVIp2lawIogtbnrDI/6cx7ClsUyqe4TKI 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: xJsxeGk9UGSYhyxCdZMQQVfD7/jerluGDpXwSvHE47URVeU1wYAd44OjF8u97WWa/JXlqsiWcot7HmsRk6PS3cWlfEY8QBSwn9wVOwkdzwFS7rgHlSwclV9+EbgSASg+p7HP8vEgzp/2IyXjowEPpWIkeyLuWSCKIM++tmwdLrZyRTYKCjkqOEBuIimeA+j5BeNJpsGV05Q+LaqYnp1/zv2+wUIw/yuB9CbdXIrXY5qdD9XAQ2t905ehI0p7V8V1M6TKq6LgebBTrfmVysDEhSGlKBpRYe88l2MhJmP+Bhcwppt0rRFnTjjCsjLHyDh24734e6JygDg8EjuEuj0Ff7Rbh79Gc8cBhlStpKcF6jH292iydt24nh/T8hrmQyZ70EpVIkOHiQ0zr8oHTW4yjDisIFQcklDcgh46wcgcR2snhtyG4ELxK2k18KMHKAa8BARpTHrOpTGe/YuGlxau9mKXaCwYzkOkKcQpDv+WpSXeWTlwVfGncjyMHT9OycQDv3ULd4L32MWop9enxjwUdvkSlIgSz+w3i/kbe8kTk/plTc60WZl9ICvV3t2ADUhWsTRvhOd1hTGadvAeqWgGuoESucvCKGRmxpWxjVrVcr4cWJKsA3eK1LHjWnZAMov3mEn0Pj2U54XGQfSaxarFFRvtL885NjsyHUeIJkop8eAHMzLb2IyKts+2P93EWQp82scIHqz+3kJfP8GZIOeBUuuJy6Dp33gMxyotVBXeDjaB68kBC3rrq3EPe+pTwo5ZixjtN5pjs1Vo21eKk5scqvLUeyKfddKsTsxRoQLSQDOmODq6fLX8uskMzs8KMR+J/FMDYV+Al0Z4ZRepKmr+Lml3SMbJ/usMV9h+Na9g+VKZRhw1NyfsxNG3BK86a9m1t693c87iDMzas0U5J9IOBAy9Ao3mb4l2oKoQkFLX4Vz3Uwd9WCQh0y9jJUdzgBnUsK8tw6pepxBaeKOP/g6tRK7q69yJ5FJVCQcG7XSJruINl9aC7oPH9viMwJUxZfbksQwee9rYar6FSlZB6GDdk891qcBUOqrBbUd80tKu48bYrXRgDgKWJ1HfzsboIoGVw6J4vsBlHtSlFMb6yCem+Yt3SrnmpWmTuCdXfxVBL1fSmJLEPtcnrZCeXh5TfyKjFqfG3ofuva6CYWSvn6RYK1YzzlU/E+oVya0q/ejgnPNxQP0DyJYLV9rNPQ33MuD3quf2D/QppOMx4WtQ2hIC9eo9eTyugSm1OWoDr8EMDrILjJ4uwMYFrpvo1nweQ0j6GSjasgmyoNUihcrW4NGlcYN1Hg3aByfEU1R7WrFlbkFXZpzot74zJKXQ5JMRoT7S X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9dbc1996-1b0a-4384-6854-08d905ac0a0d X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:11.2035 (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: q5ZWH1yUWSIDuHyUAZSci9Aczf70dTTAK447zBDVoo/GmBKoJXhPCF6AytsR7NjrceV189xx91MmE5rXgVrgP/ADfIcKJJmX7FSuhzVCBuE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.0.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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() wirthout s->lock held 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. We are going to track in-flight writes (and other operations with host data clusters) with help of host-range-references recently implemented. So cluster would be "free" when its refcount is 0 and host-range-refcnt is 0 too. 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 qcow2_host_range_unref(). In update_refcount() we just discard if host-range-refcnt is 0 and register postponded discard if it isnt. We implement postponed discard functionality so that qcow2_host_range_unref() doesn't have to load refcounts. So in qcow2_host_range_unref() we just do postcponed discard if it is registered in HostCluster struct. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 4 +++ block/qcow2-host-range-refs.c | 47 +++++++++++++++++++++++++++++++++++ block/qcow2-refcount.c | 23 +++++++++++------ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index d6de9543c4..c40548c4fb 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -911,6 +911,10 @@ void qcow2_host_range_unref(BlockDriverState *bs, int64_t offset, uint64_t qcow2_get_host_range_refcnt(BlockDriverState *bs, int64_t cluster_index); +bool qcow2_host_cluster_postponed_discard(BlockDriverState *bs, + int64_t cluster_index, + enum qcow2_discard_type type); + /* qcow2-cluster.c functions */ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, bool exact_size); diff --git a/block/qcow2-host-range-refs.c b/block/qcow2-host-range-refs.c index 54f0be27a4..e07cb06184 100644 --- a/block/qcow2-host-range-refs.c +++ b/block/qcow2-host-range-refs.c @@ -30,6 +30,13 @@ typedef struct HostCluster { /* For convenience, keep cluster_index here */ int64_t cluster_index; + + /* + * Qcow2 refcount of this host cluster is zero. So, when all dynamic users + * put their references back, we should discard the cluster. + */ + bool postponed_discard; + enum qcow2_discard_type postponed_discard_type; } HostCluster; void qcow2_init_host_range_refs(BDRVQcow2State *s) @@ -122,6 +129,46 @@ qcow2_host_range_unref(BlockDriverState *bs, int64_t offset, int64_t length) continue; } + if (!cl->postponed_discard) { + g_hash_table_remove(s->host_range_refs, &cluster_index); + continue; + } + + /* + * OK. refcnt become 0 and we should do postponed discard. Let's keep + * host_range_refcnt = 1 during this final IO operation. + */ + if (s->discard_passthrough[cl->postponed_discard_type]) { + int64_t cluster_offset = cluster_index << s->cluster_bits; + if (s->cache_discards) { + qcow2_cache_host_discard(bs, cluster_offset, s->cluster_size); + } else { + /* Discard is optional, ignore the return value */ + bdrv_pdiscard(bs->file, cluster_offset, s->cluster_size); + } + } + g_hash_table_remove(s->host_range_refs, &cluster_index); + + if (cluster_index < s->free_cluster_index) { + s->free_cluster_index = cluster_index; + } + } +} + +bool qcow2_host_cluster_postponed_discard(BlockDriverState *bs, + int64_t cluster_index, + enum qcow2_discard_type type) +{ + BDRVQcow2State *s = bs->opaque; + HostCluster *cl = find_host_cluster(s, cluster_index); + + if (!cl) { + return false; } + + cl->postponed_discard = true; + cl->postponed_discard_type = type; + + return true; } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 72e6d1efd7..7f238649db 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -878,9 +878,6 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, } else { refcount += addend; } - if (refcount == 0 && cluster_index < s->free_cluster_index) { - s->free_cluster_index = cluster_index; - } s->set_refcount(refcount_block, block_index, refcount); if (refcount == 0) { @@ -900,8 +897,20 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, qcow2_cache_discard(s->l2_table_cache, table); } - if (s->discard_passthrough[type]) { - qcow2_cache_host_discard(bs, cluster_offset, s->cluster_size); + if (!qcow2_host_cluster_postponed_discard(bs, cluster_index, + type)) + { + /* + * Refcount is zero as well as host-range-refcnt. Cluster is + * free. + */ + if (cluster_index < s->free_cluster_index) { + s->free_cluster_index = cluster_index; + } + if (s->discard_passthrough[type]) { + qcow2_cache_host_discard(bs, cluster_offset, + s->cluster_size); + } } } } @@ -963,7 +972,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs, /* - * 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 @@ -979,7 +988,7 @@ static int is_cluster_free(BlockDriverState *bs, int64_t cluster_index) return ret; } - return refcount == 0; + return refcount == 0 && qcow2_get_host_range_refcnt(bs, cluster_index) == 0; } /* return < 0 if error */ From patchwork Thu Apr 22 16:30: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: 1469317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=d2DZDSuH; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR3DM5VhKz9sVq for ; Fri, 23 Apr 2021 02:44:34 +1000 (AEST) Received: from localhost ([::1]:57070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcRJ-0002aK-5g for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:44:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEm-0007bT-Ub; Thu, 22 Apr 2021 12:31:32 -0400 Received: from mail-eopbgr00116.outbound.protection.outlook.com ([40.107.0.116]:34309 helo=EUR02-AM5-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 1lZcEk-0003vI-Mm; Thu, 22 Apr 2021 12:31:32 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SXIL3FXQjQRtnEoLvheA6vlmJPjMFB5uZHzg5t8RrA7+lxppS5BB12hNMhM+S9sXm6VGX0YAyykTuuQBP6/hU4od4E8poqbW3Hs553JMKHgwst1QYPr+cgmFSwGOdcghkyPwXa9d+gUmiKzW86QnlwUZeWnpu1Q9EWgUa/JmQliJriVDO5CrTiUkkFRr0w0xGh5gzd7C/EWEQbbD9E9APWV3iI5jr6iFSm9nbjkym4IvjmVvbG6LhWTD7wcrXtEwotlea3eDHLnSNOaHek9u8auTklDZ/iMO5RHdf3M1Tz0Q/xVAsbUasVoJCBD5wTD9cxKYSvWTqgO+aT5L33elhg== 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=ZWWcweis0PQ09WAuArn3/p9ryekxClrE6bAUzwiMNtI=; b=Bb1loXWe/mtui1UdBiehLsrQXHhQCDOHkP0MzDvbE6K0KTF8b5IGqoGgqzsEtn5Vp1J0LNGj/sla9pKah6aZ5NOSkocOr2ck0yOl3EFYxvOb2b5XKdm+u3WDPsLcQ2CMcmsFZFFD8S/1w8hUAPIpRA9ZkUM4Gyg67T+oVXH9NzaQkBvMKapm08g7QqEpYuClIHdoLm93xkD+ciX3ItgpldwPRFxRgccTF7JhQFgpy1ly9/XCH3eIA2mU9hwRjMpDXdjSsNK9sZpP1gtLDIEePXXjYNm3EmynOJQzp6aJZa0jWzJCvRqKm5WhXm8i94ieoxuABZXNTZtMiVs2Jp+p+A== 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=ZWWcweis0PQ09WAuArn3/p9ryekxClrE6bAUzwiMNtI=; b=d2DZDSuHJEiybst1UkUtPrEH3EGa6htBIpmHO6Tp0nvSudk/1kOm8k1ZHuZaxWHyZYCBiYjr4OojYHricUlMaYKsHuO3S5QpZugYqe6jpRVDsMaxa6Qt8mDlXeThE6tCi6BcnCDZjaEoLbO46lvVMFZAPOpfKWf4O7mbrk70L5E= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31:12 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:12 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 11/12] qcow2: protect data writing by host range reference Date: Thu, 22 Apr 2021 19:30:45 +0300 Message-Id: <20210422163046.442932-12-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 625663e8-4731-4c75-394e-08d905ac0a8f X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4XRNf2udSqBxEMVCOSCOOtST411Pxl6PcTi6ZqdXAAXZEs7DN3rsIZTuBHgwRhq+3Bwi6I/FeS13ik+8inGR+b7/Zv8Pm7AvWKO85RAOMgBnDsrXBCu48PBX+UWz/BqgMWWeTO1qRmOIkqIFWO0PTtJaQNQQk+5LbUUV7DrMa3Apaq8yBtPiFr54TUgtjZBAAbmZ4Xu6/Bk1TfkbJSKdPAW8IQitwY+U0bNS8vX0RFRJjG0BMJf6HWHRntWVz2jVKdxMHO55OLYiXxfAyL3oGO348subS+5oTnNJzo/dl2jgfFGqVBGXmcIFD1T5iw+HWGfafMMsMId5dNiPBU1ZkY3yMLpldK2KLa6Y2R81bh6oIlnsHKf/tl6ceJrxyA5y21eC7eN8RiAxO1hG5dWTJhlkN2/L5RvoUH5EkNur5AEbCTUKmt+jM8q7TfMUB2j/1SNw8uOQEJ9mbQtwp5hFfqBex3ppjwJnrvd960FQoZAE5c3uSqrJLmMYEGL5iS5Pm+hJ4XeD381rbZ4xRrX9nfwir522/P4uf8q0IzT/D0cTJyvjgvRZYG7N+M0bC9zkFV/H3IgSYY4lu5lUgcLTAaeVxEO/+uPKS3khciKjuv7j7Gk10ejWaVeiJrL2zLNaSwu5xZ7Ll4qZRIfVrTXZYf36mf5ifUMLgr4WWQkRxgee3mGKZIXf+7xmKVrwn6MD 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: w6uzBz9rc3Aj1Bmz0iZjbYFAJjapqMjID3EBQSNccEclAfr7LszDczrzhxvZG8M+e5XRc4bvXZidW4Pm7VKPW+LJ7987/M6NZ6zQBz45Ab4hIVh9YYX3JH3BCLec9NARNd1PQs9ltQxPwUn5HXIIqytFxuXLdiGk7YvgqmEN3UyZJlRTKCaRmFY0h7FrUuImRsNXsc0ULcJa8QiyZiteFGePgUOGrvlIgHX6g3KGHCbm0m04MqEh67vxLbmgGEH21J+E90cRmXiypm5QvRMGC3DMjx0jy8jWYjtKZJ5I6QwuOXJhJq4ESo8Jrz7eaeztPinoWWs8KuX69Vm5MZkoA7Ue7UGdy1hI9ieBUI2tHNW3bOHcDGmI7EzxmWyrTBirgiSnCsczJD2pnrAEkF4hpGb/G5xEbzIY/Nz8yOHEfP/XUCOa79UZnkKIaeR3wLEqsJCsroEFy2N7rW8D2MwIH7OpMzP+W8qLCq68n/57EijiFftxsP3yISz1xSRbDb4xHR8wkAYQAlqmBT89KZSMv5ocYjtUOcAy7BxtknBTsNBUkwJ8fXvUzak6HM1ZV/BPwG9cV/aPOtBGdS2tXVNmbRVK5UYkd7ZiVg1If0mXBCk6JrddP5G7r4Da1y9ANYXLoRwI5pBhcuVybJKpvzc2+Pnss6l59Wn0PzSrWlPKKUVZje4YyUtrE3OVVYIdY73LIPGlWdSwOkcv6voPmVGzw26ju9jX6qh7LHNIlmjzQ5C9WxlLP2FPFT7uxETI1PkwF32wwCj07EmpZ4/YdZphu8YO1X2Gpv6ShmPKfMdpB+ScmpEAzq/S+ZStuPpatr8IrLw1g9PnzRbUCUEc9mvHUw3yz+ARO2KUJiBxSP4FM2+34mZlzxvXL4OucHcQ/4gYbb1qv3hwKANrQhh7hbWOjusd01zRVovTIUjE+xZNkOUu2b5QQIviNd+j9OWGqt5N9N7uU10fHAcoa0HhfOt+F7XSamMUWstsQ6PE3K6bMTaMuDXbfleViz0TDD7TS7FGOdzYNCekt1fOHTzve/e9fQ1GGd/LBw4rGiARMGKKrCRpeyQPulYWEzsh7gGt7/CMTQwoZ33aDLRR4eVk8FudMTaQvQvwZ/6PdZcnnUxnm/PqQH16sgZBqROew2N88qMmnwtkASqYL+qCV3e7SCiJXQyBSftr0E+0rxy2q/vLKisMRYYxkdDtNVUYd6eERKuFI6ykJlVbm4Hk9kj9/Lz1kxZYFnBQ5ZUpcpR3561q81Ag2EVWgxN4wuCF4mNr8pGIRhnLV+sn84H9JlioWq3kh9q9TzzLl8FVbTRaomjCvYVEth/6YvkfjFsxf1p1ZluT X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 625663e8-4731-4c75-394e-08d905ac0a8f X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:12.0567 (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: 88Wq7nTdmQ1vENQwNR0Pc1c+bck43VAHSwBRUAvSviQM6diUCYGoyYZkOFPwz0Kv9i+tHmOAu4pIM146/0vlTk49xkRVtgFPajh1VU04/1k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.0.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We have 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 host-range-refs, 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 host-range-ref are zero for this cluster. Let's call qcow2_host_range_ref() in cluster allocation functions: qcow2_alloc_host_offset() and qcow2_alloc_compressed_cluster_offset() used on when writing host clusters. So that now these functions returns "referenced" range, which caller should finally unref. Iotest qcow2-discard-during-rewrite is enabled, as it works now. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-cluster.c | 13 +++++++++++++ block/qcow2.c | 16 ++++++++++++++++ .../tests/qcow2-discard-during-rewrite | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 6105d4e7e0..999a739024 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -809,6 +809,10 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, * already allocated at the offset, return an error. * * Return 0 on success and -errno in error cases + * + * On success the host range [*host_offset, *host_offset + compressed_size) is + * referenced. Caller is responsible to unref it by qcow2_host_range_unref() + * after finishing IO operation with this range. */ int qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset, @@ -866,6 +870,9 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); *host_offset = cluster_offset & s->cluster_offset_mask; + + qcow2_host_range_ref(bs, *host_offset, compressed_size); + return 0; } @@ -1738,6 +1745,10 @@ out: * is queued and will be reentered when the dependency has completed. * * Return 0 on success and -errno in error cases + * + * On success the host range [*host_offset, *host_offset + *bytes) is + * referenced. Caller is responsible to unref it by qcow2_host_range_unref() + * after finishing IO operation with this range. */ int qcow2_alloc_host_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, @@ -1848,6 +1859,8 @@ again: assert(offset_into_cluster(s, *host_offset) == offset_into_cluster(s, offset)); + qcow2_host_range_ref(bs, *host_offset, *bytes); + return 0; } diff --git a/block/qcow2.c b/block/qcow2.c index aa298c9e42..d0d2eaa914 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2489,6 +2489,8 @@ static int handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) * Called with s->lock unlocked * l2meta - if not NULL, qcow2_co_pwritev_task() will consume it. Caller must * not use it somehow after qcow2_co_pwritev_task() call + * + * Function consumes range reference both on success and failure. */ static coroutine_fn int qcow2_co_pwritev_task(BlockDriverState *bs, uint64_t host_offset, @@ -2554,6 +2556,9 @@ out_unlocked: out_locked: qcow2_handle_l2meta(bs, &l2meta, false); + + qcow2_host_range_unref(bs, host_offset, bytes); + qemu_co_mutex_unlock(&s->lock); qemu_vfree(crypt_buf); @@ -2610,6 +2615,7 @@ static coroutine_fn int qcow2_co_pwritev_part( ret = qcow2_pre_write_overlap_check(bs, 0, host_offset, cur_bytes, true); if (ret < 0) { + qcow2_host_range_unref(bs, host_offset, cur_bytes); goto out_locked; } @@ -3151,6 +3157,9 @@ static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offset, goto out; } + /* We do truncate under mutex, don't bother with host range refs */ + qcow2_host_range_unref(bs, host_offset, cur_bytes); + for (m = meta; m != NULL; m = m->next) { m->prealloc = true; } @@ -4122,12 +4131,14 @@ qcow2_co_copy_range_to(BlockDriverState *bs, ret = qcow2_pre_write_overlap_check(bs, 0, host_offset, cur_bytes, true); if (ret < 0) { + qcow2_host_range_unref(bs, host_offset, cur_bytes); goto fail; } qemu_co_mutex_unlock(&s->lock); ret = bdrv_co_copy_range_to(src, src_offset, s->data_file, host_offset, cur_bytes, read_flags, write_flags); + qcow2_host_range_unref(bs, host_offset, cur_bytes); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto fail; @@ -4540,6 +4551,7 @@ qcow2_co_pwritev_compressed_task(BlockDriverState *bs, ssize_t out_len; uint8_t *buf, *out_buf; uint64_t cluster_offset; + bool unref_range = false; assert(bytes == s->cluster_size || (bytes < s->cluster_size && (offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS))); @@ -4574,6 +4586,7 @@ qcow2_co_pwritev_compressed_task(BlockDriverState *bs, qemu_co_mutex_unlock(&s->lock); goto fail; } + unref_range = true; ret = qcow2_pre_write_overlap_check(bs, 0, cluster_offset, out_len, true); qemu_co_mutex_unlock(&s->lock); @@ -4589,6 +4602,9 @@ qcow2_co_pwritev_compressed_task(BlockDriverState *bs, success: ret = 0; fail: + if (unref_range) { + qcow2_host_range_unref(bs, cluster_offset, out_len); + } qemu_vfree(buf); g_free(out_buf); return ret; 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. # From patchwork Thu Apr 22 16:30: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: 1469315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.a=rsa-sha256 header.s=selector2 header.b=UzHCbdCm; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FR39m71LZz9sVq for ; Fri, 23 Apr 2021 02:42:20 +1000 (AEST) Received: from localhost ([::1]:52714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZcPC-0000j8-Av for incoming@patchwork.ozlabs.org; Thu, 22 Apr 2021 12:42:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZcEn-0007e1-T5; Thu, 22 Apr 2021 12:31:34 -0400 Received: from mail-eopbgr40129.outbound.protection.outlook.com ([40.107.4.129]:3204 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 1lZcEl-0003yB-OO; Thu, 22 Apr 2021 12:31:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T9aG/2NTuK4L1b47xGHVropXE0ltoxz3pyQCa7hys/UKYHu/mridpnh8DXxtqqOVYzTFTp3jLfRpvOvY9tZVB7FS5Q8evBctKzB2p7dBQttR9qDRoppIr6TcSsoWK87BeXgDFPzmIXsFXp6kE2JsoyjJyfdZbPux4Lyy0RU8AHir6mZsYgjpq3LTd5yP+j5ut3WUcsTpC57y6dfCfLben2mka90jlb5pWaS+AWQ2yDKA6KqSzNPcfiI/9TzMihK35DqDMkTeH3eHW/RkpUz8jG6mGtE6gJhzWpNIyWr3G8C7jvD98bmVImQtY9t2o0Cw9p9eZVuAVGcc/VVsitoAnw== 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=J0aj8X3EAh1h1aoYAEOld6mkPEkYJEWMxFysi/PMbYU=; b=iq1+6lUR67QNY5ChfsvMg+N1XvUeEkAresyjH2P113spcwPmFQ1XyyZoPjDYAdT6NHCvRFE5hrY3gN7FZhGV/QlbHETBThGEbBozJRfFxSNAQ5IHYF0LSgvIAJMvHnWJbpWzsXYbehPDbvV38ryn5imwg3gMATXbxu20+lX8mBMTgO38KvQHvivAQPDgV+rNEd8kMk7vthhqHhkvU5jsCY1LvopOJaEM/95aph7jDQp7ipo0KWCjrn8Qd1A6qU2OyJeK7SFTu2pcnmQRv2bVIdS4PSPd0wsMBVnNNv2+YqledjHPiJhhEMMyL90kircBJiX2EC5IE5qylQPO4KT3kw== 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=J0aj8X3EAh1h1aoYAEOld6mkPEkYJEWMxFysi/PMbYU=; b=UzHCbdCmgN6C5NvtNb5WhhxPTaZOVK54/H0dEcLL1LfgTnhNJ5zLRme1Hkhz14//bSzwsyEKixbgRrGR/ZYCLqXk8fUffLXvcpxyMRTjpwjpTadkPcyUj3WxzCAlLLhcH5Lx/XxEePdckHElJPkPHD3ooby2IcUwmcqnZeVsduM= 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 AM6PR08MB3861.eurprd08.prod.outlook.com (2603:10a6:20b:80::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 16:31:13 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 16:31:12 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v6 12/12] qcow2: protect data reading by host range reference Date: Thu, 22 Apr 2021 19:30:46 +0300 Message-Id: <20210422163046.442932-13-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210422163046.442932-1-vsementsov@virtuozzo.com> References: <20210422163046.442932-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.222] X-ClientProxiedBy: HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) 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.222) by HE1PR0501CA0006.eurprd05.prod.outlook.com (2603:10a6:3:1a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 22 Apr 2021 16:31:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 413ddaa3-34c4-43de-b2e5-08d905ac0b13 X-MS-TrafficTypeDiagnostic: AM6PR08MB3861: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:284; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TWImK05cqVO6PC35KAwSrxRLp5q5i1dmeB89ZSGa+56dMZtOaVf60lwou97QglbvKtgO26mmJ5kuMAURxJ4PZEs53To07ceBGQb6VotKXjmWXqcNKjx2tXJnpZEfHhkw7O9tRroazyp6ESd0/dnGBMQ5BBY4kEvShk8Jv4W2lu7za6Xjp5xpaU1NAc1fPbj0uoGUn+ilktf0mb6Yy4OBlbeSI+horxStJhb/3FSSJpv7cAMTTh9+fe5hMP0mh7+YvchS9nbKg5GDO/Vo+zJkOfaZBwnKr7SNTyQHXdpdrTB/33+lPlERUl+i6DfLYosQ56xbrsVbCxtP1uotmbF7J1r2NEwjZZ2FfKWKPUaVEYfy4U1VtredrAovY/SWnrrh/lMtRojI+3hiC4FbGwazmGwXvAA2LR3fzotpkfcsDa6yNUb8y33ZNK0H2e7N5ExGypqoNrhAfSYT7Or4S4JFOy/JBLCpXrgiSotD5/Ox2rV/tanuv7bX8Nsy7c7XjJImknurRji4tVgFX8pcB9NAIUsJmKhz8/YoOuSFErpl+vQwvOZWsliAjt77EHwvspmcGCOsOjdJ9PIUzHpXwfoNrNRGNRSJsduSlOt2xDbnVIPDS4BUriIijTaGXd2ugMF/X7T2WAAzSvr58PpthxYB50Cekdg2dLvXCIvIkGjseWLfxTBfe0KSV6K/S3TJ0Nij 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)(376002)(346002)(136003)(366004)(39840400004)(396003)(6666004)(4326008)(19627235002)(107886003)(26005)(6486002)(956004)(2906002)(83380400001)(2616005)(52116002)(316002)(478600001)(8936002)(66476007)(6916009)(66556008)(66946007)(38100700002)(1076003)(38350700002)(5660300002)(6506007)(8676002)(186003)(6512007)(16526019)(36756003)(86362001)(69590400013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: uRAD/1B9iIEWb9DcK2AJ7/dzc1qcQ5wV1LTK48as4q/cYo5hc4Lj+z/2gSjxB2VyNL9tzPYF4mtjLypw/BZ30xsyTkyWwnEDlMRzrCNZXsI94uG1xYqfmxduIMANaexlgv4Oe3KBYpPtjZeTwC0dSa/1bIPadhPRPz7qZnU7fvayajfYqDUTn/HbV64lK22O7dXhTQI7CXfDxfqzoQiKf6oLehsWFS05dERMHhkf/xhYT8QblryV9kal/dPT72egUbwIPF+7TrRlg3ddMywH3lktmxgtFsmXOTTtq5WuOa820bbhSr6DIy9Lio9XFcy5mv93M5Y3BM5+xRGHhvnG9OLyy9L/A24xXmAPzsO5HiBYREPNvjFthgFtipyOX5NYpZKQV78EMdpiYtGSszRYm/rwAqy4t8vmLrgE9draxWuztEkk/5IdFk155VzN4gHO442gHSczAmJ47NpIbk2BtzTa9lsJaCZCZ18VB5VepZMEfZvO9LQQTIsl+tnVJjH2vO2JCKGdwEtPERiEBoOVXnjdjPZMXmUmzT7+FVg63VXuJbxcaH4AlZnvHCUQAznrPTGCHHBuBJo16I0p1GOaX0FUv4JiFun6gkw7gTQFW9cPrteBJYCe3c8UskzZv46sVN0Kb5vSSwFHIbtKKnH98AxHizSHTic5t7jKESZad3/hBVm4VSENJBpn2eIgOwzqx2cP8HQI6nQAkK70VZcBgx8lRnX4foWtubzOEjdiHoXecIzmG3S0Dw/NPsSL11HCRATwoUQpHCOkakyBQg1GutGDuqSrLj4EVaH7pAQaooG1Yo4QtJBT3CaNxyfBm/pM04ocgMo4GQAIRXiy8wgU1EVyJCRaawDpU8Sn5iuqgzhBWS7315+riMkT4UlDMFxIzM3UUn1w2+4hfJVgoUbYUwSMG5uCDVJNpp8lEOqg+eBZSs5d7By2+DNgv8tSj+bF4U+DTV7ZaVH4RWboiO0dOkUeRnzxCJiytMizP43r5aOUtZXCBMhRepCLu551TVmH5AyTu31o3MKNCN6R1FQVrR5qbmt5+xm1cYPMpdU8d75oI5x2tyX3ZLztn9/JpikZIxgyV5Qk39+/gn7+26kcBY7kuoWT2vPiBrH1P1Lbjlk6N+876Q1d/Vc9x21etJI+eIOJLcmEqZ5xRjeenpPiD4rribDscOrn5Hl3fs13Eg4dfmd+JXVRDipGfA+ToIyTgR7dP8ndfWCZB3bd21CoWsmqCaD09qQ18ezBM4rOpCQxQUX9Dg12d9wl3JPTDM3FWBGJdD+vxx/QtkggLXadeAe+DZKyO1JfPFoME+iQwlO+JnyiWwijktsIUrXrZBCT X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 413ddaa3-34c4-43de-b2e5-08d905ac0b13 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 16:31:12.9388 (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: 1F9Dn3SdVJUDbhriGhZk0z3s4acfoSMeqrKrIWZzmBiMXea/q4XmRtssORVVc/6TGHiTpNg6Qv1DpDAsVmnKjrMseO5Jx5qEGNfXiQMZUco= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3861 Received-SPF: pass client-ip=40.107.4.129; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Similarly to previous commit: host cluster may be discarded and reused for another cluster or metadata during data read. This is not as dangerous as write path, we will not corrupt data or metadata. Still it's bad: guest will probably see data or metadata which it should not see, so it's a kind of security hole. Let's fix it too. Data reading goes through qcow2_get_host_offset(). Let's reference range returned by this function. Read path differs from write, as we have to handle compressed cluster descriptor. Also, we should handle ZERO and UNALLOCATED clusters, for which we have nothing to ref. So, to keep the whole logic in one place, create qcow2_put_host_offset(), which should be always called after qcow2_get_host_offset(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 3 +++ block/qcow2-cluster.c | 38 ++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 15 +++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index c40548c4fb..2ac61eccc5 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -926,6 +926,9 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, QCow2SubclusterType *subcluster_type); +void qcow2_put_host_offset(BlockDriverState *bs, + unsigned int bytes, uint64_t host_offset, + QCow2SubclusterType subcluster_type); int qcow2_alloc_host_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, QCowL2Meta **m); diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 999a739024..126d95b062 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -568,6 +568,10 @@ static int coroutine_fn do_perform_cow_write(BlockDriverState *bs, * Compressed clusters are always processed one by one. * * Returns 0 on success, -errno in error cases. + * + * The returned range is referenced, so that it can't be discarded in parallel. + * Caller is responsible to unref by qcow2_put_host_offset() after finishing IO + * operations with the range. */ int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, @@ -721,6 +725,17 @@ out: *subcluster_type = type; + if (type == QCOW2_SUBCLUSTER_COMPRESSED) { + uint64_t coffset; + int csize; + + qcow2_parse_compressed_cluster_descriptor(s, *host_offset, &coffset, + &csize); + qcow2_host_range_ref(bs, coffset, csize); + } else if (*host_offset) { + qcow2_host_range_ref(bs, *host_offset, *bytes); + } + return 0; fail: @@ -728,6 +743,29 @@ fail: return ret; } +/* + * Caller of qcow2_get_host_offset() must call qcow2_put_host_offset() with + * returned parameters of qcow2_get_host_offset() when caller don't need them + * anymore. + */ +void qcow2_put_host_offset(BlockDriverState *bs, + unsigned int bytes, uint64_t host_offset, + QCow2SubclusterType subcluster_type) +{ + BDRVQcow2State *s = bs->opaque; + + if (subcluster_type == QCOW2_SUBCLUSTER_COMPRESSED) { + uint64_t coffset; + int csize; + + qcow2_parse_compressed_cluster_descriptor(s, host_offset, &coffset, + &csize); + qcow2_host_range_unref(bs, coffset, csize); + } else if (host_offset) { + qcow2_host_range_unref(bs, host_offset, bytes); + } +} + /* * get_cluster_table * diff --git a/block/qcow2.c b/block/qcow2.c index d0d2eaa914..d3461b7243 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2069,6 +2069,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs, return ret; } + qcow2_put_host_offset(bs, bytes, host_offset, type); + *pnum = bytes; if ((type == QCOW2_SUBCLUSTER_NORMAL || @@ -2227,6 +2229,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverState *bs, return 0; } +/* Function consumes host range reference if needed */ static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type, uint64_t host_offset, @@ -2272,6 +2275,8 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, g_assert_not_reached(); } + qcow2_put_host_offset(bs, bytes, host_offset, subc_type); + return ret; } @@ -2320,6 +2325,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, (type == QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && !bs->backing)) { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); + qcow2_put_host_offset(bs, cur_bytes, host_offset, type); } else { if (!aio && cur_bytes != bytes) { aio = aio_task_pool_new(QCOW2_MAX_WORKERS); @@ -3968,6 +3974,12 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, return ret; } + /* + * We do the whole thing under s->lock, so we are safe in modifying + * metadata. We don't need the reference. + */ + qcow2_put_host_offset(bs, nr, off, type); + if (type != QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && type != QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && type != QCOW2_SUBCLUSTER_ZERO_PLAIN && @@ -4064,6 +4076,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, break; case QCOW2_SUBCLUSTER_COMPRESSED: + qcow2_put_host_offset(bs, cur_bytes, copy_offset, type); ret = -ENOTSUP; goto out; @@ -4079,6 +4092,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, copy_offset, dst, dst_offset, cur_bytes, read_flags, cur_write_flags); + qcow2_put_host_offset(bs, cur_bytes, copy_offset, type); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto out; @@ -4700,6 +4714,7 @@ void qcow2_parse_compressed_cluster_descriptor(BDRVQcow2State *s, (*coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); } +/* Function consumes host range reference */ static int coroutine_fn qcow2_co_preadv_compressed(BlockDriverState *bs, uint64_t cluster_descriptor,