From nobody Wed Oct 29 22:35:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525883572094508.1367315436811; Wed, 9 May 2018 09:32:52 -0700 (PDT) Received: from localhost ([::1]:57543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGS1K-00019V-Bh for importer@patchew.org; Wed, 09 May 2018 12:32:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGRvz-0005BL-2P for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGRvx-0001VA-JC for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42108 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGRvp-0001Bc-4i; Wed, 09 May 2018 12:27:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBFFE8010F67; Wed, 9 May 2018 16:27:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-193.ams2.redhat.com [10.36.117.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E539202342D; Wed, 9 May 2018 16:27:07 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 9 May 2018 18:25:58 +0200 Message-Id: <20180509162637.15575-4-kwolf@redhat.com> In-Reply-To: <20180509162637.15575-1-kwolf@redhat.com> References: <20180509162637.15575-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 16:27:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 16:27:08 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 03/42] blockjob: Move RateLimit to BlockJob X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Every block job has a RateLimit, and they all do the exact same thing with it, so it should be common infrastructure. Move the struct field for a start. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Max Reitz --- include/block/blockjob.h | 4 ++++ block/backup.c | 5 ++--- block/commit.c | 5 ++--- block/mirror.c | 6 +++--- block/stream.c | 5 ++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index a2cc52233b..22bf418209 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -27,6 +27,7 @@ #define BLOCKJOB_H =20 #include "block/block.h" +#include "qemu/ratelimit.h" =20 typedef struct BlockJobDriver BlockJobDriver; typedef struct BlockJobTxn BlockJobTxn; @@ -118,6 +119,9 @@ typedef struct BlockJob { /** Speed that was set with @block_job_set_speed. */ int64_t speed; =20 + /** Rate limiting data structure for implementing @speed. */ + RateLimit limit; + /** The completion function that will be called when the job completes= . */ BlockCompletionFunc *cb; =20 diff --git a/block/backup.c b/block/backup.c index 5d95805472..7585c4391e 100644 --- a/block/backup.c +++ b/block/backup.c @@ -35,7 +35,6 @@ typedef struct BackupBlockJob { /* bitmap for sync=3Dincremental */ BdrvDirtyBitmap *sync_bitmap; MirrorSyncMode sync_mode; - RateLimit limit; BlockdevOnError on_source_error; BlockdevOnError on_target_error; CoRwlock flush_rwlock; @@ -199,7 +198,7 @@ static void backup_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed, SLICE_TIME); + ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); } =20 static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret) @@ -346,7 +345,7 @@ static bool coroutine_fn yield_and_check(BackupBlockJob= *job) * (without, VM does not reboot) */ if (job->common.speed) { - uint64_t delay_ns =3D ratelimit_calculate_delay(&job->limit, + uint64_t delay_ns =3D ratelimit_calculate_delay(&job->common.limit, job->bytes_read); job->bytes_read =3D 0; block_job_sleep_ns(&job->common, delay_ns); diff --git a/block/commit.c b/block/commit.c index 50b191c980..beec5d0ad6 100644 --- a/block/commit.c +++ b/block/commit.c @@ -35,7 +35,6 @@ enum { =20 typedef struct CommitBlockJob { BlockJob common; - RateLimit limit; BlockDriverState *commit_top_bs; BlockBackend *top; BlockBackend *base; @@ -201,7 +200,7 @@ static void coroutine_fn commit_run(void *opaque) block_job_progress_update(&s->common, n); =20 if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, n); + delay_ns =3D ratelimit_calculate_delay(&s->common.limit, n); } else { delay_ns =3D 0; } @@ -225,7 +224,7 @@ static void commit_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed, SLICE_TIME); + ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); } =20 static const BlockJobDriver commit_job_driver =3D { diff --git a/block/mirror.c b/block/mirror.c index 77ee9b1791..95da62544f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -36,7 +36,6 @@ typedef struct MirrorBuffer { =20 typedef struct MirrorBlockJob { BlockJob common; - RateLimit limit; BlockBackend *target; BlockDriverState *mirror_top_bs; BlockDriverState *source; @@ -450,7 +449,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) offset +=3D io_bytes; nb_chunks -=3D DIV_ROUND_UP(io_bytes, s->granularity); if (s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, io_bytes_acc= t); + delay_ns =3D ratelimit_calculate_delay(&s->common.limit, + io_bytes_acct); } } return delay_ns; @@ -916,7 +916,7 @@ static void mirror_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed, SLICE_TIME); + ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); } =20 static void mirror_complete(BlockJob *job, Error **errp) diff --git a/block/stream.c b/block/stream.c index 8369852bda..a1d4768c2e 100644 --- a/block/stream.c +++ b/block/stream.c @@ -33,7 +33,6 @@ enum { =20 typedef struct StreamBlockJob { BlockJob common; - RateLimit limit; BlockDriverState *base; BlockdevOnError on_error; char *backing_file_str; @@ -189,7 +188,7 @@ static void coroutine_fn stream_run(void *opaque) /* Publish progress */ block_job_progress_update(&s->common, n); if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, n); + delay_ns =3D ratelimit_calculate_delay(&s->common.limit, n); } else { delay_ns =3D 0; } @@ -219,7 +218,7 @@ static void stream_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed, SLICE_TIME); + ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); } =20 static const BlockJobDriver stream_job_driver =3D { --=20 2.13.6