Blame SOURCES/kvm-blockjob-Implement-block_job_set_speed-centrally.patch

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