From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922964; cv=none; d=zohomail.com; s=zohoarc; b=i3Zst1Hu0Q8K546oRRResNSa+s1VjDORMMW16vQIByfAcFT/pk4ngy5+ck3R4Jq6Mn34w57OJMmsqjt/XtApRz3hFim2QbpsI6TplfGksKj9LO5yQZ/q1EfZNnmhgr5f+jX9mP8562r2yKM/Wo0zbvpleVH8JeX/Y8Juisjx9RY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922964; h=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=cAkxkQ1bCMkaNvG6BT+z1v438LFKardj+85aRdXxb7E=; b=RVOwXu+R1Ot1nWs0OimQwAgvIidZNpfiY7AYHc4LzPn38wnva4LqyZ40fWkAO7kyt5dmD9mUuufD61ACL7FlHm6BJPmzs8Ogz47jTNCQBJpMY4wdNzTZS8vyqsosz4n0DXCY9cNEwbZ+rzbnssjITb3It+ld/aLYh8b6u7OijpI= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922964605855.6796007321037; Wed, 11 Mar 2020 03:36:04 -0700 (PDT) Received: from localhost ([::1]:49386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByiZ-0003yq-MB for importer@patchew.org; Wed, 11 Mar 2020 06:36:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43595) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByd9-0002vL-Bw for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd7-0001XQ-J3 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:33078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001Rk-IQ; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycx-0005cJ-Ne; Wed, 11 Mar 2020 13:30:15 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 1/9] job: refactor progress to separate object Date: Wed, 11 Mar 2020 13:29:56 +0300 Message-Id: <20200311103004.7649-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-stable@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We need it in separate to pass to the block-copy object in the next commit. Cc: qemu-stable@nongnu.org Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich Reviewed-by: Max Reitz --- include/qemu/job.h | 11 ++----- include/qemu/progress_meter.h | 58 +++++++++++++++++++++++++++++++++++ blockjob.c | 16 +++++----- job-qmp.c | 4 +-- job.c | 6 ++-- qemu-img.c | 6 ++-- 6 files changed, 76 insertions(+), 25 deletions(-) create mode 100644 include/qemu/progress_meter.h diff --git a/include/qemu/job.h b/include/qemu/job.h index bd59cd8944..32aabb1c60 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -28,6 +28,7 @@ =20 #include "qapi/qapi-types-job.h" #include "qemu/queue.h" +#include "qemu/progress_meter.h" #include "qemu/coroutine.h" #include "block/aio.h" =20 @@ -117,15 +118,7 @@ typedef struct Job { /** True if this job should automatically dismiss itself */ bool auto_dismiss; =20 - /** - * Current progress. The unit is arbitrary as long as the ratio between - * progress_current and progress_total represents the estimated percen= tage - * of work already done. - */ - int64_t progress_current; - - /** Estimated progress_current value at the completion of the job */ - int64_t progress_total; + ProgressMeter progress; =20 /** * Return code from @run and/or @prepare callback(s). diff --git a/include/qemu/progress_meter.h b/include/qemu/progress_meter.h new file mode 100644 index 0000000000..9a23ff071c --- /dev/null +++ b/include/qemu/progress_meter.h @@ -0,0 +1,58 @@ +/* + * Helper functionality for some process progress tracking. + * + * Copyright (c) 2011 IBM Corp. + * Copyright (c) 2012, 2018 Red Hat, Inc. + * Copyright (c) 2020 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef QEMU_PROGRESS_METER_H +#define QEMU_PROGRESS_METER_H + +typedef struct ProgressMeter { + /** + * Current progress. The unit is arbitrary as long as the ratio between + * current and total represents the estimated percentage + * of work already done. + */ + uint64_t current; + + /** Estimated current value at the completion of the process */ + uint64_t total; +} ProgressMeter; + +static inline void progress_work_done(ProgressMeter *pm, uint64_t done) +{ + pm->current +=3D done; +} + +static inline void progress_set_remaining(ProgressMeter *pm, uint64_t rema= ining) +{ + pm->total =3D pm->current + remaining; +} + +static inline void progress_increase_remaining(ProgressMeter *pm, + uint64_t delta) +{ + pm->total +=3D delta; +} + +#endif /* QEMU_PROGRESS_METER_H */ diff --git a/blockjob.c b/blockjob.c index 5d63b1e89d..fc850312c1 100644 --- a/blockjob.c +++ b/blockjob.c @@ -299,8 +299,8 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **er= rp) info->device =3D g_strdup(job->job.id); info->busy =3D atomic_read(&job->job.busy); info->paused =3D job->job.pause_count > 0; - info->offset =3D job->job.progress_current; - info->len =3D job->job.progress_total; + info->offset =3D job->job.progress.current; + info->len =3D job->job.progress.total; info->speed =3D job->speed; info->io_status =3D job->iostatus; info->ready =3D job_is_ready(&job->job), @@ -330,8 +330,8 @@ static void block_job_event_cancelled(Notifier *n, void= *opaque) =20 qapi_event_send_block_job_cancelled(job_type(&job->job), job->job.id, - job->job.progress_total, - job->job.progress_current, + job->job.progress.total, + job->job.progress.current, job->speed); } =20 @@ -350,8 +350,8 @@ static void block_job_event_completed(Notifier *n, void= *opaque) =20 qapi_event_send_block_job_completed(job_type(&job->job), job->job.id, - job->job.progress_total, - job->job.progress_current, + job->job.progress.total, + job->job.progress.current, job->speed, !!msg, msg); @@ -379,8 +379,8 @@ static void block_job_event_ready(Notifier *n, void *op= aque) =20 qapi_event_send_block_job_ready(job_type(&job->job), job->job.id, - job->job.progress_total, - job->job.progress_current, + job->job.progress.total, + job->job.progress.current, job->speed); } =20 diff --git a/job-qmp.c b/job-qmp.c index fbfed25a00..fecc939ebd 100644 --- a/job-qmp.c +++ b/job-qmp.c @@ -143,8 +143,8 @@ static JobInfo *job_query_single(Job *job, Error **errp) .id =3D g_strdup(job->id), .type =3D job_type(job), .status =3D job->status, - .current_progress =3D job->progress_current, - .total_progress =3D job->progress_total, + .current_progress =3D job->progress.current, + .total_progress =3D job->progress.total, .has_error =3D !!job->err, .error =3D job->err ? \ g_strdup(error_get_pretty(job->err)) : NULL, diff --git a/job.c b/job.c index 04409b40aa..134a07b92e 100644 --- a/job.c +++ b/job.c @@ -369,17 +369,17 @@ void job_unref(Job *job) =20 void job_progress_update(Job *job, uint64_t done) { - job->progress_current +=3D done; + progress_work_done(&job->progress, done); } =20 void job_progress_set_remaining(Job *job, uint64_t remaining) { - job->progress_total =3D job->progress_current + remaining; + progress_set_remaining(&job->progress, remaining); } =20 void job_progress_increase_remaining(Job *job, uint64_t delta) { - job->progress_total +=3D delta; + progress_increase_remaining(&job->progress, delta); } =20 void job_event_cancelled(Job *job) diff --git a/qemu-img.c b/qemu-img.c index 804630a368..59a720abf6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -882,9 +882,9 @@ static void run_block_job(BlockJob *job, Error **errp) do { float progress =3D 0.0f; aio_poll(aio_context, true); - if (job->job.progress_total) { - progress =3D (float)job->job.progress_current / - job->job.progress_total * 100.f; + if (job->job.progress.total) { + progress =3D (float)job->job.progress.current / + job->job.progress.total * 100.f; } qemu_progress_print(progress, 0); } while (!job_is_ready(&job->job) && !job_is_completed(&job->job)); --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922977; cv=none; d=zohomail.com; s=zohoarc; b=EyLOIsJ55gIGwj50SeY92y0cS41GPERAkgUgNDP4K19/w8By/ep91/q3XIc1905wiunKoNszTy1fyLw/tuKKbaff0yT3dvfnYZHrXlKjnuln/LImCFFTkvR9ugiTx0MEYiHNHd4T/9NqFNgRV9FwNFj1GD8m9T+J+gCJpuSIfyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922977; h=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=1haaOhSQet8Ak4eyr5yopGdEHB1al3VDklDufx0Sdvo=; b=A3rpJMhveQPq5Hgqy1g34ZbWdujaMIWWmE2ktEynFkiKtYOpU9QR2pSsUZC90LI+eGDZoHhU8BPqikIpI0vz4/ClpmEPOg+i1pDVY3iDPmGwzMYDq1VMgvZydSKk7PQ9ix1zP7q5a1AVgXLrN/lxgm6U0mjPwkz8Tr3/SaK5A9k= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922977566671.7337031711783; Wed, 11 Mar 2020 03:36:17 -0700 (PDT) Received: from localhost ([::1]:49388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByim-0004M1-Jd for importer@patchew.org; Wed, 11 Mar 2020 06:36:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43655) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBydC-0002zs-K9 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBydB-0001Zp-0c for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:30 -0400 Received: from relay.sw.ru ([185.231.240.75]:33074) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001Ro-Hu; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycx-0005cJ-TW; Wed, 11 Mar 2020 13:30:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 2/9] block/block-copy: fix progress calculation Date: Wed, 11 Mar 2020 13:29:57 +0300 Message-Id: <20200311103004.7649-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-stable@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Assume we have two regions, A and B, and region B is in-flight now, region A is not yet touched, but it is unallocated and should be skipped. Correspondingly, as progress we have total =3D A + B current =3D 0 If we reset unallocated region A and call progress_reset_callback, it will calculate 0 bytes dirty in the bitmap and call job_progress_set_remaining, which will set total =3D current + 0 =3D 0 + 0 =3D 0 So, B bytes are actually removed from total accounting. When job finishes we'll have total =3D 0 current =3D B , which doesn't sound good. This is because we didn't considered in-flight bytes, actually when calculating remaining, we should have set (in_flight + dirty_bytes) as remaining, not only dirty_bytes. To fix it, let's refactor progress calculation, moving it to block-copy itself instead of fixing callback. And, of course, track in_flight bytes count. We still have to keep one callback, to maintain backup job bytes_read calculation, but it will go on soon, when we turn the whole backup process into one block_copy call. Cc: qemu-stable@nongnu.org Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich --- include/block/block-copy.h | 15 +++++---------- block/backup.c | 13 ++----------- block/block-copy.c | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 0a161724d7..9def00068c 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -26,7 +26,6 @@ typedef struct BlockCopyInFlightReq { } BlockCopyInFlightReq; =20 typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque); -typedef void (*ProgressResetCallbackFunc)(void *opaque); typedef struct BlockCopyState { /* * BdrvChild objects are not owned or managed by block-copy. They are @@ -36,6 +35,7 @@ typedef struct BlockCopyState { BdrvChild *source; BdrvChild *target; BdrvDirtyBitmap *copy_bitmap; + int64_t in_flight_bytes; int64_t cluster_size; bool use_copy_range; int64_t copy_size; @@ -60,15 +60,9 @@ typedef struct BlockCopyState { */ bool skip_unallocated; =20 + ProgressMeter *progress; /* progress_bytes_callback: called when some copying progress is done.= */ ProgressBytesCallbackFunc progress_bytes_callback; - - /* - * progress_reset_callback: called when some bytes reset from copy_bit= map - * (see @skip_unallocated above). The callee is assumed to recalculate= how - * many bytes remain based on the dirty bit count of copy_bitmap. - */ - ProgressResetCallbackFunc progress_reset_callback; void *progress_opaque; =20 SharedResource *mem; @@ -79,12 +73,13 @@ BlockCopyState *block_copy_state_new(BdrvChild *source,= BdrvChild *target, BdrvRequestFlags write_flags, Error **errp); =20 -void block_copy_set_callbacks( +void block_copy_set_progress_callback( BlockCopyState *s, ProgressBytesCallbackFunc progress_bytes_callback, - ProgressResetCallbackFunc progress_reset_callback, void *progress_opaque); =20 +void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm); + void block_copy_state_free(BlockCopyState *s); =20 int64_t block_copy_reset_unallocated(BlockCopyState *s, diff --git a/block/backup.c b/block/backup.c index 1383e219f5..8694e0394b 100644 --- a/block/backup.c +++ b/block/backup.c @@ -57,15 +57,6 @@ static void backup_progress_bytes_callback(int64_t bytes= , void *opaque) BackupBlockJob *s =3D opaque; =20 s->bytes_read +=3D bytes; - job_progress_update(&s->common.job, bytes); -} - -static void backup_progress_reset_callback(void *opaque) -{ - BackupBlockJob *s =3D opaque; - uint64_t estimate =3D bdrv_get_dirty_count(s->bcs->copy_bitmap); - - job_progress_set_remaining(&s->common.job, estimate); } =20 static int coroutine_fn backup_do_cow(BackupBlockJob *job, @@ -464,8 +455,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, job->cluster_size =3D cluster_size; job->len =3D len; =20 - block_copy_set_callbacks(bcs, backup_progress_bytes_callback, - backup_progress_reset_callback, job); + block_copy_set_progress_callback(bcs, backup_progress_bytes_callback, = job); + block_copy_set_progress_meter(bcs, &job->common.job.progress); =20 /* Required permissions are already taken by backup-top target */ block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, diff --git a/block/block-copy.c b/block/block-copy.c index 79798a1567..e2d7b3b887 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -127,17 +127,20 @@ BlockCopyState *block_copy_state_new(BdrvChild *sourc= e, BdrvChild *target, return s; } =20 -void block_copy_set_callbacks( +void block_copy_set_progress_callback( BlockCopyState *s, ProgressBytesCallbackFunc progress_bytes_callback, - ProgressResetCallbackFunc progress_reset_callback, void *progress_opaque) { s->progress_bytes_callback =3D progress_bytes_callback; - s->progress_reset_callback =3D progress_reset_callback; s->progress_opaque =3D progress_opaque; } =20 +void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm) +{ + s->progress =3D pm; +} + /* * block_copy_do_copy * @@ -269,7 +272,9 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, =20 if (!ret) { bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); - s->progress_reset_callback(s->progress_opaque); + progress_set_remaining(s->progress, + bdrv_get_dirty_count(s->copy_bitmap) + + s->in_flight_bytes); } =20 *count =3D bytes; @@ -331,15 +336,18 @@ int coroutine_fn block_copy(BlockCopyState *s, trace_block_copy_process(s, start); =20 bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start); + s->in_flight_bytes +=3D chunk_end - start; =20 co_get_from_shres(s->mem, chunk_end - start); ret =3D block_copy_do_copy(s, start, chunk_end, error_is_read); co_put_to_shres(s->mem, chunk_end - start); + s->in_flight_bytes -=3D chunk_end - start; if (ret < 0) { bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start= ); break; } =20 + progress_work_done(s->progress, chunk_end - start); s->progress_bytes_callback(chunk_end - start, s->progress_opaque); start =3D chunk_end; ret =3D 0; --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922750; cv=none; d=zohomail.com; s=zohoarc; b=UIF+F+e/Eu8YBywASbm9EY7fbh/M224zCzxCgWbmrV34WJur1XRtnvS6J7SpcLGPEMuokv3f/o7u3fzc7A6mVBi84vtGiR9/G9EJvlkmrIobpF65KJRBJN6b7M9EMTldGiD7PFGJhWzN4gvibGOibCKPnh9bXu1P+JgPog/IFb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922750; h=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=Hua1cEl03K0HM2IhuG6dg/x0pGRPwE0Awtmr6n+zZ/I=; b=DKmDVSge55AOiNJOkkUPqDMLGbXTZIbTyAP49Ffg5OJCwIav135/67L92NkV6znL9PpS8ThF1fvcMC9tfECXxhHc6i4FEqdpjaXvfFRRUrNcqJJsEo0JqcMbOb+Wj6BgU/T6AqwCqb+5EPGkg1QoAMLAJQmOUXxNZSezCtx99wY= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922750161655.1293398490795; Wed, 11 Mar 2020 03:32:30 -0700 (PDT) Received: from localhost ([::1]:49316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByf6-0005Xz-Aq for importer@patchew.org; Wed, 11 Mar 2020 06:32:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43555) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByd8-0002to-6H for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd6-0001Wz-VF for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:26 -0400 Received: from relay.sw.ru ([185.231.240.75]:33054) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001Rb-IP; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycy-0005cJ-3u; Wed, 11 Mar 2020 13:30:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 3/9] block/block-copy: specialcase first copy_range request Date: Wed, 11 Mar 2020 13:29:58 +0300 Message-Id: <20200311103004.7649-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In block_copy_do_copy we fallback to read+write if copy_range failed. In this case copy_size is larger than defined for buffered IO, and there is corresponding commit. Still, backup copies data cluster by cluster, and most of requests are limited to one cluster anyway, so the only source of this one bad-limited request is copy-before-write operation. Further patch will move backup to use block_copy directly, than for cases where copy_range is not supported, first request will be oversized in each backup. It's not good, let's change it now. Fix is simple: just limit first copy_range request like buffer-based request. If it succeed, set larger copy_range limit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich Reviewed-by: Max Reitz --- block/block-copy.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index e2d7b3b887..ddd61c1652 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -70,16 +70,19 @@ void block_copy_state_free(BlockCopyState *s) g_free(s); } =20 +static uint32_t block_copy_max_transfer(BdrvChild *source, BdrvChild *targ= et) +{ + return MIN_NON_ZERO(INT_MAX, + MIN_NON_ZERO(source->bs->bl.max_transfer, + target->bs->bl.max_transfer)); +} + BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, int64_t cluster_size, BdrvRequestFlags write_flags, Error *= *errp) { BlockCopyState *s; BdrvDirtyBitmap *copy_bitmap; - uint32_t max_transfer =3D - MIN_NON_ZERO(INT_MAX, - MIN_NON_ZERO(source->bs->bl.max_transfer, - target->bs->bl.max_transfer)); =20 copy_bitmap =3D bdrv_create_dirty_bitmap(source->bs, cluster_size, NUL= L, errp); @@ -99,7 +102,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, = BdrvChild *target, .mem =3D shres_create(BLOCK_COPY_MAX_MEM), }; =20 - if (max_transfer < cluster_size) { + if (block_copy_max_transfer(source, target) < cluster_size) { /* * copy_range does not respect max_transfer. We don't want to both= er * with requests smaller than block-copy cluster size, so fallback= to @@ -114,12 +117,11 @@ BlockCopyState *block_copy_state_new(BdrvChild *sourc= e, BdrvChild *target, s->copy_size =3D cluster_size; } else { /* - * copy_range does not respect max_transfer (it's a TODO), so we f= actor - * that in here. + * We enable copy-range, but keep small copy_size, until first + * successful copy_range (look at block_copy_do_copy). */ s->use_copy_range =3D true; - s->copy_size =3D MIN(MAX(cluster_size, BLOCK_COPY_MAX_COPY_RANGE), - QEMU_ALIGN_DOWN(max_transfer, cluster_size)); + s->copy_size =3D MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER); } =20 QLIST_INIT(&s->inflight_reqs); @@ -172,6 +174,22 @@ static int coroutine_fn block_copy_do_copy(BlockCopySt= ate *s, s->copy_size =3D MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER); /* Fallback to read+write with allocated buffer */ } else { + if (s->use_copy_range) { + /* + * Successful copy-range. Now increase copy_size. copy_ra= nge + * does not respect max_transfer (it's a TODO), so we fact= or + * that in here. + * + * Note: we double-check s->use_copy_range for the case wh= en + * parallel block-copy request unsets it during previous + * bdrv_co_copy_range call. + */ + s->copy_size =3D + MIN(MAX(s->cluster_size, BLOCK_COPY_MAX_COPY_RANGE= ), + QEMU_ALIGN_DOWN(block_copy_max_transfer(s->sou= rce, + s->tar= get), + s->cluster_size)); + } goto out; } } @@ -179,7 +197,10 @@ static int coroutine_fn block_copy_do_copy(BlockCopySt= ate *s, /* * In case of failed copy_range request above, we may proceed with buf= fered * request larger than BLOCK_COPY_MAX_BUFFER. Still, further requests = will - * be properly limited, so don't care too much. + * be properly limited, so don't care too much. Moreover the most like= ly + * case (copy_range is unsupported for the configuration, so the very = first + * copy_range request fails) is handled by setting large copy_size only + * after first successful copy_range. */ =20 bounce_buffer =3D qemu_blockalign(s->source->bs, nbytes); --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922870; cv=none; d=zohomail.com; s=zohoarc; b=expu/EU47Xm3MLlWwIMfVnsMGcmf8IelC/ZcF3F9YbIYztucIdzi4JtNAgxdN91q9yjNOMQa2L7+FTYTb0WSYtDnWn3TrrUepM0M2dNvkOVD4pEGipxzlOe/dINNC1KGrgqknqlJ0rVtVkXdtJnWAta7m3h0/P8xMG3xdC/mc0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922870; h=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=jB+dhupHan0XKpRr1Lf9SgI0sCxxM6Mc+cdB/VaCj2M=; b=nk92aeD3DGnLrq/uhpb5zQMrE6/+Zz6ZuKiFQkIwei0GHZ8spgMsg3iKSbMvj5v81lPas/7roqW6dOKk8ZekLfTJsBkyFX/rD7+O9IlzPXA//oFdejp/4MYVfk0Ojpfbnp4AnKoifsBsI6lE9mVdR8XnnyAJ9NNS4N7ziTbCOrM= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922870541440.5636498559369; Wed, 11 Mar 2020 03:34:30 -0700 (PDT) Received: from localhost ([::1]:49342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByh3-0000ig-Cw for importer@patchew.org; Wed, 11 Mar 2020 06:34:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43589) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByd9-0002v6-8L for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd7-0001XY-N4 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:33066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001Rf-IA; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycy-0005cJ-Cq; Wed, 11 Mar 2020 13:30:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 4/9] block/block-copy: use block_status Date: Wed, 11 Mar 2020 13:29:59 +0300 Message-Id: <20200311103004.7649-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use bdrv_block_status_above to chose effective chunk size and to handle zeroes effectively. This substitutes checking for just being allocated or not, and drops old code path for it. Assistance by backup job is dropped too, as caching block-status information is more difficult than just caching is-allocated information in our dirty bitmap, and backup job is not good place for this caching anyway. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich Reviewed-by: Max Reitz --- block/block-copy.c | 73 +++++++++++++++++++++++++++++++++++++--------- block/trace-events | 1 + 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index ddd61c1652..b075dba206 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -155,7 +155,7 @@ void block_copy_set_progress_meter(BlockCopyState *s, P= rogressMeter *pm) */ static int coroutine_fn block_copy_do_copy(BlockCopyState *s, int64_t start, int64_t end, - bool *error_is_read) + bool zeroes, bool *error_is_rea= d) { int ret; int nbytes =3D MIN(end, s->len) - start; @@ -165,6 +165,18 @@ static int coroutine_fn block_copy_do_copy(BlockCopySt= ate *s, assert(QEMU_IS_ALIGNED(end, s->cluster_size)); assert(end < s->len || end =3D=3D QEMU_ALIGN_UP(s->len, s->cluster_siz= e)); =20 + if (zeroes) { + ret =3D bdrv_co_pwrite_zeroes(s->target, start, nbytes, s->write_f= lags & + ~BDRV_REQ_WRITE_COMPRESSED); + if (ret < 0) { + trace_block_copy_write_zeroes_fail(s, start, ret); + if (error_is_read) { + *error_is_read =3D false; + } + } + return ret; + } + if (s->use_copy_range) { ret =3D bdrv_co_copy_range(s->source, start, s->target, start, nby= tes, 0, s->write_flags); @@ -230,6 +242,38 @@ out: return ret; } =20 +static int block_copy_block_status(BlockCopyState *s, int64_t offset, + int64_t bytes, int64_t *pnum) +{ + int64_t num; + BlockDriverState *base; + int ret; + + if (s->skip_unallocated && s->source->bs->backing) { + base =3D s->source->bs->backing->bs; + } else { + base =3D NULL; + } + + ret =3D bdrv_block_status_above(s->source->bs, base, offset, bytes, &n= um, + NULL, NULL); + if (ret < 0 || num < s->cluster_size) { + /* + * On error or if failed to obtain large enough chunk just fallbac= k to + * copy one cluster. + */ + num =3D s->cluster_size; + ret =3D BDRV_BLOCK_ALLOCATED | BDRV_BLOCK_DATA; + } else if (offset + num =3D=3D s->len) { + num =3D QEMU_ALIGN_UP(num, s->cluster_size); + } else { + num =3D QEMU_ALIGN_DOWN(num, s->cluster_size); + } + + *pnum =3D num; + return ret; +} + /* * Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocati= on. @@ -308,7 +352,6 @@ int coroutine_fn block_copy(BlockCopyState *s, { int ret =3D 0; int64_t end =3D bytes + start; /* bytes */ - int64_t status_bytes; BlockCopyInFlightReq req; =20 /* @@ -325,7 +368,7 @@ int coroutine_fn block_copy(BlockCopyState *s, block_copy_inflight_req_begin(s, &req, start, end); =20 while (start < end) { - int64_t next_zero, chunk_end; + int64_t next_zero, chunk_end, status_bytes; =20 if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) { trace_block_copy_skip(s, start); @@ -343,24 +386,28 @@ int coroutine_fn block_copy(BlockCopyState *s, chunk_end =3D next_zero; } =20 - if (s->skip_unallocated) { - ret =3D block_copy_reset_unallocated(s, start, &status_bytes); - if (ret =3D=3D 0) { - trace_block_copy_skip_range(s, start, status_bytes); - start +=3D status_bytes; - continue; - } - /* Clamp to known allocated region */ - chunk_end =3D MIN(chunk_end, start + status_bytes); + ret =3D block_copy_block_status(s, start, chunk_end - start, + &status_bytes); + if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { + bdrv_reset_dirty_bitmap(s->copy_bitmap, start, status_bytes); + progress_set_remaining(s->progress, + bdrv_get_dirty_count(s->copy_bitmap) + + s->in_flight_bytes); + trace_block_copy_skip_range(s, start, status_bytes); + start +=3D status_bytes; + continue; } =20 + chunk_end =3D MIN(chunk_end, start + status_bytes); + trace_block_copy_process(s, start); =20 bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start); s->in_flight_bytes +=3D chunk_end - start; =20 co_get_from_shres(s->mem, chunk_end - start); - ret =3D block_copy_do_copy(s, start, chunk_end, error_is_read); + ret =3D block_copy_do_copy(s, start, chunk_end, ret & BDRV_BLOCK_Z= ERO, + error_is_read); co_put_to_shres(s->mem, chunk_end - start); s->in_flight_bytes -=3D chunk_end - start; if (ret < 0) { diff --git a/block/trace-events b/block/trace-events index 1a7329b736..29dff8881c 100644 --- a/block/trace-events +++ b/block/trace-events @@ -48,6 +48,7 @@ block_copy_process(void *bcs, int64_t start) "bcs %p star= t %"PRId64 block_copy_copy_range_fail(void *bcs, int64_t start, int ret) "bcs %p star= t %"PRId64" ret %d" block_copy_read_fail(void *bcs, int64_t start, int ret) "bcs %p start %"PR= Id64" ret %d" block_copy_write_fail(void *bcs, int64_t start, int ret) "bcs %p start %"P= RId64" ret %d" +block_copy_write_zeroes_fail(void *bcs, int64_t start, int ret) "bcs %p st= art %"PRId64" ret %d" =20 # ../blockdev.c qmp_block_job_cancel(void *job) "job %p" --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922743; cv=none; d=zohomail.com; s=zohoarc; b=DzoteyxCuksmDH+kZmHS7tLigV8K5A1RD7RL9K45JJLT8cZtb0v4JurjNvNiHKUgU4N1OJfya2ucmUwh2JdfnKsnmRhObHeBPjqhy1XcEP+i9AiwcwZvzJ5cIKHz0T/W8yQDhTm7N5mpKoDafvARwfE6PfopzgtIq8QfxoPB4vA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922743; h=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=glRqmaS7VfTuhf4QZ1U+wywglHR6f0bEtkjyOfysbcQ=; b=YZ0JLsK7EK+IA9CZu8AWI0iZf1TQ+L0GmIKHsuNY69bWXsO/5uKxl70Swp4yrY2BgcotE5dni3kwH+7RcuSUwQUyV32dlN1LU8kEn0h5ch5QQ1HtFEIfW6E1fmnu+CzQ5wOqgpJhrTdCi5lJJ9J/8EKV87OiekKRfu0Fx3AimQc= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922743899511.69462394524544; Wed, 11 Mar 2020 03:32:23 -0700 (PDT) Received: from localhost ([::1]:49314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByez-0005NP-Ls for importer@patchew.org; Wed, 11 Mar 2020 06:32:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43546) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByd7-0002tg-SB for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd6-0001Wu-Sw for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:25 -0400 Received: from relay.sw.ru ([185.231.240.75]:33052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001Ra-I9; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycy-0005cJ-Kf; Wed, 11 Mar 2020 13:30:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 5/9] block/block-copy: factor out find_conflicting_inflight_req Date: Wed, 11 Mar 2020 13:30:00 +0300 Message-Id: <20200311103004.7649-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Split find_conflicting_inflight_req to be used separately. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich Reviewed-by: Max Reitz --- block/block-copy.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index b075dba206..251d415a2c 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -24,23 +24,30 @@ #define BLOCK_COPY_MAX_BUFFER (1 * MiB) #define BLOCK_COPY_MAX_MEM (128 * MiB) =20 +static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState = *s, + int64_t start, + int64_t end) +{ + BlockCopyInFlightReq *req; + + QLIST_FOREACH(req, &s->inflight_reqs, list) { + if (end > req->start_byte && start < req->end_byte) { + return req; + } + } + + return NULL; +} + static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s, int64_t start, int64_t end) { BlockCopyInFlightReq *req; - bool waited; - - do { - waited =3D false; - QLIST_FOREACH(req, &s->inflight_reqs, list) { - if (end > req->start_byte && start < req->end_byte) { - qemu_co_queue_wait(&req->wait_queue, NULL); - waited =3D true; - break; - } - } - } while (waited); + + while ((req =3D find_conflicting_inflight_req(s, start, end))) { + qemu_co_queue_wait(&req->wait_queue, NULL); + } } =20 static void block_copy_inflight_req_begin(BlockCopyState *s, --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922900; cv=none; d=zohomail.com; s=zohoarc; b=UWkhoJCMrkfND3VGUiFf2jzI73wYAnXIIKip7wGYAuxXBRn033Lz8BaNUcvVidXqLX62Y/lmdm6cJSXFr+YSnHq05SYsf+DDCmSOBHWRaNcICQjXJ55ya5lpTaSv/KTkWWxVTY9mUFsZDYedRd8InYHjgTiT8u3WSM2B4vpH5nY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922900; h=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=p2TVO74jdAIxaRyU0y+w+9zHXRC22JUJQrZwm32wNtU=; b=OzpTl+ewQRc07oN3quDqnaezYoOuxdPWy3ew8SDEdOoKtQTEE20oDAgRdjAM1SSolPpZ7wBZJvkXXh2e10c35yNp8NeW8arXQMlYyRpfpM9C7H2Tb9XMnkb7RmovmK+ki8gzvLryXcu8K0Ll1uJsoHjR09QIJLpuVhV6fFutN78= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922900937885.6578863615434; Wed, 11 Mar 2020 03:35:00 -0700 (PDT) Received: from localhost ([::1]:49348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByhX-0001Pd-IB for importer@patchew.org; Wed, 11 Mar 2020 06:34:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43590) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByd9-0002v7-8S for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd7-0001XL-Iw for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:33046) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001RY-I7; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycy-0005cJ-P0; Wed, 11 Mar 2020 13:30:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 6/9] block/block-copy: refactor interfaces to use bytes instead of end Date: Wed, 11 Mar 2020 13:30:01 +0300 Message-Id: <20200311103004.7649-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We have a lot of "chunk_end - start" invocations, let's switch to bytes/cur_bytes scheme instead. While being here, improve check on block_copy_do_copy parameters to not overflow when calculating nbytes and use int64_t for bytes in block_copy for consistency. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich Reviewed-by: Max Reitz --- include/block/block-copy.h | 6 +-- block/block-copy.c | 78 ++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 9def00068c..7fd36e528b 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -19,8 +19,8 @@ #include "qemu/co-shared-resource.h" =20 typedef struct BlockCopyInFlightReq { - int64_t start_byte; - int64_t end_byte; + int64_t start; + int64_t bytes; QLIST_ENTRY(BlockCopyInFlightReq) list; CoQueue wait_queue; /* coroutines blocked on this request */ } BlockCopyInFlightReq; @@ -85,7 +85,7 @@ void block_copy_state_free(BlockCopyState *s); int64_t block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count); =20 -int coroutine_fn block_copy(BlockCopyState *s, int64_t start, uint64_t byt= es, +int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t byte= s, bool *error_is_read); =20 #endif /* BLOCK_COPY_H */ diff --git a/block/block-copy.c b/block/block-copy.c index 251d415a2c..4c947e548b 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -26,12 +26,12 @@ =20 static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState = *s, int64_t start, - int64_t end) + int64_t bytes) { BlockCopyInFlightReq *req; =20 QLIST_FOREACH(req, &s->inflight_reqs, list) { - if (end > req->start_byte && start < req->end_byte) { + if (start + bytes > req->start && start < req->start + req->bytes)= { return req; } } @@ -41,21 +41,21 @@ static BlockCopyInFlightReq *find_conflicting_inflight_= req(BlockCopyState *s, =20 static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s, int64_t start, - int64_t end) + int64_t bytes) { BlockCopyInFlightReq *req; =20 - while ((req =3D find_conflicting_inflight_req(s, start, end))) { + while ((req =3D find_conflicting_inflight_req(s, start, bytes))) { qemu_co_queue_wait(&req->wait_queue, NULL); } } =20 static void block_copy_inflight_req_begin(BlockCopyState *s, BlockCopyInFlightReq *req, - int64_t start, int64_t end) + int64_t start, int64_t bytes) { - req->start_byte =3D start; - req->end_byte =3D end; + req->start =3D start; + req->bytes =3D bytes; qemu_co_queue_init(&req->wait_queue); QLIST_INSERT_HEAD(&s->inflight_reqs, req, list); } @@ -153,24 +153,28 @@ void block_copy_set_progress_meter(BlockCopyState *s,= ProgressMeter *pm) /* * block_copy_do_copy * - * Do copy of cluser-aligned chunk. @end is allowed to exceed s->len only = to - * cover last cluster when s->len is not aligned to clusters. + * Do copy of cluster-aligned chunk. Requested region is allowed to exceed + * s->len only to cover last cluster when s->len is not aligned to cluster= s. * * No sync here: nor bitmap neighter intersecting requests handling, only = copy. * * Returns 0 on success. */ static int coroutine_fn block_copy_do_copy(BlockCopyState *s, - int64_t start, int64_t end, + int64_t start, int64_t bytes, bool zeroes, bool *error_is_rea= d) { int ret; - int nbytes =3D MIN(end, s->len) - start; + int64_t nbytes =3D MIN(start + bytes, s->len) - start; void *bounce_buffer =3D NULL; =20 + assert(start >=3D 0 && bytes > 0 && INT64_MAX - start >=3D bytes); assert(QEMU_IS_ALIGNED(start, s->cluster_size)); - assert(QEMU_IS_ALIGNED(end, s->cluster_size)); - assert(end < s->len || end =3D=3D QEMU_ALIGN_UP(s->len, s->cluster_siz= e)); + assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); + assert(start < s->len); + assert(start + bytes <=3D s->len || + start + bytes =3D=3D QEMU_ALIGN_UP(s->len, s->cluster_size)); + assert(nbytes < INT_MAX); =20 if (zeroes) { ret =3D bdrv_co_pwrite_zeroes(s->target, start, nbytes, s->write_f= lags & @@ -354,11 +358,10 @@ int64_t block_copy_reset_unallocated(BlockCopyState *= s, } =20 int coroutine_fn block_copy(BlockCopyState *s, - int64_t start, uint64_t bytes, + int64_t start, int64_t bytes, bool *error_is_read) { int ret =3D 0; - int64_t end =3D bytes + start; /* bytes */ BlockCopyInFlightReq req; =20 /* @@ -369,32 +372,32 @@ int coroutine_fn block_copy(BlockCopyState *s, bdrv_get_aio_context(s->target->bs)); =20 assert(QEMU_IS_ALIGNED(start, s->cluster_size)); - assert(QEMU_IS_ALIGNED(end, s->cluster_size)); + assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); =20 block_copy_wait_inflight_reqs(s, start, bytes); - block_copy_inflight_req_begin(s, &req, start, end); + block_copy_inflight_req_begin(s, &req, start, bytes); =20 - while (start < end) { - int64_t next_zero, chunk_end, status_bytes; + while (bytes) { + int64_t next_zero, cur_bytes, status_bytes; =20 if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) { trace_block_copy_skip(s, start); start +=3D s->cluster_size; + bytes -=3D s->cluster_size; continue; /* already copied */ } =20 - chunk_end =3D MIN(end, start + s->copy_size); + cur_bytes =3D MIN(bytes, s->copy_size); =20 next_zero =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start, - chunk_end - start); + cur_bytes); if (next_zero >=3D 0) { assert(next_zero > start); /* start is dirty */ - assert(next_zero < chunk_end); /* no need to do MIN() */ - chunk_end =3D next_zero; + assert(next_zero < start + cur_bytes); /* no need to do MIN() = */ + cur_bytes =3D next_zero - start; } =20 - ret =3D block_copy_block_status(s, start, chunk_end - start, - &status_bytes); + ret =3D block_copy_block_status(s, start, cur_bytes, &status_bytes= ); if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { bdrv_reset_dirty_bitmap(s->copy_bitmap, start, status_bytes); progress_set_remaining(s->progress, @@ -402,30 +405,31 @@ int coroutine_fn block_copy(BlockCopyState *s, s->in_flight_bytes); trace_block_copy_skip_range(s, start, status_bytes); start +=3D status_bytes; + bytes -=3D status_bytes; continue; } =20 - chunk_end =3D MIN(chunk_end, start + status_bytes); + cur_bytes =3D MIN(cur_bytes, status_bytes); =20 trace_block_copy_process(s, start); =20 - bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start); - s->in_flight_bytes +=3D chunk_end - start; + bdrv_reset_dirty_bitmap(s->copy_bitmap, start, cur_bytes); + s->in_flight_bytes +=3D cur_bytes; =20 - co_get_from_shres(s->mem, chunk_end - start); - ret =3D block_copy_do_copy(s, start, chunk_end, ret & BDRV_BLOCK_Z= ERO, + co_get_from_shres(s->mem, cur_bytes); + ret =3D block_copy_do_copy(s, start, cur_bytes, ret & BDRV_BLOCK_Z= ERO, error_is_read); - co_put_to_shres(s->mem, chunk_end - start); - s->in_flight_bytes -=3D chunk_end - start; + co_put_to_shres(s->mem, cur_bytes); + s->in_flight_bytes -=3D cur_bytes; if (ret < 0) { - bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start= ); + bdrv_set_dirty_bitmap(s->copy_bitmap, start, cur_bytes); break; } =20 - progress_work_done(s->progress, chunk_end - start); - s->progress_bytes_callback(chunk_end - start, s->progress_opaque); - start =3D chunk_end; - ret =3D 0; + progress_work_done(s->progress, cur_bytes); + s->progress_bytes_callback(cur_bytes, s->progress_opaque); + start +=3D cur_bytes; + bytes -=3D cur_bytes; } =20 block_copy_inflight_req_end(&req); --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922736; cv=none; d=zohomail.com; s=zohoarc; b=dXPlySEBpAnuEv44tC8dGnVSQf6z07eedOEh/FgObB2IUve2cUpC3WFpAAFEf7rl9zl5d1iTld7dvDeN+aY31d+W0p/xn4h2gkv9HbzJ8/yz6T1YdE/f/1G8HmVQRM/21GW40pLD6r9atPAt1jmZM9oNfCAszWF0kj7ahPoMEwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922736; h=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=kZXbnDGYrS/fFSqf6OQ5zQ21UuBPEEQUzUGEOm1P+U8=; b=np+8VnO5qZeM1v+psX3q2rXGuf7p8yNLwrJInqGBbMhUDhSWS0z2bt9w3y6CcAtiWKMa6t5hXRWSFVCJ3gHkPlPEPz6x9PFIfSyk0E2644ANuRyUehMCpkEn28+JdY47lPiLaevwPPvqemWv2mMEDZ8kFqUJw6JPdheDW73z/j4= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 15839227363741022.1053983110268; Wed, 11 Mar 2020 03:32:16 -0700 (PDT) Received: from localhost ([::1]:49312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByep-0004xn-Rn for importer@patchew.org; Wed, 11 Mar 2020 06:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43599) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByd9-0002vm-NA for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd7-0001Xd-Ne for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:33050) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001RX-II; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycz-0005cJ-2h; Wed, 11 Mar 2020 13:30:17 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 7/9] block/block-copy: rename start to offset in interfaces Date: Wed, 11 Mar 2020 13:30:02 +0300 Message-Id: <20200311103004.7649-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" offset/bytes pair is more usual naming in block layer, let's use it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich Reviewed-by: Max Reitz --- include/block/block-copy.h | 4 +- block/block-copy.c | 82 +++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 7fd36e528b..b76efb736f 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -19,7 +19,7 @@ #include "qemu/co-shared-resource.h" =20 typedef struct BlockCopyInFlightReq { - int64_t start; + int64_t offset; int64_t bytes; QLIST_ENTRY(BlockCopyInFlightReq) list; CoQueue wait_queue; /* coroutines blocked on this request */ @@ -85,7 +85,7 @@ void block_copy_state_free(BlockCopyState *s); int64_t block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count); =20 -int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t byte= s, +int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool *error_is_read); =20 #endif /* BLOCK_COPY_H */ diff --git a/block/block-copy.c b/block/block-copy.c index 4c947e548b..8b91fa0b06 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -25,13 +25,13 @@ #define BLOCK_COPY_MAX_MEM (128 * MiB) =20 static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState = *s, - int64_t start, + int64_t offset, int64_t bytes) { BlockCopyInFlightReq *req; =20 QLIST_FOREACH(req, &s->inflight_reqs, list) { - if (start + bytes > req->start && start < req->start + req->bytes)= { + if (offset + bytes > req->offset && offset < req->offset + req->by= tes) { return req; } } @@ -40,21 +40,21 @@ static BlockCopyInFlightReq *find_conflicting_inflight_= req(BlockCopyState *s, } =20 static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s, - int64_t start, + int64_t offset, int64_t bytes) { BlockCopyInFlightReq *req; =20 - while ((req =3D find_conflicting_inflight_req(s, start, bytes))) { + while ((req =3D find_conflicting_inflight_req(s, offset, bytes))) { qemu_co_queue_wait(&req->wait_queue, NULL); } } =20 static void block_copy_inflight_req_begin(BlockCopyState *s, BlockCopyInFlightReq *req, - int64_t start, int64_t bytes) + int64_t offset, int64_t bytes) { - req->start =3D start; + req->offset =3D offset; req->bytes =3D bytes; qemu_co_queue_init(&req->wait_queue); QLIST_INSERT_HEAD(&s->inflight_reqs, req, list); @@ -161,26 +161,26 @@ void block_copy_set_progress_meter(BlockCopyState *s,= ProgressMeter *pm) * Returns 0 on success. */ static int coroutine_fn block_copy_do_copy(BlockCopyState *s, - int64_t start, int64_t bytes, + int64_t offset, int64_t bytes, bool zeroes, bool *error_is_rea= d) { int ret; - int64_t nbytes =3D MIN(start + bytes, s->len) - start; + int64_t nbytes =3D MIN(offset + bytes, s->len) - offset; void *bounce_buffer =3D NULL; =20 - assert(start >=3D 0 && bytes > 0 && INT64_MAX - start >=3D bytes); - assert(QEMU_IS_ALIGNED(start, s->cluster_size)); + assert(offset >=3D 0 && bytes > 0 && INT64_MAX - offset >=3D bytes); + assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); - assert(start < s->len); - assert(start + bytes <=3D s->len || - start + bytes =3D=3D QEMU_ALIGN_UP(s->len, s->cluster_size)); + assert(offset < s->len); + assert(offset + bytes <=3D s->len || + offset + bytes =3D=3D QEMU_ALIGN_UP(s->len, s->cluster_size)); assert(nbytes < INT_MAX); =20 if (zeroes) { - ret =3D bdrv_co_pwrite_zeroes(s->target, start, nbytes, s->write_f= lags & + ret =3D bdrv_co_pwrite_zeroes(s->target, offset, nbytes, s->write_= flags & ~BDRV_REQ_WRITE_COMPRESSED); if (ret < 0) { - trace_block_copy_write_zeroes_fail(s, start, ret); + trace_block_copy_write_zeroes_fail(s, offset, ret); if (error_is_read) { *error_is_read =3D false; } @@ -189,10 +189,10 @@ static int coroutine_fn block_copy_do_copy(BlockCopyS= tate *s, } =20 if (s->use_copy_range) { - ret =3D bdrv_co_copy_range(s->source, start, s->target, start, nby= tes, + ret =3D bdrv_co_copy_range(s->source, offset, s->target, offset, n= bytes, 0, s->write_flags); if (ret < 0) { - trace_block_copy_copy_range_fail(s, start, ret); + trace_block_copy_copy_range_fail(s, offset, ret); s->use_copy_range =3D false; s->copy_size =3D MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER); /* Fallback to read+write with allocated buffer */ @@ -228,19 +228,19 @@ static int coroutine_fn block_copy_do_copy(BlockCopyS= tate *s, =20 bounce_buffer =3D qemu_blockalign(s->source->bs, nbytes); =20 - ret =3D bdrv_co_pread(s->source, start, nbytes, bounce_buffer, 0); + ret =3D bdrv_co_pread(s->source, offset, nbytes, bounce_buffer, 0); if (ret < 0) { - trace_block_copy_read_fail(s, start, ret); + trace_block_copy_read_fail(s, offset, ret); if (error_is_read) { *error_is_read =3D true; } goto out; } =20 - ret =3D bdrv_co_pwrite(s->target, start, nbytes, bounce_buffer, + ret =3D bdrv_co_pwrite(s->target, offset, nbytes, bounce_buffer, s->write_flags); if (ret < 0) { - trace_block_copy_write_fail(s, start, ret); + trace_block_copy_write_fail(s, offset, ret); if (error_is_read) { *error_is_read =3D false; } @@ -358,7 +358,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, } =20 int coroutine_fn block_copy(BlockCopyState *s, - int64_t start, int64_t bytes, + int64_t offset, int64_t bytes, bool *error_is_read) { int ret =3D 0; @@ -371,64 +371,64 @@ int coroutine_fn block_copy(BlockCopyState *s, assert(bdrv_get_aio_context(s->source->bs) =3D=3D bdrv_get_aio_context(s->target->bs)); =20 - assert(QEMU_IS_ALIGNED(start, s->cluster_size)); + assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); =20 - block_copy_wait_inflight_reqs(s, start, bytes); - block_copy_inflight_req_begin(s, &req, start, bytes); + block_copy_wait_inflight_reqs(s, offset, bytes); + block_copy_inflight_req_begin(s, &req, offset, bytes); =20 while (bytes) { int64_t next_zero, cur_bytes, status_bytes; =20 - if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) { - trace_block_copy_skip(s, start); - start +=3D s->cluster_size; + 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 */ } =20 cur_bytes =3D MIN(bytes, s->copy_size); =20 - next_zero =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start, + next_zero =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, offset, cur_bytes); if (next_zero >=3D 0) { - assert(next_zero > start); /* start is dirty */ - assert(next_zero < start + cur_bytes); /* no need to do MIN() = */ - cur_bytes =3D next_zero - start; + assert(next_zero > offset); /* offset is dirty */ + assert(next_zero < offset + cur_bytes); /* no need to do MIN()= */ + cur_bytes =3D next_zero - offset; } =20 - ret =3D block_copy_block_status(s, start, cur_bytes, &status_bytes= ); + ret =3D block_copy_block_status(s, offset, cur_bytes, &status_byte= s); if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { - bdrv_reset_dirty_bitmap(s->copy_bitmap, start, status_bytes); + bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, status_bytes); progress_set_remaining(s->progress, bdrv_get_dirty_count(s->copy_bitmap) + s->in_flight_bytes); - trace_block_copy_skip_range(s, start, status_bytes); - start +=3D status_bytes; + trace_block_copy_skip_range(s, offset, status_bytes); + offset +=3D status_bytes; bytes -=3D status_bytes; continue; } =20 cur_bytes =3D MIN(cur_bytes, status_bytes); =20 - trace_block_copy_process(s, start); + trace_block_copy_process(s, offset); =20 - bdrv_reset_dirty_bitmap(s->copy_bitmap, start, cur_bytes); + bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, cur_bytes); s->in_flight_bytes +=3D cur_bytes; =20 co_get_from_shres(s->mem, cur_bytes); - ret =3D block_copy_do_copy(s, start, cur_bytes, ret & BDRV_BLOCK_Z= ERO, + 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); s->in_flight_bytes -=3D cur_bytes; if (ret < 0) { - bdrv_set_dirty_bitmap(s->copy_bitmap, start, cur_bytes); + bdrv_set_dirty_bitmap(s->copy_bitmap, offset, cur_bytes); break; } =20 progress_work_done(s->progress, cur_bytes); s->progress_bytes_callback(cur_bytes, s->progress_opaque); - start +=3D cur_bytes; + offset +=3D cur_bytes; bytes -=3D cur_bytes; } =20 --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922880; cv=none; d=zohomail.com; s=zohoarc; b=OQRrysP+QyaBgQdLiChha3abQjsbQ93MCTzpvsMky/GpTDKEGTHqSXBPK+8aJgjtrUzzPtq6NuniX1nORGnyU2CpdEKOWlk0XdaR1ZEeM6xK9u4+K3Ft4+B36GdiDPuhwZ1a5GNvS5z/eKWD/rTkoYXMs50rlZUK011ENaSaV4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922880; h=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=NVU0OQl5VWBiUZv4VI00W/XlEDFPzbNWFMBMI7B/PWE=; b=MfJuRc0kMn1wbhfFo89FP4V7mtMF31HX5onviFRocny5yQA0e3RYSFzF9Pxxsj7BXONBZDrRDFrqS9xd/Qlw8xsgXorzemkGBduE8dFFNCXf/n1PmLqga1zQiYptcdkFO7lNvzDRwPRKaSdOBGXXL1v571r0wqKG5Fw69BlVOTk= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922880101962.9173207288965; Wed, 11 Mar 2020 03:34:40 -0700 (PDT) Received: from localhost ([::1]:49346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByhD-00013i-4N for importer@patchew.org; Wed, 11 Mar 2020 06:34:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43601) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByd9-0002vx-Q1 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd8-0001Xq-0O for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:33058) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001Rc-NX; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycz-0005cJ-At; Wed, 11 Mar 2020 13:30:17 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 8/9] block/block-copy: reduce intersecting request lock Date: Wed, 11 Mar 2020 13:30:03 +0300 Message-Id: <20200311103004.7649-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, block_copy operation lock the whole requested region. But there is no reason to lock clusters, which are already copied, it will disturb other parallel block_copy requests for no reason. Let's instead do the following: Lock only sub-region, which we are going to operate on. Then, after copying all dirty sub-regions, we should wait for intersecting requests block-copy, if they failed, we should retry these new dirty clusters. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich --- block/block-copy.c | 129 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 24 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 8b91fa0b06..44a64a94c8 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -39,29 +39,72 @@ static BlockCopyInFlightReq *find_conflicting_inflight_= req(BlockCopyState *s, return NULL; } =20 -static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s, - int64_t offset, - int64_t bytes) +/* + * If there are no intersecting requests return false. Otherwise, wait for= the + * first found intersecting request to finish and return true. + */ +static bool coroutine_fn block_copy_wait_one(BlockCopyState *s, int64_t of= fset, + int64_t bytes) { - BlockCopyInFlightReq *req; + BlockCopyInFlightReq *req =3D find_conflicting_inflight_req(s, offset,= bytes); =20 - while ((req =3D find_conflicting_inflight_req(s, offset, bytes))) { - qemu_co_queue_wait(&req->wait_queue, NULL); + if (!req) { + return false; } + + qemu_co_queue_wait(&req->wait_queue, NULL); + + 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) { + assert(!find_conflicting_inflight_req(s, offset, bytes)); + + bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); + s->in_flight_bytes +=3D bytes; + req->offset =3D offset; req->bytes =3D bytes; qemu_co_queue_init(&req->wait_queue); QLIST_INSERT_HEAD(&s->inflight_reqs, req, list); } =20 -static void coroutine_fn block_copy_inflight_req_end(BlockCopyInFlightReq = *req) +/* + * block_copy_inflight_req_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) + */ +static void coroutine_fn block_copy_inflight_req_shrink(BlockCopyState *s, + BlockCopyInFlightReq *req, int64_t new_bytes) { + if (new_bytes =3D=3D req->bytes) { + return; + } + + assert(new_bytes > 0 && new_bytes < req->bytes); + + s->in_flight_bytes -=3D req->bytes - new_bytes; + bdrv_set_dirty_bitmap(s->copy_bitmap, + req->offset + new_bytes, req->bytes - new_bytes); + + req->bytes =3D new_bytes; + qemu_co_queue_restart_all(&req->wait_queue); +} + +static void coroutine_fn block_copy_inflight_req_end(BlockCopyState *s, + BlockCopyInFlightReq = *req, + int ret) +{ + s->in_flight_bytes -=3D req->bytes; + if (ret < 0) { + bdrv_set_dirty_bitmap(s->copy_bitmap, req->offset, req->bytes); + } QLIST_REMOVE(req, list); qemu_co_queue_restart_all(&req->wait_queue); } @@ -357,12 +400,19 @@ int64_t block_copy_reset_unallocated(BlockCopyState *= s, return ret; } =20 -int coroutine_fn block_copy(BlockCopyState *s, - int64_t offset, int64_t bytes, - bool *error_is_read) +/* + * block_copy_dirty_clusters + * + * Copy dirty clusters in @offset/@bytes range. + * Returns 1 if dirty clusters found and successfully copied, 0 if no dirty + * clusters found and -errno on failure. + */ +static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s, + int64_t offset, int64_t = bytes, + bool *error_is_read) { int ret =3D 0; - BlockCopyInFlightReq req; + bool found_dirty =3D false; =20 /* * block_copy() user is responsible for keeping source and target in s= ame @@ -374,10 +424,8 @@ int coroutine_fn block_copy(BlockCopyState *s, assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); assert(QEMU_IS_ALIGNED(bytes, s->cluster_size)); =20 - block_copy_wait_inflight_reqs(s, offset, bytes); - block_copy_inflight_req_begin(s, &req, offset, bytes); - while (bytes) { + BlockCopyInFlightReq req; int64_t next_zero, cur_bytes, status_bytes; =20 if (!bdrv_dirty_bitmap_get(s->copy_bitmap, offset)) { @@ -387,6 +435,8 @@ int coroutine_fn block_copy(BlockCopyState *s, continue; /* already copied */ } =20 + found_dirty =3D true; + cur_bytes =3D MIN(bytes, s->copy_size); =20 next_zero =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, offset, @@ -396,10 +446,14 @@ int coroutine_fn block_copy(BlockCopyState *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); =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); if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) { - bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, status_bytes); + block_copy_inflight_req_end(s, &req, 0); progress_set_remaining(s->progress, bdrv_get_dirty_count(s->copy_bitmap) + s->in_flight_bytes); @@ -409,21 +463,15 @@ int coroutine_fn block_copy(BlockCopyState *s, continue; } =20 - cur_bytes =3D MIN(cur_bytes, status_bytes); - trace_block_copy_process(s, offset); =20 - bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, cur_bytes); - s->in_flight_bytes +=3D cur_bytes; - 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); - s->in_flight_bytes -=3D cur_bytes; + block_copy_inflight_req_end(s, &req, ret); if (ret < 0) { - bdrv_set_dirty_bitmap(s->copy_bitmap, offset, cur_bytes); - break; + return ret; } =20 progress_work_done(s->progress, cur_bytes); @@ -432,7 +480,40 @@ int coroutine_fn block_copy(BlockCopyState *s, bytes -=3D cur_bytes; } =20 - block_copy_inflight_req_end(&req); + return found_dirty; +} + +/* + * block_copy + * + * Copy requested region, accordingly to dirty bitmap. + * Collaborate with parallel block_copy requests: if they succeed it will = help + * us. If they fail, we will retry not-copied regions. So, if we return er= ror, + * it means that some I/O operation failed in context of _this_ block_copy= call, + * not some parallel operation. + */ +int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, + bool *error_is_read) +{ + int ret; + + do { + ret =3D block_copy_dirty_clusters(s, offset, bytes, error_is_read); + + if (ret =3D=3D 0) { + ret =3D block_copy_wait_one(s, offset, bytes); + } + + /* + * We retry in two cases: + * 1. Some progress done + * Something was copied, which means that there were yield poin= ts + * and some new dirty bits may have appeared (due to failed par= allel + * block-copy requests). + * 2. We have waited for some intersecting block-copy request + * It may have failed and produced new dirty bits. + */ + } while (ret > 0); =20 return ret; } --=20 2.21.0 From nobody Wed May 15 01:19:35 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583922877; cv=none; d=zohomail.com; s=zohoarc; b=UFASgQ6IdTtAP+r3kucJNNvXelpnFl+Jv19MUJWfiXGUNi1Ylu/ClVWwcdTxfPf4ScnlbPafsVE+5ebdpuukulJhk9h9+DUSHt12Q9Zm6x9fB32MQKDvyNIvPsl6MzGA+8yvV4aDEecD2uRdFGlFgN6bM+l8r8vIfwF9XYSVuU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583922877; 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=ZhMJmAorbPu7vDoNUFnkdc/dmnq7N3iKqdkccYpcFL0=; b=L0r5A0kb5oE2o7duwL00KSw6wwQNqc9lRTQIIqP/7oaFeNTgBoW53L1msaE5fM6VFFOVB2WnkUg++RVts3fgm6h9E0z4b7ydRMQE4Vv4kYlj3GCC8RZ7XFtfw9xbdEKIR1mSjE9ayfNrn0YSePffuq4YLIMIMgCXjqkNXnBoXTM= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail 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 1583922877124688.0845836551753; Wed, 11 Mar 2020 03:34:37 -0700 (PDT) Received: from localhost ([::1]:49344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jByh9-0000ut-Vw for importer@patchew.org; Wed, 11 Mar 2020 06:34:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43609) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBydA-0002wo-B6 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jByd8-0001Y2-Aa for qemu-devel@nongnu.org; Wed, 11 Mar 2020 06:30:28 -0400 Received: from relay.sw.ru ([185.231.240.75]:33068) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jByd3-0001Rg-IO; Wed, 11 Mar 2020 06:30:21 -0400 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jBycz-0005cJ-IS; Wed, 11 Mar 2020 13:30:17 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 9/9] block/block-copy: hide structure definitions Date: Wed, 11 Mar 2020 13:30:04 +0300 Message-Id: <20200311103004.7649-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200311103004.7649-1-vsementsov@virtuozzo.com> References: <20200311103004.7649-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Hide structure definitions and add explicit API instead, to keep an eye on the scope of the shared fields. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich Reviewed-by: Max Reitz --- include/block/block-copy.h | 52 +++------------------------------ block/backup-top.c | 6 ++-- block/backup.c | 25 ++++++++-------- block/block-copy.c | 59 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 62 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index b76efb736f..aac85e1488 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -18,55 +18,8 @@ #include "block/block.h" #include "qemu/co-shared-resource.h" =20 -typedef struct BlockCopyInFlightReq { - int64_t offset; - int64_t bytes; - QLIST_ENTRY(BlockCopyInFlightReq) list; - CoQueue wait_queue; /* coroutines blocked on this request */ -} BlockCopyInFlightReq; - typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque); -typedef struct BlockCopyState { - /* - * BdrvChild objects are not owned or managed by block-copy. They are - * provided by block-copy user and user is responsible for appropriate - * permissions on these children. - */ - BdrvChild *source; - BdrvChild *target; - BdrvDirtyBitmap *copy_bitmap; - int64_t in_flight_bytes; - int64_t cluster_size; - bool use_copy_range; - int64_t copy_size; - uint64_t len; - QLIST_HEAD(, BlockCopyInFlightReq) inflight_reqs; - - BdrvRequestFlags write_flags; - - /* - * skip_unallocated: - * - * Used by sync=3Dtop jobs, which first scan the source node for unall= ocated - * areas and clear them in the copy_bitmap. During this process, the = bitmap - * is thus not fully initialized: It may still have bits set for areas= that - * are unallocated and should actually not be copied. - * - * This is indicated by skip_unallocated. - * - * In this case, block_copy() will query the source=E2=80=99s allocati= on status, - * skip unallocated regions, clear them in the copy_bitmap, and invoke - * block_copy_reset_unallocated() every time it does. - */ - bool skip_unallocated; - - ProgressMeter *progress; - /* progress_bytes_callback: called when some copying progress is done.= */ - ProgressBytesCallbackFunc progress_bytes_callback; - void *progress_opaque; - - SharedResource *mem; -} BlockCopyState; +typedef struct BlockCopyState BlockCopyState; =20 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, int64_t cluster_size, @@ -88,4 +41,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool *error_is_read); =20 +BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s); +void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip); + #endif /* BLOCK_COPY_H */ diff --git a/block/backup-top.c b/block/backup-top.c index 1bfb360bd3..3b50c06e2c 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -38,6 +38,7 @@ typedef struct BDRVBackupTopState { BlockCopyState *bcs; BdrvChild *target; bool active; + int64_t cluster_size; } BDRVBackupTopState; =20 static coroutine_fn int backup_top_co_preadv( @@ -57,8 +58,8 @@ static coroutine_fn int backup_top_cbw(BlockDriverState *= bs, uint64_t offset, return 0; } =20 - off =3D QEMU_ALIGN_DOWN(offset, s->bcs->cluster_size); - end =3D QEMU_ALIGN_UP(offset + bytes, s->bcs->cluster_size); + off =3D QEMU_ALIGN_DOWN(offset, s->cluster_size); + end =3D QEMU_ALIGN_UP(offset + bytes, s->cluster_size); =20 return block_copy(s->bcs, off, end - off, NULL); } @@ -238,6 +239,7 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverSta= te *source, goto fail; } =20 + state->cluster_size =3D cluster_size; state->bcs =3D block_copy_state_new(top->backing, state->target, cluster_size, write_flags, &local_er= r); if (local_err) { diff --git a/block/backup.c b/block/backup.c index 8694e0394b..7430ca5883 100644 --- a/block/backup.c +++ b/block/backup.c @@ -102,7 +102,7 @@ static void backup_cleanup_sync_bitmap(BackupBlockJob *= job, int ret) =20 if (ret < 0 && job->bitmap_mode =3D=3D BITMAP_SYNC_MODE_ALWAYS) { /* If we failed and synced, merge in the bits we didn't copy: */ - bdrv_dirty_bitmap_merge_internal(bm, job->bcs->copy_bitmap, + bdrv_dirty_bitmap_merge_internal(bm, block_copy_dirty_bitmap(job->= bcs), NULL, true); } } @@ -145,7 +145,8 @@ void backup_do_checkpoint(BlockJob *job, Error **errp) return; } =20 - bdrv_set_dirty_bitmap(backup_job->bcs->copy_bitmap, 0, backup_job->len= ); + bdrv_set_dirty_bitmap(block_copy_dirty_bitmap(backup_job->bcs), 0, + backup_job->len); } =20 static BlockErrorAction backup_error_action(BackupBlockJob *job, @@ -190,7 +191,7 @@ static int coroutine_fn backup_loop(BackupBlockJob *job) BdrvDirtyBitmapIter *bdbi; int ret =3D 0; =20 - bdbi =3D bdrv_dirty_iter_new(job->bcs->copy_bitmap); + bdbi =3D bdrv_dirty_iter_new(block_copy_dirty_bitmap(job->bcs)); while ((offset =3D bdrv_dirty_iter_next(bdbi)) !=3D -1) { do { if (yield_and_check(job)) { @@ -210,14 +211,14 @@ static int coroutine_fn backup_loop(BackupBlockJob *j= ob) return ret; } =20 -static void backup_init_copy_bitmap(BackupBlockJob *job) +static void backup_init_bcs_bitmap(BackupBlockJob *job) { bool ret; uint64_t estimate; + BdrvDirtyBitmap *bcs_bitmap =3D block_copy_dirty_bitmap(job->bcs); =20 if (job->sync_mode =3D=3D MIRROR_SYNC_MODE_BITMAP) { - ret =3D bdrv_dirty_bitmap_merge_internal(job->bcs->copy_bitmap, - job->sync_bitmap, + ret =3D bdrv_dirty_bitmap_merge_internal(bcs_bitmap, job->sync_bit= map, NULL, true); assert(ret); } else { @@ -226,12 +227,12 @@ static void backup_init_copy_bitmap(BackupBlockJob *j= ob) * We can't hog the coroutine to initialize this thoroughly. * Set a flag and resume work when we are able to yield safely. */ - job->bcs->skip_unallocated =3D true; + block_copy_set_skip_unallocated(job->bcs, true); } - bdrv_set_dirty_bitmap(job->bcs->copy_bitmap, 0, job->len); + bdrv_set_dirty_bitmap(bcs_bitmap, 0, job->len); } =20 - estimate =3D bdrv_get_dirty_count(job->bcs->copy_bitmap); + estimate =3D bdrv_get_dirty_count(bcs_bitmap); job_progress_set_remaining(&job->common.job, estimate); } =20 @@ -240,7 +241,7 @@ static int coroutine_fn backup_run(Job *job, Error **er= rp) BackupBlockJob *s =3D container_of(job, BackupBlockJob, common.job); int ret =3D 0; =20 - backup_init_copy_bitmap(s); + backup_init_bcs_bitmap(s); =20 if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP) { int64_t offset =3D 0; @@ -259,12 +260,12 @@ static int coroutine_fn backup_run(Job *job, Error **= errp) =20 offset +=3D count; } - s->bcs->skip_unallocated =3D false; + block_copy_set_skip_unallocated(s->bcs, false); } =20 if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { /* - * All bits are set in copy_bitmap to allow any cluster to be copi= ed. + * All bits are set in bcs bitmap to allow any cluster to be copie= d. * This does not actually require them to be copied. */ while (!job_is_cancelled(job)) { diff --git a/block/block-copy.c b/block/block-copy.c index 44a64a94c8..05227e18bf 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -24,6 +24,55 @@ #define BLOCK_COPY_MAX_BUFFER (1 * MiB) #define BLOCK_COPY_MAX_MEM (128 * MiB) =20 +typedef struct BlockCopyInFlightReq { + int64_t offset; + int64_t bytes; + QLIST_ENTRY(BlockCopyInFlightReq) list; + CoQueue wait_queue; /* coroutines blocked on this request */ +} BlockCopyInFlightReq; + +typedef struct BlockCopyState { + /* + * BdrvChild objects are not owned or managed by block-copy. They are + * provided by block-copy user and user is responsible for appropriate + * permissions on these children. + */ + BdrvChild *source; + BdrvChild *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t in_flight_bytes; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_size; + uint64_t len; + QLIST_HEAD(, BlockCopyInFlightReq) inflight_reqs; + + BdrvRequestFlags write_flags; + + /* + * skip_unallocated: + * + * Used by sync=3Dtop jobs, which first scan the source node for unall= ocated + * areas and clear them in the copy_bitmap. During this process, the = bitmap + * is thus not fully initialized: It may still have bits set for areas= that + * are unallocated and should actually not be copied. + * + * This is indicated by skip_unallocated. + * + * In this case, block_copy() will query the source=E2=80=99s allocati= on status, + * skip unallocated regions, clear them in the copy_bitmap, and invoke + * block_copy_reset_unallocated() every time it does. + */ + bool skip_unallocated; + + ProgressMeter *progress; + /* progress_bytes_callback: called when some copying progress is done.= */ + ProgressBytesCallbackFunc progress_bytes_callback; + void *progress_opaque; + + SharedResource *mem; +} BlockCopyState; + static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState = *s, int64_t offset, int64_t bytes) @@ -517,3 +566,13 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t= offset, int64_t bytes, =20 return ret; } + +BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s) +{ + return s->copy_bitmap; +} + +void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip) +{ + s->skip_unallocated =3D skip; +} --=20 2.21.0