From nobody Thu Dec 18 17:52:38 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 1526399937477665.4889622459366; Tue, 15 May 2018 08:58:57 -0700 (PDT) Received: from localhost ([::1]:44527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIcLo-00057u-Il for importer@patchew.org; Tue, 15 May 2018 11:58:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIc4S-0006iX-Tc for qemu-devel@nongnu.org; Tue, 15 May 2018 11:41:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIc4R-0001U4-0A for qemu-devel@nongnu.org; Tue, 15 May 2018 11:41:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34244 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 1fIc4L-0001OC-1a; Tue, 15 May 2018 11:40:53 -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 9B5F4BB409; Tue, 15 May 2018 15:40:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-164.ams2.redhat.com [10.36.117.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDE2B200BC1E; Tue, 15 May 2018 15:40:51 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 15 May 2018 17:40:10 +0200 Message-Id: <20180515154033.19899-15-kwolf@redhat.com> In-Reply-To: <20180515154033.19899-1-kwolf@redhat.com> References: <20180515154033.19899-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, 15 May 2018 15:40:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 15 May 2018 15:40:52 +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] [PULL 14/37] 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, qemu-devel@nongnu.org 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 Reviewed-by: Max Reitz Reviewed-by: John Snow --- include/block/blockjob.h | 2 ++ include/block/blockjob_int.h | 3 --- block/backup.c | 13 ------------- block/commit.c | 14 -------------- block/mirror.c | 26 ++++++-------------------- block/stream.c | 14 -------------- blockjob.c | 12 ++++-------- 7 files changed, 12 insertions(+), 72 deletions(-) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 22bf418209..82f52f4b14 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 BLOCK_JOB_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 d5a515de9b..ad510d5a0c 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 702c139368..6955d68804 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) @@ -596,7 +595,7 @@ static void mirror_throttle(MirrorBlockJob *s) { int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); =20 - if (now - s->last_pause_ns > SLICE_TIME) { + if (now - s->last_pause_ns > BLOCK_JOB_SLICE_TIME) { s->last_pause_ns =3D now; block_job_sleep_ns(&s->common, 0); } else { @@ -799,11 +798,10 @@ static void coroutine_fn mirror_run(void *opaque) =20 /* Note that even when no rate limit is applied we need to yield * periodically with no pending I/O so that bdrv_drain_all() retur= ns. - * We do so every SLICE_TIME nanoseconds, or when there is an erro= r, - * or when the source is clean, whichever comes first. - */ + * We do so every BLKOCK_JOB_SLICE_TIME nanoseconds, or when there= is + * an error, or when the source is clean, whichever comes first. */ delta =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_n= s; - if (delta < SLICE_TIME && + if (delta < BLOCK_JOB_SLICE_TIME && s->common.iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { if (s->in_flight >=3D MAX_IN_FLIGHT || s->buf_free_count =3D= =3D 0 || (cnt =3D=3D 0 && s->in_flight > 0)) { @@ -869,7 +867,8 @@ static void coroutine_fn mirror_run(void *opaque) ret =3D 0; =20 if (s->synced && !should_complete) { - delay_ns =3D (s->in_flight =3D=3D 0 && cnt =3D=3D 0 ? SLICE_TI= ME : 0); + delay_ns =3D (s->in_flight =3D=3D 0 && + cnt =3D=3D 0 ? BLOCK_JOB_SLICE_TIME : 0); } trace_mirror_before_sleep(s, cnt, s->synced, delay_ns); block_job_sleep_ns(&s->common, delay_ns); @@ -908,17 +907,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); @@ -1003,7 +991,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, @@ -1014,7 +1001,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 ebc26a5245..2f4b768338 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, BLOCK_JOB_SLICE_TIME); + job->speed =3D speed; if (speed && speed <=3D old_speed) { return; --=20 2.13.6