From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11023134.outbound.protection.outlook.com [40.107.159.134]) by lore.virtuozzo.com (Postfix) with ESMTPS id D0B45802A5 for ; Wed, 30 Sep 2026 11:17:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JXVk+JPNqEPrzDJt3NMai3oLazl42g6lQJf1oehEr5IgLBwuAryf5eUfy1K5mMwu1SIU/NFsBDSZ2A3rkACZX0icOlUzfITBKvFJ4pnKOC+Hi6vQIsyiRTkcAqTNBb13rV43LLS5rXT5fDWUulvpzR7ojBVDkAY967IvbG37Jr7ZziL2tYpmlJdZ2cyifOW2dyPP4Xi/t0qdlr36quqYgJpEPvchWhb4ViJr4tjldJPObyRwYzZHLulYaP2usTGmb2DU4qCHAZDWUIHBV5nX4ZjojwKrhB9r3VfVu+C6cYpIUbERIsus7/vnQbQjnPrHsITqwiDQW908o6apRjPV3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Xoekckfgh6I8beqUKXt9Czn5NJH9uWWK2HFdRba0lSA=; b=BlEl7B7eirQzmpkyyYPriOKpU2VXkTZ6S+HoYy7YVNBkDp4EeEYeIi5vEdxbd6RBPyR7/i/9hbh93+K6kKzRJxIHRjJKHfkazUr4kGKwfRCk/hpNRD21V0DfP9+WSuVbzgcDpcMqasLQ8Ujf+/nH2Kgm/auMDHNTgAJ7W1Gk05nGQcCld84zRxHRQv2F3HhcEhep5ZQtRiLhFx5M2Y/hTBOwoXHsw4HCAA7AaRM+JSU4Tzf1QaVKEBmIaKLtxJCBDxr+p2kncCk1ze+u1gTAXX15pfmTMcWBo5koeQykkX62C5fhDz4xbkxOPp+w9xJ75k1v2skKUXo2C+hBEA+qBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 2a00:1450:4864:31::10) smtp.rcpttodomain=virtuozzo.com smtp.mailfrom=openvz.org; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=openvz.org; dkim=pass (signature was verified) header.d=openvz.org; arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.onmicrosoft.com; s=selector2-virtuozzo-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xoekckfgh6I8beqUKXt9Czn5NJH9uWWK2HFdRba0lSA=; b=MZUDT80Ux4iVeCCJTCOSGgQKdtmioYttWboWkokOrKLjAMV8v9VLKK9puBBms9lW+ZJgQqklwmcpf+1T5PGsP0e6XFIScH50z0ZPAmpFUpNwIzCMxHVmhlSN7zNryE64J1YJfXGl9+dXVsHWTKnjeFrUdAvgFeA2c+mZIxXtM1s= Received: from DUZPR01CA0084.eurprd01.prod.exchangelabs.com (2603:10a6:10:46a::11) by PA1PR08MB613562.eurprd08.prod.outlook.com (2603:10a6:102:54a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.472.15; Wed, 30 Sep 2026 11:17:54 +0000 Received: from DB1PEPF000509FA.eurprd03.prod.outlook.com (2603:10a6:10:46a:cafe::40) by DUZPR01CA0084.outlook.office365.com (2603:10a6:10:46a::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.472.16 via Frontend Transport; Wed, 30 Sep 2026 11:17:54 +0000 Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 2a00:1450:4864:31::10) smtp.mailfrom=openvz.org; dkim=pass (signature was verified) header.d=openvz.org;dmarc=pass action=none header.from=openvz.org; Received-SPF: Pass (protection.outlook.com: domain of openvz.org designates 2a00:1450:4864:31::10 as permitted sender) receiver=protection.outlook.com; client-ip=2a00:1450:4864:31::10; helo=mail-wm2-x10.google.com; pr=C Received: from mail-wm2-x10.google.com (2a00:1450:4864:31::10) by DB1PEPF000509FA.mail.protection.outlook.com (2603:10a6:18:3::6d4) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.472.14 via Frontend Transport; Wed, 30 Sep 2026 11:17:54 +0000 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49fff6f0f87so25684765e9.3 for ; Wed, 30 Sep 2026 04:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790767073; x=1791371873; darn=virtuozzo.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Xoekckfgh6I8beqUKXt9Czn5NJH9uWWK2HFdRba0lSA=; b=QW35hXUab6XuP4Spi2t6OaeQNC7hc7M9cWMyXMhOoYPqFCEvkLDgicTADYhh8xihLJ NcK+OA/rU5K/BLU4rRtLdBerTx9MkVJVFhkeRCWg2CTKed/5ezsOoUogRrsQ0+inGljN mbqht7K57bmT7qqZ52mafljjUVuMb7zcoGtMZycv/BD60yTL1IIGtKM1Ju/D/44KYLzr gwTAoWMKBxQeg9E9zdbx45aCYDXPj76QMhLkbYx0j8Yo5tddu6BXcLZJzjz22srd0eoY wk/JCJZXJsYZ7ZcGJak0lJ7UJLyD4D7AtXqsb5BS5aDP7T8ZswLvSEYdBtdFeSI/Fm5Y B3yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790767073; x=1791371873; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Xoekckfgh6I8beqUKXt9Czn5NJH9uWWK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 5b1f17b1804b1-4a01afe8735mr14576905e9.18.1790767073241; Wed, 30 Sep 2026 04:17:53 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01cd002bcsm3092365e9.4.2026.09.30.04.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 04:17:52 -0700 (PDT) From: "Denis V. Lunev" To: svt-core@virtuozzo.com Cc: andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH hci-8.0 6/9] block/block-copy: extract block_copy_set_task_method() #VSTOR-134085 Date: Wed, 30 Sep 2026 13:17:36 +0200 Message-ID: <20260930111739.3866427-7-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930111739.3866427-1-den@openvz.org> References: <20260930111739.3866427-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-EOPTenantAttributedMessage: 0bc7f26d-0264-416e-a6fc-8352af79c58f:0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509FA:EE_|PA1PR08MB613562:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a93fbb8-40a4-492a-5d5b-08df1ee4790f X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 0 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|43022699015|376014|61400799027|6059299003|48200799018|82310400026|9140799003|55112099003|18002099003|22082099003|16102099003|56012099006|10067099003|5063699009; X-Microsoft-Antispam-Message-Info: cBWZOPJBSBB1Aothj1R8k6KJm0jHDjQCnSdz+lpdoWeA+tj8/bCldrv7CVILB3oNCR1trUpzw2oigBZ+2+XHTnS5yvKBxhxR9Z1cg+gzN3ls/2hiJZ5BxZLJTm0ROcodVoBM1rnptkNo7+m8Rooa+MnfMzrpQddQJnOf5OmoLPAraTL8NcvWIdOdOhrAM2wOzJjMlmi5OhNFg60R5dqCfPogy87ur/e9asWVfZCVKTxypGsh4hztPjLnOCoZwT7Ao6n6aFSdnYtgxjgrAiX7y3Pe0x1AGBkkYXnIIKZ+TiF8PxipkDMJ7AdK779HLXptqmUEn0wkrsIyPe7kroGSMg+KWQK5Gc33SbJ7dNZaV6G97Lq0w5tPSDoPAh4TRzqqsOszRRx5jCI6urs6y7ICqrwe+hNatuZpUlS+LWms8r8IazxjiU3v2eWNV5f57rfOB+//l0+I8RqDA9cGlstI0rJiG1+Z//vjEcJX4sCvtrJ6agzDKD8RaOnQ1a9Iib0iwCqIRgqTCp7dablcH1qPe2rh15cjL7h41TFB67jow4nOW9jW96JyRcSOaIAYPEaOS5uqI2kVWBHqKsieMcWRD80lWLK3ji0NoU1TRuuzxxL4O0AFb0APuGgu3MRS+Vp/eCzNCjuB0eGo+5lP39LlWQo9uajNrn5ddgzKFt9NL0A0tLxSu6obNL0QK+e/A7vFuB7R2n/4FioysK+4oc6kxOwV0elyGXcxox7p1EdsS/XWcw/8KVI/Ilz2tcLzcH+8rJ6CcirwQDJBbou3yqTXDBsJ7ZjuHpeqAyKVQoQvasSeaaFi27dXCwE0uZbH6XmmHjcGRdrr5jMQtnJGwZD8hwDXa2zYAB8UTay34p5z9NBcQleVuW7OCcCGW8s8RAzuGIWvAjaNn/mpGp/SfBu81rpYdLLsz04lvqz/V4FSs1+zbPsCvFlJmLZ3ouisJM58 X-Forefront-Antispam-Report: CIP:2a00:1450:4864:31::10;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail-wm2-x10.google.com;PTR:mail-wm2-x10.google.com;CAT:NONE;SFS:(13230040)(43022699015)(376014)(61400799027)(6059299003)(48200799018)(82310400026)(9140799003)(55112099003)(18002099003)(22082099003)(16102099003)(56012099006)(10067099003)(5063699009);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: X/9cNGvsug0tupqO8Rcfyf7IEQpRO3j/yJOLjKYASxromOTA2XfPyOzJjBLONBHCjBIJAt7Jc2taN5225+nLmBmtgrUdkIUY44BfvRBrIT8RfinFAFoAd3UVwoVP0IZYtT9BkrxagWzC0cemL6J5GtfP5C6gAkhPr3YTVu/BkcMMTRxWkkuSKySqf72NdeE++6r181LfwHoJyL5+c7YVkcKaX05jP0KclaxcH8Us443SVI5aukJaD5fsau/qn2Q2DY4TwGP5GueVS1dGDDeqWsn3DQ7Jfc/W0LnUqImvCJllOotDE7nuWtcXn/kZldOOfH2A9AL9yCQOu2rEUOEpWIB23eQzsLlC0YBxGA5XzYkYJExjtBnu0NUylSOMGa3jdd34cPgNnMTnha9ErKhktBbwR9yPmMYMD4IjknUPx7xqVLeHXE1K06q7KdaWFUs5 X-ExternalRecipientOutboundConnectors: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-Auto-Response-Suppress: DR, OOF, AutoReply X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 11:17:54.1942 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a93fbb8-40a4-492a-5d5b-08df1ee4790f X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509FA.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR08MB613562 List-Id: From: Denis V. Lunev Move the per-task block-status query and its skip_unallocated and BDRV_BLOCK_ZERO handling out of block_copy_dirty_clusters() into block_copy_set_task_method(). No behavior change. The next patch changes that decision, and having it in one place keeps that change to just the new logic. The block-status result no longer lands in the caller's @ret, so drop the note saying @ret may be positive at the out: label. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev --- block/block-copy.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index aecbe0c16ab..e210688b1df 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -780,6 +780,35 @@ int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s, return ret; } +/* + * Decide how @task is copied: COPY_WRITE_ZEROES if it reads as zero. May + * shrink @task. Returns false if @task is to be skipped (already ended, + * not freed). + */ +static bool coroutine_fn GRAPH_RDLOCK +block_copy_set_task_method(BlockCopyState *s, BlockCopyTask *task) +{ + int ret; + int64_t status_bytes; + + ret = block_copy_block_status(s, task->req.offset, task->req.bytes, + &status_bytes); + assert(ret >= 0); /* never fail */ + if (status_bytes < task->req.bytes) { + block_copy_task_shrink(task, status_bytes); + } + if (qatomic_read(&s->skip_unallocated) && !(ret & BDRV_BLOCK_ALLOCATED)) { + block_copy_task_end(task, 0); + trace_block_copy_skip_range(s, task->req.offset, task->req.bytes); + return false; + } + if (ret & BDRV_BLOCK_ZERO) { + task->method = COPY_WRITE_ZEROES; + } + + return true; +} + /* * block_copy_dirty_clusters * @@ -812,7 +841,6 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state) while (bytes && aio_task_pool_status(aio) == 0 && !qatomic_read(&call_state->cancelled)) { BlockCopyTask *task; - int64_t status_bytes; task = block_copy_task_create(s, call_state, offset, bytes); if (!task) { @@ -826,24 +854,12 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state) found_dirty = true; - ret = block_copy_block_status(s, task->req.offset, task->req.bytes, - &status_bytes); - assert(ret >= 0); /* never fail */ - if (status_bytes < task->req.bytes) { - block_copy_task_shrink(task, status_bytes); - } - if (qatomic_read(&s->skip_unallocated) && - !(ret & BDRV_BLOCK_ALLOCATED)) { - block_copy_task_end(task, 0); - trace_block_copy_skip_range(s, task->req.offset, task->req.bytes); + if (!block_copy_set_task_method(s, task)) { offset = task_end(task); bytes = end - offset; g_free(task); continue; } - if (ret & BDRV_BLOCK_ZERO) { - task->method = COPY_WRITE_ZEROES; - } if (!call_state->ignore_ratelimit) { uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0); @@ -884,8 +900,6 @@ out: * block_copy_task_run. If it fails, it means some task already failed * for real reason, let's return first failure. * Still, assert that we don't rewrite failure by success. - * - * Note: ret may be positive here because of block-status result. */ assert(ret >= 0 || aio_task_pool_status(aio) < 0); ret = aio_task_pool_status(aio); -- 2.53.0