From nobody Sat May 18 17:34:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1588166014; cv=pass; d=zohomail.com; s=zohoarc; b=YHrv5Im6j81Yv/wxGosTlJDa80ldVWaSttDoHNqmku2qcNqj5kAYanSDPCoMl+PTCErGXP8AEIHVYUWmnqB9JPNod7lUMLOjqno55cu8Q59d7c9eMWw2Uta/Vb44CJGxOJ0+uHphuxEsere+20jscxbd34SKMQBiix0ib3FctvA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588166014; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ln4J+gXgYopBJjdwMRlDdnwd0zyUvPHCA7EC1VSZv4A=; b=JL+H1DIeW8F1IzMHoqUTzGr/1YHUMoi5t6flHnK445SZEbgV+icgNG2kj4wLfrm6SdT+cLEY8fk6gihpshGg0hrQUYnCW8G/kdssklx9o3Ij8Bo5w69xCnXTImPnCbD29uUAZyRI0dlnDAE9i/Z2LIq2Kc0z6sQDMkoA6Cf8s7Q= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588166014110432.73086264074084; Wed, 29 Apr 2020 06:13:34 -0700 (PDT) Received: from localhost ([::1]:51484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmWq-0002HJ-No for importer@patchew.org; Wed, 29 Apr 2020 09:13:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34750) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmV7-0007wi-U4 for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTmUz-000856-Nm for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:45 -0400 Received: from mail-eopbgr80118.outbound.protection.outlook.com ([40.107.8.118]:18917 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jTmSl-0007bZ-5z; Wed, 29 Apr 2020 09:09:19 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5446.eurprd08.prod.outlook.com (2603:10a6:20b:107::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Wed, 29 Apr 2020 13:09:14 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.023; Wed, 29 Apr 2020 13:09:14 +0000 Received: from localhost.localdomain (185.215.60.184) by AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Wed, 29 Apr 2020 13:09:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sg/RfQQGADZFpnrUdCQ76VDlmjxpmS54qYgTky5fCLVTdQlstlVCPui15227zRqMuaxgsa7Yya+bkQb5isjefPMqhDt68U/l6/ThBUDTsSMkz7J1Yqwer3o7VrTxVA0DZ809PqdgVrCS1BtaoshHZ7Yfs7jbuRmWsLhwKn53xuM9W07K9NByFIkYKSSJOjmhBAaxiUCeYnUq6ayS3dCuMxL9w1n28DQ+YOTVolVoZTa/gwXlPf9PZOV9Yv040i41gS0cgiMddRzDqT3/oU8kK58DjuuuBlvduqvZzSGpG8S41JhxeDAI7/2rP1f6PFz9cNDEMyKQWl1GkLzMLl5xGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ln4J+gXgYopBJjdwMRlDdnwd0zyUvPHCA7EC1VSZv4A=; b=AZ1bW8khu5js54fwEw1Pmj7kq4rezTmvtvDCh9//tKmNBqvOGsotATb2Fm9oXQMqlLykQBSNfSaNwJ/xzD/auWf/iWr0v8AFSaM7xBG7448Mptnw5qUIe+inHE2VqRENN7yc/bw0eC+qJhIuDXyC/A+RPEOWcnZ4+4ZPYdXYK1l/2l70QxzFIUvBBM9j0tz0kM4tjjIxkQ4dCLzSSYMC5WS4ZyAzzROLyGhz3+zyTH9t67hT1UsJcORwTnNSP0wcpxSfaZlv9FZ9l15FLfIMy0rrP4/lxVWYlFs1K6iRD0uEF7eM7jFndyS2nV2RQXf4eq5wR9sYHK2bfggGGNM6/w== 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=Ln4J+gXgYopBJjdwMRlDdnwd0zyUvPHCA7EC1VSZv4A=; b=qPSQWEgKxrUByXvo1DgJM41BUw0YYPTFtQ49a5Kxg5B9oAKbzts1Y+f4WdvLaQmIlnngTmkjpjuEpL14HnNon5Qsz3iqJy/z49KJFjFs3U3w9DA0Y+07dcWhysbHOALLWxleSmJabl/e7UKhGVNKyfk0UyT6IQk+Hcp7denKmyo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 1/5] block/block-copy: rename in-flight requests to tasks Date: Wed, 29 Apr 2020 16:08:43 +0300 Message-Id: <20200429130847.28124-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429130847.28124-1-vsementsov@virtuozzo.com> References: <20200429130847.28124-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.184] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a86e1e9-bda0-47cb-f04b-08d7ec3e8434 X-MS-TrafficTypeDiagnostic: AM7PR08MB5446: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:345; X-Forefront-PRVS: 03883BD916 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(346002)(39840400004)(366004)(396003)(8936002)(16526019)(2616005)(107886003)(6512007)(66946007)(66556008)(66476007)(316002)(36756003)(6486002)(52116002)(5660300002)(186003)(6506007)(26005)(4326008)(956004)(1076003)(69590400007)(478600001)(6666004)(86362001)(2906002)(6916009)(8676002)(334744003); DIR:OUT; SFP:1102; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fJv9zj73vA8sBV0w2lTuOJFaozCoTrSiKiEOVOvoe3aDkOYFoEo/2ZtPlrgvSDA2PiD1pM+hHyMT+AAIUMew8+1K9FxuQ/V3aIJ+kPcwwxyMSxR+dfw6Q4u56gPYPrgGHgJWeiibSuvSE+avWP+TYuVemF+/eyEKWmm1Pvn/sJXmdH/VUuFnVX5lbvdMcNK1QGF0C+xwqCc8pEE6pNjVg9WROL2xiIzgvpOoFl0PKNchk3ppBZCC+cewPPosjNIKStkBLFnJe4j150dtBSfftQ0sTRmDPodghylzw5OAZW13YP7jjPMfYky+e7EhSugiKQ7e8DI/XnX7UEO4ez1qlCSj5nHvo+OO1myv1dwgGo9PPgCnZDaRIbVBLWBn09pPJb/YAP1f1VpVbofkBu/dwPehgXchmVMvDINS0YiIAYe1spUKUUu1Jzoq5f3qmAgNtKrA3DcncKF2be2SzA73/JE1PxhKD9pxx654GqYu8T0GLC6SiU5QWt80aeJwnl9YhCq1JO6IkhRZT4jKRib8IA== X-MS-Exchange-AntiSpam-MessageData: +OgWoYx522ExxDaJCvLVldO0xBA8urvKJ+2smOWA5XoPyN/Lt7cw3EcQk63H8X6S63+Zqp85LYnNIPHtui/3gqUMHV6Y+vC0jEp5arS9E36iSTtyVTHrJI3UrthCkAw+eHBNZ8OhG1C/t22cQPX5at7lt7NmCQS9Ile1EIbD3VrTWlqOTowEFn1zURbThtGYbTHLwmnXLJpTenEBycuLTIuN3m27IOAFf8Kl3dv1IxMimhJFKvYCKMfoSfHNUE4ow5Uxxl+MQOhWaAIfzBEG5x703FNO7rkezjYEzkbjWh5pmmuL1FwbrqSR3lCG5OW/yWLKzSzAF3jLjmUe1eBuGQUZJOf+ErMSDtyjF6UH/U9VPqSv1z4wZ+GlJxkVIB/vlvph74SE3rcJ3DNWpiwYKLSuCh8WOvGPoUUC+AAjPRD6KI8PFNth4sjkBIZpH9tgox+2MZRcBzB0MOr4fgjXC23U5NobW9H6bTysMcJpLH5SxKnGtjfFcYfElsEcOvS/yz54wVipiK2x7NwAsKjmIrVBAAK042jF94UUdXv3sJ7KonLbFNQhjKZZX5QWQZXim1u7AVHqPrp7JU7UE+OW3ecPPal5Ho1Jx9l7ng8FT2yuISIU7wv+note5To7s8gyp/pPrza/fYQpWhTz5wW1H8eiGP9KREpvHqltS1N38Ct+Y8JzmLic+gUFNmorxKeZVTVqMYEKAOLT95nBKJVn8K9g3gYN+XE+Q0xskD6aO0i/XDukpp67Id74GUdc9YXgnz952O5G93b4VAPN0EwGrscS80k+aWBxktBbl5MHpDk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a86e1e9-bda0-47cb-f04b-08d7ec3e8434 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2020 13:09:14.8235 (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: 8UXx2O8bKsTrCKiPznLailH0HERgI0+rQlDExTXyez9fX7oIilJR7xHWFW6upOm5J+3k/k8FRxqO/QPy5i7PFTJP9KE/co/RL3c8v/Joc7A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5446 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.8.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 09:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.8.118 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We are going to use aio-task-pool API and extend in-flight request structure to be a successor of AioTask, so rename things appropriately. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/block-copy.c | 98 +++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 05227e18bf..bbb29366dc 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -24,12 +24,12 @@ #define BLOCK_COPY_MAX_BUFFER (1 * MiB) #define BLOCK_COPY_MAX_MEM (128 * MiB) =20 -typedef struct BlockCopyInFlightReq { +typedef struct BlockCopyTask { int64_t offset; int64_t bytes; - QLIST_ENTRY(BlockCopyInFlightReq) list; - CoQueue wait_queue; /* coroutines blocked on this request */ -} BlockCopyInFlightReq; + QLIST_ENTRY(BlockCopyTask) list; + CoQueue wait_queue; /* coroutines blocked on this task */ +} BlockCopyTask; =20 typedef struct BlockCopyState { /* @@ -45,7 +45,7 @@ typedef struct BlockCopyState { bool use_copy_range; int64_t copy_size; uint64_t len; - QLIST_HEAD(, BlockCopyInFlightReq) inflight_reqs; + QLIST_HEAD(, BlockCopyTask) tasks; =20 BdrvRequestFlags write_flags; =20 @@ -73,15 +73,14 @@ typedef struct BlockCopyState { SharedResource *mem; } BlockCopyState; =20 -static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState = *s, - int64_t offset, - int64_t bytes) +static BlockCopyTask *find_conflicting_task(BlockCopyState *s, + int64_t offset, int64_t bytes) { - BlockCopyInFlightReq *req; + BlockCopyTask *t; =20 - QLIST_FOREACH(req, &s->inflight_reqs, list) { - if (offset + bytes > req->offset && offset < req->offset + req->by= tes) { - return req; + QLIST_FOREACH(t, &s->tasks, list) { + if (offset + bytes > t->offset && offset < t->offset + t->bytes) { + return t; } } =20 @@ -89,73 +88,72 @@ static BlockCopyInFlightReq *find_conflicting_inflight_= req(BlockCopyState *s, } =20 /* - * If there are no intersecting requests return false. Otherwise, wait for= the - * first found intersecting request to finish and return true. + * If there are no intersecting tasks return false. Otherwise, wait for the + * first found intersecting tasks to finish and return true. */ static bool coroutine_fn block_copy_wait_one(BlockCopyState *s, int64_t of= fset, int64_t bytes) { - BlockCopyInFlightReq *req =3D find_conflicting_inflight_req(s, offset,= bytes); + BlockCopyTask *task =3D find_conflicting_task(s, offset, bytes); =20 - if (!req) { + if (!task) { return false; } =20 - qemu_co_queue_wait(&req->wait_queue, NULL); + qemu_co_queue_wait(&task->wait_queue, NULL); =20 return true; } =20 /* Called only on full-dirty region */ -static void block_copy_inflight_req_begin(BlockCopyState *s, - BlockCopyInFlightReq *req, - int64_t offset, int64_t bytes) +static void block_copy_task_begin(BlockCopyState *s, BlockCopyTask *task, + int64_t offset, int64_t bytes) { - assert(!find_conflicting_inflight_req(s, offset, bytes)); + assert(!find_conflicting_task(s, offset, bytes)); =20 bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); s->in_flight_bytes +=3D bytes; =20 - req->offset =3D offset; - req->bytes =3D bytes; - qemu_co_queue_init(&req->wait_queue); - QLIST_INSERT_HEAD(&s->inflight_reqs, req, list); + task->offset =3D offset; + task->bytes =3D bytes; + qemu_co_queue_init(&task->wait_queue); + QLIST_INSERT_HEAD(&s->tasks, task, list); } =20 /* - * block_copy_inflight_req_shrink + * block_copy_task_shrink * - * Drop the tail of the request to be handled later. Set dirty bits back a= nd - * wake up all requests waiting for us (may be some of them are not inters= ecting - * with shrunk request) + * Drop the tail of the task to be handled later. Set dirty bits back and + * wake up all tasks waiting for us (may be some of them are not intersect= ing + * with shrunk task) */ -static void coroutine_fn block_copy_inflight_req_shrink(BlockCopyState *s, - BlockCopyInFlightReq *req, int64_t new_bytes) +static void coroutine_fn block_copy_task_shrink(BlockCopyState *s, + BlockCopyTask *task, + int64_t new_bytes) { - if (new_bytes =3D=3D req->bytes) { + if (new_bytes =3D=3D task->bytes) { return; } =20 - assert(new_bytes > 0 && new_bytes < req->bytes); + assert(new_bytes > 0 && new_bytes < task->bytes); =20 - s->in_flight_bytes -=3D req->bytes - new_bytes; + s->in_flight_bytes -=3D task->bytes - new_bytes; bdrv_set_dirty_bitmap(s->copy_bitmap, - req->offset + new_bytes, req->bytes - new_bytes); + task->offset + new_bytes, task->bytes - new_byte= s); =20 - req->bytes =3D new_bytes; - qemu_co_queue_restart_all(&req->wait_queue); + task->bytes =3D new_bytes; + qemu_co_queue_restart_all(&task->wait_queue); } =20 -static void coroutine_fn block_copy_inflight_req_end(BlockCopyState *s, - BlockCopyInFlightReq = *req, - int ret) +static void coroutine_fn block_copy_task_end(BlockCopyState *s, + BlockCopyTask *task, int ret) { - s->in_flight_bytes -=3D req->bytes; + s->in_flight_bytes -=3D task->bytes; if (ret < 0) { - bdrv_set_dirty_bitmap(s->copy_bitmap, req->offset, req->bytes); + bdrv_set_dirty_bitmap(s->copy_bitmap, task->offset, task->bytes); } - QLIST_REMOVE(req, list); - qemu_co_queue_restart_all(&req->wait_queue); + QLIST_REMOVE(task, list); + qemu_co_queue_restart_all(&task->wait_queue); } =20 void block_copy_state_free(BlockCopyState *s) @@ -223,7 +221,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source,= BdrvChild *target, s->copy_size =3D MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER); } =20 - QLIST_INIT(&s->inflight_reqs); + QLIST_INIT(&s->tasks); =20 return s; } @@ -474,7 +472,7 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); =20 while (bytes) { - BlockCopyInFlightReq req; + BlockCopyTask task; int64_t next_zero, cur_bytes, status_bytes; =20 if (!bdrv_dirty_bitmap_get(s->copy_bitmap, offset)) { @@ -495,14 +493,14 @@ static int coroutine_fn block_copy_dirty_clusters(Blo= ckCopyState *s, assert(next_zero < offset + cur_bytes); /* no need to do MIN()= */ cur_bytes =3D next_zero - offset; } - block_copy_inflight_req_begin(s, &req, offset, cur_bytes); + block_copy_task_begin(s, &task, offset, cur_bytes); =20 ret =3D block_copy_block_status(s, offset, cur_bytes, &status_byte= s); assert(ret >=3D 0); /* never fail */ cur_bytes =3D MIN(cur_bytes, status_bytes); - block_copy_inflight_req_shrink(s, &req, cur_bytes); + block_copy_task_shrink(s, &task, cur_bytes); if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { - block_copy_inflight_req_end(s, &req, 0); + block_copy_task_end(s, &task, 0); progress_set_remaining(s->progress, bdrv_get_dirty_count(s->copy_bitmap) + s->in_flight_bytes); @@ -518,7 +516,7 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, ret =3D block_copy_do_copy(s, offset, cur_bytes, ret & BDRV_BLOCK_= ZERO, error_is_read); co_put_to_shres(s->mem, cur_bytes); - block_copy_inflight_req_end(s, &req, ret); + block_copy_task_end(s, &task, ret); if (ret < 0) { return ret; } --=20 2.21.0 From nobody Sat May 18 17:34:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1588166003; cv=pass; d=zohomail.com; s=zohoarc; b=NGsBREC1Qz37O+s85JOje1xnTy/jrSwrRMU1mGugGmnRYk0L1+Q8xHDYjcZWNd2AEphzHHcxWUVNVHz0tm48cDOxulCQgHtzP65qkqtSaHtRQkhYbB6ykhMsNqFOOhjtcXUoe076b9iUbaJ8E35vgWgQshyHC4CISHUKnFVOvMU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588166003; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FseS9y9dE4GNUMXB/bqW54x6DCElqlOU+2wOmVvQJdc=; b=hFA2BoUZd6KnzKHhbNkKzm0Dqhn7qImhEbYkopbNX+jhTgS2LiyeJUWlV1P2E96JwZhmiEMonXad0x6t7txuvK6LLeFHRbEgO/gKYRIs6SsbVVoqMdOdGiBwmuKIZYV143O1cNKnl8KcbJxcRKXE8q5Z9wYN04L2cBW+t0ywOQs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588166003905878.8856641830643; Wed, 29 Apr 2020 06:13:23 -0700 (PDT) Received: from localhost ([::1]:50606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmWg-0001mc-BN for importer@patchew.org; Wed, 29 Apr 2020 09:13:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34756) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmV8-0007xp-Gr for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTmV0-00085D-7p for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:46 -0400 Received: from mail-eopbgr80118.outbound.protection.outlook.com ([40.107.8.118]:18917 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jTmSm-0007bZ-7J; Wed, 29 Apr 2020 09:09:20 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5446.eurprd08.prod.outlook.com (2603:10a6:20b:107::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Wed, 29 Apr 2020 13:09:15 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.023; Wed, 29 Apr 2020 13:09:15 +0000 Received: from localhost.localdomain (185.215.60.184) by AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Wed, 29 Apr 2020 13:09:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VtgyVtESb2QJEJ287jLp4SzE6tbel41MKaCwG8ZO2/d6yDxHPBpZ5gVMx8fKE7C7oX/nEIZjhy0urp7DRb744iwKD/s8Hh7H9fsz6MKEAFGLh/q9gkXEZ+Q/VBYhfsYV0wcNSMTGkwlwKZQxFt8iJM7V/0djPFU4djCIQiofHRJXBzn7B2iADiWnezPeMpsOOjb2B0vmsYaVe4gC3OgsHpU+sQiY10pUa0HGBkPO/5jImweFa/YxuhfD+RqiU7yb9dZ9t9ipSGHh9ARf7grnzm73YEZmfeR4iwzOvVVEOvuHIa601GzmLQrRGh3i1BEqXWiv+cJJN26pkh3ynT+8YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FseS9y9dE4GNUMXB/bqW54x6DCElqlOU+2wOmVvQJdc=; b=ASlW30wN3lLx4pVyIxJMw5GnKmsQ7UmQRh/WAp7s2S0QoBhFGW4eoGkFXL/Mu5gMmgz1YR+smgWTVM565S11Pf4qhYuZoT2Q1WKs+UjDw+A5MR15HANKRBF81vz4hc9evQeaF9ACZCi1dvCFyHJ+159iuGvtfmjqDcNSN27fSNDfU1s/pEM3XwBYE4vx2mjFQEQgVREYv8UJA4DHjTQRl/OGWkBSoZpsnWtqv10XugGibKxZSIQI98psZN+gQjLDaoFt2WKCFCOC6AMciwbTxc6yNs5ElaBxCHk+7b+aU7tctpFdRL74NalwinF5dc0OjtKzgAQsu/9r/kt1a4//gA== 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=FseS9y9dE4GNUMXB/bqW54x6DCElqlOU+2wOmVvQJdc=; b=NgS0R+QIlfYtBxedXzQn3Alee3pd9uCd0rVTljfgWCqZ98YrTaIdAP8UWu2KEtpEZGgCC7atSaWnwsQ0bgZYViNHnc7fHflJpQp0aLqLN771QERPDB2n0VUU5lQock0UwXziLcnoFkBoT42xsjYzlJjUnKrUMzlHqJ/Yi789I80= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 2/5] block/block-copy: alloc task on each iteration Date: Wed, 29 Apr 2020 16:08:44 +0300 Message-Id: <20200429130847.28124-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429130847.28124-1-vsementsov@virtuozzo.com> References: <20200429130847.28124-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.184] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30d870fa-dfce-41cb-edd3-08d7ec3e84a2 X-MS-TrafficTypeDiagnostic: AM7PR08MB5446: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:69; X-Forefront-PRVS: 03883BD916 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(346002)(39840400004)(366004)(396003)(8936002)(16526019)(2616005)(107886003)(6512007)(66946007)(66556008)(66476007)(316002)(36756003)(6486002)(52116002)(5660300002)(186003)(6506007)(26005)(4326008)(956004)(1076003)(69590400007)(478600001)(6666004)(86362001)(2906002)(6916009)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /sXK6xZ/mhHhXLRu5eA2BaVqch87W+dS+9yOkJ4ZxUFz/ASvjXZNumB1u229tWtWK2W9y5qi8IsATANc3PSX24svnS6PLmnS346mfqFgKbRaAN1HuP8AKy1IjPoiIy7+ulKsqSvXfOfyneR8yScMrG2wC4sPjQXLaF0K2mEDrpeeMXBm/VXnxC14yk/GfCu27fqDTuWDxsY7maqpqAnq4LE3TS+n7ARFPtCbXlfdpvZUguLq2N8yD+ZDqwavwiEHWRO11KVL74f25n3vOkA+Fc1e5+72q55kJcBYmyy9Rxm1Z6babma4BvI52J6AYwsuuoKO+aKBFPOfE1Ui1v7dXZ1aTP/0DvvlsRWOZ5Jn3cflV38kXKQRFQXHrkBhRTmY/twwGNMMD0HEEuGm0MyiB/lxfXyYHCBc30QC7LCmlzW6jnTUdGlXzvboUb+qUegFg2primHl9Uzbt39tw8gONzyJK6KlhYZt+qdNtgSzfSLCJRtcKGaC6apU0cEQqseT X-MS-Exchange-AntiSpam-MessageData: wHyxkz1J+JXgKXNExuMvFbtLyj5WrBOB1eT3pHmdawB0lUqauPeWGnzYGm4G9ejKC6Z0IBB+vkM5IZFI2EbS9BgTydNAbiFN488C/GJpqicbTNwJHP7P4zbUZi4zR/S9ZAJ5xZQUKE9wA6SsoGlGcZsoWF2/HNGWcXSXPmxrSQF+S5SywvZ3tj0OHwjqWOzIQMloweR8R0xlQxIDv+8gqKlvHIdhjj6Iu8AyHfCdLOjFnmPUMwRWvdRk2CTihcznPHlg+geGnJM6hlxDbOM/s1QQI0B2I1ug/IyVcQWz9NUQFtfwFAf8F0QRxCyybTnfzrE5QfxKVX4ySvPfBk7DkGv8MOf2QkW3GOwI2tbAd68W9FT9LAr4SJm5pXTUp8VbpUYiwMtzBBVj9vqihuG48vfpY6qgJiiqF/wQt+h1+mjBd41qgj40G6ttZsX3PDlovp3opJE98vejvnROee3tuaWv11kJKH1+YY1j/grNnZYYNcH5IXpgyIguRtI6bGyWBT85tCIltj829Pf3a+42TRbAsRYvWBMZql9hmuS4YXksOoVlqoZPhXVy2S33TO4zOBEQ0pEcqRbE8OlqbYXMLjMn9eSofNlF2AED2RE0K2gj/XtwV/3K2Hxs9OqEbGi/3HyKCovzlbd+DLl8AhSI+INfyttTk0KYtbzppVt8QAZwBmbWkYKYKhXx9IL1+Tt64OlEvYbwYay6FoG03mPsCclNjW0x207oO0QEdNcuGkwnfqYUa/A9BO0EEPOzL1c7kXEU/mW1mlCSwvrFuIx1sNWibBV05j2uBje5ffR/C54= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30d870fa-dfce-41cb-edd3-08d7ec3e84a2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2020 13:09:15.5205 (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: DX6X351wMGSKmqXKHTSqsA2bi6F1E5NVlGEkUCwjJa4mh1JHLDow0ewgFvHaC3ObDrLdd7hO/zAXlOckIetT5tN3wm8lNC4rnVoENkgsw8c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5446 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.8.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 09:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.8.118 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We are going to use aio-task-pool API, so tasks will be handled in parallel. We need therefore separate allocated task on each iteration. Introduce this logic now. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/block-copy.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index bbb29366dc..8d1b9ab9f0 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -106,9 +106,11 @@ static bool coroutine_fn block_copy_wait_one(BlockCopy= State *s, int64_t offset, } =20 /* Called only on full-dirty region */ -static void block_copy_task_begin(BlockCopyState *s, BlockCopyTask *task, - int64_t offset, int64_t bytes) +static BlockCopyTask *block_copy_task_create(BlockCopyState *s, + int64_t offset, int64_t bytes) { + BlockCopyTask *task =3D g_new(BlockCopyTask, 1); + assert(!find_conflicting_task(s, offset, bytes)); =20 bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); @@ -118,6 +120,8 @@ static void block_copy_task_begin(BlockCopyState *s, Bl= ockCopyTask *task, task->bytes =3D bytes; qemu_co_queue_init(&task->wait_queue); QLIST_INSERT_HEAD(&s->tasks, task, list); + + return task; } =20 /* @@ -472,7 +476,7 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); =20 while (bytes) { - BlockCopyTask task; + g_autofree BlockCopyTask *task =3D NULL; int64_t next_zero, cur_bytes, status_bytes; =20 if (!bdrv_dirty_bitmap_get(s->copy_bitmap, offset)) { @@ -493,14 +497,14 @@ static int coroutine_fn block_copy_dirty_clusters(Blo= ckCopyState *s, assert(next_zero < offset + cur_bytes); /* no need to do MIN()= */ cur_bytes =3D next_zero - offset; } - block_copy_task_begin(s, &task, offset, cur_bytes); + task =3D block_copy_task_create(s, offset, cur_bytes); =20 ret =3D block_copy_block_status(s, offset, cur_bytes, &status_byte= s); assert(ret >=3D 0); /* never fail */ cur_bytes =3D MIN(cur_bytes, status_bytes); - block_copy_task_shrink(s, &task, cur_bytes); + block_copy_task_shrink(s, task, cur_bytes); if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { - block_copy_task_end(s, &task, 0); + block_copy_task_end(s, task, 0); progress_set_remaining(s->progress, bdrv_get_dirty_count(s->copy_bitmap) + s->in_flight_bytes); @@ -516,7 +520,7 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, ret =3D block_copy_do_copy(s, offset, cur_bytes, ret & BDRV_BLOCK_= ZERO, error_is_read); co_put_to_shres(s->mem, cur_bytes); - block_copy_task_end(s, &task, ret); + block_copy_task_end(s, task, ret); if (ret < 0) { return ret; } --=20 2.21.0 From nobody Sat May 18 17:34:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1588166005; cv=pass; d=zohomail.com; s=zohoarc; b=ejchcFPeUWcYXvAW7umd8uYv7E6FfpQkzflK838DDWTAGynFUQRD0i2MK8v74MVxrf+SDdzGtXQ39M6d2Vv0E0V3hUSpEn3VjLCN3G2tET/BKRxaxLVjy4LLK6/Rs81jb83ALL7qx6nJ85eXyIi6zhZKTsBrYFMdC/5RajgDj9I= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588166005; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EbDSSgyfAn2eQ3B78rvdS9sD+o3H2ESB4pBZdgcChJU=; b=V4JReRduXz19s/Nz0zmmEdoJ7b3g0FzXKnTHaGSSKWc73Czs1LRCBZH8otjcp02gABUIWqotqp9jiHfJ3WuKI70aIgQpfhxp7NcyuUhdoTcaem6NChHxPebCbaB0m/jRk4OV4DRaV892DHxKrSw9xShU8mSHWAhmqL9hnA+xDm0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588166005152568.3985117862483; Wed, 29 Apr 2020 06:13:25 -0700 (PDT) Received: from localhost ([::1]:50710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmWh-0001xg-LV for importer@patchew.org; Wed, 29 Apr 2020 09:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34764) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmV9-0007zT-5x for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTmV0-00085Q-Oe for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:46 -0400 Received: from mail-eopbgr80118.outbound.protection.outlook.com ([40.107.8.118]:18917 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jTmSn-0007bZ-6x; Wed, 29 Apr 2020 09:09:21 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5446.eurprd08.prod.outlook.com (2603:10a6:20b:107::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Wed, 29 Apr 2020 13:09:16 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.023; Wed, 29 Apr 2020 13:09:16 +0000 Received: from localhost.localdomain (185.215.60.184) by AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Wed, 29 Apr 2020 13:09:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lr1mqp7i6oDIS8WIPp9Dro1daO8uH48jISoD5cWLVIm7OmUOJ8guaO5qCpoOgZOLgXXi74auAeoZ+xG/lH2Nyc1NSPs3BLHBbUDDWndIBsCLSdyent4Xi+Vpnsdx8XwtXN011jrjT/POZfpjpwEoObX0R9yih0GIFD1snP574aWcELI9y58RqzPMWkDa6Nlq+qCJMsD/o2a03b1vr2CgzmCHh/QVTta836hC+hSKWyKu4KAhhSHamBPbwbGFMFGwavwLuaL4oYlH4H31GUsIpoKpHTBLBb1ZfwCyHabGWAgOgDBaFOydgRmShllCQ57w+2gbkYR660YqkKfNSJrRtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EbDSSgyfAn2eQ3B78rvdS9sD+o3H2ESB4pBZdgcChJU=; b=mgPIKJS1Nj84TRyLIqrCQMcjtCA58zHyfXGZytmy9lQZCU+BvJkAZu1xcyImAq1igPGNFa3JKqD8YShN21iLEFG8vMK8+TjLbI33lBUg7LmxJnSZkqbeO8QQRTEspwu0es0fU4YQtJ2OCunipfmZFOiw+k4ZVUW8VZLzr8ZodUMpufjQBaVZsI/u1HlaDpOVmsC93di2LgtGqIByrIRS9/7aDX8ZWxbqo89UPId4pZ/JXgsDKxEpqqQ+PGpXy8jYYfFR3ofymq4Kc7XHTa6xA0j84Yi83zMnaCUeYFYAHl3b7F9r77SiNA8kHS2xHkegiy7Leml4z1O5klEQvUiQ1A== 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=EbDSSgyfAn2eQ3B78rvdS9sD+o3H2ESB4pBZdgcChJU=; b=sEMytH3tRMq0iCGiT3GZHjaLLoujx9C+zZWc+GJ7BrC6WyXSXpaqDx+D6W8PfgK9Grpv9DhmlofUW1dXTK5GMdrtVFagMLMYagWI7WRB2P6hUr4SCLNMLkB50Q4CBIqkoLRDOOjQ96/zgshnnZEhLy3VtiPvMz4dernHNrG1/es= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 3/5] block/block-copy: add state pointer to BlockCopyTask Date: Wed, 29 Apr 2020 16:08:45 +0300 Message-Id: <20200429130847.28124-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429130847.28124-1-vsementsov@virtuozzo.com> References: <20200429130847.28124-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.184] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8a721c68-2416-48a6-8d47-08d7ec3e850f X-MS-TrafficTypeDiagnostic: AM7PR08MB5446: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:206; X-Forefront-PRVS: 03883BD916 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(346002)(39840400004)(366004)(396003)(8936002)(16526019)(2616005)(107886003)(6512007)(66946007)(66556008)(66476007)(316002)(36756003)(6486002)(52116002)(5660300002)(186003)(6506007)(26005)(4326008)(956004)(1076003)(69590400007)(478600001)(6666004)(86362001)(2906002)(6916009)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N2xiVl1IbhPFZGWYP/QxpoSg+9ZUoiUG/nj6WjzdzuFUPgEX2S5B0QNwXR8AhxDGEThBo6CkULjJNRWCDw7WwtZOSf+rglBY1+hBoP7KNfcwMpTUH3GfntgF3XIySOklHfo5atBJAO4158rG+uvj4ERWqbByEFxaiXpAcXqPbX9sgj5As4oIKyaWRcZ6cEoOaiDV98L/1GVIusN9Aesj8S4h39by8bH+ul7Dok20NumSad8lhCsfpp3UiKW5dNS7n8yK1hbhJRDiINCpioIpVNLceT25A6DZCH6+qEyNr50eWmtiX3FbGhGBr0haOzA8d5e2TXQlvFxuqRttfXeLKqwj8DKzfUaDqzRyJhjCCsb4i2FioqCWlCejqZ9ffpn/1e2gvBDth9HjvO6E3Jnwr7XxiumM9PdZk1fFWlfNMIMQfTIhvY8XPGT81HFBtSw0vCx2/gree9eCxrTFNwyGfjm4JOd0rEVsZtlJ3byKIyzdIjN0/c7q6NMPlaEEB/d7 X-MS-Exchange-AntiSpam-MessageData: ZzfW4dJDWKn2bPuyw1r5f7m6pvW9qJqdGXM/ktRJK6084F0t196rt06JZP0VHmSA/dTWAB+T7YzA0xdvnK+pQSvw2wxwBeBdosgfWnFJ2dwb1ieat9h7RYNWJBWFQYALf1qUh+MNhXcXDdSJ14LEgZ2hmK7e1O8jUZasSLQ3m+h+r3LsEReYpTh93Cu/+1zlOuBShj1deW4MIwacaAp1fh2PZgaA1jx5kmU22DMAhRSI5GhTpPFZlX89H2UDoledyuz7QiNeXS3ZL+EPdnEjAdCCD1yz05VOCUNwL7QCp4NdPCml89aAt0e7fZttQ9ryHzsJuHLouqEeSYQv/S3YgaS9HW4wdlv4FeuzVuofSrjyah7C0qfPHzjSLhzia16VcdfWxq5LVABpneUpfiDY2dutd7lV1e3LoNah4AJSw+QCEbJ1NPy5xTmuGWfegj+hhi7UBETMv5crXlB636wKSsDAOcyuuZkY1pmi+8RcUtW34D/dJN7PGPXba0hn0y/LRmJIC6sjgEPYGyT/qgCK08myOCcMoSCwiWZ0qJhoeuLhYb63IYyqMWUawJ8/METw1qAaAguQSwoWCgKcUqhW9Ptv1QyLuDHd8CXrBwdrjIMBUHLk5P/TAiTid03UhZI8eww5UF+4obJx+2ugxqxFynmMtptGcihGEc/xEQRKPfGobdTGck16TYXahp1P7iJJEbY1dVn2C/LRHq8FfU/E6MaB6vmVFlptU6BMp5GPouO3089oXEZDs7fbOCus6vVbsn71KTAv5QwU4mbmBAmHuQo10zpAHn+VahZiyA2jBUE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a721c68-2416-48a6-8d47-08d7ec3e850f X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2020 13:09:16.2333 (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: 4ZrxqNaBPxMFnVQygttj5tRxvwMMWELfQgpyEXYPE6xMl8weufS/pko+WaXpsOB2uPRP0Tf08nHrvUIIXBE7XAoxEW8oDJks9bdGEwzS8rw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5446 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.8.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 09:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.8.118 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We are going to use aio-task-pool API, so we'll need state pointer in BlockCopyTask anyway. Add it now and use where possible. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/block-copy.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 8d1b9ab9f0..35ff9cc3ef 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -25,6 +25,7 @@ #define BLOCK_COPY_MAX_MEM (128 * MiB) =20 typedef struct BlockCopyTask { + BlockCopyState *s; int64_t offset; int64_t bytes; QLIST_ENTRY(BlockCopyTask) list; @@ -116,8 +117,11 @@ static BlockCopyTask *block_copy_task_create(BlockCopy= State *s, bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); s->in_flight_bytes +=3D bytes; =20 - task->offset =3D offset; - task->bytes =3D bytes; + *task =3D (BlockCopyTask) { + .s =3D s, + .offset =3D offset, + .bytes =3D bytes, + }; qemu_co_queue_init(&task->wait_queue); QLIST_INSERT_HEAD(&s->tasks, task, list); =20 @@ -131,8 +135,7 @@ static BlockCopyTask *block_copy_task_create(BlockCopyS= tate *s, * wake up all tasks waiting for us (may be some of them are not intersect= ing * with shrunk task) */ -static void coroutine_fn block_copy_task_shrink(BlockCopyState *s, - BlockCopyTask *task, +static void coroutine_fn block_copy_task_shrink(BlockCopyTask *task, int64_t new_bytes) { if (new_bytes =3D=3D task->bytes) { @@ -141,20 +144,19 @@ static void coroutine_fn block_copy_task_shrink(Block= CopyState *s, =20 assert(new_bytes > 0 && new_bytes < task->bytes); =20 - s->in_flight_bytes -=3D task->bytes - new_bytes; - bdrv_set_dirty_bitmap(s->copy_bitmap, + task->s->in_flight_bytes -=3D task->bytes - new_bytes; + bdrv_set_dirty_bitmap(task->s->copy_bitmap, task->offset + new_bytes, task->bytes - new_byte= s); =20 task->bytes =3D new_bytes; qemu_co_queue_restart_all(&task->wait_queue); } =20 -static void coroutine_fn block_copy_task_end(BlockCopyState *s, - BlockCopyTask *task, int ret) +static void coroutine_fn block_copy_task_end(BlockCopyTask *task, int ret) { - s->in_flight_bytes -=3D task->bytes; + task->s->in_flight_bytes -=3D task->bytes; if (ret < 0) { - bdrv_set_dirty_bitmap(s->copy_bitmap, task->offset, task->bytes); + bdrv_set_dirty_bitmap(task->s->copy_bitmap, task->offset, task->by= tes); } QLIST_REMOVE(task, list); qemu_co_queue_restart_all(&task->wait_queue); @@ -502,9 +504,9 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, ret =3D block_copy_block_status(s, offset, cur_bytes, &status_byte= s); assert(ret >=3D 0); /* never fail */ cur_bytes =3D MIN(cur_bytes, status_bytes); - block_copy_task_shrink(s, task, cur_bytes); + block_copy_task_shrink(task, cur_bytes); if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { - block_copy_task_end(s, task, 0); + block_copy_task_end(task, 0); progress_set_remaining(s->progress, bdrv_get_dirty_count(s->copy_bitmap) + s->in_flight_bytes); @@ -520,7 +522,7 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, ret =3D block_copy_do_copy(s, offset, cur_bytes, ret & BDRV_BLOCK_= ZERO, error_is_read); co_put_to_shres(s->mem, cur_bytes); - block_copy_task_end(s, task, ret); + block_copy_task_end(task, ret); if (ret < 0) { return ret; } --=20 2.21.0 From nobody Sat May 18 17:34:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1588166098; cv=pass; d=zohomail.com; s=zohoarc; b=Wu+dX2k32Zp4muaJkU34aWIjHxqPhh6clzbWV4C6NBN8DnGqBR+wy8iOb5nUug/H9pzlfUq68WiNdFas4aWDaL05d0K3NkZQc1CkXzinp0ne6XaJmDARKMqhfwOhiuQBhx2FdDz95U/139GlKo46Sa7jt2jy835P/c05sIKEnlI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588166098; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Gw89ul5DChI1jdaCSD5v/qnlhmxpIx9EKk3XxHDGSvo=; b=gaDcen7rEPId7twaaCVcGQXP8rQZFRVkxI9ZWjxTTArAvQi0t/3tGdsAKpKY682fgFwezTqna+AG8TFM8QlTcbYZtC6zm8cX2yByt0sXlEW5kqiUALvQS16hzCc4ZBHfNWkwzJbq0HweLqKp8s6dJ05EHcUexDbKYYlaKY3Y6/4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588166098834535.408328186873; Wed, 29 Apr 2020 06:14:58 -0700 (PDT) Received: from localhost ([::1]:58000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmYD-0004xQ-EC for importer@patchew.org; Wed, 29 Apr 2020 09:14:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34774) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmV9-000813-SF for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTmV1-00085a-DL for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:47 -0400 Received: from mail-eopbgr80118.outbound.protection.outlook.com ([40.107.8.118]:18917 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jTmSo-0007bZ-6u; Wed, 29 Apr 2020 09:09:22 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5446.eurprd08.prod.outlook.com (2603:10a6:20b:107::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Wed, 29 Apr 2020 13:09:17 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.023; Wed, 29 Apr 2020 13:09:17 +0000 Received: from localhost.localdomain (185.215.60.184) by AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Wed, 29 Apr 2020 13:09:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jX5etUp9JqAE/BTofr7QWltG9fbDasmUw59bwPGt7S2Usvkl3kMVyXgNJlrvPXdjgBOEmxY+YPiT2PY6+16PqryEezBAbLxSZ+kPfyz0+f+gkekk/HEN8NNZWmQbp/hVBLhAETWlCRf4dAMOij6VfJ95q0iNKyjoPJeE3xRiH2wVn3n/RoCr7WKoKzCn0D3PH0giRcL1Zs0cRAhSF0+3zpJmvLYw7sbuRilDgsUK2mMBayBo91SnPAZfbgJv7c9OyeE2SHJfo3U08JF1HU3+JZhXUheI3ClLKBGBDs4fzBCTWC12AJRW+6ZOP7R0a7uVc+tVd05ZvOGVi+5Fi4Vaqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gw89ul5DChI1jdaCSD5v/qnlhmxpIx9EKk3XxHDGSvo=; b=a1MsAe0gJI4KWID0jgdBT5CXrMcb69AAoNFZihsxaww0BkU2MiQBca+eeSfK5XpPuGdlRLCxaE7WbaWQL3knMNI+RgQr0Vr2gTQuZDcoihPj0CvO/msI3zHmei4ZiErAXPLNLjxS7Thre21X2MpKwdfLFEXGI3aX8eUSkYON20K0Z8Eqb3CG51knkEzR5fZJOPkc8sph+z7GPnPaqhwR8a1cVc9l2655mG+Jmqsj/AGCTQB9FnCX3/cOpT3XjcavUcGJvd/1x5tPiflAmlu27YBh0JDtI3aQlZaHbzXYQQnDYtUkSVWUIUITKfUu+8pjB4FG5aOzOOvWOV6ptdUeDA== 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=Gw89ul5DChI1jdaCSD5v/qnlhmxpIx9EKk3XxHDGSvo=; b=fsB8QxoNwVoFTVAH4hmYRJcFdHiZZgbpInrFQ63yHrQ9VqBAZ2OiBJ5QwR7owXwr/zypHzB67BEcwZwK6wqoo2qJJZIbfmpfRHLvSFpsJ5RxOczHAUBpSR7hbifgdabJ7tAabHHX2zNbDkMMx9omaDs7+cPT74Uef5mkx7qbYvI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 4/5] block/block-copy: refactor task creation Date: Wed, 29 Apr 2020 16:08:46 +0300 Message-Id: <20200429130847.28124-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429130847.28124-1-vsementsov@virtuozzo.com> References: <20200429130847.28124-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.184] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9df23ff8-1f26-48cc-56a4-08d7ec3e8575 X-MS-TrafficTypeDiagnostic: AM7PR08MB5446: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:800; X-Forefront-PRVS: 03883BD916 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(346002)(39840400004)(366004)(396003)(8936002)(16526019)(2616005)(107886003)(6512007)(66946007)(66556008)(66476007)(316002)(36756003)(6486002)(52116002)(5660300002)(186003)(6506007)(26005)(4326008)(956004)(1076003)(69590400007)(478600001)(6666004)(86362001)(2906002)(6916009)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NuiCMbxPxcwUxlJnwqKx33F2j44QFHHcwStUeyJ8IDs262fNIf99v31k+c4eEcPV8U00ILjX6CsIZcAHP3zv8U8ZK7NJDK44RYkIP3I8BKP8R9fETEc9xgRCobBluzeR2SPayuR87jFQ4eS2beJdgJhjt1CldcjvAG9XpOEWe/1Lqrb7LElIXTJFGw1kMDDrPKVKNQxQlST0rCILJ2YVdQZt7W5hTR6Xs5eS57bcWS4F30Xtgi2tisZMysc4NhtCnsQZXvH6Scu1ZERKeXmb4w6aYZgbfbBFgVE4VBL+/cK1+b+VpUd0RHIkiho91tkeMmxcN2gYnR7fHRVPnND8fJB69ecKCHxH8PABd/eWPoV2cYA2wSFxL00ca0l6xlJf/qwLceqK69sbSD4wnmJMQv+OeUSKtC3v2dOli46ezSEw4gAqwG3Z5Vj5Qh1ulbM08Hfx73Ya0+CEvdb7JXOxl2PUunLRQNFlhH7+lsRfB2VfEmBp36ss9Sbrh4YRb/zj X-MS-Exchange-AntiSpam-MessageData: B+EWsO+HlYLmwayR8SS/1GqS7FUsrNWqwywbKUEBMDMcldZiwtm92wsptttc7TUsKjASGbt8UD7YL7b97DKlAVSW3isEl0jVQdX1U+ZHkK0iZNqQTOS5JZl0HaKkM+ZJWTKa8znTJZHUWhr0a2wl7iz1qW3qFYf0nDihl7wIzvc9Sm4HaDJSWQBFD+9ZkDMwfrQsZkF5Y/CcQgntPJ3qvIIwv8NfU4wblz+hrb9JwJkfNDoXj5Tb92IJQa7hsaBQVoIrbLLLAV4TkCZfVP4vYJKfobqHVD27K6vXvDT+zLT+4qP8zd5vdswsdR2kV0haEYn32ntvJMMtvNBy4O6zSDX/m0l/WB2sb73laRLtoL0aOrzxgYpcgE0sjB1Z6QGh+T7wHEW7ZGGZPm114OGagxMRrr4iZTqkwJjlPuXKwEjSRIkgzbITsOPdtZfyzp9MqhLvXn3CaQwBQqCfLmFaXb9VGf3/qB867UzvQ3vDyErGIvdVB7GuXIM0UxxpGUq9dE2bHzg/xhvFtc3Twb1LSnLrZYFG+JiT23LwSp8zAb+S4ysUoaejDGRwYoJINR0/QYOzAYdoP1llxOWbuoJb6XIIuhzyXeLKAicYJdwHlQAE4t6tlIxrjz/1wHAUvmnjbpThLaPvhIogmI6y36EQ6T8bwHMT5fqDUYsg0AG+tGh+gTJHk0cNZ+jnXsfjEexdf4onjF/M5nAS78v3x5FmqnmoEgR2qzGAh8PHa+SMOSLi2e/4OBR+jlW7QQWGC9jqHz1gGHmKA7fNl9v25z0WCKNtcmslRHJBHn06dWKkEf0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9df23ff8-1f26-48cc-56a4-08d7ec3e8575 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2020 13:09:16.9412 (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: jhvHZvL7zkQRsZYxDg8B4+aeVexg+Bn+G3H6WhyHbQ4LWsRgYz2J1BoMIhoErTMCpMBpX8uldfLt8egFYxD1YGByqtDGcyOmk8SuNlgHrVE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5446 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.8.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 09:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.8.118 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Instead of just relying on the comment "Called only on full-dirty region" in block_copy_task_create() let's move initial dirty area search directly to block_copy_task_create(). Let's also use effective bdrv_dirty_bitmap_next_dirty_area instead of looping through all non-dirty clusters. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/block-copy.c | 80 ++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 35ff9cc3ef..f560338647 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -32,6 +32,11 @@ typedef struct BlockCopyTask { CoQueue wait_queue; /* coroutines blocked on this task */ } BlockCopyTask; =20 +static int64_t task_end(BlockCopyTask *task) +{ + return task->offset + task->bytes; +} + typedef struct BlockCopyState { /* * BdrvChild objects are not owned or managed by block-copy. They are @@ -106,17 +111,29 @@ static bool coroutine_fn block_copy_wait_one(BlockCop= yState *s, int64_t offset, return true; } =20 -/* Called only on full-dirty region */ +/* + * Search for the first dirty area in offset/bytes range and create task at + * the beginning of it. + */ static BlockCopyTask *block_copy_task_create(BlockCopyState *s, int64_t offset, int64_t bytes) { - BlockCopyTask *task =3D g_new(BlockCopyTask, 1); + BlockCopyTask *task; =20 + if (!bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap, + offset, offset + bytes, + s->copy_size, &offset, &bytes)) + { + return NULL; + } + + /* region is dirty, so no existent tasks possible in it */ assert(!find_conflicting_task(s, offset, bytes)); =20 bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); s->in_flight_bytes +=3D bytes; =20 + task =3D g_new(BlockCopyTask, 1); *task =3D (BlockCopyTask) { .s =3D s, .offset =3D offset, @@ -466,6 +483,7 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, { int ret =3D 0; bool found_dirty =3D false; + int64_t end =3D offset + bytes; =20 /* * block_copy() user is responsible for keeping source and target in s= ame @@ -479,58 +497,52 @@ static int coroutine_fn block_copy_dirty_clusters(Blo= ckCopyState *s, =20 while (bytes) { g_autofree BlockCopyTask *task =3D NULL; - int64_t next_zero, cur_bytes, status_bytes; + int64_t status_bytes; =20 - if (!bdrv_dirty_bitmap_get(s->copy_bitmap, offset)) { - trace_block_copy_skip(s, offset); - offset +=3D s->cluster_size; - bytes -=3D s->cluster_size; - continue; /* already copied */ + task =3D block_copy_task_create(s, offset, bytes); + if (!task) { + /* No more dirty bits in the bitmap */ + trace_block_copy_skip_range(s, offset, bytes); + break; + } + if (task->offset > offset) { + trace_block_copy_skip_range(s, offset, task->offset - offset); } =20 found_dirty =3D true; =20 - cur_bytes =3D MIN(bytes, s->copy_size); - - next_zero =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, offset, - cur_bytes); - if (next_zero >=3D 0) { - assert(next_zero > offset); /* offset is dirty */ - assert(next_zero < offset + cur_bytes); /* no need to do MIN()= */ - cur_bytes =3D next_zero - offset; - } - task =3D block_copy_task_create(s, offset, cur_bytes); - - ret =3D block_copy_block_status(s, offset, cur_bytes, &status_byte= s); + ret =3D block_copy_block_status(s, task->offset, task->bytes, + &status_bytes); assert(ret >=3D 0); /* never fail */ - cur_bytes =3D MIN(cur_bytes, status_bytes); - block_copy_task_shrink(task, cur_bytes); + if (status_bytes < task->bytes) { + block_copy_task_shrink(task, status_bytes); + } if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { block_copy_task_end(task, 0); progress_set_remaining(s->progress, bdrv_get_dirty_count(s->copy_bitmap) + s->in_flight_bytes); - trace_block_copy_skip_range(s, offset, status_bytes); - offset +=3D status_bytes; - bytes -=3D status_bytes; + trace_block_copy_skip_range(s, task->offset, task->bytes); + offset =3D task_end(task); + bytes =3D end - offset; continue; } =20 - trace_block_copy_process(s, offset); + trace_block_copy_process(s, task->offset); =20 - co_get_from_shres(s->mem, cur_bytes); - ret =3D block_copy_do_copy(s, offset, cur_bytes, ret & BDRV_BLOCK_= ZERO, - error_is_read); - co_put_to_shres(s->mem, cur_bytes); + co_get_from_shres(s->mem, task->bytes); + ret =3D block_copy_do_copy(s, task->offset, task->bytes, + ret & BDRV_BLOCK_ZERO, error_is_read); + co_put_to_shres(s->mem, task->bytes); block_copy_task_end(task, ret); if (ret < 0) { return ret; } =20 - progress_work_done(s->progress, cur_bytes); - s->progress_bytes_callback(cur_bytes, s->progress_opaque); - offset +=3D cur_bytes; - bytes -=3D cur_bytes; + progress_work_done(s->progress, task->bytes); + s->progress_bytes_callback(task->bytes, s->progress_opaque); + offset =3D task_end(task); + bytes =3D end - offset; } =20 return found_dirty; --=20 2.21.0 From nobody Sat May 18 17:34:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1588166220; cv=pass; d=zohomail.com; s=zohoarc; b=QK/q72rjbQSMGqJt8WtECYBX81aDx9HGpiKm00MGlXUsUqfQnhu7Gdz8g413eB56+zF+6DCzsnBVsiahowDDG0XkB3nrnVLgkcsTs4WygIZwasu5WtMRpElkpdTYUTRVmDJdYxZ5gqBp9zWwZ1yK9LCywxW/oRPHa520kqv138M= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588166220; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wQlosi03mxhactT/54a4+buxoex9q2Jrlj5nqM3FiOA=; b=AQoohd5Nk7XvBGg0lEKtBby3R0Vb2aJTNJuNvtcJnNO2LMJRyvApqk2uGNGIHiyyu427Eco4HcXVCDgjebPnSyTEbgR5a/kQtye65PBkvzuwEQ90NYJpJeJMEFFaOGoEXbj5gFmmDef3PQuX1sXplwwBlSc8C/nlKFJF/9wzYMM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588166220455145.11259711072353; Wed, 29 Apr 2020 06:17:00 -0700 (PDT) Received: from localhost ([::1]:35010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmaB-0007GR-4v for importer@patchew.org; Wed, 29 Apr 2020 09:16:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34792) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTmVB-00083j-Sg for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTmV2-000865-VU for qemu-devel@nongnu.org; Wed, 29 Apr 2020 09:11:49 -0400 Received: from mail-eopbgr80118.outbound.protection.outlook.com ([40.107.8.118]:18917 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jTmSp-0007bZ-5L; Wed, 29 Apr 2020 09:09:23 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5446.eurprd08.prod.outlook.com (2603:10a6:20b:107::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Wed, 29 Apr 2020 13:09:17 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.023; Wed, 29 Apr 2020 13:09:17 +0000 Received: from localhost.localdomain (185.215.60.184) by AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Wed, 29 Apr 2020 13:09:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NvZ7KQbbg8nJGGxKPNVyBtnkvDFlcssYLi6m+A85dQHjfffuwrVp3iQnsojUOYJ9tO7TniyNKQtWrqUFvO2Q/RVsOVRG/8NLY3ZQuBFPXZucdjJvI45u982sGrgG8DetiGppa1vvt2l7vzfDt+9M/HLogZPlsuXtOHZLEYzgUauCeQKg1OGw7JL6zJC63fAFn9WP+wZShTq6v0k9WQr7lNtuuSX1hD4V2cBcL2dn/EnPU4/nGAXFe114viyYg+aib8T+lKGA+DAnhhZbKbbQQ+laoY+4ZIeCl8kx4+ZgThqabYw6PaU6phPNppXMCtIiFsa9arB5mZDLIA3GIMHzAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wQlosi03mxhactT/54a4+buxoex9q2Jrlj5nqM3FiOA=; b=AxnA7/JwrzhPLLciHUtzFKwkXwpBR/ImxHiueq35jgC1n2qLcxnq5rWG2ONPpErP2wZyGR5GH66wiQCh6fKVysk9o+tXz7c/0XprDCqlWfp/7YiyEuaH65g3qCvwa0igPWqWdbNpo1QbfuUMx3YDB2lgb22oJ1JNqJtqADcAWp6ZgQNPGBshniOttTZPF4SgW6cFQKXnkaJrZllXf/IEesstWdwGk9mUzMYOW0+wT4ti5Wou1w2V9xQRqfmzV7IYpgAfK1DTPTm3DwjT4V67i54VAf6qG+zYfo5kY8SXJweRcIIj+oAiY1X9B0EPVKPdtiCZ8XA5iiJKUM1en4vTvg== 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=wQlosi03mxhactT/54a4+buxoex9q2Jrlj5nqM3FiOA=; b=fK8a2ZwArSH43utvGaI4Vqt4l6bmwCkusqN+7IspV2EVJohD3jOQGC2GWcP6N5PefVFTHRJSB/vZtVKQIa+JX/bqY7gsfGnFqjjPptF0l/QZm1XRpjYFl/IzgSKiok+td08Jy9oGXpxm9MaIfJQ3/w6QM8bPh+1y22lC4zjSox8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 5/5] block/block-copy: use aio-task-pool API Date: Wed, 29 Apr 2020 16:08:47 +0300 Message-Id: <20200429130847.28124-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429130847.28124-1-vsementsov@virtuozzo.com> References: <20200429130847.28124-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:208:122::44) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.184] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8bc081e7-9fb6-4227-91ae-08d7ec3e85e2 X-MS-TrafficTypeDiagnostic: AM7PR08MB5446: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:393; X-Forefront-PRVS: 03883BD916 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(346002)(39840400004)(366004)(396003)(8936002)(16526019)(2616005)(107886003)(6512007)(66946007)(66556008)(66476007)(316002)(36756003)(6486002)(52116002)(5660300002)(186003)(6506007)(26005)(4326008)(956004)(1076003)(69590400007)(478600001)(6666004)(86362001)(2906002)(6916009)(8676002)(334744003); DIR:OUT; SFP:1102; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 25pV9yH80vJDsvuEHYbreTJCaFLfXGUnpAknOnLPxgGQIsdUNIIA6eMdHtBk8aVq0skFchJpRBt0ZXeXCw+zYidpHGAysYwCg+AGyMqTsaKsuFYr5DSdnOGdDZWuNW0RTBoN5IUZFikQB1Dlbo3ZXJccAuJHvZzdlEpde/NKco9E/Z3uzGq+mVfOtz7jIujWe1pCF1WhF/0c2iko+LE3F9+nMN7bMgyYSRVmB1TBa/2bGRgh/NOKZvY0KeK9VVdkvHmwyLduQA85vyUwYVHb986p5qxUzIB6Pzx0E5zah2JMcrFI9oBwY2ol9dBVuznXpwzL3bT5Btu1MuJmZFjWjjBeva+riePikI2xCrkafidN9KPhhpVEUZC3xKROVfzvJ6E7LjJwF1DzPB46nbXnMIMc9n/1hsPqDGFf7aoJCTsneJbI41ZI2TmtwfGCkOoP7HsZxkmfCgvp+13vykJjmvZHpCs8L212u7HCXYZR+PwupOxRY5mFqbrpJamhGi3H5GSXi4o++du0j43Ga0oAiQ== X-MS-Exchange-AntiSpam-MessageData: hsbiu3TBmw80CSHjCruFWquyC1ld1rK0IHeI4C6SgcTSdNmc1TP34DnBiCzm1yEN8/Xb3M+fGiClHGmoE2+Bx+TVRNb09wnRQ9gVJIP590ecY57+N1oB0Dfd2kp6bGRfJUGDp8ihmqDiz/msy+9zKoSoznNyXaS+a5FI/lXAxrimYgFueZYyfECENX6ZA33antqqAwOrpZUMXvS5eUTlv1yA7b4XCbyGAgt11KjUZ0uDEHwgFqQZqsQ/NlFDv0ZJ2L1ygFZrOFYB32uAXtE+fivvFA4A+TIcF60u1iOq3fHvkGiwBLjcCoddJcRIZwqvK6QxRH2ynEoku19sdABVPnqUxFj2ndg1/fPyCBqdvfLhXaf3NnVe5mrq9spYd75j2QR51gZvqp9KZ/d9rftEaQe7eTgMGsPUcex5vaxTIYmoNPcaat0w2bfJbq1rNcMdPMVkmFmY3pskpC7+2HsHWNGzg+1DzkNT6NdBPXwNwbWX5P+cu1p2pzdGdnfLryRkRIiyQL6rjaPjmoprNxhI7WSc98/U21CzGk6sMeunVDVnBUrOgkp3A8Ss5NgUtuX3VxtSBuFGXAnVXJ6UUTxeUMUxAAqIu+2OFm4jk2Y/wdoHcCTAmx21VFmg3xH5CrT+PIRM6FfbCTdCGW8K4SaLH/WCdHT6PWBDBU7O0DsRYw33h574jaV4XJKLsXmRDec/whO0AQIayfh4J7Bli2oJ9llA1xHBCtZuwe3sIVOeKb/mQVsoujkWv0+cFZkeEvct9S91OMZcCRsRhI+7eI/KpbhAvA1eoc5Y2vQu4cNu3GA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bc081e7-9fb6-4227-91ae-08d7ec3e85e2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2020 13:09:17.6412 (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: eU5BFj+66ANdn2v7ZDGk4hOlH/wgGMZE845ja15EShNhACI4gSlE7F5NExZoKSkmMfYY8H/AK7BXSnoVaFq9nEgX1/GKxWtMtkLnZOQpRGU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5446 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.8.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 09:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.8.118 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Run block_copy iterations in parallel in aio tasks. Changes: - BlockCopyTask becomes aio task structure. Add zeroes field to pass it to block_copy_do_copy - add call state - it's a state of one call of block_copy(), shared between parallel tasks. For now used only to keep information about first error: is it read or not. - convert block_copy_dirty_clusters to aio-task loop. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 119 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 106 insertions(+), 13 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index f560338647..03500680f7 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -19,15 +19,29 @@ #include "block/block-copy.h" #include "sysemu/block-backend.h" #include "qemu/units.h" +#include "qemu/coroutine.h" +#include "block/aio_task.h" =20 #define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB) #define BLOCK_COPY_MAX_BUFFER (1 * MiB) #define BLOCK_COPY_MAX_MEM (128 * MiB) +#define BLOCK_COPY_MAX_WORKERS 64 + +static coroutine_fn int block_copy_task_entry(AioTask *task); + +typedef struct BlockCopyCallState { + bool failed; + bool error_is_read; +} BlockCopyCallState; =20 typedef struct BlockCopyTask { + AioTask task; + BlockCopyState *s; + BlockCopyCallState *call_state; int64_t offset; int64_t bytes; + bool zeroes; QLIST_ENTRY(BlockCopyTask) list; CoQueue wait_queue; /* coroutines blocked on this task */ } BlockCopyTask; @@ -116,6 +130,7 @@ static bool coroutine_fn block_copy_wait_one(BlockCopyS= tate *s, int64_t offset, * the beginning of it. */ static BlockCopyTask *block_copy_task_create(BlockCopyState *s, + BlockCopyCallState *call_stat= e, int64_t offset, int64_t bytes) { BlockCopyTask *task; @@ -135,7 +150,9 @@ static BlockCopyTask *block_copy_task_create(BlockCopyS= tate *s, =20 task =3D g_new(BlockCopyTask, 1); *task =3D (BlockCopyTask) { + .task.func =3D block_copy_task_entry, .s =3D s, + .call_state =3D call_state, .offset =3D offset, .bytes =3D bytes, }; @@ -263,6 +280,38 @@ void block_copy_set_progress_meter(BlockCopyState *s, = ProgressMeter *pm) s->progress =3D pm; } =20 +/* + * Takes ownership of @task + * + * If pool is NULL directly run the task, otherwise schedule it into the p= ool. + * + * Returns: task.func return code if pool is NULL + * otherwise -ECANCELED if pool status is bad + * otherwise 0 (successfully scheduled) + */ +static coroutine_fn int block_copy_task_run(AioTaskPool *pool, + BlockCopyTask *task) +{ + if (!pool) { + int ret =3D task->task.func(&task->task); + + g_free(task); + return ret; + } + + aio_task_pool_wait_slot(pool); + if (aio_task_pool_status(pool) < 0) { + co_put_to_shres(task->s->mem, task->bytes); + block_copy_task_end(task, -ECANCELED); + g_free(task); + return -ECANCELED; + } + + aio_task_pool_start_task(pool, &task->task); + + return 0; +} + /* * block_copy_do_copy * @@ -366,6 +415,27 @@ out: return ret; } =20 +static coroutine_fn int block_copy_task_entry(AioTask *task) +{ + BlockCopyTask *t =3D container_of(task, BlockCopyTask, task); + bool error_is_read; + int ret; + + ret =3D block_copy_do_copy(t->s, t->offset, t->bytes, t->zeroes, + &error_is_read); + if (ret < 0 && !t->call_state->failed) { + t->call_state->failed =3D true; + t->call_state->error_is_read =3D error_is_read; + } else { + progress_work_done(t->s->progress, t->bytes); + t->s->progress_bytes_callback(t->bytes, t->s->progress_opaque); + } + co_put_to_shres(t->s->mem, t->bytes); + block_copy_task_end(t, ret); + + return ret; +} + static int block_copy_block_status(BlockCopyState *s, int64_t offset, int64_t bytes, int64_t *pnum) { @@ -484,6 +554,8 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, int ret =3D 0; bool found_dirty =3D false; int64_t end =3D offset + bytes; + AioTaskPool *aio =3D NULL; + BlockCopyCallState call_state =3D {false, false}; =20 /* * block_copy() user is responsible for keeping source and target in s= ame @@ -495,11 +567,11 @@ static int coroutine_fn block_copy_dirty_clusters(Blo= ckCopyState *s, assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); =20 - while (bytes) { - g_autofree BlockCopyTask *task =3D NULL; + while (bytes && aio_task_pool_status(aio) =3D=3D 0) { + BlockCopyTask *task; int64_t status_bytes; =20 - task =3D block_copy_task_create(s, offset, bytes); + task =3D block_copy_task_create(s, &call_state, offset, bytes); if (!task) { /* No more dirty bits in the bitmap */ trace_block_copy_skip_range(s, offset, bytes); @@ -519,6 +591,7 @@ static int coroutine_fn block_copy_dirty_clusters(Block= CopyState *s, } if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { block_copy_task_end(task, 0); + g_free(task); progress_set_remaining(s->progress, bdrv_get_dirty_count(s->copy_bitmap) + s->in_flight_bytes); @@ -527,25 +600,45 @@ static int coroutine_fn block_copy_dirty_clusters(Blo= ckCopyState *s, bytes =3D end - offset; continue; } + task->zeroes =3D ret & BDRV_BLOCK_ZERO; =20 trace_block_copy_process(s, task->offset); =20 co_get_from_shres(s->mem, task->bytes); - ret =3D block_copy_do_copy(s, task->offset, task->bytes, - ret & BDRV_BLOCK_ZERO, error_is_read); - co_put_to_shres(s->mem, task->bytes); - block_copy_task_end(task, ret); - if (ret < 0) { - return ret; - } =20 - progress_work_done(s->progress, task->bytes); - s->progress_bytes_callback(task->bytes, s->progress_opaque); offset =3D task_end(task); bytes =3D end - offset; + + if (!aio && bytes) { + aio =3D aio_task_pool_new(BLOCK_COPY_MAX_WORKERS); + } + + ret =3D block_copy_task_run(aio, task); + if (ret < 0) { + goto out; + } + } + +out: + if (aio) { + aio_task_pool_wait_all(aio); + + /* + * We are not really interested in -ECANCELED returned from + * block_copy_task_run. If it fails, it means some task already fa= iled + * for real reason, let's return first failure. + * Still, assert that we don't rewrite failure by success. + */ + assert(ret =3D=3D 0 || aio_task_pool_status(aio) < 0); + ret =3D aio_task_pool_status(aio); + + aio_task_pool_free(aio); + } + if (error_is_read && ret < 0) { + *error_is_read =3D call_state.error_is_read; } =20 - return found_dirty; + return ret < 0 ? ret : found_dirty; } =20 /* --=20 2.21.0