From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 13/37] blockjob: Move RateLimit to BlockJob
Date: Tue, 15 May 2018 17:40:09 +0200 [thread overview]
Message-ID: <20180515154033.19899-14-kwolf@redhat.com> (raw)
In-Reply-To: <20180515154033.19899-1-kwolf@redhat.com>
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 <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
---
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
#include "block/block.h"
+#include "qemu/ratelimit.h"
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;
+ /** Rate limiting data structure for implementing @speed. */
+ RateLimit limit;
+
/** The completion function that will be called when the job completes. */
BlockCompletionFunc *cb;
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=incremental */
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 speed, 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);
}
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 = ratelimit_calculate_delay(&job->limit,
+ uint64_t delay_ns = ratelimit_calculate_delay(&job->common.limit,
job->bytes_read);
job->bytes_read = 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 {
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);
if (copy && s->common.speed) {
- delay_ns = ratelimit_calculate_delay(&s->limit, n);
+ delay_ns = ratelimit_calculate_delay(&s->common.limit, n);
} else {
delay_ns = 0;
}
@@ -225,7 +224,7 @@ static void commit_set_speed(BlockJob *job, int64_t speed, 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);
}
static const BlockJobDriver commit_job_driver = {
diff --git a/block/mirror.c b/block/mirror.c
index 56a7ce2f55..702c139368 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -36,7 +36,6 @@ typedef struct MirrorBuffer {
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(MirrorBlockJob *s)
offset += io_bytes;
nb_chunks -= DIV_ROUND_UP(io_bytes, s->granularity);
if (s->common.speed) {
- delay_ns = ratelimit_calculate_delay(&s->limit, io_bytes_acct);
+ delay_ns = 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 speed, 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);
}
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 {
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 = ratelimit_calculate_delay(&s->limit, n);
+ delay_ns = ratelimit_calculate_delay(&s->common.limit, n);
} else {
delay_ns = 0;
}
@@ -219,7 +218,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, 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);
}
static const BlockJobDriver stream_job_driver = {
--
2.13.6
next prev parent reply other threads:[~2018-05-15 15:41 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 15:39 [Qemu-devel] [PULL 00/37] Block layer patches Kevin Wolf
2018-05-15 15:39 ` [Qemu-devel] [PULL 01/37] block-backend: simplify blk_get_aio_context Kevin Wolf
2018-05-15 15:39 ` [Qemu-devel] [PULL 02/37] block: Support byte-based aio callbacks Kevin Wolf
2018-05-15 15:39 ` [Qemu-devel] [PULL 03/37] file-win32: Switch to byte-based callbacks Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 04/37] null: Switch to byte-based read/write Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 05/37] rbd: Switch to byte-based callbacks Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 06/37] vxhs: " Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 07/37] block: Drop last of the sector-based aio callbacks Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 08/37] block: Merge .bdrv_co_writev{, _flags} in drivers Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 09/37] hmp: Allow using a qdev id in block_set_io_throttle Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 10/37] blockjob: expose error string via query Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 11/37] blockjob: Fix assertion in block_job_finalize() Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 12/37] blockjob: Wrappers for progress counter access Kevin Wolf
2018-05-15 15:40 ` Kevin Wolf [this message]
2018-05-15 15:40 ` [Qemu-devel] [PULL 14/37] blockjob: Implement block_job_set_speed() centrally Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 15/37] blockjob: Introduce block_job_ratelimit_get_delay() Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 16/37] blockjob: Add block_job_driver() Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 17/37] iotests: Split 214 off of 122 Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 18/37] Fix error message about compressed clusters with OFLAG_COPIED Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 19/37] specs/qcow2: Clarify that compressed clusters have the COPIED bit reset Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 20/37] qcow2: Give the refcount cache the minimum possible size by default Kevin Wolf
2018-05-25 17:10 ` Peter Maydell
2018-05-28 8:38 ` Kevin Wolf
2018-05-28 8:58 ` Alberto Garcia
2018-05-28 13:49 ` Peter Maydell
2018-05-28 13:58 ` Alberto Garcia
2018-05-15 15:40 ` [Qemu-devel] [PULL 21/37] docs: Document the new default sizes of the qcow2 caches Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 22/37] iotests: Add failure matching to common.qemu Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 23/37] iotests: Skip 181 and 201 without userfaultfd Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 24/37] block: Add COR filter driver Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 25/37] block: BLK_PERM_WRITE includes ..._UNCHANGED Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 26/37] block: Add BDRV_REQ_WRITE_UNCHANGED flag Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 27/37] block: Set BDRV_REQ_WRITE_UNCHANGED for COR writes Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 28/37] block/quorum: Support BDRV_REQ_WRITE_UNCHANGED Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 29/37] block: Support BDRV_REQ_WRITE_UNCHANGED in filters Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 30/37] iotests: Clean up wrap image in 197 Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 31/37] iotests: Copy 197 for COR filter driver Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 32/37] iotests: Add test for COR across nodes Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 33/37] qemu-img: Check post-truncation size Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 34/37] block: Document BDRV_REQ_WRITE_UNCHANGED support Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 35/37] qemu-io: Use purely string blockdev options Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 36/37] qemu-img: Use only string options in img_open_opts Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 37/37] iotests: Add test for -U/force-share conflicts Kevin Wolf
2018-05-15 16:59 ` [Qemu-devel] [PULL 00/37] Block layer patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180515154033.19899-14-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).