From patchwork Mon Aug 22 09:05:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7D5C8C32772 for ; Mon, 22 Aug 2022 09:11:49 +0000 (UTC) Received: from localhost ([::1]:60288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3TI-0005nK-Go for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:11:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NO-0005dn-T8; Mon, 22 Aug 2022 05:05:42 -0400 Received: from mail-eopbgr60133.outbound.protection.outlook.com ([40.107.6.133]:44801 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 1oQ3NM-0006xe-VV; Mon, 22 Aug 2022 05:05:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LRX2Jank3IQaOT3tEvruVKFhrhgb4mBOqVS4RjVd/+xeeZWathbTi6xbDN/Naooy0alKcqODkpxJqwh4wnz3fxYHAeo6J6aG3N5W5Knf3QBaM0lmI1zpWkRpQ7oWs6/aiitd3iaSQIm897hUdiwAPtiqCBHq26Plc7PavTnXUukVf+VN/tfoYNItjYN+4BckG5vvl9oTDUyJmMNFG9BHa96gYE3wBf+Och272Vt7LBRe1OgyhjmvDlaQFGwceWcy2ABhsAVp/FfqNXoNPDjfcfPy2j1zb6VOAn/rmXsGkQCI4JWxyU1WfKzao0dMWauWMpVaHagw/Kr9j96SgZLtaQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bfjCEB1XhsFtO2vnQC5cI2LPQqJ2CsUn3sTDnhFvbmU=; b=axvRuGS1dsbtrMVDMT0bsGbmrp3ARDb6lFQ7ZZMSUV6ei6oIy0fON0JgsSW3Lixbc3RhfzUYZJqZwApmxskja713La42dTgD0WBVlIc/Vzsgzbvq6jhmlDePowhAK0JKmZowB2qdbiokz1vbeqyllHeq9Y2J+2z4lCsdNpLhH3KPcjVGZUCf74ubZ0NH1jdwzrgE3UVVm0Hdcajr73p1DvwnnA9+zdi4VXWjGqS9Z3r+6wlQcJt1kQhI2erzXyEfBsJWLrodTR6jFo4dIM9Hp7c9mIOd07WSKGjZpg3JSsFred3I2MVh/vswze/rVYTUPfXNnvZM6nsg+51VZ+GAVA== 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=bfjCEB1XhsFtO2vnQC5cI2LPQqJ2CsUn3sTDnhFvbmU=; b=FoGxMbY7CS8D7bmE468uthiA14qLmhpZuVdistBMKWZHgjjr/jDyfoHwuJn5cPbUa0uWX80xZRLTNypeoQgytHLrzS1KsAao4EH4NVkUEY7Iq0LO/Jsryb56LihusYz+XVu2KOgKdqbwXmJ0RGXWGF08HuJ3JV5dPjBfzOJyuB4SwReEmF2LyZ9VLS/CvD589vkqVDslZ06tk34+9DiPjRj6h4C48qeVIRU0I+XKri9daBRU6oolA3DrVc488HgueuxidysGWyyWnxJYqS+GCbsAHX5mtxEXOL/muAnyc/w5ptZ+bq+Y8V+jsPIGyIdcbTmJwFlVl+4IgIZ4hGfdNw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:31 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:31 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 1/9] parallels: Out of image offset in BAT leads to image inflation Date: Mon, 22 Aug 2022 11:05:09 +0200 Message-Id: <20220822090517.2289697-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3469d46b-f051-4dcb-97f0-08da841d75aa X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r3rTKCXEQZQqVgkftzY3sH2/2Og9CJidx4fjwdCXJmiCBUoWg79HzYvaU7U6PQmV9qGlhW7olGtn8yU7smXjuUGVrlofGeWGWugd1LfaR5bEUJK9nOE+da3eo6EZWErY8Q1ycO0vcikWZP9Hd1LIByr4UqvI41rK1713eZMImmuy20Ig1F5H2ZshihFPxoOUpyMY1OBW37H8Y0YqAXq1hQq6zPLS9RsQc5yr1U1aBY4q+U8yERtTmoqAgkZ+Q0479+GK5CnB/yAXaQti25GVgfyuwr/2d5LUq+ri1wavC90iO0866LrQc/RnbQnvK6zEzmogjfonD2fL35aResA6TGZTVQE/EVAFTNF5NuUkWcn8Qp4C4xraDm/hCtWq8XYEmhJgQKQauC68Yp+pUPM39GRZY5pziaZxJGTt/BCey0INI8Lrpb5Mfibg2Ps9YHItfeHYkEEhBVNL0uhsJIqMweSnLisaaUBOOWDuVO3oQf2AzrPtEsm/1Clmvuec5gYYDunU2LWdCz9P/ZEOnm878Oy3RWK1DFIMqUX3XISBBqp78VQpNchRGAs3TTzkZTnOUiYhdAb7pb5Ao/53JxAhA97nmVCZQVrr6ilBWzBISTAy2pXbyRkott2FaQuxF27QeFjHNZr75vSbvSUuAfDYv05ZiP9u9oXiqfZqqIOUw5WXwoJ0u3qEZ1QhM3GErd2Vxvt7HYpVNP5m0e6K97SY1XROgr4IV3FE1SeoCdqwzcSXB7o1bCPGoCXs0qW9LvPOx597PgnHjHUHbzveT9U2Hg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cOzUOd11zBR2kfFJCBwT8DVXziOYKaWqkmybY/AtD0MDztDJbr6BxDJfMByxOmpn1iX9DksqcRW8/YFTNvODaEBoyXZkgms2tN3O8t1Izbv8S5k71BzJD7siCEzbcWPzdBd8SkBDXwau7eIYEcrSvKFp6AAipKcEEEpJS6P3ZYmZVQOUMKNfikPY0Ans/o8292Jt50TxTC5S6VgqS22l94Y/s5eROEjV2OXpI3Nji/SnxpYBkdzbta2o1JRipsQhs1wPkkBz5ORshtcvuz5Jogmab8AxREBhiM0G8KscIEdxQ1mOvaW5SAYbkgD5ohIgq5EMVBVnPLbQEoinJPfR1+Fopw1MCxCYBOgqxQ+mMON+oxjJMoNHpAMiv0S9qJZrGZp78QQLgUQToS0u2opjkPORGzshe8aS5+kgf96QTVFYRlrHvhMucZj2sA3iOrosvBYQBG5fNZRYiZHOT5+WxfvDjV/vH+ALUd/hgDhHKphUgC+OK3Vupz0NcTIaZ1rBR+Mbmd7GExjYE63UAHOOI7sFLNUszg6VHpGg4Y5Phj7MJQfJ8lSEefr40rVQJgv0KxsYkwUYpUL0GWV4BpvP/wcC8Zv5yBYdk3V9Qk1cvU0B+ik/4Z0GjPQ+fdY3ahOzR2Ws/PuQBhsCjppiQRPb6Ke/s4ZWJO6Y0EO49nbIW2zYmIaesmdqtbPVUX4NVSDZY9KzMFu5epZ4cIS+PRlYTChWt0zScScKewWzDjez5uQrPzez72Wan5Np4rgtmQu4o8t3m0Hxn5kfoQr+1qz5DuUNJoOSpWgs70FCjgCiUXI0IJYCeFusvrYqdojOEVgdCJ7nIu2rrrmw3BPs8nkOSN/FdUwpBHJgc2EE89DmtfQFQF/t0nXylxafuxeuTTHELXT5J0xqQfkbeJHwhvCMKjDQwjKxnl3MS7Jpj3FYgdfINSSq+S76ZeEcBfIg7XSA/38492ykUgo2GAwEEd7nI+rkoxlts3iae6VsPwb02O/l3dUkWVBY1usMwZMO1fDa7Vkv2Rv278KJVneJDrdRv462YgCLrwIgQ+0NS8PbiUaO7EFTXwaq81tnTcko3BvrPI42L0PKPCuylzTs6TQom1MHVoXs8/cNmb7vXJqwaYy+4DEPd01L6m5smgI/4eI3PB9v+ibkYC/etGsuvOhER2SXf9PPSdzwJtVE26k6IufMoWImMUa31V7Y2egwphTscjpkaEGYKY1KgyYCFmbUDs3sOf6qimv5T/4ohgHfhD0OoKA559ygGjBOQpitzUayt3sf88L4Qp3VEbGFpwdulJVsiCdGswt7n9QyPqxR9M+8cpYE5SN3WedMym7C+QWfX2NGezO4+ga4kQrJcHhvIh1zMb0ngJuH4XighEQPM/qegS72/u/vdLqsb6wSTS+jFneZ2fGalWBX5eyH7DE/zl3wcdc07LOHDvZRsokGqrGKyrSCm1aIqiVs31vwm03LaWZ5KELCsT41gJii2oJkKNLMQWl0CtsWCJ8xjq2yVSXJY9zEVq2yEyN9mcRVWiYeKBJe1a8gbA13rt8q6DSf0W2lhqUWI1f5f/WldC8LayQmwawDly+5MtWY1QMaQ0Wd9ueIZJb4Bdf6ZeZMZLfXMii6U/aAou9zigMcuTtAmXA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3469d46b-f051-4dcb-97f0-08da841d75aa X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:29.0642 (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: /JJcDoJqPXP5iht39AN5LvTsl4k792sMMoLt7LOpH7NkfANzgA4IhINmWsatJuFnD70R40X73uchR2ZwWnnu/GxHD6tf4LeimizJ1cgJwso= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" data_end field in BDRVParallelsState is set to the biggest offset present in BAT. If this offset is outside of the image, any further write will create the cluster at this offset and/or the image will be truncated to this offset on close. This is definitely not correct. Raise an error in parallels_open() if data_end points outside the image and it is not a check (let the check to repaire the image). Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev --- block/parallels.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/parallels.c b/block/parallels.c index a229c06f25..c245ca35cd 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -732,6 +732,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, BDRVParallelsState *s = bs->opaque; ParallelsHeader ph; int ret, size, i; + int64_t file_size; QemuOpts *opts = NULL; Error *local_err = NULL; char *buf; @@ -811,6 +812,19 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, } } + file_size = bdrv_getlength(bs->file->bs); + if (file_size < 0) { + ret = file_size; + goto fail; + } + + file_size >>= BDRV_SECTOR_BITS; + if (s->data_end > file_size && !(flags & BDRV_O_CHECK)) { + error_setg(errp, "parallels: Offset in BAT is out of image"); + ret = -EINVAL; + goto fail; + } + if (le32_to_cpu(ph.inuse) == HEADER_INUSE_MAGIC) { /* Image was not closed correctly. The check is mandatory */ s->header_unclean = true; From patchwork Mon Aug 22 09:05:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950426 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 233BEC28D13 for ; Mon, 22 Aug 2022 09:29:27 +0000 (UTC) Received: from localhost ([::1]:57458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3kL-0002u2-0e for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:29:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NZ-000624-2s; Mon, 22 Aug 2022 05:05:53 -0400 Received: from mail-eopbgr60133.outbound.protection.outlook.com ([40.107.6.133]:44801 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 1oQ3NX-0006xe-Hz; Mon, 22 Aug 2022 05:05:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HIL4iwnUrAlYWs/gSBCOBC6Mkd7R+ArWQsi+2RIPPXT7/AoIefWMewU6YzbmYwzTaezNHIm08jSfFNWZv1WWM3Y0ZdCRVPW/qPeAZihpyexBInUVTI6cVgmqJANQC+Dd7ghniKeDB7Jbl9ynhTkva1e/T8neyTo+3QyQTu4jLU1jMsgEz72+Owb8jp51JjmVngV8QClwo0psfPxVa+WMJXhOA7DB9NenlL/lmMN/uw530hAeaxu52com8B8DiZVQCxecTOgbYXG3HFTw1D7VDfrR6Y7CLQUwQK+z+NbQ4lLN9X4zLXEL+qlVaGqY/25OBqEyZZ0nb6/SsVwA0mlmbA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+UsiwBXCTJRDf6V2FL4tt9kbiVXailcT0LYAP1hwVqo=; b=ELhStOqEL8Z/PsNKbjtuNPDr4bFhbK8D3GqAbCsYidxsTzH4EtFlTuT8YSkD48QWDRwJRhEmy9N5RM1G6HtJGdUZ315ypj69f0zoPZ/MEPZHiPUQLq9WnsLD8a3Dk4D+UTSyZcYamw6e+s1ZgTvOM0lUpz4gVoQhAl2vzXmNFEwDLfx+5ZqaqhXpnpYcRXjpVTEdipg1mYWOKwwdwuTqHAlDwKi4yavV6dW41kVAGXIigSuz0U86D8Ww+ycB4JZIuIG7fEoqoD9qiAc2bmC+l+n+ksCPDLnzFSFkK/LjFj46vQdCuBDpGaAlDLwFv6sD16K4LX0GltVVXH34gfa4SQ== 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=+UsiwBXCTJRDf6V2FL4tt9kbiVXailcT0LYAP1hwVqo=; b=BRTqnNFn0HJcvkhNsSkYht648Al/gd4ejXhfZF2kUhbvEHW3Um/jZBJIhYYoB+eszZUdO+2LsAh2kBOP825iW8zR13B0S9ayB5cyTks0Mz0BVOnxNeLgCrp6sqzK8Ga4O9CMvO/teKdMI5Ilkl5mEkmBqMLHMDR7CnnSZxgA/0ggw8fcVLW+1kvLLuxe+cPj3ImjBixAAUnSzmjpwXtnA/A2/+/gNRzFigBv9r52PGSWElPmP8JjtQM/JpeX+6f6bfgKa2dgRYQOsQoac10zGCbPcfD4ZBdegbrhhA9UJITC0AcJoy6EEp6hJEgXGd/gIEOz4qjBlBLCkUMp72tbdA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:31 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:31 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 2/9] parallels: Fix data_end field value in parallels_co_check() Date: Mon, 22 Aug 2022 11:05:10 +0200 Message-Id: <20220822090517.2289697-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbd4c777-de48-4ef9-ae80-08da841d7632 X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c/H+IRolFE/0XfOaiLq0cF7ApYVlaqF6OYSDKVkTI4WaEnvhRojmuKn0uON5JV97pYkhM3BP5PTnnK6RkayqGzjbpbUD+0T8VvGEIA+ZM+NcvGWuTBc5VRyuCxJBC8hPSTbNzeND1PdGGFP0F9kSmmIawXSpGstSC2uxBSBQhUrm/UlrH8JWEy8ni7Kq4uEXLoDfBOkguXskoTUKRCtPmgax1HIeVuTYzI1ee93oqu03HxboIze5HDSylMXaX1STERE0eJ0A7ddApi+ZYsUyKvKsPPQLpifH10TT+G9jRYMSXp87vPLkkyrTphjLMN5LXptNStOao4S1rgJErpVr2SQR+a20cVsSyvIhMCs6e6Tn33VOwnpjqmvwEefQDPde7RjhHsF731FahpwcqE5u8Hg9qXhgDICxxHFkp0J/Sp+hVaOLWtBo7M67iO7ziHDGpZEa0NB9Sj6EN4i8rBa6LrflO+AypxzyogNJSjs89Lnva1PSMBl0FLFR8sgsEEq7w2ZaPm3prVRGfBpMgk63SO6eFGU9imuBy8eMQgtxL2cJoaEzUDcIjF9xw6yyf8aIedwUmesDP9PzX+FCXVfanczu4a3Dqfp4STmPKaD/l/OeDIJnVVAdFXbQhKqWIAQ9twT07fQGBgLXyV5fpRhf8aXBHNqY3lRItRzscnvDYvh9VjURUAbVTb0q5IxGI+YFpv4YNTN9X1OMT9mVbADU+Y64+nzkk1gW3tsV8gabs52qU1CmIj4OVCBmPae5EV7XzOVfxUrCRhlW3A6lJfHEYg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(4744005)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0nRnZEQXs7xBVUNaXWXcegxBAoXIgfBfPo+G9YYMh6mzhvzyfxAo/M0ZoX1IrKU3SfKSK1kvoZBcWxoUkQKhwBUduxcD6Tx9kDvTB1yxsPDByOkaPIma6dOLB1xxtb8uljvmt3vVYG04zQjoxQNfsumM32AGGiXt7cVzXjOSQkCAnlZX44bFnmyWG053As8umpy1Y0NxVmXCQMzLaPkGZmbOFgHzo/AUZvWgef/+T7++5Ok7yypttvC6fLchMYpH1tp/tLV/n5cXmkcqm0h+4Z5alFICEIPWVli9xlIiDcz0q4kTnT/pTrI80RDMvBn4HCTp/NU/dI3sTLKUKvp37jPwhcKHGwXVgJpZ2rslRJYtrQfgIM5VKnrMMAyGOb/Bp503sqyhOlhAMVe3c0WHhHX9vpZpfRxV6EGvPskk3wMXRocrjFhKYdAZnCMYC7vpKmgdtrnzhYzcb3ziac5dVjYSyd6i3+ml18LwJUS6NPwbGoaVPHgbTqT5PEehlgGgUgwJOJaZfw8CDJheCphRxSwgRLgd3AcwvZJCs9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hThRBHQJTXjXUGeWudBw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbd4c777-de48-4ef9-ae80-08da841d7632 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:29.9703 (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: 1xa3Cw785QfkziXzsXYN3UnW22nOIGdMT0peZPD0i8X3QGwj5tTSPtIYcEpvXT3LCW+NZ6STs8tVFUnWOs2IIhYNI1SFxAehLJRoVHDPZ6U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Make data_end pointing to the end of the last cluster if a leak was fixed. Otherwise set the file size to data_end. Signed-off-by: Alexander Ivanov --- block/parallels.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/block/parallels.c b/block/parallels.c index c245ca35cd..2be56871bc 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -513,7 +513,15 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, res->leaks_fixed += count; } } - + /* + * If res->image_end_offset less than the file size, + * a leak was fixed and we should set the new offset to s->data_end. + * Otherwise set the file size to s->data_end. + */ + if (res->image_end_offset < size && fix & BDRV_FIX_LEAKS) { + size = res->image_end_offset; + } + s->data_end = size >> BDRV_SECTOR_BITS; out: qemu_co_mutex_unlock(&s->lock); return ret; From patchwork Mon Aug 22 09:05:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3E9E2C28D13 for ; Mon, 22 Aug 2022 09:21:58 +0000 (UTC) Received: from localhost ([::1]:54322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3d7-0000xU-7e for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:21:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NS-0005lO-EV; Mon, 22 Aug 2022 05:05:46 -0400 Received: from mail-eopbgr60129.outbound.protection.outlook.com ([40.107.6.129]:44014 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 1oQ3NO-0006yB-HO; Mon, 22 Aug 2022 05:05:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h8q6aq/SjjKdCkMU87GTfTQwZfOWerrSRX+kyOx5+j71e33/NyUeV1UpYmvGHBYjSLS/pHOaNKfAaIXaHFPfC9GxmQK5Q15v1SBQ6n/8jvJgLMi5p02cm/3WYMIu2eunAkV5A4Uy6vIPmMwS9S7lUSSgck+mLjc0RZobnCzFUr9fgivyTojR1+YbVPyjeYOey3wOe68AmOxUa8U/YKEZj+1zu0yyYRJogu9Qa/EEesSQibdAqrkaQbZA64mlvtHPibwVSMnJdTyoEJItrID1UtYkfJfHBVOqmZz486D0ZDVR1Y0McUiEz7C8rI4SLtvvQEY7tjHfe1ohcDCfhg3Bug== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Cqto7lvGtXhX9CUe/ICCmwu+VfWEpn8KP+AocZrou5k=; b=UGzBrNylwjvkVfbxCgBkX5nS67JcAlB5qHW2KQmWWT1lF2pfmzMHldCdDL6Nz1+Ws56RdNxJ22S9j4Vt6DpZrfOzeprw8Ab1YE9Zt5rgRwRbTEOdumcO99HeXYNq81J4oNteA06CdlkYY9gPAK2Qp1tClQJBOTgS8/slCS3Jdddf3j2fPQTMc4HzJUhOHPdp+fzfAY/Nh/b4wKC3UbsMlJztFIj5hPOzkt4XiaDMWe/Uw976adIeSoCGbNtC1n82wIPOGmA9ov4hewRhujjZNJ6z8a3KeYdZ1S7D30dzDceD4VH01rCPYPI1K5TEYv1eFYhPTMHvP5BOrDC3iBE6ug== 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=Cqto7lvGtXhX9CUe/ICCmwu+VfWEpn8KP+AocZrou5k=; b=V2m9mTgaXk4FLOLOt1GnTtskSIUc73Ij55+kR+LAq2gDvNn1GFMh+jOznYTZu+GeO5ZLwsCmScgNUyBEagpKdGQRm5pKg3EOgiGz9BBk6K3mL9ZnE0DeUn4fDd0wJhhkI0D3sgOtFFhd40OuC3pQaHO5ZsPBTNJwa4bmu6KzZV3LyddMMAkdDM2ZGmPsrnAXGM0gJ+JgpqbC41zaTsPUnOB0Lr6vUnayhwlFF3Uj++9vGWOw37urTM2Lm5ZCBPvgjqO2vqxoUO2e0YNOjWVBXAJgvmvUWNpoAK3JURGKWzqJ3WOambBwj5rbD1mzyrRyh6aYjs515t+DNc9aQRjgtg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:31 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:31 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 3/9] parallels: create parallels_set_bat_entry_helper() to assign BAT value Date: Mon, 22 Aug 2022 11:05:11 +0200 Message-Id: <20220822090517.2289697-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d8dd6471-9e85-4246-8cc2-08da841d76ba X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hCkBm/99geyEGDmRf6aGDBiQCjHoavMFf1TH4hnPRXBYeIwo5nV84edZuXxtFwwq1b5+6MM8ZwH2cAScT6aXm0gKGo6FD4TwdgozHKg9ndaMa7HD/sX1P4ERCm0hlgUco1J6RhuT7YJgaZKnfi3f79aqkltnclB+btkyThA8Pi44JBIRxJ/1499ptreDgj6fg2gSm9ldSJt3UziRWxEybqV54SQWaclZtmZyuARCyg5pGEO0+NFJhQtGxco6qaun4kQ9CTFqjSuj5oKPW0Ht+tDjVB6zGIaas6OTCT0AEtVZ0B87jOuJl2Fy9hoMeywNOtV0PTtdCNmZrUleaHzYf6LtIMBt96Qsy1CdNm/6KmI+veb3oeBu3xvlZi3Sny/1LhOlkwHWUGodFdawkBURRAL1UVAO/tturljPK05d3b3zwId1AkyaKxAuFhCWWNwzhyT/qQG41+Ma+JuFJsm3NQq0NHxWiYC83VYr8kj6m/gwHNVgRXKviTtXVbbBYDJb+MBXHv3osKBd0OP8S0uRaO5CQYlXUmoIgpOTH10Ti4V0Vvf0CHoeygezrt1mPB22475hr/D4KQPN8RLIv45TPIRWExdYTROXmdKYuAv9doWYQPZfjBOX0AO2l8cvI4FGIxFcECQ1pT428xO5TZvy3EwX9I49Cu+2exPC866n0m9pjbYGtoNUh4YzGwV95G3xYL42xo2gT5bTDjNtHWGWKNyqx6f9AjRvaFDEU2UIsOF/v6nkvJAqSEFdq8+IMFiGN1b0hfTdPSq+2BJiwiiFPQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tTawIhWO47FNHHxaNYpT3xwVN8z4XmwUxC8qqSLMuoJjDx7hCuk7tcs7sKMjicnqVmcOWItYA0AyL2m86CHgUGEDvQk/0EYFDKBHqQjKOBmRboirYDFzYP249a1EWec8HR3EKh52wsriqgJQBj/UgsVf/CtgJr3vHW0ILeyCvyGm+b7NgK9rGd3uKsP1yeWFHtJIN+4FsNevcqV0UHZ7va0YX9MRe3a63DEiat3Jl7UKTRyvGH3P9/DC078KFTiQ/Y0+emedA0atVyANj6xLZjf6X9OsCcswblTr/qG6I9WKNSVg+MHfOB7VMt0KdMHNmiKoM5YWiRMtbhNUctksoDv+H+muU9yYeQC0xbEPb88Te3RSHqv+LTpqIVpP4KK26mjUzWW4Ya5tHPBPpqAcJkJjaMYQMQm5p7j63G9Nky4rloWvB6cZfHRf9xNiCMJy8ClC2349ODd50Ko7Hyuc9PTfBpgsIZZZmgHfJCZb4mZJG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+Gosrhdx0NmjIbubNdUotf70uRP5SlqH0jIkPKzESiqY1k= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8dd6471-9e85-4246-8cc2-08da841d76ba X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:30.9701 (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: 8UTg0DxNxOFVTpQV+DFDHP/BfXa07hIJ5CcjIi30pqsKr2v/Exr2QcUjjME8crVxLEvAPGf4wgl8Kgi1IGW6BldDzOxOtGbnGlfvJ1WDjTU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.129; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This helper will be reused in next patches during parallels_co_check rework to simplify its code. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/parallels.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 2be56871bc..8733ef8a70 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -165,6 +165,13 @@ static int64_t block_status(BDRVParallelsState *s, int64_t sector_num, return start_off; } +static void parallels_set_bat_entry(BDRVParallelsState *s, + uint32_t index, uint32_t offset) +{ + s->bat_bitmap[index] = cpu_to_le32(offset); + bitmap_set(s->bat_dirty_bmap, bat_entry_off(index) / s->bat_dirty_block, 1); +} + static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { @@ -250,10 +257,8 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num, } for (i = 0; i < to_allocate; i++) { - s->bat_bitmap[idx + i] = cpu_to_le32(s->data_end / s->off_multiplier); + parallels_set_bat_entry(s, idx + i, s->data_end / s->off_multiplier); s->data_end += s->tracks; - bitmap_set(s->bat_dirty_bmap, - bat_entry_off(idx + i) / s->bat_dirty_block, 1); } return bat2sect(s, idx) + sector_num % s->tracks; From patchwork Mon Aug 22 09:05:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5675DC28D13 for ; Mon, 22 Aug 2022 09:15:15 +0000 (UTC) Received: from localhost ([::1]:43204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3WW-0003aO-V3 for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:15:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NR-0005hD-2K; Mon, 22 Aug 2022 05:05:45 -0400 Received: from mail-eopbgr60133.outbound.protection.outlook.com ([40.107.6.133]:44801 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 1oQ3NP-0006xe-FD; Mon, 22 Aug 2022 05:05:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gJxqBz1jnby6dJIVHO15vsfIYaX52qQLTF02lDbCcZuOmRB7cRtfvBUdJfKmO1ooFw6bspRrzAy+iXr5MyYUvs/QfpLOg/86R219r1PflcUmaDRzRYh+ls7lqdX47JXUHPqNn+lthS5pig8pHUc8WO6GbXw+sCPia81DkPMtXy3A5wEgjqmYr6mjnnkpuEUl8LF70yiHO/Nph6sRPvqfxws/V80vViSMuJXbCLwlPJafH4WBPRjq4ISR2yAD8WVi+/8KxH9glHMBJE2Y8kzBXgfu2ri+oZy96Si7fumc/wyaRE5CBS2+LG0tb7GhWYWz3qFNSnpbxlCJnAbu5GCEqA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZDm4eZCjvQDbnOyqjxJHnM3ZJWF+6M9FzAvCU7W1YbQ=; b=U3bWe8deZfIClIa4rtt/Qh1SPIH5wkRSyKKyqJDdk4Had+INhV3br/rFufr3OQgLOhiKYZzSfra5oI76ljXTfMaz7hvPoeBKsN9C7IOeGrtsbHlJPSFTVg8ViT/PzdhN+KUfcveG70GjBaGovYsVEvnBcdOmzS8rUp4Ygsn7hOTq/q6X16lFKvr+6M6ZwvvFG36tIAAQoWjYch8OLkg/9eOehzDyrSnmHBBnRNznCL4n3kXIngOMXY2GfOehn61BzSX2N+VlHvCszNHgRjgJR2Zu2wdtZbr1zechYBSIp1Svp/3yTcNMDD0yLOaSzJCjn6opJtKhQBLkTvR9HszXUA== 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=ZDm4eZCjvQDbnOyqjxJHnM3ZJWF+6M9FzAvCU7W1YbQ=; b=gSYU0GNJWTcNzazax1Il7Mf1FHrivfZGkRqpGL/S7rcHEItirTk8vDKRH151K4422OESocb7cIxiPvH36tW6+Poew/6NkZAADMRFux+tqy5Z3YA0pZXKf4CoGFnw1b3cH3fnAsLmMDvYA7TdBM8JilOd8kqkvJCu/fymvGO/7vIcPvXTNmVx1IBKIpvxurREdvzCNjoFV66Pt9Xk/rqM+EG+Jttg8qWR2Gl2xXgwAFA1JWiZjqHpUFkuKkkfV2RNaVq0/xuXJ8ZJvPJ1IqMMl81VN4RLB8boVAkl9EOGy6LQKqUUXNsJGxgrjqiobx0KGEiDqjA+6ImtUJmrqepJ1A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:32 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:32 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 4/9] parallels: Use generic infrastructure for BAT writing in parallels_co_check() Date: Mon, 22 Aug 2022 11:05:12 +0200 Message-Id: <20220822090517.2289697-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb83cf8c-0e3f-4691-299e-08da841d774c X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JVQsoLSgJVAb95ZkqY7jUMhfXCKbhZDFmy79in6kmwEp5Ehm7vxAKQI98DDjT056wxtK2PgAjxfoK9S4HqCFhk/iU0sDIRMw62kfUFmPjH6dZMc6dlXRClE/x8mfYs9v1VNk4lsVI6z1Q3Sk6N1pQU57E0oiDhIf/AjaMJA6q+Dvx56lWUk3tbLTsyMtDtpLSsX2cpTJrmv+1f7GlivVGioLq0HYeG55tz8h3alf9DzHUIUhrZlJBYS7xrTzu8rzufLEoIUh+uzhifUCFzw4/7nV/WfMLcJGfIsFXYAFYNXj7ZIKRGf+9sXe8/oDs+BFsk474VarVJ5/RZtk+cBNcDnL0Aoab7/FjVq5fCv88TerJLhXdFHU4dcSntSHWb5pWTzHTFneycpuKzL8hnDdENrIjCSc+G69hbTw1JVUpwx7W2sCVUcltjh+Ecy8dPMHSc/bnLljOYIQNSrm43TahM3k7qNmzV8lrVo8FI1bWtltS2cD0hl9YjJtleZmVnYlE5/zr3gDiSRreXxYNwKO/nsLokEwQYzCZSYfjEEgbdWuRu2wfE5KJKuh9I7CZjK3r5LAfMSuewyc5O8Qx3ToctKOMDbKiuUdMr3hwc3HxDJZHex4Twa7beaGz/0ej/EbABYwhUCYV2fmOPViQ/A5FZVOOZfxh6ptaVnm2yOP/28J/j+02MvPgUi/j4dnDINkMvDDVemQNykP0G9HqGfjSoJGdOCW1OOrKitVRsIgz9lLqmCpJiG+SNE0hbKuhuAOZVQiShULrfNW+Pa+jvFK5uzF9vTh4hGfLtKqApABC5E= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s2hI2Z6MeR31I9CJ9UsKRVQloJAc08WDajuxfR2hRqDDsKxsfXT8XfkbuNDAFnW6ve+V8WsKabbeipvE13jqZKGDuxYXNPlb9WZXqedefTWx1lpK3bMxpWbL21zA/8+7y1VYFp9jPgzkxTJv20V5uaay8stkmas6U0tnr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hzFYjjcmGa2XR6rfoZg63WzsAcXgpq1y7EX+9fBhBm7nWqlLll9+jRZlFq8XXtS25/WFJeK1pUZsZMZrIISc+dEDHF5J3WWvobmczAf6EP63nsCBWbEpYUxVhkQhamxUyUhOFyHIoGTkjrPjFh8zzaHgbpkZij5pX1LGLH1VtzZGM1EFfnQrAqUj41NWyuxU1f+pDzb3eNchuodqtNXUFPVJvMJYEFn0gv7EglQvExyV2YZhTbFfzzla+FZFXbCKe5yoYYAdZsWxotpS+KOtbUczCraxs24rF1LsYtdCXZbHVnimc82eWd72HxHex/A2HlueSDy75i+EOuFWNGFV8XubMrhz4nlqL694KMdPIPS+l1O4ZzPuSZicJoTM71kHJvYnRKSM/Ayo= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb83cf8c-0e3f-4691-299e-08da841d774c X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:32.0337 (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: ceExg9AAAycOa2gNtyVUHmJ32Jr0ci+C1hgKHloyhpiNt0do9Akt6PN5i35Y2yyVrSVjjK3ZlPdlAtYWP0w+lGNlxluEUKi0K4mjKMP+1GE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" BAT is written in the context of conventional operations over the image inside bdrv_co_flush() when it calls parallels_co_flush_to_os() callback. Thus we should not modify BAT array directly, but call parallels_set_bat_entry() helper and bdrv_co_flush() further on. After that there is no need to manually write BAT and track its modification. This makes code more generic and allows to split parallels_set_bat_entry() for independent pieces. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev --- block/parallels.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 8733ef8a70..357c345517 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -425,9 +425,8 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, { BDRVParallelsState *s = bs->opaque; int64_t size, prev_off, high_off; - int ret; + int ret = 0; uint32_t i; - bool flush_bat = false; size = bdrv_getlength(bs->file->bs); if (size < 0) { @@ -466,9 +465,8 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, res->corruptions++; if (fix & BDRV_FIX_ERRORS) { prev_off = 0; - s->bat_bitmap[i] = 0; + parallels_set_bat_entry(s, i, 0); res->corruptions_fixed++; - flush_bat = true; continue; } } @@ -484,15 +482,6 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, prev_off = off; } - ret = 0; - if (flush_bat) { - ret = bdrv_co_pwrite_sync(bs->file, 0, s->header_size, s->header, 0); - if (ret < 0) { - res->check_errors++; - goto out; - } - } - res->image_end_offset = high_off + s->cluster_size; if (size > res->image_end_offset) { int64_t count; @@ -529,6 +518,14 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, s->data_end = size >> BDRV_SECTOR_BITS; out: qemu_co_mutex_unlock(&s->lock); + + if (ret == 0) { + ret = bdrv_co_flush(bs); + if (ret < 0) { + res->check_errors++; + } + } + return ret; } From patchwork Mon Aug 22 09:05:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id AE9C8C28D13 for ; Mon, 22 Aug 2022 09:15:07 +0000 (UTC) Received: from localhost ([::1]:43202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3WU-0003W4-Hq for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:15:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NT-0005pF-Pb; Mon, 22 Aug 2022 05:05:47 -0400 Received: from mail-eopbgr60133.outbound.protection.outlook.com ([40.107.6.133]:44801 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 1oQ3NR-0006xe-MY; Mon, 22 Aug 2022 05:05:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YXeiNZ7ir63NTGVC5Rf32ARy1WoYbT4OlHZNNmbMTy1jUB+ObXBESOaTpwpjEAEXSBXtjTgEnKP/JhnrxhykIhI8Au0/l6IBQd/S2zqTsejZ6ttLK+WhmwlnGR8qN1QEIN/dpXM7xb9dGIa8YnmY+HV55sL1jM2ViWEYmwR91hgm73lIV5yiL0a59031snmznFVBDMA89NMJV9s4+goQkE1GiBmoea7n5B2PtmZGbBSlIdCBPBm7kJcsJJqk1aNDGb7GHOr13mX/J6hOafzDgUVPEJZjEe+VTmL0ng7nQxZK/or5UXKteNvUlzCTMoN8aRmOqn5z4DwACVyNH97JSw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lKby+1IUvLf++yw2IWxy9kCV73GPYkijaDD2GtrXcRM=; b=lB6Lqj11R3NSz42/N8Ce2HwHKhx7zTO7BpClm9Lt5+204oD+PulwdVWV5MWxxRvXOTpYylcm45IVbIW90/+svQI0IUwse9sa0Jyd/N3ikJYzzzuteya0sQQCrMJMIPsDFbcmguBWNMJAcuGvraMEO/OsNlTfM0B+Xi4JYI+xUWLdB1O80lv2nhBq+AmyqKd69IMlvaAcDjW3Es6g6NoAGHnS0OYw0P6XWEmdboyClSa8i0Xt3iIv9aXIiCCeZuVhRIYkP2qX9y1XP4dFnGJz4eqyfnknmbMMNlwz9CLvHKyry+ouqP1Irwt5pT7J8RewjnY+SuSbrz4Z1MFuZSvdgQ== 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=lKby+1IUvLf++yw2IWxy9kCV73GPYkijaDD2GtrXcRM=; b=XeH0dHeq6BkbZrnfP9arWN8TmPFrgJ7eLb06KlpMoNO8dAUOQ/epD6cL27Neu3VOmXZY2Yov63pFLtWpYQ1ub4LiNGGAJjHJecLeD2wtM8t9iCFGsfq/MGAlCu1CCe/s+dlHAC3g9crRRtRKotC9ui9Bgitwz9phF9bJevuEaP2xCpqZe883hTQgUtc2j33AVJVfR0vF7cfVlL/TSM1YV/claSgsQ8zOq78557dVAMJPLXizgSoSJ/qRBbWNPtRomD0M53R1+EQm6kHmWPp9GmFgvkz5v28IdMCs9Io0ixvtf1Ao9y6kbEjwyRTYf26fwEKj6fJrB8SLXTlUvBQGmA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:33 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:33 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 5/9] parallels: Move check of unclean image to a separate function Date: Mon, 22 Aug 2022 11:05:13 +0200 Message-Id: <20220822090517.2289697-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05336854-d66c-4ee8-dfd8-08da841d77eb X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: up0tkKSL9XmOkZytzq5BqWeGbrJ641mWwruzhs9TTVG6KpduyXE0+NlUdoMQW6GKkL+JjqPY+TqPnIzPd5+XtKPDKtI55XXG44aMVFLjdoPw+0B/E/G1qVeyXYEC9gWBz/D6DZOkPOBRdFTBkzOqQHjlksYM6TYEDgrIw0fOefgseHVQH4WyuIuR2R4zpkj7A4I5R2d9PKs4Zt3gZiBFrjAx0A4zIIlDE1ByhkDO85VtktsjZgvqh5hXlN1VptFGr03R2iZ/JmNRbJZiwF11oV0rAurBae+agXV0+th/CuRIfeUWtTp16p+TvEd2D8lSbCG8YxO4/VpG5/I1/wo0sPe6HrvtVBohoyfHi69o2oHhuP9PI456cKG++E314/Xr6aOKBiwbhuByglYuUw8fuiSr9yit+sreFIGfGaC7gSZ1hzEGNPqO3ZK0GN8nBw0czGDhi3ryEW99IOtjHAn1iaytGasa+6gh4oHoG0OAyqPa4BOVsKtzuQIBZwJP11OiQzbDUydOnTW1A9UTt8XYR+o+6dPCPyBeoPCDIm/oj1SlOEUfw8Ls0lA0lu/78k1xM5hr1wk+E28H7lfKB4qsJ286NWKWtxhpXb2SZUJuz4jyypdb+PuzmHBpterJrfhbbpJaWH61D5jAxDefgeFERJtuoQhrsEcaUhb2s0YnId4UG6gXiCFj+Z2lzWk1o8x/Ls2QHjyhfyPnaPOf8RhXzOoxqRdSWtO0yFcmrsNyZWt02MfTf888vbN8kVgPm9LUF3cF9s8ogtMb45Z9EWpKJg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5duVW64RARiGmNYcw3MnGnpyxOQNLB5shC5zWx5XWBGXlv+ZJXjSO7O7fjOoyeUqbXvQVPhQj6O4WAA7gFomCr4zFtLqBH+ao/6qXrAYDJpuUC30B2LGtjucPh17l/GfamwvgojQmktKsTdma6M1Kkv7e8vkVBDc58e91JAv9xiIETlndCF14dgJBOsoIEE3zBHhIrYnzGOJFUf05uEV20r0A3762Mog6Nr9JzrRP+YUMkdzTvChJSYE6X0aYFKiukpAMOqYgB/nOBOk5zr7eCjl8R7+mBjOxPPMD9YV9d08rdn5T6h4my9jo/FyZGQ4ko2YdrgOwnBndfRrhkbOw7odMW6oKa/YMZzF5284SDVINZScU4vwca2HPDxiJxRUaYY7V327S1TZWM42qqkpugBOHfO5CV0CtkdBYfQkVhQE03xNOtzmAjBnRl0AnW3Z0bsWxLLh8qf/GLqPJpGaQmeMyiqQ933EmGEF4xeI7M2+eRsHL+lob1GYA/GTMUk4SyonsBDCJ18bezpoYX4xbOP5fzAfuFBNaI4FJIMVThTNU8lzLzHlm+EKYzXEgAVt9MzPuhdVYJugjmfWgz8o53UegaQ5nb2BE4wrkA8BkT/MjFoDVpAJpptq+WJnUj00JSSsTVF7CHwCsY3qu4NBef1+ZDk+4khFRAKLnzgyRyk/76+IPvdshL24UVGLwCUWtKYlThkGgRMpuCBiLpmig1yiqCHOcoPA2cWX5XoKzAh+XxINu/rxTR80iKtGE7E8PJ/gGYeeA2bV+727dTMrsFuXtJ47NWMekMr25UjPeYfYN5Fuu9fs/3Xv/rWug0Wgri4RSOIXySNAPsguglLJFpWH2tvDSERPOO9Hd/x/z07KUk4IrOHTfJpcjyE//Nb8NElJJ3mCS9tT1QQpPM3hCQIlk9hWiR7gHTJfR+RTV95NvmTguYqeVz2sILbJWuvR7wU8ndg+684OC47BWg0Lu14nmo14NPEcluu4Zy086cFxXZw/kEsxPzLdPvPclezcGJxYGjgqdregehEYTDHP1zV/3iefvLVRZGC2k1REGNypLFHxvSPJqOE7nrtOLPtfAHSt5sA1/VLYtX9kNnnbco++ZzSlnPl8Chl2IuIBtG5Bj3VIXZgLlhAxftiIS2koNjDTKzRzr/YtPBPqJFC72RUU7FKM80buuJ5MnRvqoifSQwEqut5NqN38TJJYSUtymJaRySr1Jvefj2SRb66NQDyOTexga8K79XsouPALboRe3kOTnM+9nClajBK46QMRrnPmMddO2cPcKNnmF9pn1VXgmgzzc2e8N1LqJH8C+306J+gQc1r6OO8hU/IOEH/dney8Xq/qLA4O95DrC5LdTEjxE8vWdHjvV7Zeicjr3QJzzOT4nD7KcV066mN3YMctCTjO4YRI44XY2a2DKoD2NDyo2TIjo7ujNsF71A+ZFXnOEiSm6dfNJwatl2hOya7zzaQmiNIczzWG8ivRSMLv9t3BaRSnwof2Tf0S9KlFFG75n7z/e+wp1WOd5CYsVNMBttbWtSyZVxlwOaXcgCajWPdJz7AutmiAxY7s8VWb9AFmcJ3m+ugDxtSL5REBHgJrMTxndnOh5HpYV9OMDvEIOWUmU+ZMZ6l/zdHeSXYn5qE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05336854-d66c-4ee8-dfd8-08da841d77eb X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:33.0179 (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: QSS1X07ksc0zyO0+VV93MAMwhucaZhMqr4833zRoVEsQTAlcIZx4rjvg6sEH7xsUOCFjqqbaPHHL+jmwjhrFcuwnHYcbSVOcHE7YXM0hMZs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/parallels.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 357c345517..a35035e231 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -418,6 +418,25 @@ static coroutine_fn int parallels_co_readv(BlockDriverState *bs, return ret; } +static void parallels_check_unclean(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + + if (!s->header_unclean) { + return; + } + + fprintf(stderr, "%s image was not closed correctly\n", + fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); + res->corruptions++; + if (fix & BDRV_FIX_ERRORS) { + /* parallels_close will do the job right */ + res->corruptions_fixed++; + s->header_unclean = false; + } +} static int coroutine_fn parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res, @@ -435,16 +454,8 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, } qemu_co_mutex_lock(&s->lock); - if (s->header_unclean) { - fprintf(stderr, "%s image was not closed correctly\n", - fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); - res->corruptions++; - if (fix & BDRV_FIX_ERRORS) { - /* parallels_close will do the job right */ - res->corruptions_fixed++; - s->header_unclean = false; - } - } + + parallels_check_unclean(bs, res, fix); res->bfi.total_clusters = s->bat_size; res->bfi.compressed_clusters = 0; /* compression is not supported */ From patchwork Mon Aug 22 09:05:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BCF1BC28D13 for ; Mon, 22 Aug 2022 09:23:00 +0000 (UTC) Received: from localhost ([::1]:33040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3e3-0002F2-1h for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:22:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NV-0005uM-U3; Mon, 22 Aug 2022 05:05:49 -0400 Received: from mail-eopbgr60129.outbound.protection.outlook.com ([40.107.6.129]:44014 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 1oQ3NT-0006yB-2y; Mon, 22 Aug 2022 05:05:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PYOVV6tZD+8u36H6XVaaz4yI/VZT3WFo5i1Cwq6UbibWLAQMRipM1fMvHbW1mLZQrJZiorO1Q1PkO2hJCVzwf+MALiFGvKYHvfQkfg866HggRfd7xXYyry/cGGpA5GLBRjct8W1I0KPtIHKP5fnfvzDPi70uS/mKRgYhBrVeh9qv5cax39hoJQ0kCx/HDve0+DNl23bLz3oiF2tYC7jo6jjMyrumGGyuOd2xdpyVC9CyqwA0UVw+w8H6N0dZLcWxLZqsyCOyO6NVG/7qtidgW+fY0QRlgUzLsajP37gVjHx7Kla03k4x0sBdz/GU7oSzLERD/MCs9g3XmdhagVdG5w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8UyXo4RABmlKEgWXRunM44X2Hz6d71hKRJy4m1/7v4U=; b=PlN15HaVoqV2UF33DRkVNwH7ULjBOzl1yUvRhwqo9OOc/2NNxNcYDzBG/IySS8oU49sXj+MrhEXiCA7sbEx//mjpd++HMmPjNUnXOWd8pdw0KcyIa2tB2OW7PggzSyQbriuW8aHCLqm52CgvweIdzSsF6BYz8Y5s+nMt6CMm71FtRADfToJ44HIopMKD6CiZh7YqqtKlfLUOHl4meWiT0PwzAyCs0W1qoR+/2147wdT26+tWG+mTEkSA2q5ti/M+HE93C59LjTpcgaJAIxHNPpUKAVoeWCy7/rZIFBOdSGXb4m+Q/6es+/FdfnNZdl1V+IH2iMGDPe9BRUpupzGSAQ== 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=8UyXo4RABmlKEgWXRunM44X2Hz6d71hKRJy4m1/7v4U=; b=lAvSTLtR0RkhwboMe95/sSFL4EvPPValKF7CJPSdSYrOxKDylLuqPkG4cFupx5whWTaY0CUsJfKiZNQY3R9AAAQKcENiZeFfaKlGG3OXNvS6d4M2rabG12ZF0GeQiuc1S0SSYnsSOZCOMjYSngfN9BRMJuxZXjOM6OK0Ism6E0aRzJqBijnEAKBIy9RBFlWh0whjE1wg86a1dRqNnvVfuyvaLj51b+up2BtFqHir0V2fw57E59Zrjl+dEk959TnmeJgmz4FxvuJfL6hgbGTzsjpjKJEU7GHCqkxkh23Jzi0MgAUFsoyY43Xr4L/IgmLzBJklSE3qMYKN3d8IO0iS6w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:34 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:34 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 6/9] parallels: Move check of cluster outside image to a separate function Date: Mon, 22 Aug 2022 11:05:14 +0200 Message-Id: <20220822090517.2289697-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4299c3b8-f0c1-4683-a7d3-08da841d78ad X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d2GnH7t0DXUVtfzIjOt/jSD1U8gMxKjU95Bu/o3LHEffU0il5mRhvJUhMcVe3/MfK5ZumKtCrLBizhc2XHVdz+/LFNojXabKMCq7UqY5FhEZmMKYbj4W7Ix5AOAeQ2D0UgPZV5819mkNtFb7mx/MR9nQ2VvVA62YKIHG0zW+o+1xvRbpSQJZv+Z9d6oGN2L8bHuLzAzUVxgCODr/zR1zQziAGlyLvTAGQouGtoldKxkQNzvfmRwD7gyBx/fL29fJu6tqL2oCa9tiLwGYB6mJVONXDOcsEXeBvjedSpT7vZGijtOsOD6XgjZianU/VPG3cLmGg1Xk9ZI8NXYOQYDan15Re6wbACuxkiY6wyDvlWn3vCQNoVI1B765Snp/PGjQ9E0FJDVH2zLCWtQXmfhe+U1uRGfXLXHSPw/HgPIVz5agr6kFIsq0KsS1b5dPZClAgJRlKf8V5MOhC5PgH+AHngBjDzOEGtOhkDyLH8/32fMZ5Z/NrLhdcYmxOtJuKRuEu+wRDWlvHjAzADkM5wxtePKyP2VGUNz05xDMslFSAxJzxibEP4HKq1LJijpgGbcIVr4ed+tOV9y0/XLtRfH1Aif1KRff5gwTdDL34Hcso8ePX+dinR00mJhGarZRgqzvtyhqKJawv0BchAIFofFgSAhQLnVyzlyMqbKGVOLxAbsgylXj2g2f9GcY1x3Z0b4ytO2DfdUAtt1SRozYr88i2Yd70AZd0AULEtnjNl7PqB4wN4qAtblte2xi3L8oGN40RraQnl9PK+ibWL3hQ2qWug== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nE/hBITs71tvvhpsPVD74nggQ90BCfgKfu6bj6ygIzAkqFmmN1URuIcLErXjRPowpMUaq7qcZVsUHnFbBQnWd1muOOXLZSSMpF/gNx5SKQGfbHJgjBD8nYcQ64VwSVYBkFB3PsbsMDv8lvWik0AbKjKd30+EZYnqB9JjzMtJ1hzT8PaS9j0z8rMBfeX+uBTz0g51VYJDGNmlUQfoayPwO3aT+bMeyzMqqQ1/9u91bFk91WTohUwh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PGPxeJnPS53lTqT5cYCxJbL7SMjyon1VEGXAaWML8sIc9t9uf+aIvPbpdJeOqb54WlVLBGU2Rr4rYLVlowdqD+ZpcADTqrJjCQA4dJ1LQ1i+rhjQvG7K5oASmj7F/ihFZ/8OioipJWtMJm7xhPGzGbwyqacXuUd1rSyqElpF9f+fh3mgVGYKIV9bDd6EYhEKrUGojCOjv7OPQbJi0gLP+h9rz9swZRWXnHRqCWcryYc2nDRfCcz6zrEw9WKp+JOuptdofxBTrG1w+3Dk0oV5bZyzDFIog143Wsxy6Ka61MhI+RjYzFps4yNx0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4299c3b8-f0c1-4683-a7d3-08da841d78ad X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:34.1785 (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: MbaMlw81rlxcCLQ82m4QKNVROjXAxuUqoQ/vjTqjGSfHl9a61atcdcW5pukgBq5BiLGp3fa5R69ZBRRhYuelGMttWKDzMafXeM+2q3sy30s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.129; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/parallels.c | 50 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index a35035e231..bf074f247c 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -438,13 +438,43 @@ static void parallels_check_unclean(BlockDriverState *bs, } } +static int parallels_check_outside_image(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + uint32_t i; + int64_t off, size; + + size = bdrv_getlength(bs->file->bs); + if (size < 0) { + res->check_errors++; + return size; + } + + for (i = 0; i < s->bat_size; i++) { + off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off > size) { + fprintf(stderr, "%s cluster %u is outside image\n", + fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); + res->corruptions++; + if (fix & BDRV_FIX_ERRORS) { + parallels_set_bat_entry(s, i, 0); + res->corruptions_fixed++; + } + } + } + + return 0; +} + static int coroutine_fn parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; int64_t size, prev_off, high_off; - int ret = 0; + int ret; uint32_t i; size = bdrv_getlength(bs->file->bs); @@ -457,6 +487,11 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, parallels_check_unclean(bs, res, fix); + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + goto out; + } + res->bfi.total_clusters = s->bat_size; res->bfi.compressed_clusters = 0; /* compression is not supported */ @@ -469,19 +504,6 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, continue; } - /* cluster outside the image */ - if (off > size) { - fprintf(stderr, "%s cluster %u is outside image\n", - fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); - res->corruptions++; - if (fix & BDRV_FIX_ERRORS) { - prev_off = 0; - parallels_set_bat_entry(s, i, 0); - res->corruptions_fixed++; - continue; - } - } - res->bfi.allocated_clusters++; if (off > high_off) { high_off = off; From patchwork Mon Aug 22 09:05:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 42E40C32772 for ; Mon, 22 Aug 2022 09:28:56 +0000 (UTC) Received: from localhost ([::1]:57454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3jr-0002YT-A8 for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:28:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NW-0005z1-W5; Mon, 22 Aug 2022 05:05:51 -0400 Received: from mail-eopbgr60133.outbound.protection.outlook.com ([40.107.6.133]:44801 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 1oQ3NU-0006xe-5v; Mon, 22 Aug 2022 05:05:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oJLAPVjg5khdG0/3KXKlIwhUqgpuBvJ7cfVUE1Ji4I0uLnOguoI1cLg/eu9QOrVuky3Ez55VveHiyY/tBEM2Y4iYKQ9UhCz3jHdhytTGvLUamuOuxHKmVe3zc06QDq9Zq4cL9oSaOvwjZRLJvDSoEZ28ns/4ZPkigO6ZkkWV1Vgvl9QrhsqX9i6rbXf5FbCdNsQp6I4++CBtkRucOQgRwPXttmno2fyXGJqOoKkfIf1o+IIbeVQjVzIkQN+6ROOWbj/IVQe/kcLANrLs9cd7MJF8MnXekAJcKOA8jCFH15s5F2lCfTDnP66txbxKt5qDdFpQ69ooFXYQM4MeRzEbGw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C4xOgP6Mx+oZfmDjMMRf+8vtcgPH3bMCkqWDMW37x5Q=; b=Ce8S7aUVWOwHRQi3bqdyRkbCI/uB0vN7266umLffT5JXZdOH561ViYioPMjyqymIpY54QmDcdjQTQdaKwHKYgQctlrVXjakBX1VDkFgnDPrkazs7dmZVY6By8zfoamMVB3hvn0nNgTMxtjbqQMajqXFUL9T1kaZ/nwhgtoZVQtoPRvwxI3OBlCa5QsUCUqF3CNNLsh5spCR9i6CbiyPJg3HXlFCaaNqFTYnQEoYq5LXi8h7BLNzPxgINQFCGbpqT8/LiKdIor9OibLFnzGu+CfskR7+vFa79mVLUHmj2wOXVYomn6QzNEchh+POa8UoX7fV8Mlhu7Q3tsyFxMbUNBg== 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=C4xOgP6Mx+oZfmDjMMRf+8vtcgPH3bMCkqWDMW37x5Q=; b=0dV/pKmHrizFlgmqSA8GjjmHFSWixoC2jJCrXYX6BHeLQ8s2EWfysysTTO4aFdgA2S/OFdw7KDg8MTeG1cj1rrvZfx3u1bcr5OKoHgMvYU/1k2Vq5wI/C3au0y9ZU9Xbv8s9/mlFOv5+ab0fog5KkSjLRh8c/mOY2WbeZ2W8uHlYTPGY+nDE2XQzA6Z1J5g1KK5sJxsb4QN53w65MkIbpXndwtWEDLKJSbNhsRpdD5LoOIgJ9Y+BKtdOFmATZSlcQOCmQb2Q75XyO/gsrH8z9jtj9QaoJHPcZu1qxYLQYhhJzvlqWc0VaBMYXItnQKl1oQkB0174cz/7iz1n0Em59g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:34 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:34 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 7/9] parallels: Move check of leaks to a separate function Date: Mon, 22 Aug 2022 11:05:15 +0200 Message-Id: <20220822090517.2289697-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c441dd81-85e7-488a-d7b4-08da841d7924 X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EJixuNhX9wf+KJvNsR8jfz/Hz231Z1Gr9j1MsellKZqfojOFTf+RfyKG366+7Y3Oc4JekDFibV8xMnzdlVT8Rmayx/tuIdJEDhbdzLaGzPYQk+6zq4dgW1FkfLeiIr3Bi8G4VMGbC/bswquD/hiLKb5PM2rkvCq0d3l02gUgaPXlClD7OX6+RIDyW0tlhvFEkAtQR1TjkQIrK42FLb5Fq89phsyPo2Cc51eAJsMtjYsTG8P2oVoSHsjAJ/HisBHALvJSncfsUy4uvqMaGyGYuOTKObsMowgY3nEiS59xTOMH7x+YBTbbw1K7RPCmecJwEKfB8alDCFLuUZd7zQ9UUeu2cjDxIeJxydN54E6SwwK/xNo6dK3rMOzd8VakffPhN27AeLjaURqPOlMuK8BZNJWERo/v/3uA2rgoD2nU/poMdRVtpD5OwaejqRFCl+Q9/8E2v2wnHoEtZunMLy2OKdUMdAOhJnBZFIcdG6yAbEyqbqkDoFZy5MSrQe7ltHxLbNowtI4ob4PDAbSCiNBFPG3H0kDEEtJ5+DMyJgYddRMaBvnPQVRv9T5E+YAiYX/UBTG5QJJGjHRTwGsuYz7zyzt+wBTzGDtvCh0LXLvBkni97Cj+4WhEOM0qGaPjkgvhljL8dFgkCmifvCPiWVz0EhqLjc0GPzKq+l7eC7KnwhxAD4oXR4J9HgO9QCatk2b0BuFTqMAE8A6d8O2wG24mJ5mV4RGzLYWLCdXcKcBRvJ4uHGHrWCTbXb8dH7G3LejsBVxyg8vL3Bwuit6YR6N0Kw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xrKxvcLaPlMiVJh6j0/3Hq7rO+Wh4SpkfwJ0F+uhVlRgLwRKLojM9iQBf+koETgDFVuNOe5D4BI0qUi00eBlt27H/oVEyVvuoOjRyhCEAkrhGL4OL6WYjanlzJHtSjaexLPC4M2qo7fQ800MqRnDkCXkCCq5v1z3cncAbAImLNi33oXVkiqwXjdJVnh3XEQMlfTU36oAmNY+cFn824FyjaYWE6crweOnx/XhBI4LekOTQBykQS+NR7saHxqpKhD2A9PB8+RKi6pEHqnWxQ55M141rOihidgTXdVB07q+gVogk9pAFfbz57wFm9Qd1fitmh2tQIuPMjdjpSvEBje+iPWBi2fqMrK89AIOeVP+jtSGgVN7Pq4ZvbE2uf04ATyb+nkZ10MP0mhLhP7MSScaXcE5ZyiOQ4v6xR6lweG/l8mjWz2hd1aoCvHhka9cIVaDH5fR5V+qWZwDw3LH6WaFkP7O/xw7vNK0KgbUwbffkn4juS0e9rh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+g5/S3iqD7SAnmKMLJwgWn8S0TL+zlpnTYGRL/E3yrcylO7ed44YeYodfezHQ3bB1CrMhw+qHv+PPO7qZg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c441dd81-85e7-488a-d7b4-08da841d7924 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:34.8971 (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: usFnwItEI8KeX664VQsMJpj7wZ/hso949dR2OIE1K+taMF1wbQSWsxpfR+ZfkbubOYGhslSib30y1P79sVWN+7FErsN11XttQpLoTvpGBPg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov --- block/parallels.c | 87 +++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index bf074f247c..12e8d382f3 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -468,14 +468,13 @@ static int parallels_check_outside_image(BlockDriverState *bs, return 0; } -static int coroutine_fn parallels_co_check(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static int parallels_check_leak(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; - int64_t size, prev_off, high_off; - int ret; - uint32_t i; + int64_t size, off, high_off, count; + int i, ret; size = bdrv_getlength(bs->file->bs); if (size < 0) { @@ -483,41 +482,16 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, return size; } - qemu_co_mutex_lock(&s->lock); - - parallels_check_unclean(bs, res, fix); - - ret = parallels_check_outside_image(bs, res, fix); - if (ret < 0) { - goto out; - } - - res->bfi.total_clusters = s->bat_size; - res->bfi.compressed_clusters = 0; /* compression is not supported */ - high_off = 0; - prev_off = 0; for (i = 0; i < s->bat_size; i++) { - int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS; - if (off == 0) { - prev_off = 0; - continue; - } - - res->bfi.allocated_clusters++; + off = bat2sect(s, i) << BDRV_SECTOR_BITS; if (off > high_off) { high_off = off; } - - if (prev_off != 0 && (prev_off + s->cluster_size) != off) { - res->bfi.fragmented_clusters++; - } - prev_off = off; } res->image_end_offset = high_off + s->cluster_size; if (size > res->image_end_offset) { - int64_t count; count = DIV_ROUND_UP(size - res->image_end_offset, s->cluster_size); fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", @@ -535,11 +509,12 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, if (ret < 0) { error_report_err(local_err); res->check_errors++; - goto out; + return ret; } res->leaks_fixed += count; } } + /* * If res->image_end_offset less than the file size, * a leak was fixed and we should set the new offset to s->data_end. @@ -549,6 +524,52 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, size = res->image_end_offset; } s->data_end = size >> BDRV_SECTOR_BITS; + + return 0; +} + +static int coroutine_fn parallels_co_check(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int64_t prev_off; + int ret; + uint32_t i; + + qemu_co_mutex_lock(&s->lock); + + parallels_check_unclean(bs, res, fix); + + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + goto out; + } + + ret = parallels_check_leak(bs, res, fix); + if (ret < 0) { + goto out; + } + + res->bfi.total_clusters = s->bat_size; + res->bfi.compressed_clusters = 0; /* compression is not supported */ + + prev_off = 0; + for (i = 0; i < s->bat_size; i++) { + int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off == 0) { + prev_off = 0; + continue; + } + + res->bfi.allocated_clusters++; + + if (prev_off != 0 && (prev_off + s->cluster_size) != off) { + res->bfi.fragmented_clusters++; + } + prev_off = off; + } + out: qemu_co_mutex_unlock(&s->lock); From patchwork Mon Aug 22 09:05:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 466E8C28D13 for ; Mon, 22 Aug 2022 09:26:58 +0000 (UTC) Received: from localhost ([::1]:49076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3hx-00071B-Ag for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:26:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NY-00060u-8W; Mon, 22 Aug 2022 05:05:52 -0400 Received: from mail-eopbgr60129.outbound.protection.outlook.com ([40.107.6.129]:44014 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 1oQ3NW-0006yB-F5; Mon, 22 Aug 2022 05:05:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k4omuruiKpvFpv10dNBlOvVhv6qdX5Ni9x5//ZkHdAv2RHFgPV6vhxT/ZP1XBqkEGwovtPf1ziBfhXhwsGu4tVvTM6QJ18HsRQeGOAx7JS5a+Ofz3dnCKc48FXperuqpGnCS6HjlfrP0cJTOrDignHTZ92vK6sBUCinssnKRw5JwlDi8avkm1Ebh48U7VRa6zk9Jtal4P3OuDMEFMXBHq/VhvPRE6HA1tIccuFF5xTU6WyFnI3rKKf9a1vxDuYBg5tN9zu3yDmChjR10N8JnIwqrH7CegV5lxx5moipMtinC0ekcoullVKjfqZ33jGKtBE+5GVGQ14+DVnUxk9wHow== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NY1d+vmyYp73ILXzqGFIEFj1iysQ+Wo2GXLo4IrsRVA=; b=MCpP2ZbPL8KOFJ1Fq+ICrxl3oSgQPxPOQfj5cTcSPBXCoGMykrr0mpH0QArpL5wyHlyFTH2UW8cfdOCWhkfkGx6Eraf8lRmX9wq5jvY/NJOhitI3Ta69mLxihEvW8/9SjYwXC+R4W9WOhLUXTmiZrPGiLUkAhWfEhtl7Nls2Bbmlcq/CW4Ybw6BLHHvAXnhrd/wEu+dwwb8erS40wnibaVT4amKWH3HQkdkCr9QGj5b2Dot+vPLn/55p3lS7ZFeGV9QthGiris16kqQglw6slA7EtFM9QrGeaeBraZApYzIKKs/Hf1XJQu858llPKbec/hO5U6AFvPiwaxJ506scDA== 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=NY1d+vmyYp73ILXzqGFIEFj1iysQ+Wo2GXLo4IrsRVA=; b=SWOZhN7a8GtaUpFcQ50CuHx3ag7Sk00glWQGqtukUJ9Uqb1y3dwRkhOme9JbkpHbII3k1UEUW7klm6E+srPoxMvEJdRC6P7lYr0Ltk91iTgxbEmOVNkHQIDYe+moRZNFoV7QqlcWhw/ZE2qzdAI8L8ZKS1YUfoCIJNasbtk2eadhf2wMJNedZlfG/yiwE+Ln2+zFWCXlXr/5Xbqn6B7fWzU3u/M+R37J1Kvu5dSB4RlGoYnALY7FuIIz7dSBpShI6z3v/WmrLma2bcHVXyStu4YKeoQCekuR2BH3GkCKvQq8xR2skh5hMYMozYHWlSaXp/xx19z8DdAvvz/rAH70aw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM6PR08MB3382.eurprd08.prod.outlook.com (2603:10a6:20b:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 09:05:36 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:36 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 8/9] parallels: Move statistic collection to a separate function Date: Mon, 22 Aug 2022 11:05:16 +0200 Message-Id: <20220822090517.2289697-9-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1d587366-a7c0-4c46-9604-08da841d79dc X-MS-TrafficTypeDiagnostic: AM6PR08MB3382:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P1xNfYAlcwifrGvOuvsNaW69P0IW3FaPZ39x9L1l9ar7bziyceytDWsK/DbfB4viPit2c7rpKSgvh7cJlT7f2ZQGD67Z0wIZ049rPCNJgUXRglF6O8r2DQ/AM6SJDHDwtrWN1Ma2hxUBCM/qV3qtk8EwFdwdHb3IaBX6506nm91cYjEFc4ZFI8S8Fqb+KfTBW2XdKD/BZ6ftm4WDwDBHmDvKreWs//Py2BBdf0a3S37gK5fhQ0AXeSg+7pLtAdcI6YBrkXKsqCXxfbEmpDUh9aPf3bLF9wDIV1dw9s9TBrNN/Ucddfc9IQhUKvaHjYlRBmvrfNPsypKAHgNINHiOCVNCvEqXKKEYTT1/z4JDbi98xmCBnyTZB7Nida00GGKIwAmotUfZXVQXfVuedT4Fqls4Vpu5Buk+7IVIUHkLXLhQDA7mJzTfTrmbkmesHyuCZceBh5pBkxb6ns6McHZGwNKfB7FX6AI/6D070Ew+3/fRqk6M6ij1riWP9NnsBLAsYJH5YG/klXvqUPrT57FePG06AUmPDTF0Wi6vkbRRNryabiVcDadZS9L8537BDTlvB3upJKHbhIJ93tzZo+R/mD+4wp5Xu7oqJOKZPEpK/3sSs5vlKcRFgIbHFMwhUKogQZNeqUs2Ig3sjVmFnhXGl2oNtzx0/hy0juSDSBHiwSoUxfdwleT06tWq7MTs40xWSOt3Futq4dgfNrEKdYsiyf9rwLCQI8wTOjNtt4XrPXg/1Y+D5qSd3B9tSAEvooe1NjtDJ7VFbRfxE+APuz7XhQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(39840400004)(396003)(366004)(4326008)(8936002)(6666004)(6506007)(6512007)(26005)(5660300002)(44832011)(52116002)(83380400001)(36756003)(6916009)(316002)(66946007)(8676002)(66476007)(66556008)(2906002)(38350700002)(38100700002)(2616005)(1076003)(186003)(86362001)(6486002)(41300700001)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rdMHosnmmA9OFbi5be4vCgvDn8LNeke42qdQ6+/Kh2OzG3hTg9F9QQqD4jdYWZfykjzt+6eLjPhmRqEkauo9tioEQuOzGCFNmz+i4CJgYGxPXbx0x1JzqxxknBg85iBrzXg1DlG+Es2LqibqcoFBeDx8uEJYb/TSnO7CEwEHmAoLEqqwoJ0fuSVhzVoxDyoZcj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/NcgdXVDaUZxRZdaRFkzGQNZjsXvLedzpgntptiNgDwqBS28Y/UL6URdapqLcmVy/Lav0uh+XKTmWN1xb5TjZTe3Wk8GMxMM0XPzqtHjfm91LHrf9RbpSmoP6Ewqjv4xfQOL3os7lRTpj6OC1eSpAZbnODQ6ARXAWaN6vqHJ9GWkxN7f9TC5W2jbIBgKKHQTGuepGlj6bHILsRD4dcLIXPLXn4kz0+T/yIxeS9Ms4HCsDDiZNnDIvEjcxI/ldEh+sPd7d0zCFaZJbWXTyb1wc0ELxPwGFH8ScT6eBbkjTkvTNlauE4mB7g8bekKrEa5DU+94JIbAhhV1JlczLkdldflBr7E+6VY1bQ0i1Bmv4Fi9tKXMl4BPLZQ4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d587366-a7c0-4c46-9604-08da841d79dc X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:36.0857 (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: XWa+/Mdef4jMoFHFFktq9wdyR7yvZPv/YIR1PXbvfgpC6hU9ZlwYZ1enIgKfzKM/4gLYLBbwG/byKL490z2lCLJFtbqpzcFhtjLaeNU2wQ4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3382 Received-SPF: pass client-ip=40.107.6.129; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/parallels.c | 53 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 12e8d382f3..0fe6dd3237 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -528,47 +528,56 @@ static int parallels_check_leak(BlockDriverState *bs, return 0; } -static int coroutine_fn parallels_co_check(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static void parallels_collect_statistics(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; - int64_t prev_off; - int ret; + int64_t off, prev_off; uint32_t i; - qemu_co_mutex_lock(&s->lock); - - parallels_check_unclean(bs, res, fix); - - ret = parallels_check_outside_image(bs, res, fix); - if (ret < 0) { - goto out; - } - - ret = parallels_check_leak(bs, res, fix); - if (ret < 0) { - goto out; - } - res->bfi.total_clusters = s->bat_size; res->bfi.compressed_clusters = 0; /* compression is not supported */ prev_off = 0; for (i = 0; i < s->bat_size; i++) { - int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS; + off = bat2sect(s, i) << BDRV_SECTOR_BITS; if (off == 0) { prev_off = 0; continue; } - res->bfi.allocated_clusters++; - if (prev_off != 0 && (prev_off + s->cluster_size) != off) { res->bfi.fragmented_clusters++; } + prev_off = off; + res->bfi.allocated_clusters++; } +} + +static int coroutine_fn parallels_co_check(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int ret; + + qemu_co_mutex_lock(&s->lock); + + parallels_check_unclean(bs, res, fix); + + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + goto out; + } + + ret = parallels_check_leak(bs, res, fix); + if (ret < 0) { + goto out; + } + + parallels_collect_statistics(bs, res, fix); out: qemu_co_mutex_unlock(&s->lock); From patchwork Mon Aug 22 09:05:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12950416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5729AC28D13 for ; Mon, 22 Aug 2022 09:26:20 +0000 (UTC) Received: from localhost ([::1]:35838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ3hJ-0006Mo-Q5 for qemu-devel@archiver.kernel.org; Mon, 22 Aug 2022 05:26:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NU-0005tJ-MO; Mon, 22 Aug 2022 05:05:48 -0400 Received: from mail-eopbgr50133.outbound.protection.outlook.com ([40.107.5.133]:35904 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ3NO-0006xs-E6; Mon, 22 Aug 2022 05:05:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=acBm6MaFP2ZqejJuopNwg2It2kWPclWp4ve7xpHdBLE8HmMAGajNcTpJqkyn6AL/KwMGg8uRKxbEt3JNEx9J86YsIMoNUYG1PXjobglIu85TuuiBTgFrJlUrovA4CzeXMtsPeEXR9GR8z+JKbNUoVQB9asds9RB/fEXKHszsm7nPPvjQP+Jk+eqonHOP4Ksb6BPz+Z70Jb575aX0f+ixJaxzikbp/IyhkT6jTur2avBz1WOUtNTSR0Ue8R182e6fDfcoOwmUUByD8vRhTnggskLf7deWRjDcCjai0eJO59xIUb6AtKKm/5JglPLOICJZCHInVtr5xkOlKEr9viEK8Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MvzcU4lPj7OU+Y9IuchDVapPQwkUp3HHBcVB7RPa58c=; b=ZH72sE7ETf0odXXU7ZO3vFfYQbV2JfXsPyJg9u2BE3VzFD1ksMj0MdsEHrgmWzeRQ48MRpyasg21KHQCzEFiwvzz76cbcbpRm6igESSI4mfb7LccazV9pMOEgdIb2MpnaD6Gzrlfee9LzEHt2b+0nCzbyWFoGO2g5SRdCQMurClVHgkUJHoOZLh/tjW+u1kghFf0PK5RaSmZbTKpNXzcIpZgOrVNt+HtUlmeObllfcSd1E7uWpL5z04YKWj5bes0Vvk6esYLg7ybG/0Cf8VZwRUQPQfFvCOau2LFF1Zd54WJT5Z9DrRhiov5KW5DRe4kwjCL9durq/YW07ctB4TF5g== 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=MvzcU4lPj7OU+Y9IuchDVapPQwkUp3HHBcVB7RPa58c=; b=UPvGdbIB5nan/e3tyoy6uvCKdZMSSio++c10Q347rtIg6Pw1kBNZyDD7bVmspQSA5Aaz3tqK2vgZXkBMoRIVXF0pxfUWH2vc4mTg7x9Ay+soSy0+QfO1r1vooBTFcQgHgX2fjohKJMVg7v1BgscyuaQA5ZfwIeoCxsf7KQV14AuBf3DPjijwYwWXPETFdHXeCDeZVboLz2SGmB5AZBIsbnRyxFwO/VpQCo4MwIEv8Tli9D465pBWgmnkmBeYC3sYb3ZcIywi3woju0/g1zlmdAcURfEZt6df/N38AKndZSfbfrOEY2p1bUBox/mpm8sOIweNUmIXWyzgtxp4QnLaRg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AS8PR08MB8112.eurprd08.prod.outlook.com (2603:10a6:20b:54e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.22; Mon, 22 Aug 2022 09:05:37 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%7]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 09:05:37 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v5 9/9] parallels: Replace qemu_co_mutex_lock by WITH_QEMU_LOCK_GUARD Date: Mon, 22 Aug 2022 11:05:17 +0200 Message-Id: <20220822090517.2289697-10-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> References: <20220822090517.2289697-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0088.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::16) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ce13406-9113-4447-db03-08da841d7a47 X-MS-TrafficTypeDiagnostic: AS8PR08MB8112:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8RkUXvJEh6ZiWRKKGgOB0MqsivigW72ZPepuZ28pUeqQoXNm1SJt1bpAWx+SLyYnVaRWjdRdo7jFYNQzMLT+upr2uNQ5ir6TDoW37z6N8LDXn9c8X6k0tk6UYmcwUN6OFJ9YZthYvKIucdPl2GrAaJcE2X2X4PwMTkiVX8z0ST53G5xebsw0u/7UEbvhgC3dckonSRKR1I+xpOMtGLNdIUuV5DGOAbE9/Y7rWwvLiNeyDDSqFFoYsl3+og61YlPgEXgtrMA8QnrNn6ZYqqhtt2ZkkOeGE+86lOJTVGkli+aGd5LP/RvUYERyswhyWRTgx+WLLDPL0WKodtC5KCZFvytjW/vn0DvzjlPdHcRYNXxcAGhxsZh24Y4WGBDqrhHVnMOmkRR5v0jg1vZapD/s/6DRP92Va4z6sqszEAJ8dUFPVLt1xFl9UJopWeln6H0cUVACzB/9L1+yoykFag5YqLXPIySkwbrLxPtrYOIieObFf2Sa3W6uFfP/8aFizUgI8kpzZoXYYH+Ex4V7quCVOrUcO1+9W26C+ZdoiTIpx4nZp4h2cD4YRVeXoIYavhr3IkG6hoawaUYz5puEKkqllXHmZUEaTSS0TnaAvjFGE4cTXpcloee8aesO2Mo26dThxyIPenSnutTdCRcqPguolmZVlh/xT0FIDW9PTFYB7U2j1YIi/ip31UqcTh6fMbFUDUn+AWN4DK20rP6Z8I/IPu/m5rcbnDPq8PeHhesxvRxneKF2EAXcpu+sAbmuwSGiD2yV3qxh1atDs931nX1vpA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(346002)(376002)(39840400004)(366004)(136003)(396003)(83380400001)(38100700002)(2906002)(38350700002)(66476007)(66946007)(478600001)(6486002)(4326008)(8676002)(66556008)(1076003)(6916009)(44832011)(6666004)(186003)(316002)(8936002)(6506007)(26005)(6512007)(52116002)(5660300002)(41300700001)(36756003)(86362001)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: H/RwBLlLxt9uSlKRHiZ+5/5PQEalnf3E6raM7USTEj6x32x/c4Q6ZHreKRN2DDpJiGyrqpqVeReiNtBh1nTZVrNPPI/01b5rVf/8e3OXyjco3fPtttkcZR+mR+dHvVYsZFmW9q7d5vE1KdSUX4jkmawzdDRhBPjSNTCG5NRSORTnFHq8OYFJ8VVqv4rfDLUZ9KiCW1mNlCtox+ahnFfUk3MNDSgz2G2wYTCMmoeNe3SgC+tUyJo5KYafc+IMmeyxgvBinTSLk92lKxAPbrL8DjAbdBiK1y/PQcUYWF5MPAM3uhu18axEvAIN9yEz7uEeqX1QmSQbWKYq82sDKSHJSHCAbjESoRd3MrH9mK7kckBd112ypNXULW3ki3NriKNjaFSIG4cpyPcadsNVX2I5k8ghs6gcuDXW5BWI/9aSB/xZQAedD9FWorDT7YBU5w9sy0QXiY/PaKPD/DoChaXavXga09Sav+p3LN4KH57LDLIW0ftxQkz6WdyClG19zJ2zGn1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Z8TDcl86uP0QYpYLg1hO1rDW4YF4Zi6n51zdts= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ce13406-9113-4447-db03-08da841d7a47 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 09:05:36.9605 (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: uuYTPj54uXzrgKkkTWEJNhhAxxp2GQ39yZm/0OSrHlHrj55YqsKHdwxZP5M3JN1tgM2ecGPMPVMrQhsI9JIjEYc3FotnYT2Rp/cdeSbW/Jw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8112 Received-SPF: pass client-ip=40.107.5.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replace the way we use mutex in parallels_co_check() for simplier and less error prone code. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev --- block/parallels.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 0fe6dd3237..47ef25b193 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -563,30 +563,25 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, BDRVParallelsState *s = bs->opaque; int ret; - qemu_co_mutex_lock(&s->lock); + WITH_QEMU_LOCK_GUARD(&s->lock) { + parallels_check_unclean(bs, res, fix); - parallels_check_unclean(bs, res, fix); + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + return ret; + } - ret = parallels_check_outside_image(bs, res, fix); - if (ret < 0) { - goto out; - } + ret = parallels_check_leak(bs, res, fix); + if (ret < 0) { + return ret; + } - ret = parallels_check_leak(bs, res, fix); - if (ret < 0) { - goto out; + parallels_collect_statistics(bs, res, fix); } - parallels_collect_statistics(bs, res, fix); - -out: - qemu_co_mutex_unlock(&s->lock); - - if (ret == 0) { - ret = bdrv_co_flush(bs); - if (ret < 0) { - res->check_errors++; - } + ret = bdrv_co_flush(bs); + if (ret < 0) { + res->check_errors++; } return ret;