From nobody Wed Oct 29 09:22:36 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 1524585313737795.6194951080296; Tue, 24 Apr 2018 08:55:13 -0700 (PDT) Received: from localhost ([::1]:59260 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB0Hg-00062O-Lu for importer@patchew.org; Tue, 24 Apr 2018 11:55:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAzoy-0007j4-1Q for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:25:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAzow-0007fr-LJ for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:25:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34830 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 1fAzos-0007YR-RC; Tue, 24 Apr 2018 11:25:26 -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 74E91FB674; Tue, 24 Apr 2018 15:25:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-100.ams2.redhat.com [10.36.117.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64C2D202323A; Tue, 24 Apr 2018 15:25:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 24 Apr 2018 17:24:45 +0200 Message-Id: <20180424152515.25664-4-kwolf@redhat.com> In-Reply-To: <20180424152515.25664-1-kwolf@redhat.com> References: <20180424152515.25664-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.1]); Tue, 24 Apr 2018 15:25:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 24 Apr 2018 15:25:26 +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] [RFC PATCH 03/33] blockjob: Implement block_job_set_speed() centrally 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, jcody@redhat.com, jsnow@redhat.com, qemu-devel@nongnu.org, mreitz@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" All block job drivers support .set_speed and all of them duplicate the same code to implement it. Move that code to blockjob.c and remove the now useless callback. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/blockjob.h | 2 ++ include/block/blockjob_int.h | 3 --- block/backup.c | 13 ------------- block/commit.c | 14 -------------- block/mirror.c | 14 -------------- block/stream.c | 14 -------------- blockjob.c | 12 ++++-------- 7 files changed, 6 insertions(+), 66 deletions(-) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 22bf418209..5aa8a6aaec 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -29,6 +29,8 @@ #include "block/block.h" #include "qemu/ratelimit.h" =20 +#define SLICE_TIME 100000000ULL /* ns */ + typedef struct BlockJobDriver BlockJobDriver; typedef struct BlockJobTxn BlockJobTxn; =20 diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 642adce68b..870bd346a8 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -41,9 +41,6 @@ struct BlockJobDriver { /** String describing the operation, part of query-block-jobs QMP API = */ BlockJobType job_type; =20 - /** Optional callback for job types that support setting a speed limit= */ - void (*set_speed)(BlockJob *job, int64_t speed, Error **errp); - /** Mandatory: Entrypoint for the Coroutine. */ CoroutineEntry *start; =20 diff --git a/block/backup.c b/block/backup.c index 7585c4391e..8468fd9f94 100644 --- a/block/backup.c +++ b/block/backup.c @@ -27,7 +27,6 @@ #include "qemu/error-report.h" =20 #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16) -#define SLICE_TIME 100000000ULL /* ns */ =20 typedef struct BackupBlockJob { BlockJob common; @@ -190,17 +189,6 @@ static int coroutine_fn backup_before_write_notify( return backup_do_cow(job, req->offset, req->bytes, NULL, true); } =20 -static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) -{ - BackupBlockJob *s =3D container_of(job, BackupBlockJob, common); - - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } - ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); -} - static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret) { BdrvDirtyBitmap *bm; @@ -540,7 +528,6 @@ static const BlockJobDriver backup_job_driver =3D { .instance_size =3D sizeof(BackupBlockJob), .job_type =3D BLOCK_JOB_TYPE_BACKUP, .start =3D backup_run, - .set_speed =3D backup_set_speed, .commit =3D backup_commit, .abort =3D backup_abort, .clean =3D backup_clean, diff --git a/block/commit.c b/block/commit.c index beec5d0ad6..46cbeaec3e 100644 --- a/block/commit.c +++ b/block/commit.c @@ -31,8 +31,6 @@ enum { COMMIT_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ }; =20 -#define SLICE_TIME 100000000ULL /* ns */ - typedef struct CommitBlockJob { BlockJob common; BlockDriverState *commit_top_bs; @@ -216,21 +214,9 @@ out: block_job_defer_to_main_loop(&s->common, commit_complete, data); } =20 -static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp) -{ - CommitBlockJob *s =3D container_of(job, CommitBlockJob, common); - - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } - ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); -} - static const BlockJobDriver commit_job_driver =3D { .instance_size =3D sizeof(CommitBlockJob), .job_type =3D BLOCK_JOB_TYPE_COMMIT, - .set_speed =3D commit_set_speed, .start =3D commit_run, }; =20 diff --git a/block/mirror.c b/block/mirror.c index aece2b185c..de495fddc4 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -22,7 +22,6 @@ #include "qemu/ratelimit.h" #include "qemu/bitmap.h" =20 -#define SLICE_TIME 100000000ULL /* ns */ #define MAX_IN_FLIGHT 16 #define MAX_IO_BYTES (1 << 20) /* 1 Mb */ #define DEFAULT_MIRROR_BUF_SIZE (MAX_IN_FLIGHT * MAX_IO_BYTES) @@ -904,17 +903,6 @@ immediate_exit: block_job_defer_to_main_loop(&s->common, mirror_exit, data); } =20 -static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp) -{ - MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); - - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } - ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); -} - static void mirror_complete(BlockJob *job, Error **errp) { MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); @@ -999,7 +987,6 @@ static void mirror_drain(BlockJob *job) static const BlockJobDriver mirror_job_driver =3D { .instance_size =3D sizeof(MirrorBlockJob), .job_type =3D BLOCK_JOB_TYPE_MIRROR, - .set_speed =3D mirror_set_speed, .start =3D mirror_run, .complete =3D mirror_complete, .pause =3D mirror_pause, @@ -1010,7 +997,6 @@ static const BlockJobDriver mirror_job_driver =3D { static const BlockJobDriver commit_active_job_driver =3D { .instance_size =3D sizeof(MirrorBlockJob), .job_type =3D BLOCK_JOB_TYPE_COMMIT, - .set_speed =3D mirror_set_speed, .start =3D mirror_run, .complete =3D mirror_complete, .pause =3D mirror_pause, diff --git a/block/stream.c b/block/stream.c index a1d4768c2e..797d7c4f21 100644 --- a/block/stream.c +++ b/block/stream.c @@ -29,8 +29,6 @@ enum { STREAM_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ }; =20 -#define SLICE_TIME 100000000ULL /* ns */ - typedef struct StreamBlockJob { BlockJob common; BlockDriverState *base; @@ -210,21 +208,9 @@ out: block_job_defer_to_main_loop(&s->common, stream_complete, data); } =20 -static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp) -{ - StreamBlockJob *s =3D container_of(job, StreamBlockJob, common); - - if (speed < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, "speed"); - return; - } - ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME); -} - static const BlockJobDriver stream_job_driver =3D { .instance_size =3D sizeof(StreamBlockJob), .job_type =3D BLOCK_JOB_TYPE_STREAM, - .set_speed =3D stream_set_speed, .start =3D stream_run, }; =20 diff --git a/blockjob.c b/blockjob.c index 46c8923986..9b79abc821 100644 --- a/blockjob.c +++ b/blockjob.c @@ -659,22 +659,18 @@ static bool block_job_timer_pending(BlockJob *job) =20 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) { - Error *local_err =3D NULL; int64_t old_speed =3D job->speed; =20 - if (!job->driver->set_speed) { - error_setg(errp, QERR_UNSUPPORTED); - return; - } if (block_job_apply_verb(job, BLOCK_JOB_VERB_SET_SPEED, errp)) { return; } - job->driver->set_speed(job, speed, &local_err); - if (local_err) { - error_propagate(errp, local_err); + if (speed < 0) { + error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } =20 + ratelimit_set_speed(&job->limit, speed, SLICE_TIME); + job->speed =3D speed; if (speed && speed <=3D old_speed) { return; --=20 2.13.6