|
|
ae23c9 |
From bd3d631a2e5d982559f99bac55718813dde1b783 Mon Sep 17 00:00:00 2001
|
|
|
ae23c9 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Date: Tue, 26 Jun 2018 09:47:54 +0200
|
|
|
ae23c9 |
Subject: [PATCH 086/268] blockjob: Implement block_job_set_speed() centrally
|
|
|
ae23c9 |
|
|
|
ae23c9 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Message-id: <20180626094856.6924-12-kwolf@redhat.com>
|
|
|
ae23c9 |
Patchwork-id: 81102
|
|
|
ae23c9 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 11/73] blockjob: Implement block_job_set_speed() centrally
|
|
|
ae23c9 |
Bugzilla: 1513543
|
|
|
ae23c9 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
All block job drivers support .set_speed and all of them duplicate the
|
|
|
ae23c9 |
same code to implement it. Move that code to blockjob.c and remove the
|
|
|
ae23c9 |
now useless callback.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
(cherry picked from commit 18bb69287ea522ab696e1bea818b93e5eaa85745)
|
|
|
ae23c9 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ae23c9 |
---
|
|
|
ae23c9 |
block/backup.c | 13 -------------
|
|
|
ae23c9 |
block/commit.c | 14 --------------
|
|
|
ae23c9 |
block/mirror.c | 26 ++++++--------------------
|
|
|
ae23c9 |
block/stream.c | 14 --------------
|
|
|
ae23c9 |
blockjob.c | 12 ++++--------
|
|
|
ae23c9 |
include/block/blockjob.h | 2 ++
|
|
|
ae23c9 |
include/block/blockjob_int.h | 3 ---
|
|
|
ae23c9 |
7 files changed, 12 insertions(+), 72 deletions(-)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/block/backup.c b/block/backup.c
|
|
|
ae23c9 |
index 7585c43..8468fd9 100644
|
|
|
ae23c9 |
--- a/block/backup.c
|
|
|
ae23c9 |
+++ b/block/backup.c
|
|
|
ae23c9 |
@@ -27,7 +27,6 @@
|
|
|
ae23c9 |
#include "qemu/error-report.h"
|
|
|
ae23c9 |
|
|
|
ae23c9 |
#define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16)
|
|
|
ae23c9 |
-#define SLICE_TIME 100000000ULL /* ns */
|
|
|
ae23c9 |
|
|
|
ae23c9 |
typedef struct BackupBlockJob {
|
|
|
ae23c9 |
BlockJob common;
|
|
|
ae23c9 |
@@ -190,17 +189,6 @@ static int coroutine_fn backup_before_write_notify(
|
|
|
ae23c9 |
return backup_do_cow(job, req->offset, req->bytes, NULL, true);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
|
ae23c9 |
-{
|
|
|
ae23c9 |
- BackupBlockJob *s = container_of(job, BackupBlockJob, common);
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
- if (speed < 0) {
|
|
|
ae23c9 |
- error_setg(errp, QERR_INVALID_PARAMETER, "speed");
|
|
|
ae23c9 |
- return;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
- ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
|
|
|
ae23c9 |
-}
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
BdrvDirtyBitmap *bm;
|
|
|
ae23c9 |
@@ -540,7 +528,6 @@ static const BlockJobDriver backup_job_driver = {
|
|
|
ae23c9 |
.instance_size = sizeof(BackupBlockJob),
|
|
|
ae23c9 |
.job_type = BLOCK_JOB_TYPE_BACKUP,
|
|
|
ae23c9 |
.start = backup_run,
|
|
|
ae23c9 |
- .set_speed = backup_set_speed,
|
|
|
ae23c9 |
.commit = backup_commit,
|
|
|
ae23c9 |
.abort = backup_abort,
|
|
|
ae23c9 |
.clean = backup_clean,
|
|
|
ae23c9 |
diff --git a/block/commit.c b/block/commit.c
|
|
|
ae23c9 |
index beec5d0..46cbeae 100644
|
|
|
ae23c9 |
--- a/block/commit.c
|
|
|
ae23c9 |
+++ b/block/commit.c
|
|
|
ae23c9 |
@@ -31,8 +31,6 @@ enum {
|
|
|
ae23c9 |
COMMIT_BUFFER_SIZE = 512 * 1024, /* in bytes */
|
|
|
ae23c9 |
};
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-#define SLICE_TIME 100000000ULL /* ns */
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
typedef struct CommitBlockJob {
|
|
|
ae23c9 |
BlockJob common;
|
|
|
ae23c9 |
BlockDriverState *commit_top_bs;
|
|
|
ae23c9 |
@@ -216,21 +214,9 @@ out:
|
|
|
ae23c9 |
block_job_defer_to_main_loop(&s->common, commit_complete, data);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
|
ae23c9 |
-{
|
|
|
ae23c9 |
- CommitBlockJob *s = container_of(job, CommitBlockJob, common);
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
- if (speed < 0) {
|
|
|
ae23c9 |
- error_setg(errp, QERR_INVALID_PARAMETER, "speed");
|
|
|
ae23c9 |
- return;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
- ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
|
|
|
ae23c9 |
-}
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
static const BlockJobDriver commit_job_driver = {
|
|
|
ae23c9 |
.instance_size = sizeof(CommitBlockJob),
|
|
|
ae23c9 |
.job_type = BLOCK_JOB_TYPE_COMMIT,
|
|
|
ae23c9 |
- .set_speed = commit_set_speed,
|
|
|
ae23c9 |
.start = commit_run,
|
|
|
ae23c9 |
};
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/block/mirror.c b/block/mirror.c
|
|
|
ae23c9 |
index a515ec1..d5e0ff2 100644
|
|
|
ae23c9 |
--- a/block/mirror.c
|
|
|
ae23c9 |
+++ b/block/mirror.c
|
|
|
ae23c9 |
@@ -22,7 +22,6 @@
|
|
|
ae23c9 |
#include "qemu/ratelimit.h"
|
|
|
ae23c9 |
#include "qemu/bitmap.h"
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-#define SLICE_TIME 100000000ULL /* ns */
|
|
|
ae23c9 |
#define MAX_IN_FLIGHT 16
|
|
|
ae23c9 |
#define MAX_IO_BYTES (1 << 20) /* 1 Mb */
|
|
|
ae23c9 |
#define DEFAULT_MIRROR_BUF_SIZE (MAX_IN_FLIGHT * MAX_IO_BYTES)
|
|
|
ae23c9 |
@@ -596,7 +595,7 @@ static void mirror_throttle(MirrorBlockJob *s)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
- if (now - s->last_pause_ns > SLICE_TIME) {
|
|
|
ae23c9 |
+ if (now - s->last_pause_ns > BLOCK_JOB_SLICE_TIME) {
|
|
|
ae23c9 |
s->last_pause_ns = now;
|
|
|
ae23c9 |
block_job_sleep_ns(&s->common, 0);
|
|
|
ae23c9 |
} else {
|
|
|
ae23c9 |
@@ -799,11 +798,10 @@ static void coroutine_fn mirror_run(void *opaque)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
/* Note that even when no rate limit is applied we need to yield
|
|
|
ae23c9 |
* periodically with no pending I/O so that bdrv_drain_all() returns.
|
|
|
ae23c9 |
- * We do so every SLICE_TIME nanoseconds, or when there is an error,
|
|
|
ae23c9 |
- * or when the source is clean, whichever comes first.
|
|
|
ae23c9 |
- */
|
|
|
ae23c9 |
+ * We do so every BLKOCK_JOB_SLICE_TIME nanoseconds, or when there is
|
|
|
ae23c9 |
+ * an error, or when the source is clean, whichever comes first. */
|
|
|
ae23c9 |
delta = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_ns;
|
|
|
ae23c9 |
- if (delta < SLICE_TIME &&
|
|
|
ae23c9 |
+ if (delta < BLOCK_JOB_SLICE_TIME &&
|
|
|
ae23c9 |
s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
|
|
ae23c9 |
if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 ||
|
|
|
ae23c9 |
(cnt == 0 && s->in_flight > 0)) {
|
|
|
ae23c9 |
@@ -869,7 +867,8 @@ static void coroutine_fn mirror_run(void *opaque)
|
|
|
ae23c9 |
ret = 0;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
if (s->synced && !should_complete) {
|
|
|
ae23c9 |
- delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0);
|
|
|
ae23c9 |
+ delay_ns = (s->in_flight == 0 &&
|
|
|
ae23c9 |
+ cnt == 0 ? BLOCK_JOB_SLICE_TIME : 0);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
|
|
|
ae23c9 |
block_job_sleep_ns(&s->common, delay_ns);
|
|
|
ae23c9 |
@@ -908,17 +907,6 @@ immediate_exit:
|
|
|
ae23c9 |
block_job_defer_to_main_loop(&s->common, mirror_exit, data);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
|
ae23c9 |
-{
|
|
|
ae23c9 |
- MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
- if (speed < 0) {
|
|
|
ae23c9 |
- error_setg(errp, QERR_INVALID_PARAMETER, "speed");
|
|
|
ae23c9 |
- return;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
- ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
|
|
|
ae23c9 |
-}
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
static void mirror_complete(BlockJob *job, Error **errp)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
|
ae23c9 |
@@ -1003,7 +991,6 @@ static void mirror_drain(BlockJob *job)
|
|
|
ae23c9 |
static const BlockJobDriver mirror_job_driver = {
|
|
|
ae23c9 |
.instance_size = sizeof(MirrorBlockJob),
|
|
|
ae23c9 |
.job_type = BLOCK_JOB_TYPE_MIRROR,
|
|
|
ae23c9 |
- .set_speed = mirror_set_speed,
|
|
|
ae23c9 |
.start = mirror_run,
|
|
|
ae23c9 |
.complete = mirror_complete,
|
|
|
ae23c9 |
.pause = mirror_pause,
|
|
|
ae23c9 |
@@ -1014,7 +1001,6 @@ static const BlockJobDriver mirror_job_driver = {
|
|
|
ae23c9 |
static const BlockJobDriver commit_active_job_driver = {
|
|
|
ae23c9 |
.instance_size = sizeof(MirrorBlockJob),
|
|
|
ae23c9 |
.job_type = BLOCK_JOB_TYPE_COMMIT,
|
|
|
ae23c9 |
- .set_speed = mirror_set_speed,
|
|
|
ae23c9 |
.start = mirror_run,
|
|
|
ae23c9 |
.complete = mirror_complete,
|
|
|
ae23c9 |
.pause = mirror_pause,
|
|
|
ae23c9 |
diff --git a/block/stream.c b/block/stream.c
|
|
|
ae23c9 |
index a1d4768..797d7c4 100644
|
|
|
ae23c9 |
--- a/block/stream.c
|
|
|
ae23c9 |
+++ b/block/stream.c
|
|
|
ae23c9 |
@@ -29,8 +29,6 @@ enum {
|
|
|
ae23c9 |
STREAM_BUFFER_SIZE = 512 * 1024, /* in bytes */
|
|
|
ae23c9 |
};
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-#define SLICE_TIME 100000000ULL /* ns */
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
typedef struct StreamBlockJob {
|
|
|
ae23c9 |
BlockJob common;
|
|
|
ae23c9 |
BlockDriverState *base;
|
|
|
ae23c9 |
@@ -210,21 +208,9 @@ out:
|
|
|
ae23c9 |
block_job_defer_to_main_loop(&s->common, stream_complete, data);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
|
ae23c9 |
-{
|
|
|
ae23c9 |
- StreamBlockJob *s = container_of(job, StreamBlockJob, common);
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
- if (speed < 0) {
|
|
|
ae23c9 |
- error_setg(errp, QERR_INVALID_PARAMETER, "speed");
|
|
|
ae23c9 |
- return;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
- ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
|
|
|
ae23c9 |
-}
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
static const BlockJobDriver stream_job_driver = {
|
|
|
ae23c9 |
.instance_size = sizeof(StreamBlockJob),
|
|
|
ae23c9 |
.job_type = BLOCK_JOB_TYPE_STREAM,
|
|
|
ae23c9 |
- .set_speed = stream_set_speed,
|
|
|
ae23c9 |
.start = stream_run,
|
|
|
ae23c9 |
};
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/blockjob.c b/blockjob.c
|
|
|
ae23c9 |
index d0a2ac5..0f7214c 100644
|
|
|
ae23c9 |
--- a/blockjob.c
|
|
|
ae23c9 |
+++ b/blockjob.c
|
|
|
ae23c9 |
@@ -667,22 +667,18 @@ static void block_job_completed_txn_success(BlockJob *job)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
- Error *local_err = NULL;
|
|
|
ae23c9 |
int64_t old_speed = job->speed;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
- if (!job->driver->set_speed) {
|
|
|
ae23c9 |
- error_setg(errp, QERR_UNSUPPORTED);
|
|
|
ae23c9 |
- return;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
if (block_job_apply_verb(job, BLOCK_JOB_VERB_SET_SPEED, errp)) {
|
|
|
ae23c9 |
return;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
- job->driver->set_speed(job, speed, &local_err);
|
|
|
ae23c9 |
- if (local_err) {
|
|
|
ae23c9 |
- error_propagate(errp, local_err);
|
|
|
ae23c9 |
+ if (speed < 0) {
|
|
|
ae23c9 |
+ error_setg(errp, QERR_INVALID_PARAMETER, "speed");
|
|
|
ae23c9 |
return;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
+ ratelimit_set_speed(&job->limit, speed, BLOCK_JOB_SLICE_TIME);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
job->speed = speed;
|
|
|
ae23c9 |
if (speed && speed <= old_speed) {
|
|
|
ae23c9 |
return;
|
|
|
ae23c9 |
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
|
|
|
ae23c9 |
index 22bf418..82f52f4 100644
|
|
|
ae23c9 |
--- a/include/block/blockjob.h
|
|
|
ae23c9 |
+++ b/include/block/blockjob.h
|
|
|
ae23c9 |
@@ -29,6 +29,8 @@
|
|
|
ae23c9 |
#include "block/block.h"
|
|
|
ae23c9 |
#include "qemu/ratelimit.h"
|
|
|
ae23c9 |
|
|
|
ae23c9 |
+#define BLOCK_JOB_SLICE_TIME 100000000ULL /* ns */
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
typedef struct BlockJobDriver BlockJobDriver;
|
|
|
ae23c9 |
typedef struct BlockJobTxn BlockJobTxn;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
|
|
|
ae23c9 |
index d5a515d..ad510d5 100644
|
|
|
ae23c9 |
--- a/include/block/blockjob_int.h
|
|
|
ae23c9 |
+++ b/include/block/blockjob_int.h
|
|
|
ae23c9 |
@@ -41,9 +41,6 @@ struct BlockJobDriver {
|
|
|
ae23c9 |
/** String describing the operation, part of query-block-jobs QMP API */
|
|
|
ae23c9 |
BlockJobType job_type;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
- /** Optional callback for job types that support setting a speed limit */
|
|
|
ae23c9 |
- void (*set_speed)(BlockJob *job, int64_t speed, Error **errp);
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
/** Mandatory: Entrypoint for the Coroutine. */
|
|
|
ae23c9 |
CoroutineEntry *start;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
--
|
|
|
ae23c9 |
1.8.3.1
|
|
|
ae23c9 |
|